From 1ce5164e707a798ae4e099bdab6fe4e97cbc6cbe Mon Sep 17 00:00:00 2001 From: Yassine Guedidi Date: Mon, 21 Aug 2023 23:53:42 +0200 Subject: [PATCH] Make testSaveIsArchivedAfterPatch and testSaveIsStarredAfterPatch consistent --- src/Wallabag/CoreBundle/DataFixtures/EntryFixtures.php | 9 ++++++++- .../ApiBundle/Controller/EntryRestControllerTest.php | 6 ++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Wallabag/CoreBundle/DataFixtures/EntryFixtures.php b/src/Wallabag/CoreBundle/DataFixtures/EntryFixtures.php index 97681a3d8..92f629424 100644 --- a/src/Wallabag/CoreBundle/DataFixtures/EntryFixtures.php +++ b/src/Wallabag/CoreBundle/DataFixtures/EntryFixtures.php @@ -17,6 +17,8 @@ class EntryFixtures extends Fixture implements DependentFixtureInterface */ public function load(ObjectManager $manager): void { + $now = new \DateTime(); + $entries = [ 'entry1' => [ 'user' => 'admin-user', @@ -72,7 +74,7 @@ class EntryFixtures extends Fixture implements DependentFixtureInterface 'content' => 'This is my content /o/', 'language' => 'fr', 'starred' => true, - 'starred_at' => new \DateTime(), + 'starred_at' => $now, 'preview' => 'http://0.0.0.0/image.jpg', ], 'entry6' => [ @@ -85,6 +87,7 @@ class EntryFixtures extends Fixture implements DependentFixtureInterface 'content' => 'This is my content /o/', 'language' => 'de', 'archived' => true, + 'archived_at' => $now, 'tags' => ['bar-tag'], 'is_not_parsed' => true, ], @@ -122,6 +125,10 @@ class EntryFixtures extends Fixture implements DependentFixtureInterface $entry->setArchived($item['archived']); } + if (isset($item['archived_at'])) { + $entry->setArchivedAt($item['archived_at']); + } + if (isset($item['preview'])) { $entry->setPreviewPicture($item['preview']); } diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index 34d2124ba..e07cb4c32 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@ -1022,6 +1022,7 @@ class EntryRestControllerTest extends WallabagApiTestCase public function testSaveIsArchivedAfterPatch() { + $now = new \DateTime(); $entry = $this->client->getContainer() ->get(EntityManagerInterface::class) ->getRepository(Entry::class) @@ -1043,6 +1044,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertSame(1, $content['is_archived']); $this->assertSame($previousTitle . '++', $content['title']); + $this->assertGreaterThanOrEqual((new \DateTime($content['archived_at']))->getTimestamp(), $now->getTimestamp()); } public function testSaveIsStarredAfterPatch() @@ -1056,6 +1058,9 @@ class EntryRestControllerTest extends WallabagApiTestCase if (!$entry) { $this->markTestSkipped('No content found in db.'); } + + $previousTitle = $entry->getTitle(); + $this->client->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [ 'title' => $entry->getTitle() . '++', ]); @@ -1065,6 +1070,7 @@ class EntryRestControllerTest extends WallabagApiTestCase $content = json_decode($this->client->getResponse()->getContent(), true); $this->assertSame(1, $content['is_starred']); + $this->assertSame($previousTitle . '++', $content['title']); $this->assertGreaterThanOrEqual((new \DateTime($content['starred_at']))->getTimestamp(), $now->getTimestamp()); }