From fc14f86ae4798ca67dd6330a4fac65d9ed780b91 Mon Sep 17 00:00:00 2001 From: Kevin Jiang Date: Sun, 21 Jul 2024 16:25:41 +1200 Subject: [PATCH] test: Add test for http_status filter --- fixtures/EntryFixtures.php | 15 +++++++ tests/Command/ExportCommandTest.php | 2 +- .../Api/EntryRestControllerTest.php | 45 +++++++++++++++++++ tests/Controller/EntryControllerTest.php | 24 +++++----- 4 files changed, 73 insertions(+), 13 deletions(-) diff --git a/fixtures/EntryFixtures.php b/fixtures/EntryFixtures.php index 65ba832a8..22b797122 100644 --- a/fixtures/EntryFixtures.php +++ b/fixtures/EntryFixtures.php @@ -87,6 +87,17 @@ class EntryFixtures extends Fixture implements DependentFixtureInterface 'tags' => ['bar-tag'], 'is_not_parsed' => true, ], + 'entry7' => [ + 'user' => 'admin-user', + 'url' => 'http://0.0.0.0/entry7', + 'reading_time' => 12, + 'domain' => 'redirect.io', + 'mime' => 'text/html', + 'title' => 'test title entry7', + 'http_status' => '302', + 'content' => 'This is redirect/o/', + 'language' => 'de', + ], ]; foreach ($entries as $reference => $item) { @@ -133,6 +144,10 @@ class EntryFixtures extends Fixture implements DependentFixtureInterface $entry->setNotParsed($item['is_not_parsed']); } + if (isset($item['http_status'])) { + $entry->setHttpStatus($item['http_status']); + } + $manager->persist($entry); $this->addReference($reference, $entry); } diff --git a/tests/Command/ExportCommandTest.php b/tests/Command/ExportCommandTest.php index 7f39d95d2..67c11c4ef 100644 --- a/tests/Command/ExportCommandTest.php +++ b/tests/Command/ExportCommandTest.php @@ -47,7 +47,7 @@ class ExportCommandTest extends WallabagTestCase 'username' => 'admin', ]); - $this->assertStringContainsString('Exporting 5 entrie(s) for user admin...', $tester->getDisplay()); + $this->assertStringContainsString('Exporting 6 entrie(s) for user admin...', $tester->getDisplay()); $this->assertStringContainsString('Done', $tester->getDisplay()); $this->assertFileExists('admin-export.json'); } diff --git a/tests/Controller/Api/EntryRestControllerTest.php b/tests/Controller/Api/EntryRestControllerTest.php index 25ffe612b..2fa0c3399 100644 --- a/tests/Controller/Api/EntryRestControllerTest.php +++ b/tests/Controller/Api/EntryRestControllerTest.php @@ -170,6 +170,50 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type')); } + public function testGetEntriesByHttpStatusWithMatching() + { + $this->client->request('GET', '/api/entries?http_status=302'); + + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); + + $content = json_decode($this->client->getResponse()->getContent(), true); + + $this->assertGreaterThanOrEqual(1, \count($content)); + $this->assertNotEmpty($content['_embedded']['items']); + $this->assertSame(1, $content['total']); + $this->assertSame(1, $content['page']); + $this->assertGreaterThanOrEqual(1, $content['pages']); + + $this->assertSame('test title entry7', $content['_embedded']['items'][0]['title']); + $this->assertSame('302', $content['_embedded']['items'][0]['http_status']); + + $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type')); + } + + public function testGetEntriesByHttpStatusNoMatching() + { + $this->client->request('GET', '/api/entries?http_status=404'); + + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); + + $content = json_decode($this->client->getResponse()->getContent(), true); + + $this->assertGreaterThanOrEqual(1, \count($content)); + $this->assertEmpty($content['_embedded']['items']); + $this->assertSame(0, $content['total']); + $this->assertSame(1, $content['page']); + $this->assertGreaterThanOrEqual(1, $content['pages']); + + $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type')); + } + + public function testGetEntriesWithBadHttpStatusParam() + { + $this->client->request('GET', '/api/entries?http_status=10000'); + + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); + } + public function testGetEntriesWithFullOptions() { $this->client->request('GET', '/api/entries', [ @@ -183,6 +227,7 @@ class EntryRestControllerTest extends WallabagApiTestCase 'since' => 1443274283, 'public' => 0, 'notParsed' => 0, + 'http_status' => 200, ]); $this->assertSame(200, $this->client->getResponse()->getStatusCode()); diff --git a/tests/Controller/EntryControllerTest.php b/tests/Controller/EntryControllerTest.php index 86d74a1d7..11b6cdce2 100644 --- a/tests/Controller/EntryControllerTest.php +++ b/tests/Controller/EntryControllerTest.php @@ -106,14 +106,14 @@ class EntryControllerTest extends WallabagTestCase $crawler = $client->request('GET', '/'); - $this->assertCount(4, $crawler->filter($this->entryDataTestAttribute)); + $this->assertCount(5, $crawler->filter($this->entryDataTestAttribute)); // Good URL $client->request('GET', '/bookmarklet', ['url' => $this->url]); $this->assertSame(302, $client->getResponse()->getStatusCode()); $client->followRedirect(); $crawler = $client->request('GET', '/'); - $this->assertCount(5, $crawler->filter($this->entryDataTestAttribute)); + $this->assertCount(6, $crawler->filter($this->entryDataTestAttribute)); $em = $client->getContainer() ->get(EntityManagerInterface::class); @@ -803,7 +803,7 @@ class EntryControllerTest extends WallabagTestCase $client = $this->getTestClient(); $crawler = $client->request('GET', '/all/list'); - $this->assertCount(5, $crawler->filter($this->entryDataTestAttribute)); + $this->assertCount(6, $crawler->filter($this->entryDataTestAttribute)); $entry = new Entry($this->getLoggedInUser()); $entry->setUrl($this->url); @@ -812,7 +812,7 @@ class EntryControllerTest extends WallabagTestCase $this->getEntityManager()->flush(); $crawler = $client->request('GET', '/all/list'); - $this->assertCount(6, $crawler->filter($this->entryDataTestAttribute)); + $this->assertCount(7, $crawler->filter($this->entryDataTestAttribute)); $form = $crawler->filter('button[id=submit-filter]')->form(); @@ -822,7 +822,7 @@ class EntryControllerTest extends WallabagTestCase $crawler = $client->submit($form, $data); - $this->assertCount(5, $crawler->filter($this->entryDataTestAttribute)); + $this->assertCount(6, $crawler->filter($this->entryDataTestAttribute)); } public function testFilterOnReadingTimeOnlyLower() @@ -867,7 +867,7 @@ class EntryControllerTest extends WallabagTestCase $crawler = $client->submit($form, $data); - $this->assertCount(4, $crawler->filter($this->entryDataTestAttribute)); + $this->assertCount(5, $crawler->filter($this->entryDataTestAttribute)); $entry = new Entry($this->getLoggedInUser()); $entry->setUrl($this->url); @@ -877,7 +877,7 @@ class EntryControllerTest extends WallabagTestCase $crawler = $client->submit($form, $data); - $this->assertCount(5, $crawler->filter($this->entryDataTestAttribute)); + $this->assertCount(6, $crawler->filter($this->entryDataTestAttribute)); } public function testFilterOnCreationDate() @@ -908,7 +908,7 @@ class EntryControllerTest extends WallabagTestCase $crawler = $client->submit($form, $data); - $this->assertCount(4, $crawler->filter($this->entryDataTestAttribute)); + $this->assertCount(5, $crawler->filter($this->entryDataTestAttribute)); $data = [ 'entry_filter[createdAt][left_date]' => $today->format('Y-m-d'), @@ -917,7 +917,7 @@ class EntryControllerTest extends WallabagTestCase $crawler = $client->submit($form, $data); - $this->assertCount(4, $crawler->filter($this->entryDataTestAttribute)); + $this->assertCount(5, $crawler->filter($this->entryDataTestAttribute)); $data = [ 'entry_filter[createdAt][left_date]' => '1970-01-01', @@ -1394,7 +1394,7 @@ class EntryControllerTest extends WallabagTestCase $crawler = $client->submit($form, $data); - $this->assertCount(8, $crawler->filter($this->entryDataTestAttribute)); + $this->assertCount(9, $crawler->filter($this->entryDataTestAttribute)); } public function testSearch() @@ -1418,7 +1418,7 @@ class EntryControllerTest extends WallabagTestCase $crawler = $client->submit($form, $data); - $this->assertCount(4, $crawler->filter($this->entryDataTestAttribute)); + $this->assertCount(5, $crawler->filter($this->entryDataTestAttribute)); // Add a check with useless spaces before and after the search term $crawler = $client->request('GET', '/unread/list'); @@ -1430,7 +1430,7 @@ class EntryControllerTest extends WallabagTestCase $crawler = $client->submit($form, $data); - $this->assertCount(4, $crawler->filter($this->entryDataTestAttribute)); + $this->assertCount(5, $crawler->filter($this->entryDataTestAttribute)); // Search on starred list $crawler = $client->request('GET', '/starred/list');