Make testSaveIsArchivedAfterPatch and testSaveIsStarredAfterPatch consistent

This commit is contained in:
Yassine Guedidi 2023-08-21 23:53:42 +02:00
parent a3b64611f8
commit 1ce5164e70
2 changed files with 14 additions and 1 deletions

View File

@ -17,6 +17,8 @@ class EntryFixtures extends Fixture implements DependentFixtureInterface
*/ */
public function load(ObjectManager $manager): void public function load(ObjectManager $manager): void
{ {
$now = new \DateTime();
$entries = [ $entries = [
'entry1' => [ 'entry1' => [
'user' => 'admin-user', 'user' => 'admin-user',
@ -72,7 +74,7 @@ class EntryFixtures extends Fixture implements DependentFixtureInterface
'content' => 'This is my content /o/', 'content' => 'This is my content /o/',
'language' => 'fr', 'language' => 'fr',
'starred' => true, 'starred' => true,
'starred_at' => new \DateTime(), 'starred_at' => $now,
'preview' => 'http://0.0.0.0/image.jpg', 'preview' => 'http://0.0.0.0/image.jpg',
], ],
'entry6' => [ 'entry6' => [
@ -85,6 +87,7 @@ class EntryFixtures extends Fixture implements DependentFixtureInterface
'content' => 'This is my content /o/', 'content' => 'This is my content /o/',
'language' => 'de', 'language' => 'de',
'archived' => true, 'archived' => true,
'archived_at' => $now,
'tags' => ['bar-tag'], 'tags' => ['bar-tag'],
'is_not_parsed' => true, 'is_not_parsed' => true,
], ],
@ -122,6 +125,10 @@ class EntryFixtures extends Fixture implements DependentFixtureInterface
$entry->setArchived($item['archived']); $entry->setArchived($item['archived']);
} }
if (isset($item['archived_at'])) {
$entry->setArchivedAt($item['archived_at']);
}
if (isset($item['preview'])) { if (isset($item['preview'])) {
$entry->setPreviewPicture($item['preview']); $entry->setPreviewPicture($item['preview']);
} }

View File

@ -1022,6 +1022,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
public function testSaveIsArchivedAfterPatch() public function testSaveIsArchivedAfterPatch()
{ {
$now = new \DateTime();
$entry = $this->client->getContainer() $entry = $this->client->getContainer()
->get(EntityManagerInterface::class) ->get(EntityManagerInterface::class)
->getRepository(Entry::class) ->getRepository(Entry::class)
@ -1043,6 +1044,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
$this->assertSame(1, $content['is_archived']); $this->assertSame(1, $content['is_archived']);
$this->assertSame($previousTitle . '++', $content['title']); $this->assertSame($previousTitle . '++', $content['title']);
$this->assertGreaterThanOrEqual((new \DateTime($content['archived_at']))->getTimestamp(), $now->getTimestamp());
} }
public function testSaveIsStarredAfterPatch() public function testSaveIsStarredAfterPatch()
@ -1056,6 +1058,9 @@ class EntryRestControllerTest extends WallabagApiTestCase
if (!$entry) { if (!$entry) {
$this->markTestSkipped('No content found in db.'); $this->markTestSkipped('No content found in db.');
} }
$previousTitle = $entry->getTitle();
$this->client->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [ $this->client->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [
'title' => $entry->getTitle() . '++', 'title' => $entry->getTitle() . '++',
]); ]);
@ -1065,6 +1070,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
$content = json_decode($this->client->getResponse()->getContent(), true); $content = json_decode($this->client->getResponse()->getContent(), true);
$this->assertSame(1, $content['is_starred']); $this->assertSame(1, $content['is_starred']);
$this->assertSame($previousTitle . '++', $content['title']);
$this->assertGreaterThanOrEqual((new \DateTime($content['starred_at']))->getTimestamp(), $now->getTimestamp()); $this->assertGreaterThanOrEqual((new \DateTime($content['starred_at']))->getTimestamp(), $now->getTimestamp());
} }