diff --git a/ext/tag_history/test.php b/ext/tag_history/test.php index aeca8b2ae..26443d892 100644 --- a/ext/tag_history/test.php +++ b/ext/tag_history/test.php @@ -4,30 +4,90 @@ namespace Shimmie2; +use PHPUnit\Framework\Attributes\Depends; + class TagHistoryTest extends ShimmiePHPUnitTestCase { - public function testTagHistory(): void + public function testHistoryWhenAdding(): void { + // Set original $this->log_in_as_admin(); $image_id = $this->post_image("tests/pbx_screenshot.jpg", "old_tag"); $image = Image::by_id_ex($image_id); - // Original + // Check post $this->get_page("post/view/$image_id"); $this->assert_title("Post $image_id: old_tag"); - // Modified + // Check image history + $this->get_page("tag_history/$image_id"); + $this->assert_title("Post $image_id Tag History"); + $this->assert_text("old_tag"); + + // Check global history + $this->get_page("tag_history/all/1"); + $this->assert_title("Global Tag History"); + $this->assert_text("old_tag"); + } + + #[Depends("testHistoryWhenAdding")] + public function testHistoryWhenModifying(): void + { + // Set original + $this->log_in_as_admin(); + $image_id = $this->post_image("tests/pbx_screenshot.jpg", "old_tag"); + $image = Image::by_id_ex($image_id); + + // Modify tags send_event(new TagSetEvent($image, ["new_tag"])); - // FIXME - // $this->click("View Tag History"); - // $this->assert_text("new (Set by demo"); - // $this->click("Revert To"); - // $this->get_page("post/view/$image_id"); - // $this->assert_title("Image $image_id: pbx"); + // Check post + $this->get_page("post/view/$image_id"); + $this->assert_title("Post $image_id: new_tag"); + + // Check image history + $this->get_page("tag_history/$image_id"); + $this->assert_title("Post $image_id Tag History"); + $this->assert_text("new_tag"); + // Check global history $this->get_page("tag_history/all/1"); $this->assert_title("Global Tag History"); $this->assert_text("new_tag"); } + + #[Depends("testHistoryWhenModifying")] + public function testHistoryWhenReverting(): void + { + global $database; + + // Set original + $this->log_in_as_admin(); + $image_id = $this->post_image("tests/pbx_screenshot.jpg", "old_tag"); + $image = Image::by_id_ex($image_id); + $revert_id = $database->get_one( + "SELECT id FROM tag_histories WHERE image_id = :image_id ORDER BY id DESC LIMIT 1", + ["image_id" => $image_id], + ); + + // Modify tags + send_event(new TagSetEvent($image, ["new_tag"])); + + // Revert tags + $this->post_page("tag_history/revert", ["revert" => $revert_id]); + + // Check post + $this->get_page("post/view/$image_id"); + $this->assert_title("Post $image_id: old_tag"); + + // Check image history + $this->get_page("tag_history/$image_id"); + $this->assert_title("Post $image_id Tag History"); + $this->assert_text("old_tag"); + + // Check global history + $this->get_page("tag_history/all/1"); + $this->assert_title("Global Tag History"); + $this->assert_text("old_tag"); + } }