Skip to content

Commit

Permalink
[tag_history] better testing
Browse files Browse the repository at this point in the history
  • Loading branch information
shish committed Dec 12, 2024
1 parent 9807a5f commit 161d90e
Showing 1 changed file with 69 additions and 9 deletions.
78 changes: 69 additions & 9 deletions ext/tag_history/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

0 comments on commit 161d90e

Please sign in to comment.