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
{
$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']);
}

View file

@ -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());
}