2021-12-14 18:32:47 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
2023-01-10 22:44:09 +00:00
|
|
|
|
|
|
|
namespace Shimmie2;
|
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
class FavoritesTest extends ShimmiePHPUnitTestCase
|
|
|
|
{
|
2024-01-15 14:31:51 +00:00
|
|
|
public function testFavorites(): void
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
2020-01-28 21:19:59 +00:00
|
|
|
global $user;
|
2019-05-28 16:59:38 +00:00
|
|
|
$this->log_in_as_user();
|
|
|
|
$image_id = $this->post_image("tests/pbx_screenshot.jpg", "test");
|
2009-07-28 10:45:21 +00:00
|
|
|
|
2020-01-28 21:19:59 +00:00
|
|
|
# No favourites
|
2019-05-28 16:59:38 +00:00
|
|
|
$this->get_page("post/view/$image_id");
|
2020-10-26 15:15:51 +00:00
|
|
|
$this->assert_title("Post $image_id: test");
|
2019-05-28 16:59:38 +00:00
|
|
|
$this->assert_no_text("Favorited By");
|
2009-07-28 10:45:21 +00:00
|
|
|
|
2020-01-28 21:19:59 +00:00
|
|
|
# Add a favourite
|
|
|
|
send_event(new FavoriteSetEvent($image_id, $user, true));
|
2015-09-21 09:05:32 +00:00
|
|
|
|
2020-01-28 21:19:59 +00:00
|
|
|
# Favourite shown on page
|
|
|
|
$this->get_page("post/view/$image_id");
|
2020-10-26 15:15:51 +00:00
|
|
|
$this->assert_title("Post $image_id: test");
|
2019-05-28 16:59:38 +00:00
|
|
|
$this->assert_text("Favorited By");
|
2009-07-28 10:45:21 +00:00
|
|
|
|
2020-01-28 21:19:59 +00:00
|
|
|
# Favourite shown on index
|
|
|
|
$page = $this->get_page("post/list/favorited_by=test/1");
|
|
|
|
$this->assertEquals(PageMode::REDIRECT, $page->mode);
|
|
|
|
|
|
|
|
# Favourite shown on user page
|
2019-05-28 16:59:38 +00:00
|
|
|
$this->get_page("user/test");
|
2020-10-26 15:15:51 +00:00
|
|
|
$this->assert_text("Posts favorited</a>: 1");
|
2020-01-28 21:19:59 +00:00
|
|
|
|
|
|
|
# Delete a favourite
|
|
|
|
send_event(new FavoriteSetEvent($image_id, $user, false));
|
2009-08-18 21:30:52 +00:00
|
|
|
|
2020-01-28 21:19:59 +00:00
|
|
|
# No favourites
|
|
|
|
$this->get_page("post/view/$image_id");
|
2020-10-26 15:15:51 +00:00
|
|
|
$this->assert_title("Post $image_id: test");
|
2019-05-28 16:59:38 +00:00
|
|
|
$this->assert_no_text("Favorited By");
|
|
|
|
}
|
2009-07-28 10:45:21 +00:00
|
|
|
}
|