From 273b6f06584092f3b596406bf4c0d57aa738e8bf Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Thu, 30 Mar 2017 16:07:48 +0200 Subject: Rename method from *username to *user Signed-off-by: Thomas Citharel --- tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php index beb0598a..8f2ca1cb 100644 --- a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php @@ -798,7 +798,7 @@ class ConfigControllerTest extends WallabagCoreTestCase $entryReset = $em ->getRepository('WallabagCoreBundle:Entry') - ->countAllEntriesByUsername($user->getId()); + ->countAllEntriesByUser($user->getId()); $this->assertEquals(0, $entryReset, 'Entries were reset'); } @@ -843,7 +843,7 @@ class ConfigControllerTest extends WallabagCoreTestCase $entryReset = $em ->getRepository('WallabagCoreBundle:Entry') - ->countAllEntriesByUsername($user->getId()); + ->countAllEntriesByUser($user->getId()); $this->assertEquals(0, $entryReset, 'Entries were reset'); -- cgit v1.2.3 From 6da1aebc946e6448dd0d5080ee88e79c2bae4666 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Thu, 30 Mar 2017 16:24:59 +0200 Subject: Allow to remove all archived entries Since we still support fucking SQLite, we need to retrieve all tags & annotations for archived entries before deleting them. Signed-off-by: Thomas Citharel --- .../CoreBundle/Controller/ConfigControllerTest.php | 76 ++++++++++++++++++++++ 1 file changed, 76 insertions(+) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php index 8f2ca1cb..b434a4c4 100644 --- a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php @@ -803,6 +803,82 @@ class ConfigControllerTest extends WallabagCoreTestCase $this->assertEquals(0, $entryReset, 'Entries were reset'); } + public function testResetArchivedEntries() + { + $this->logInAs('empty'); + $client = $this->getClient(); + + $em = $client->getContainer()->get('doctrine.orm.entity_manager'); + + $user = static::$kernel->getContainer()->get('security.token_storage')->getToken()->getUser(); + + $tag = new Tag(); + $tag->setLabel('super'); + $em->persist($tag); + + $entry = new Entry($user); + $entry->setUrl('http://www.lemonde.fr/europe/article/2016/10/01/pour-le-psoe-chaque-election-s-est-transformee-en-une-agonie_5006476_3214.html'); + $entry->setContent('Youhou'); + $entry->setTitle('Youhou'); + $entry->addTag($tag); + $em->persist($entry); + + $annotation = new Annotation($user); + $annotation->setText('annotated'); + $annotation->setQuote('annotated'); + $annotation->setRanges([]); + $annotation->setEntry($entry); + $em->persist($annotation); + + $tagArchived = new Tag(); + $tagArchived->setLabel('super'); + $em->persist($tagArchived); + + $entryArchived = new Entry($user); + $entryArchived->setUrl('http://www.lemonde.fr/europe/article/2016/10/01/pour-le-psoe-chaque-election-s-est-transformee-en-une-agonie_5006476_3214.html'); + $entryArchived->setContent('Youhou'); + $entryArchived->setTitle('Youhou'); + $entryArchived->addTag($tagArchived); + $entryArchived->setArchived(true); + $em->persist($entryArchived); + + $annotationArchived = new Annotation($user); + $annotationArchived->setText('annotated'); + $annotationArchived->setQuote('annotated'); + $annotationArchived->setRanges([]); + $annotationArchived->setEntry($entryArchived); + $em->persist($annotationArchived); + + $em->flush(); + + $crawler = $client->request('GET', '/config#set3'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + + $crawler = $client->click($crawler->selectLink('config.reset.archived')->link()); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertContains('flashes.config.notice.archived_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]); + + $entryReset = $em + ->getRepository('WallabagCoreBundle:Entry') + ->countAllEntriesByUsername($user->getId()); + + $this->assertEquals(1, $entryReset, 'Entries were reset'); + + $tagReset = $em + ->getRepository('WallabagCoreBundle:Tag') + ->countAllTags($user->getId()); + + $this->assertEquals(1, $tagReset, 'Tags were reset'); + + $annotationsReset = $em + ->getRepository('WallabagAnnotationBundle:Annotation') + ->findAnnotationsByPageId($annotationArchived->getId(), $user->getId()); + + $this->assertEmpty($annotationsReset, 'Annotations were reset'); + } + public function testResetEntriesCascade() { $this->logInAs('empty'); -- cgit v1.2.3 From 73f28afb19655f1a31d8d840d96deb898ba52763 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 31 Mar 2017 10:46:47 +0200 Subject: Renamed countAllEntriesByUsername method --- tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php index b434a4c4..35888f16 100644 --- a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php @@ -862,7 +862,7 @@ class ConfigControllerTest extends WallabagCoreTestCase $entryReset = $em ->getRepository('WallabagCoreBundle:Entry') - ->countAllEntriesByUsername($user->getId()); + ->countAllEntriesByUser($user->getId()); $this->assertEquals(1, $entryReset, 'Entries were reset'); -- cgit v1.2.3 From 5e9009ce86a366001616fad5b28cb59dc20ee4df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Wed, 5 Apr 2017 22:22:16 +0200 Subject: Added publication date --- tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php | 1 + 1 file changed, 1 insertion(+) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index 3eb6d47f..d4ebdf3d 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php @@ -138,6 +138,7 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); $this->assertEquals($this->url, $content->getUrl()); $this->assertContains('Google', $content->getTitle()); + $this->assertEquals('2015-03-28 15:37:39', $content->getPublishedAt()); } public function testPostNewOkUrlExist() -- cgit v1.2.3 From 7b0b3622ab2dd909028481b294c91f88a5682671 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Thu, 6 Apr 2017 09:36:20 +0200 Subject: Added author of article --- tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index d4ebdf3d..5af7f7e1 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php @@ -135,10 +135,13 @@ class EntryControllerTest extends WallabagCoreTestCase ->getRepository('WallabagCoreBundle:Entry') ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); + $author = $content->getPublishedBy(); + $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); $this->assertEquals($this->url, $content->getUrl()); $this->assertContains('Google', $content->getTitle()); - $this->assertEquals('2015-03-28 15:37:39', $content->getPublishedAt()); + $this->assertEquals('2015-03-28 15:37:39', $content->getPublishedAt()->format('Y-m-d H:i:s')); + $this->assertEquals('Morgane Tual', $author[0]); } public function testPostNewOkUrlExist() -- cgit v1.2.3 From e9c80c99bda57905e481dc7eb7748a3b5c0d9ac9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Mon, 10 Apr 2017 17:58:27 +0200 Subject: Added test for multiple authors --- .../CoreBundle/Controller/EntryControllerTest.php | 47 ++++++++++++++++++---- 1 file changed, 39 insertions(+), 8 deletions(-) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index 5af7f7e1..d26a56f8 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php @@ -144,6 +144,37 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertEquals('Morgane Tual', $author[0]); } + public function testPostWithMultipleAuthors() + { + $url = 'http://www.liberation.fr/planete/2017/04/05/donald-trump-et-xi-jinping-tentative-de-flirt-en-floride_1560768'; + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/new'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + + $form = $crawler->filter('form[name=entry]')->form(); + + $data = [ + 'entry[url]' => $url, + ]; + + $client->submit($form, $data); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $content = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findByUrlAndUserId($url, $this->getLoggedInUserId()); + + $authors = $content->getPublishedBy(); + $this->assertEquals('2017-04-05 19:26:13', $content->getPublishedAt()->format('Y-m-d H:i:s')); + $this->assertEquals('Raphaël Balenieri, correspondant à Pékin', $authors[0]); + $this->assertEquals('Frédéric Autran, correspondant à New York', $authors[1]); + } + public function testPostNewOkUrlExist() { $this->logInAs('admin'); @@ -610,7 +641,7 @@ class EntryControllerTest extends WallabagCoreTestCase $crawler = $client->submit($form, $data); - $this->assertCount(2, $crawler->filter('div[class=entry]')); + $this->assertCount(3, $crawler->filter('div[class=entry]')); } public function testFilterOnReadingTimeOnlyLower() @@ -646,7 +677,7 @@ class EntryControllerTest extends WallabagCoreTestCase $crawler = $client->submit($form, $data); - $this->assertCount(4, $crawler->filter('div[class=entry]')); + $this->assertCount(5, $crawler->filter('div[class=entry]')); } public function testFilterOnCreationDate() @@ -665,7 +696,7 @@ class EntryControllerTest extends WallabagCoreTestCase $crawler = $client->submit($form, $data); - $this->assertCount(5, $crawler->filter('div[class=entry]')); + $this->assertCount(6, $crawler->filter('div[class=entry]')); $data = [ 'entry_filter[createdAt][left_date]' => date('d/m/Y'), @@ -674,7 +705,7 @@ class EntryControllerTest extends WallabagCoreTestCase $crawler = $client->submit($form, $data); - $this->assertCount(5, $crawler->filter('div[class=entry]')); + $this->assertCount(6, $crawler->filter('div[class=entry]')); $data = [ 'entry_filter[createdAt][left_date]' => '01/01/1970', @@ -778,7 +809,7 @@ class EntryControllerTest extends WallabagCoreTestCase $form['entry_filter[previewPicture]']->tick(); $crawler = $client->submit($form); - $this->assertCount(1, $crawler->filter('div[class=entry]')); + $this->assertCount(2, $crawler->filter('div[class=entry]')); } public function testFilterOnLanguage() @@ -793,7 +824,7 @@ class EntryControllerTest extends WallabagCoreTestCase ]; $crawler = $client->submit($form, $data); - $this->assertCount(2, $crawler->filter('div[class=entry]')); + $this->assertCount(3, $crawler->filter('div[class=entry]')); $form = $crawler->filter('button[id=submit-filter]')->form(); $data = [ @@ -1018,7 +1049,7 @@ class EntryControllerTest extends WallabagCoreTestCase $crawler = $client->submit($form, $data); - $this->assertCount(1, $crawler->filter('div[class=entry]')); + $this->assertCount(2, $crawler->filter('div[class=entry]')); $crawler = $client->request('GET', '/all/list'); $form = $crawler->filter('button[id=submit-filter]')->form(); @@ -1029,7 +1060,7 @@ class EntryControllerTest extends WallabagCoreTestCase $crawler = $client->submit($form, $data); - $this->assertCount(7, $crawler->filter('div[class=entry]')); + $this->assertCount(8, $crawler->filter('div[class=entry]')); } public function testSearch() -- cgit v1.2.3 From fdd725f58cfe96d9bb9454d0347f6ff847fce69d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Thu, 20 Apr 2017 14:58:20 +0200 Subject: Added notmatches operator for tagging rule --- tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php | 6 +++--- tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php | 2 +- tests/Wallabag/CoreBundle/Controller/TagControllerTest.php | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index d26a56f8..35438c83 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php @@ -270,7 +270,7 @@ class EntryControllerTest extends WallabagCoreTestCase ->findOneByUrl($url); $tags = $entry->getTags(); - $this->assertCount(1, $tags); + $this->assertCount(2, $tags); $this->assertEquals('wallabag', $tags[0]->getLabel()); $em->remove($entry); @@ -299,8 +299,8 @@ class EntryControllerTest extends WallabagCoreTestCase $tags = $entry->getTags(); - $this->assertCount(1, $tags); - $this->assertEquals('wallabag', $tags[0]->getLabel()); + $this->assertCount(2, $tags); + $this->assertEquals('wallabag', $tags[1]->getLabel()); $em->remove($entry); $em->flush(); diff --git a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php index 32a18e26..1b8ecc49 100644 --- a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php @@ -241,7 +241,7 @@ class ExportControllerTest extends WallabagCoreTestCase $this->assertEquals($contentInDB->getLanguage(), $content[0]['language']); $this->assertEquals($contentInDB->getReadingtime(), $content[0]['reading_time']); $this->assertEquals($contentInDB->getDomainname(), $content[0]['domain_name']); - $this->assertEquals(['foo bar', 'baz'], $content[0]['tags']); + $this->assertEquals(['foo bar', 'baz', 'foot'], $content[0]['tags']); } public function testXmlExport() diff --git a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php index fa1a3539..c3b22dcd 100644 --- a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php @@ -46,7 +46,7 @@ class TagControllerTest extends WallabagCoreTestCase ->getRepository('WallabagCoreBundle:Entry') ->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId()); - $this->assertEquals(3, count($entry->getTags())); + $this->assertEquals(4, count($entry->getTags())); // tag already exists and already assigned $client->submit($form, $data); @@ -57,7 +57,7 @@ class TagControllerTest extends WallabagCoreTestCase ->getRepository('WallabagCoreBundle:Entry') ->find($entry->getId()); - $this->assertEquals(3, count($newEntry->getTags())); + $this->assertEquals(4, count($newEntry->getTags())); // tag already exists but still not assigned to this entry $data = [ @@ -72,7 +72,7 @@ class TagControllerTest extends WallabagCoreTestCase ->getRepository('WallabagCoreBundle:Entry') ->find($entry->getId()); - $this->assertEquals(3, count($newEntry->getTags())); + $this->assertEquals(4, count($newEntry->getTags())); } public function testAddMultipleTagToEntry() -- cgit v1.2.3 From 3d57d625f88203ca526adf7729b93237ecd13242 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Thu, 30 Mar 2017 17:02:10 +0200 Subject: Add basic tests Signed-off-by: Thomas Citharel --- .../Command/CleanDuplicatesCommandTest.php | 59 ++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 tests/Wallabag/CoreBundle/Command/CleanDuplicatesCommandTest.php (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Command/CleanDuplicatesCommandTest.php b/tests/Wallabag/CoreBundle/Command/CleanDuplicatesCommandTest.php new file mode 100644 index 00000000..9939d43c --- /dev/null +++ b/tests/Wallabag/CoreBundle/Command/CleanDuplicatesCommandTest.php @@ -0,0 +1,59 @@ +getClient()->getKernel()); + $application->add(new CleanDuplicatesCommand()); + + $command = $application->find('wallabag:clean-duplicates'); + + $tester = new CommandTester($command); + $tester->execute([ + 'command' => $command->getName(), + ]); + + $this->assertContains('Cleaning through 3 user accounts', $tester->getDisplay()); + $this->assertContains('Finished cleaning. 0 duplicates found in total', $tester->getDisplay()); + } + + public function testRunTagAllCommandWithBadUsername() + { + $application = new Application($this->getClient()->getKernel()); + $application->add(new CleanDuplicatesCommand()); + + $command = $application->find('wallabag:clean-duplicates'); + + $tester = new CommandTester($command); + $tester->execute([ + 'command' => $command->getName(), + 'username' => 'unknown', + ]); + + $this->assertContains('User "unknown" not found', $tester->getDisplay()); + } + + public function testRunTagAllCommandForUser() + { + $application = new Application($this->getClient()->getKernel()); + $application->add(new CleanDuplicatesCommand()); + + $command = $application->find('wallabag:clean-duplicates'); + + $tester = new CommandTester($command); + $tester->execute([ + 'command' => $command->getName(), + 'username' => 'admin', + ]); + + $this->assertContains('Cleaned 0 duplicates for user admin', $tester->getDisplay()); + } +} -- cgit v1.2.3 From a162b1a99b0bd4ccebbd129170d043a621bed710 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Wed, 3 May 2017 10:53:10 +0200 Subject: Changed export test --- tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php index 1b8ecc49..63f2c829 100644 --- a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php @@ -189,11 +189,9 @@ class ExportControllerTest extends WallabagCoreTestCase $this->assertContains($contentInDB[0]['language'], $csv[1]); $this->assertContains($contentInDB[0]['createdAt']->format('d/m/Y h:i:s'), $csv[1]); - $expectedTag = []; foreach ($contentInDB[0]['tags'] as $tag) { - $expectedTag[] = $tag['label']; + $this->assertContains($tag['label'], $csv[1]); } - $this->assertContains(implode(', ', $expectedTag), $csv[1]); } public function testJsonExport() -- cgit v1.2.3 From 662db41baee404be3427b2b11b2d1fbf0aefcc8f Mon Sep 17 00:00:00 2001 From: Bertrand Dunogier Date: Sun, 22 Jan 2017 00:42:05 +0100 Subject: Changed parsing of login_extra_fields in guzzle auth --- .../CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php b/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php index aee67259..8341b11f 100644 --- a/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php +++ b/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php @@ -24,7 +24,7 @@ class GrabySiteConfigBuilderTest extends PHPUnit_Framework_TestCase $grabySiteConfig->login_uri = 'http://example.com/login'; $grabySiteConfig->login_username_field = 'login'; $grabySiteConfig->login_password_field = 'password'; - $grabySiteConfig->login_extra_fields = ['field' => 'value']; + $grabySiteConfig->login_extra_fields = ['field=value']; $grabySiteConfig->not_logged_in_xpath = '//div[@class="need-login"]'; $grabyConfigBuilderMock -- cgit v1.2.3 From d09fe4d233477d5cb9bfc613799b05a7ca14e270 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 5 May 2017 14:33:36 +0200 Subject: Added test for deduplication --- .../Command/CleanDuplicatesCommandTest.php | 47 +++++++++++++++++++++- .../CoreBundle/Command/ExportCommandTest.php | 2 +- .../CoreBundle/Helper/ContentProxyTest.php | 2 +- 3 files changed, 48 insertions(+), 3 deletions(-) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Command/CleanDuplicatesCommandTest.php b/tests/Wallabag/CoreBundle/Command/CleanDuplicatesCommandTest.php index 9939d43c..1f5921d2 100644 --- a/tests/Wallabag/CoreBundle/Command/CleanDuplicatesCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/CleanDuplicatesCommandTest.php @@ -6,10 +6,11 @@ use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Component\Console\Tester\CommandTester; use Wallabag\CoreBundle\Command\CleanDuplicatesCommand; use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; +use Wallabag\CoreBundle\Entity\Entry; class CleanDuplicatesCommandTest extends WallabagCoreTestCase { - public function testRunTagAllCommandForAll() + public function testTagAll() { $application = new Application($this->getClient()->getKernel()); $application->add(new CleanDuplicatesCommand()); @@ -56,4 +57,48 @@ class CleanDuplicatesCommandTest extends WallabagCoreTestCase $this->assertContains('Cleaned 0 duplicates for user admin', $tester->getDisplay()); } + + public function testDuplicate() + { + $url = 'http://www.lemonde.fr/sport/visuel/2017/05/05/rondelle-prison-blanchissage-comprendre-le-hockey-sur-glace_5122587_3242.html'; + $client = $this->getClient(); + $em = $client->getContainer()->get('doctrine.orm.entity_manager'); + + $this->logInAs('admin'); + + $nbEntries = $em->getRepository('WallabagCoreBundle:Entry')->findAllByUrlAndUserId($url, $this->getLoggedInUserId()); + $this->assertCount(0, $nbEntries); + + $user = $em->getRepository('WallabagUserBundle:User')->findOneById($this->getLoggedInUserId()); + + $entry1 = new Entry($user); + $entry1->setUrl($url); + + $entry2 = new Entry($user); + $entry2->setUrl($url); + + $em->persist($entry1); + $em->persist($entry2); + + $em->flush(); + + $nbEntries = $em->getRepository('WallabagCoreBundle:Entry')->findAllByUrlAndUserId($url, $this->getLoggedInUserId()); + $this->assertCount(2, $nbEntries); + + $application = new Application($this->getClient()->getKernel()); + $application->add(new CleanDuplicatesCommand()); + + $command = $application->find('wallabag:clean-duplicates'); + + $tester = new CommandTester($command); + $tester->execute([ + 'command' => $command->getName(), + 'username' => 'admin', + ]); + + $this->assertContains('Cleaned 1 duplicates for user admin', $tester->getDisplay()); + + $nbEntries = $em->getRepository('WallabagCoreBundle:Entry')->findAllByUrlAndUserId($url, $this->getLoggedInUserId()); + $this->assertCount(1, $nbEntries); + } } diff --git a/tests/Wallabag/CoreBundle/Command/ExportCommandTest.php b/tests/Wallabag/CoreBundle/Command/ExportCommandTest.php index 6798c5d7..b21f3318 100644 --- a/tests/Wallabag/CoreBundle/Command/ExportCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/ExportCommandTest.php @@ -70,7 +70,7 @@ class ExportCommandTest extends WallabagCoreTestCase $tester->execute([ 'command' => $command->getName(), 'username' => 'admin', - 'filepath' => 'specialexport.json' + 'filepath' => 'specialexport.json', ]); $this->assertFileExists('specialexport.json'); diff --git a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php index 5956b502..8abb1bbb 100644 --- a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php +++ b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php @@ -111,7 +111,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase $this->assertEquals('http://domain.io', $entry->getUrl()); $this->assertEquals('my title', $entry->getTitle()); - $this->assertEquals($this->fetchingErrorMessage . '

But we found a short description:

desc', $entry->getContent()); + $this->assertEquals($this->fetchingErrorMessage.'

But we found a short description:

desc', $entry->getContent()); $this->assertEmpty($entry->getPreviewPicture()); $this->assertEmpty($entry->getLanguage()); $this->assertEmpty($entry->getHttpStatus()); -- cgit v1.2.3 From 89f108b45ae94cd827595461b39f869111092579 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 5 May 2017 14:54:03 +0200 Subject: Fixed @j0k3r review --- tests/Wallabag/CoreBundle/Command/CleanDuplicatesCommandTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Command/CleanDuplicatesCommandTest.php b/tests/Wallabag/CoreBundle/Command/CleanDuplicatesCommandTest.php index 1f5921d2..688cc388 100644 --- a/tests/Wallabag/CoreBundle/Command/CleanDuplicatesCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/CleanDuplicatesCommandTest.php @@ -10,7 +10,7 @@ use Wallabag\CoreBundle\Entity\Entry; class CleanDuplicatesCommandTest extends WallabagCoreTestCase { - public function testTagAll() + public function testRunCleanDuplicates() { $application = new Application($this->getClient()->getKernel()); $application->add(new CleanDuplicatesCommand()); @@ -26,7 +26,7 @@ class CleanDuplicatesCommandTest extends WallabagCoreTestCase $this->assertContains('Finished cleaning. 0 duplicates found in total', $tester->getDisplay()); } - public function testRunTagAllCommandWithBadUsername() + public function testRunCleanDuplicatesCommandWithBadUsername() { $application = new Application($this->getClient()->getKernel()); $application->add(new CleanDuplicatesCommand()); @@ -42,7 +42,7 @@ class CleanDuplicatesCommandTest extends WallabagCoreTestCase $this->assertContains('User "unknown" not found', $tester->getDisplay()); } - public function testRunTagAllCommandForUser() + public function testRunCleanDuplicatesCommandForUser() { $application = new Application($this->getClient()->getKernel()); $application->add(new CleanDuplicatesCommand()); -- cgit v1.2.3 From 7d2d1d685920e8b4975c3967c031ae0abb7098c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 5 May 2017 15:14:58 +0200 Subject: Added migrations execution after fresh install --- tests/Wallabag/CoreBundle/Command/ExportCommandTest.php | 2 +- tests/Wallabag/CoreBundle/Command/InstallCommandTest.php | 12 +++++++++--- tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Command/ExportCommandTest.php b/tests/Wallabag/CoreBundle/Command/ExportCommandTest.php index 6798c5d7..b21f3318 100644 --- a/tests/Wallabag/CoreBundle/Command/ExportCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/ExportCommandTest.php @@ -70,7 +70,7 @@ class ExportCommandTest extends WallabagCoreTestCase $tester->execute([ 'command' => $command->getName(), 'username' => 'admin', - 'filepath' => 'specialexport.json' + 'filepath' => 'specialexport.json', ]); $this->assertFileExists('specialexport.json'); diff --git a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php index 1bfd41d5..122a87d4 100644 --- a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php @@ -87,6 +87,7 @@ class InstallCommandTest extends WallabagCoreTestCase $this->assertContains('Setting up database.', $tester->getDisplay()); $this->assertContains('Administration setup.', $tester->getDisplay()); $this->assertContains('Config setup.', $tester->getDisplay()); + $this->assertContains('Run migrations.', $tester->getDisplay()); } public function testRunInstallCommandWithReset() @@ -115,12 +116,13 @@ class InstallCommandTest extends WallabagCoreTestCase $this->assertContains('Checking system requirements.', $tester->getDisplay()); $this->assertContains('Setting up database.', $tester->getDisplay()); - $this->assertContains('Droping database, creating database and schema, clearing the cache', $tester->getDisplay()); + $this->assertContains('Dropping database, creating database and schema, clearing the cache', $tester->getDisplay()); $this->assertContains('Administration setup.', $tester->getDisplay()); $this->assertContains('Config setup.', $tester->getDisplay()); + $this->assertContains('Run migrations.', $tester->getDisplay()); // we force to reset everything - $this->assertContains('Droping database, creating database and schema, clearing the cache', $tester->getDisplay()); + $this->assertContains('Dropping database, creating database and schema, clearing the cache', $tester->getDisplay()); } public function testRunInstallCommandWithDatabaseRemoved() @@ -168,6 +170,7 @@ class InstallCommandTest extends WallabagCoreTestCase $this->assertContains('Setting up database.', $tester->getDisplay()); $this->assertContains('Administration setup.', $tester->getDisplay()); $this->assertContains('Config setup.', $tester->getDisplay()); + $this->assertContains('Run migrations.', $tester->getDisplay()); // the current database doesn't already exist $this->assertContains('Creating database and schema, clearing the cache', $tester->getDisplay()); @@ -205,8 +208,9 @@ class InstallCommandTest extends WallabagCoreTestCase $this->assertContains('Setting up database.', $tester->getDisplay()); $this->assertContains('Administration setup.', $tester->getDisplay()); $this->assertContains('Config setup.', $tester->getDisplay()); + $this->assertContains('Run migrations.', $tester->getDisplay()); - $this->assertContains('Droping schema and creating schema', $tester->getDisplay()); + $this->assertContains('Dropping schema and creating schema', $tester->getDisplay()); } public function testRunInstallCommandChooseNothing() @@ -259,6 +263,7 @@ class InstallCommandTest extends WallabagCoreTestCase $this->assertContains('Setting up database.', $tester->getDisplay()); $this->assertContains('Administration setup.', $tester->getDisplay()); $this->assertContains('Config setup.', $tester->getDisplay()); + $this->assertContains('Run migrations.', $tester->getDisplay()); $this->assertContains('Creating schema', $tester->getDisplay()); } @@ -291,5 +296,6 @@ class InstallCommandTest extends WallabagCoreTestCase $this->assertContains('Setting up database.', $tester->getDisplay()); $this->assertContains('Administration setup.', $tester->getDisplay()); $this->assertContains('Config setup.', $tester->getDisplay()); + $this->assertContains('Run migrations.', $tester->getDisplay()); } } diff --git a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php index 5956b502..8abb1bbb 100644 --- a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php +++ b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php @@ -111,7 +111,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase $this->assertEquals('http://domain.io', $entry->getUrl()); $this->assertEquals('my title', $entry->getTitle()); - $this->assertEquals($this->fetchingErrorMessage . '

But we found a short description:

desc', $entry->getContent()); + $this->assertEquals($this->fetchingErrorMessage.'

But we found a short description:

desc', $entry->getContent()); $this->assertEmpty($entry->getPreviewPicture()); $this->assertEmpty($entry->getLanguage()); $this->assertEmpty($entry->getHttpStatus()); -- cgit v1.2.3 From 4eeb29ff784934fa879dd87999e07c4c7626af8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 5 May 2017 15:20:58 +0200 Subject: Fixed test --- tests/Wallabag/CoreBundle/Command/CleanDuplicatesCommandTest.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Command/CleanDuplicatesCommandTest.php b/tests/Wallabag/CoreBundle/Command/CleanDuplicatesCommandTest.php index 688cc388..e6e57f30 100644 --- a/tests/Wallabag/CoreBundle/Command/CleanDuplicatesCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/CleanDuplicatesCommandTest.php @@ -100,5 +100,9 @@ class CleanDuplicatesCommandTest extends WallabagCoreTestCase $nbEntries = $em->getRepository('WallabagCoreBundle:Entry')->findAllByUrlAndUserId($url, $this->getLoggedInUserId()); $this->assertCount(1, $nbEntries); + + $query = $em->createQuery('DELETE FROM Wallabag\CoreBundle\Entity\Entry e WHERE e.url = :url'); + $query->setParameter('url', $url); + $query->execute(); } } -- cgit v1.2.3 From 94b232bbb8de4699911a6446a1a96f75370cab50 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Tue, 9 May 2017 22:25:18 +0200 Subject: Skip auth when no credentials are found MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If we can’t find a credential for the current host, even if it required login, we won’t add them and website will be fetched without any login. --- .../GrabySiteConfigBuilderTest.php | 40 +++++++++++++++------- 1 file changed, 27 insertions(+), 13 deletions(-) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php b/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php index 8341b11f..8b50bce9 100644 --- a/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php +++ b/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php @@ -2,6 +2,8 @@ namespace Tests\Wallabag\CoreBundle\GuzzleSiteAuthenticator; +use Monolog\Handler\TestHandler; +use Monolog\Logger; use BD\GuzzleSiteAuthenticator\SiteConfig\SiteConfig; use Graby\SiteConfig\SiteConfig as GrabySiteConfig; use PHPUnit_Framework_TestCase; @@ -32,14 +34,19 @@ class GrabySiteConfigBuilderTest extends PHPUnit_Framework_TestCase ->with('example.com') ->will($this->returnValue($grabySiteConfig)); + $logger = new Logger('foo'); + $handler = new TestHandler(); + $logger->pushHandler($handler); + $this->builder = new GrabySiteConfigBuilder( $grabyConfigBuilderMock, - ['example.com' => ['username' => 'foo', 'password' => 'bar']] + ['example.com' => ['username' => 'foo', 'password' => 'bar']], + $logger ); $config = $this->builder->buildForHost('example.com'); - self::assertEquals( + $this->assertEquals( new SiteConfig([ 'host' => 'example.com', 'requiresLogin' => true, @@ -53,6 +60,10 @@ class GrabySiteConfigBuilderTest extends PHPUnit_Framework_TestCase ]), $config ); + + $records = $handler->getRecords(); + + $this->assertCount(1, $records, 'One log was recorded'); } public function testBuildConfigDoesntExist() @@ -67,19 +78,22 @@ class GrabySiteConfigBuilderTest extends PHPUnit_Framework_TestCase ->with('unknown.com') ->will($this->returnValue(new GrabySiteConfig())); - $this->builder = new GrabySiteConfigBuilder($grabyConfigBuilderMock, []); + $logger = new Logger('foo'); + $handler = new TestHandler(); + $logger->pushHandler($handler); + + $this->builder = new GrabySiteConfigBuilder( + $grabyConfigBuilderMock, + [], + $logger + ); $config = $this->builder->buildForHost('unknown.com'); - self::assertEquals( - new SiteConfig([ - 'host' => 'unknown.com', - 'requiresLogin' => false, - 'username' => null, - 'password' => null, - 'extraFields' => [], - ]), - $config - ); + $this->assertFalse($config); + + $records = $handler->getRecords(); + + $this->assertCount(1, $records, 'One log was recorded'); } } -- cgit v1.2.3 From dda6a6addc0fd54031514e81d2b55d5066b7157c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Thu, 11 May 2017 14:18:21 +0200 Subject: Added headers field in Entry --- tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php | 1 + 1 file changed, 1 insertion(+) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index 35438c83..82ac3ac3 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php @@ -142,6 +142,7 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertContains('Google', $content->getTitle()); $this->assertEquals('2015-03-28 15:37:39', $content->getPublishedAt()->format('Y-m-d H:i:s')); $this->assertEquals('Morgane Tual', $author[0]); + $this->assertArrayHasKey('x-varnish1', $content->getHeaders()); } public function testPostWithMultipleAuthors() -- cgit v1.2.3 From 1517d5772db05ce86b9958dc6545471d8702bf60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Thu, 11 May 2017 14:53:56 +0200 Subject: Replaced json_array with array And fixed failing test due to @j0k3r :trollface: --- tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index 82ac3ac3..698e5e13 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php @@ -915,7 +915,7 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $entry); $this->assertEquals($url, $entry->getUrl()); $this->assertContains('Perpignan', $entry->getTitle()); - $this->assertContains('/d9bc0fcd.jpeg', $entry->getContent()); + $this->assertContains('/c4789a7f.jpeg', $entry->getContent()); $client->getContainer()->get('craue_config')->set('download_images_enabled', 0); } -- cgit v1.2.3 From 3554364bedec2b831074d5d4e7409b4124e86a59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 12 May 2017 13:47:53 +0200 Subject: Fixed tests --- tests/Wallabag/CoreBundle/Helper/RuleBasedTaggerTest.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Helper/RuleBasedTaggerTest.php b/tests/Wallabag/CoreBundle/Helper/RuleBasedTaggerTest.php index 17b08c2a..522cf3b3 100644 --- a/tests/Wallabag/CoreBundle/Helper/RuleBasedTaggerTest.php +++ b/tests/Wallabag/CoreBundle/Helper/RuleBasedTaggerTest.php @@ -2,6 +2,7 @@ namespace Tests\Wallabag\CoreBundle\Helper; +use Psr\Log\NullLogger; use Wallabag\CoreBundle\Entity\Config; use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Entity\Tag; @@ -22,7 +23,7 @@ class RuleBasedTaggerTest extends \PHPUnit_Framework_TestCase $this->tagRepository = $this->getTagRepositoryMock(); $this->entryRepository = $this->getEntryRepositoryMock(); - $this->tagger = new RuleBasedTagger($this->rulerz, $this->tagRepository, $this->entryRepository); + $this->tagger = new RuleBasedTagger($this->rulerz, $this->tagRepository, $this->entryRepository, $this->getLogger()); } public function testTagWithNoRule() @@ -209,4 +210,9 @@ class RuleBasedTaggerTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->getMock(); } + + private function getLogger() + { + return new NullLogger(); + } } -- cgit v1.2.3 From a1146b6551da01a1fd2b5711a5cf68fb1791c055 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 12 May 2017 15:01:18 +0200 Subject: Added tests on logs records --- .../CoreBundle/Helper/RuleBasedTaggerTest.php | 25 +++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Helper/RuleBasedTaggerTest.php b/tests/Wallabag/CoreBundle/Helper/RuleBasedTaggerTest.php index 522cf3b3..1e21f400 100644 --- a/tests/Wallabag/CoreBundle/Helper/RuleBasedTaggerTest.php +++ b/tests/Wallabag/CoreBundle/Helper/RuleBasedTaggerTest.php @@ -2,7 +2,8 @@ namespace Tests\Wallabag\CoreBundle\Helper; -use Psr\Log\NullLogger; +use Monolog\Handler\TestHandler; +use Monolog\Logger; use Wallabag\CoreBundle\Entity\Config; use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Entity\Tag; @@ -16,14 +17,19 @@ class RuleBasedTaggerTest extends \PHPUnit_Framework_TestCase private $tagRepository; private $entryRepository; private $tagger; + private $logger; + private $handler; public function setUp() { $this->rulerz = $this->getRulerZMock(); $this->tagRepository = $this->getTagRepositoryMock(); $this->entryRepository = $this->getEntryRepositoryMock(); + $this->logger = $this->getLogger(); + $this->handler = new TestHandler(); + $this->logger->pushHandler($this->handler); - $this->tagger = new RuleBasedTagger($this->rulerz, $this->tagRepository, $this->entryRepository, $this->getLogger()); + $this->tagger = new RuleBasedTagger($this->rulerz, $this->tagRepository, $this->entryRepository, $this->logger); } public function testTagWithNoRule() @@ -33,6 +39,8 @@ class RuleBasedTaggerTest extends \PHPUnit_Framework_TestCase $this->tagger->tag($entry); $this->assertTrue($entry->getTags()->isEmpty()); + $records = $this->handler->getRecords(); + $this->assertCount(0, $records); } public function testTagWithNoMatchingRule() @@ -50,6 +58,8 @@ class RuleBasedTaggerTest extends \PHPUnit_Framework_TestCase $this->tagger->tag($entry); $this->assertTrue($entry->getTags()->isEmpty()); + $records = $this->handler->getRecords(); + $this->assertCount(0, $records); } public function testTagWithAMatchingRule() @@ -71,6 +81,9 @@ class RuleBasedTaggerTest extends \PHPUnit_Framework_TestCase $tags = $entry->getTags(); $this->assertSame('foo', $tags[0]->getLabel()); $this->assertSame('bar', $tags[1]->getLabel()); + + $records = $this->handler->getRecords(); + $this->assertCount(1, $records); } public function testTagWithAMixOfMatchingRules() @@ -91,6 +104,8 @@ class RuleBasedTaggerTest extends \PHPUnit_Framework_TestCase $tags = $entry->getTags(); $this->assertSame('foo', $tags[0]->getLabel()); + $records = $this->handler->getRecords(); + $this->assertCount(1, $records); } public function testWhenTheTagExists() @@ -119,6 +134,8 @@ class RuleBasedTaggerTest extends \PHPUnit_Framework_TestCase $tags = $entry->getTags(); $this->assertSame($tag, $tags[0]); + $records = $this->handler->getRecords(); + $this->assertCount(1, $records); } public function testSameTagWithDifferentfMatchingRules() @@ -139,6 +156,8 @@ class RuleBasedTaggerTest extends \PHPUnit_Framework_TestCase $tags = $entry->getTags(); $this->assertCount(1, $tags); + $records = $this->handler->getRecords(); + $this->assertCount(2, $records); } public function testTagAllEntriesForAUser() @@ -213,6 +232,6 @@ class RuleBasedTaggerTest extends \PHPUnit_Framework_TestCase private function getLogger() { - return new NullLogger(); + return new Logger('foo'); } } -- cgit v1.2.3 From be085c3d18f7c788b0931228b3d990661ae703e0 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 19 May 2017 12:41:31 +0200 Subject: Ensure download_images_enabled is disabled Even if the tests fail, that config must stay disabled after the test. Otherwise it might timeout on other test (because it'll try to save all other images) --- .../CoreBundle/Controller/EntryControllerTest.php | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index 19c8698e..116e5f32 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php @@ -8,8 +8,24 @@ use Wallabag\CoreBundle\Entity\Entry; class EntryControllerTest extends WallabagCoreTestCase { + public $downloadImagesEnabled = false; public $url = 'http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html'; + /** + * @after + * + * Ensure download_images_enabled is disabled after each script + */ + public function tearDownImagesEnabled() + { + if ($this->downloadImagesEnabled) { + $client = static::createClient(); + $client->getContainer()->get('craue_config')->set('download_images_enabled', 0); + + $this->downloadImagesEnabled = false; + } + } + public function testLogin() { $client = $this->getClient(); @@ -905,6 +921,7 @@ class EntryControllerTest extends WallabagCoreTestCase public function testNewEntryWithDownloadImagesEnabled() { + $this->downloadImagesEnabled = true; $this->logInAs('admin'); $client = $this->getClient(); @@ -935,7 +952,8 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $entry); $this->assertEquals($url, $entry->getUrl()); $this->assertContains('Perpignan', $entry->getTitle()); - $this->assertContains('/c4789a7f.jpeg', $entry->getContent()); + // instead of checking for the filename (which might change) check that the image is now local + $this->assertContains('http://v2.wallabag.org/assets/images/', $entry->getContent()); $client->getContainer()->get('craue_config')->set('download_images_enabled', 0); } @@ -945,6 +963,7 @@ class EntryControllerTest extends WallabagCoreTestCase */ public function testRemoveEntryWithDownloadImagesEnabled() { + $this->downloadImagesEnabled = true; $this->logInAs('admin'); $client = $this->getClient(); -- cgit v1.2.3 From 6bc6fb1f60e7b81a21f844dca025671a2f4a4564 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Sat, 27 May 2017 22:08:14 +0200 Subject: Move Tags assigner to a separate file Signed-off-by: Thomas Citharel --- .../CoreBundle/Helper/ContentProxyTest.php | 139 ++------------------- .../CoreBundle/Helper/TagsAssignerTest.php | 114 +++++++++++++++++ 2 files changed, 124 insertions(+), 129 deletions(-) create mode 100644 tests/Wallabag/CoreBundle/Helper/TagsAssignerTest.php (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php index 8abb1bbb..6494f348 100644 --- a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php +++ b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php @@ -7,6 +7,8 @@ use Wallabag\CoreBundle\Helper\ContentProxy; use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Entity\Tag; use Wallabag\UserBundle\Entity\User; +use Wallabag\CoreBundle\Repository\TagRepository; +use Wallabag\CoreBundle\Helper\RuleBasedTagger; class ContentProxyTest extends \PHPUnit_Framework_TestCase { @@ -33,7 +35,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase 'language' => '', ]); - $proxy = new ContentProxy($graby, $tagger, $this->getTagRepositoryMock(), $this->getLogger(), $this->fetchingErrorMessage); + $proxy = new ContentProxy($graby, $tagger, $this->getLogger(), $this->fetchingErrorMessage); $entry = $proxy->updateEntry(new Entry(new User()), 'http://user@:80'); $this->assertEquals('http://user@:80', $entry->getUrl()); @@ -67,7 +69,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase 'language' => '', ]); - $proxy = new ContentProxy($graby, $tagger, $this->getTagRepositoryMock(), $this->getLogger(), $this->fetchingErrorMessage); + $proxy = new ContentProxy($graby, $tagger, $this->getLogger(), $this->fetchingErrorMessage); $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0'); $this->assertEquals('http://0.0.0.0', $entry->getUrl()); @@ -106,7 +108,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase ], ]); - $proxy = new ContentProxy($graby, $tagger, $this->getTagRepositoryMock(), $this->getLogger(), $this->fetchingErrorMessage); + $proxy = new ContentProxy($graby, $tagger, $this->getLogger(), $this->fetchingErrorMessage); $entry = $proxy->updateEntry(new Entry(new User()), 'http://domain.io'); $this->assertEquals('http://domain.io', $entry->getUrl()); @@ -147,7 +149,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase ], ]); - $proxy = new ContentProxy($graby, $tagger, $this->getTagRepositoryMock(), $this->getLogger(), $this->fetchingErrorMessage); + $proxy = new ContentProxy($graby, $tagger, $this->getLogger(), $this->fetchingErrorMessage); $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0'); $this->assertEquals('http://1.1.1.1', $entry->getUrl()); @@ -188,7 +190,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase ], ]); - $proxy = new ContentProxy($graby, $tagger, $this->getTagRepositoryMock(), $this->getLogger(), $this->fetchingErrorMessage); + $proxy = new ContentProxy($graby, $tagger, $this->getLogger(), $this->fetchingErrorMessage); $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0'); $this->assertEquals('http://1.1.1.1', $entry->getUrl()); @@ -210,7 +212,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase $graby = $this->getMockBuilder('Graby\Graby')->getMock(); - $proxy = new ContentProxy($graby, $tagger, $this->getTagRepositoryMock(), $this->getLogger(), $this->fetchingErrorMessage); + $proxy = new ContentProxy($graby, $tagger, $this->getLogger(), $this->fetchingErrorMessage); $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0', [ 'html' => str_repeat('this is my content', 325), 'title' => 'this is my title', @@ -239,8 +241,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase ->method('tag') ->will($this->throwException(new \Exception())); - $tagRepo = $this->getTagRepositoryMock(); - $proxy = new ContentProxy($graby, $tagger, $tagRepo, $this->getLogger(), $this->fetchingErrorMessage); + $proxy = new ContentProxy($graby, $tagger, $this->getLogger(), $this->fetchingErrorMessage); $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0', [ 'html' => str_repeat('this is my content', 325), @@ -253,134 +254,14 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase $this->assertCount(0, $entry->getTags()); } - public function testAssignTagsWithArrayAndExtraSpaces() - { - $graby = $this->getMockBuilder('Graby\Graby') - ->disableOriginalConstructor() - ->getMock(); - - $tagRepo = $this->getTagRepositoryMock(); - $proxy = new ContentProxy($graby, $this->getTaggerMock(), $tagRepo, $this->getLogger(), $this->fetchingErrorMessage); - - $entry = new Entry(new User()); - - $proxy->assignTagsToEntry($entry, [' tag1', 'tag2 ']); - - $this->assertCount(2, $entry->getTags()); - $this->assertEquals('tag1', $entry->getTags()[0]->getLabel()); - $this->assertEquals('tag2', $entry->getTags()[1]->getLabel()); - } - - public function testAssignTagsWithString() - { - $graby = $this->getMockBuilder('Graby\Graby') - ->disableOriginalConstructor() - ->getMock(); - - $tagRepo = $this->getTagRepositoryMock(); - $proxy = new ContentProxy($graby, $this->getTaggerMock(), $tagRepo, $this->getLogger(), $this->fetchingErrorMessage); - - $entry = new Entry(new User()); - - $proxy->assignTagsToEntry($entry, 'tag1, tag2'); - - $this->assertCount(2, $entry->getTags()); - $this->assertEquals('tag1', $entry->getTags()[0]->getLabel()); - $this->assertEquals('tag2', $entry->getTags()[1]->getLabel()); - } - - public function testAssignTagsWithEmptyArray() - { - $graby = $this->getMockBuilder('Graby\Graby') - ->disableOriginalConstructor() - ->getMock(); - - $tagRepo = $this->getTagRepositoryMock(); - $proxy = new ContentProxy($graby, $this->getTaggerMock(), $tagRepo, $this->getLogger(), $this->fetchingErrorMessage); - - $entry = new Entry(new User()); - - $proxy->assignTagsToEntry($entry, []); - - $this->assertCount(0, $entry->getTags()); - } - - public function testAssignTagsWithEmptyString() - { - $graby = $this->getMockBuilder('Graby\Graby') - ->disableOriginalConstructor() - ->getMock(); - - $tagRepo = $this->getTagRepositoryMock(); - $proxy = new ContentProxy($graby, $this->getTaggerMock(), $tagRepo, $this->getLogger(), $this->fetchingErrorMessage); - - $entry = new Entry(new User()); - - $proxy->assignTagsToEntry($entry, ''); - - $this->assertCount(0, $entry->getTags()); - } - - public function testAssignTagsAlreadyAssigned() - { - $graby = $this->getMockBuilder('Graby\Graby') - ->disableOriginalConstructor() - ->getMock(); - - $tagRepo = $this->getTagRepositoryMock(); - $proxy = new ContentProxy($graby, $this->getTaggerMock(), $tagRepo, $this->getLogger(), $this->fetchingErrorMessage); - - $tagEntity = new Tag(); - $tagEntity->setLabel('tag1'); - - $entry = new Entry(new User()); - $entry->addTag($tagEntity); - - $proxy->assignTagsToEntry($entry, 'tag1, tag2'); - - $this->assertCount(2, $entry->getTags()); - $this->assertEquals('tag1', $entry->getTags()[0]->getLabel()); - $this->assertEquals('tag2', $entry->getTags()[1]->getLabel()); - } - - public function testAssignTagsNotFlushed() - { - $graby = $this->getMockBuilder('Graby\Graby') - ->disableOriginalConstructor() - ->getMock(); - - $tagRepo = $this->getTagRepositoryMock(); - $tagRepo->expects($this->never()) - ->method('__call'); - - $proxy = new ContentProxy($graby, $this->getTaggerMock(), $tagRepo, $this->getLogger(), $this->fetchingErrorMessage); - - $tagEntity = new Tag(); - $tagEntity->setLabel('tag1'); - - $entry = new Entry(new User()); - - $proxy->assignTagsToEntry($entry, 'tag1', [$tagEntity]); - - $this->assertCount(1, $entry->getTags()); - $this->assertEquals('tag1', $entry->getTags()[0]->getLabel()); - } - private function getTaggerMock() { - return $this->getMockBuilder('Wallabag\CoreBundle\Helper\RuleBasedTagger') + return $this->getMockBuilder(RuleBasedTagger::class) ->setMethods(['tag']) ->disableOriginalConstructor() ->getMock(); } - private function getTagRepositoryMock() - { - return $this->getMockBuilder('Wallabag\CoreBundle\Repository\TagRepository') - ->disableOriginalConstructor() - ->getMock(); - } - private function getLogger() { return new NullLogger(); diff --git a/tests/Wallabag/CoreBundle/Helper/TagsAssignerTest.php b/tests/Wallabag/CoreBundle/Helper/TagsAssignerTest.php new file mode 100644 index 00000000..bc59eeab --- /dev/null +++ b/tests/Wallabag/CoreBundle/Helper/TagsAssignerTest.php @@ -0,0 +1,114 @@ +getTagRepositoryMock(); + $tagsAssigner = new TagsAssigner($tagRepo); + + $entry = new Entry(new User()); + + $tagsAssigner->assignTagsToEntry($entry, [' tag1', 'tag2 ']); + + $this->assertCount(2, $entry->getTags()); + $this->assertEquals('tag1', $entry->getTags()[0]->getLabel()); + $this->assertEquals('tag2', $entry->getTags()[1]->getLabel()); + } + + public function testAssignTagsWithString() + { + $tagRepo = $this->getTagRepositoryMock(); + $tagsAssigner = new TagsAssigner($tagRepo); + + $entry = new Entry(new User()); + + $tagsAssigner->assignTagsToEntry($entry, 'tag1, tag2'); + + $this->assertCount(2, $entry->getTags()); + $this->assertEquals('tag1', $entry->getTags()[0]->getLabel()); + $this->assertEquals('tag2', $entry->getTags()[1]->getLabel()); + } + + public function testAssignTagsWithEmptyArray() + { + $tagRepo = $this->getTagRepositoryMock(); + $tagsAssigner = new TagsAssigner($tagRepo); + + $entry = new Entry(new User()); + + $tagsAssigner->assignTagsToEntry($entry, []); + + $this->assertCount(0, $entry->getTags()); + } + + public function testAssignTagsWithEmptyString() + { + $tagRepo = $this->getTagRepositoryMock(); + $tagsAssigner = new TagsAssigner($tagRepo); + + $entry = new Entry(new User()); + + $tagsAssigner->assignTagsToEntry($entry, ''); + + $this->assertCount(0, $entry->getTags()); + } + + public function testAssignTagsAlreadyAssigned() + { + $tagRepo = $this->getTagRepositoryMock(); + $tagsAssigner = new TagsAssigner($tagRepo); + + $tagEntity = new Tag(); + $tagEntity->setLabel('tag1'); + + $entry = new Entry(new User()); + $entry->addTag($tagEntity); + + $tagsAssigner->assignTagsToEntry($entry, 'tag1, tag2'); + + $this->assertCount(2, $entry->getTags()); + $this->assertEquals('tag1', $entry->getTags()[0]->getLabel()); + $this->assertEquals('tag2', $entry->getTags()[1]->getLabel()); + } + + public function testAssignTagsNotFlushed() + { + + $tagRepo = $this->getTagRepositoryMock(); + $tagRepo->expects($this->never()) + ->method('__call'); + + $tagsAssigner = new TagsAssigner($tagRepo); + + $tagEntity = new Tag(); + $tagEntity->setLabel('tag1'); + + $entry = new Entry(new User()); + + $tagsAssigner->assignTagsToEntry($entry, 'tag1', [$tagEntity]); + + $this->assertCount(1, $entry->getTags()); + $this->assertEquals('tag1', $entry->getTags()[0]->getLabel()); + } + + private function getTagRepositoryMock() + { + return $this->getMockBuilder(TagRepository::class) + ->disableOriginalConstructor() + ->getMock(); + } +} -- cgit v1.2.3 From de8d2a9005321a935e52f4471f031f73bb240412 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Sun, 28 May 2017 12:59:48 +0200 Subject: CS Signed-off-by: Thomas Citharel --- tests/Wallabag/CoreBundle/Helper/TagsAssignerTest.php | 6 ------ 1 file changed, 6 deletions(-) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Helper/TagsAssignerTest.php b/tests/Wallabag/CoreBundle/Helper/TagsAssignerTest.php index bc59eeab..6d6d6484 100644 --- a/tests/Wallabag/CoreBundle/Helper/TagsAssignerTest.php +++ b/tests/Wallabag/CoreBundle/Helper/TagsAssignerTest.php @@ -2,21 +2,16 @@ namespace Tests\Wallabag\CoreBundle\Helper; -use Psr\Log\NullLogger; -use Wallabag\CoreBundle\Helper\ContentProxy; use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Entity\Tag; use Wallabag\CoreBundle\Helper\TagsAssigner; use Wallabag\UserBundle\Entity\User; use Wallabag\CoreBundle\Repository\TagRepository; -use Wallabag\CoreBundle\Helper\RuleBasedTagger; class TagsAssignerTest extends \PHPUnit_Framework_TestCase { - public function testAssignTagsWithArrayAndExtraSpaces() { - $tagRepo = $this->getTagRepositoryMock(); $tagsAssigner = new TagsAssigner($tagRepo); @@ -87,7 +82,6 @@ class TagsAssignerTest extends \PHPUnit_Framework_TestCase public function testAssignTagsNotFlushed() { - $tagRepo = $this->getTagRepositoryMock(); $tagRepo->expects($this->never()) ->method('__call'); -- cgit v1.2.3 From 26650fdbf8af8d716e712e9c9c8474b42f90722d Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Tue, 30 May 2017 12:47:25 +0200 Subject: Use a better way to set input for command Actually use the correct to way handle that http://symfony.com/doc/current/components/console/helpers/questionhelper.html#testing-a-command-that-expects-input --- .../CoreBundle/Command/InstallCommandTest.php | 106 ++++++--------------- 1 file changed, 30 insertions(+), 76 deletions(-) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php index 122a87d4..71c2ffc6 100644 --- a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php @@ -67,18 +67,14 @@ class InstallCommandTest extends WallabagCoreTestCase $command = $application->find('wallabag:install'); - // We mock the QuestionHelper - $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper') - ->disableOriginalConstructor() - ->getMock(); - $question->expects($this->any()) - ->method('ask') - ->will($this->returnValue('yes_'.uniqid('', true))); - - // We override the standard helper with our mock - $command->getHelperSet()->set($question, 'question'); - $tester = new CommandTester($command); + $tester->setInputs([ + 'y', // dropping database + 'y', // create super admin + 'username_'.uniqid('', true), // username + 'password_'.uniqid('', true), // password + 'email_'.uniqid('', true).'@wallabag.it', // email + ]); $tester->execute([ 'command' => $command->getName(), ]); @@ -97,18 +93,13 @@ class InstallCommandTest extends WallabagCoreTestCase $command = $application->find('wallabag:install'); - // We mock the QuestionHelper - $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper') - ->disableOriginalConstructor() - ->getMock(); - $question->expects($this->any()) - ->method('ask') - ->will($this->returnValue('yes_'.uniqid('', true))); - - // We override the standard helper with our mock - $command->getHelperSet()->set($question, 'question'); - $tester = new CommandTester($command); + $tester->setInputs([ + 'y', // create super admin + 'username_'.uniqid('', true), // username + 'password_'.uniqid('', true), // password + 'email_'.uniqid('', true).'@wallabag.it', // email + ]); $tester->execute([ 'command' => $command->getName(), '--reset' => true, @@ -150,18 +141,13 @@ class InstallCommandTest extends WallabagCoreTestCase $command = $application->find('wallabag:install'); - // We mock the QuestionHelper - $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper') - ->disableOriginalConstructor() - ->getMock(); - $question->expects($this->any()) - ->method('ask') - ->will($this->returnValue('yes_'.uniqid('', true))); - - // We override the standard helper with our mock - $command->getHelperSet()->set($question, 'question'); - $tester = new CommandTester($command); + $tester->setInputs([ + 'y', // create super admin + 'username_'.uniqid('', true), // username + 'password_'.uniqid('', true), // password + 'email_'.uniqid('', true).'@wallabag.it', // email + ]); $tester->execute([ 'command' => $command->getName(), ]); @@ -183,23 +169,12 @@ class InstallCommandTest extends WallabagCoreTestCase $command = $application->find('wallabag:install'); - // We mock the QuestionHelper - $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper') - ->disableOriginalConstructor() - ->getMock(); - - $question->expects($this->exactly(3)) - ->method('ask') - ->will($this->onConsecutiveCalls( - false, // don't want to reset the entire database - true, // do want to reset the schema - false // don't want to create a new user - )); - - // We override the standard helper with our mock - $command->getHelperSet()->set($question, 'question'); - $tester = new CommandTester($command); + $tester->setInputs([ + 'n', // don't want to reset the entire database + 'y', // do want to reset the schema + 'n', // don't want to create a new user + ]); $tester->execute([ 'command' => $command->getName(), ]); @@ -239,22 +214,11 @@ class InstallCommandTest extends WallabagCoreTestCase $command = $application->find('wallabag:install'); - // We mock the QuestionHelper - $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper') - ->disableOriginalConstructor() - ->getMock(); - - $question->expects($this->exactly(2)) - ->method('ask') - ->will($this->onConsecutiveCalls( - false, // don't want to reset the entire database - false // don't want to create a new user - )); - - // We override the standard helper with our mock - $command->getHelperSet()->set($question, 'question'); - $tester = new CommandTester($command); + $tester->setInputs([ + 'n', // don't want to reset the entire database + 'n', // don't want to create a new user + ]); $tester->execute([ 'command' => $command->getName(), ]); @@ -275,21 +239,11 @@ class InstallCommandTest extends WallabagCoreTestCase $command = $application->find('wallabag:install'); - // We mock the QuestionHelper - $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper') - ->disableOriginalConstructor() - ->getMock(); - $question->expects($this->any()) - ->method('ask') - ->will($this->returnValue('yes_'.uniqid('', true))); - - // We override the standard helper with our mock - $command->getHelperSet()->set($question, 'question'); - $tester = new CommandTester($command); $tester->execute([ 'command' => $command->getName(), - '--no-interaction' => true, + ], [ + 'interactive' => false, ]); $this->assertContains('Checking system requirements.', $tester->getDisplay()); -- cgit v1.2.3 From 5dbf3f2326c4054782304b9a41d773a1100acf48 Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Sun, 21 May 2017 16:35:06 +0200 Subject: TagController: ignore ActionMarkAsRead when removing tag from entry Fixes #2835 Signed-off-by: Kevin Decherf --- .../CoreBundle/Controller/TagControllerTest.php | 4 ++++ tests/Wallabag/CoreBundle/Helper/RedirectTest.php | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php index c3b22dcd..e36d3924 100644 --- a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php @@ -126,9 +126,13 @@ class TagControllerTest extends WallabagCoreTestCase ->getRepository('WallabagCoreBundle:Tag') ->findOneByEntryAndTagLabel($entry, $this->tagName); + // We make a first request to set an history and test redirection after tag deletion + $client->request('GET', '/view/'.$entry->getId()); + $entryUri = $client->getRequest()->getUri(); $client->request('GET', '/remove-tag/'.$entry->getId().'/'.$tag->getId()); $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertEquals($entryUri, $client->getResponse()->getTargetUrl()); $this->assertNotContains($this->tagName, $entry->getTags()); diff --git a/tests/Wallabag/CoreBundle/Helper/RedirectTest.php b/tests/Wallabag/CoreBundle/Helper/RedirectTest.php index 0539f20a..f420d06a 100644 --- a/tests/Wallabag/CoreBundle/Helper/RedirectTest.php +++ b/tests/Wallabag/CoreBundle/Helper/RedirectTest.php @@ -89,4 +89,22 @@ class RedirectTest extends \PHPUnit_Framework_TestCase $this->assertEquals($this->routerMock->generate('homepage'), $redirectUrl); } + + public function testUserForRedirectWithIgnoreActionMarkAsRead() + { + $this->token->getUser()->getConfig()->setActionMarkAsRead(Config::REDIRECT_TO_HOMEPAGE); + + $redirectUrl = $this->redirect->to('/unread/list', '', true); + + $this->assertEquals('/unread/list', $redirectUrl); + } + + public function testUserForRedirectNullWithFallbackWithIgnoreActionMarkAsRead() + { + $this->token->getUser()->getConfig()->setActionMarkAsRead(Config::REDIRECT_TO_HOMEPAGE); + + $redirectUrl = $this->redirect->to(null, 'fallback', true); + + $this->assertEquals('fallback', $redirectUrl); + } } -- cgit v1.2.3 From bad7df8c0048285e7a6bd539e5e501ce6675d663 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Wed, 31 May 2017 10:38:15 +0200 Subject: CS & improve tags assertions --- tests/Wallabag/CoreBundle/Command/ExportCommandTest.php | 2 +- tests/Wallabag/CoreBundle/Command/TagAllCommandTest.php | 2 +- tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php | 1 - .../CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php | 2 +- 4 files changed, 3 insertions(+), 4 deletions(-) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Command/ExportCommandTest.php b/tests/Wallabag/CoreBundle/Command/ExportCommandTest.php index b21f3318..284efac4 100644 --- a/tests/Wallabag/CoreBundle/Command/ExportCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/ExportCommandTest.php @@ -10,7 +10,7 @@ use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; class ExportCommandTest extends WallabagCoreTestCase { /** - * @expectedException Symfony\Component\Console\Exception\RuntimeException + * @expectedException \Symfony\Component\Console\Exception\RuntimeException * @expectedExceptionMessage Not enough arguments (missing: "username") */ public function testExportCommandWithoutUsername() diff --git a/tests/Wallabag/CoreBundle/Command/TagAllCommandTest.php b/tests/Wallabag/CoreBundle/Command/TagAllCommandTest.php index ec31708f..4cde3679 100644 --- a/tests/Wallabag/CoreBundle/Command/TagAllCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/TagAllCommandTest.php @@ -10,7 +10,7 @@ use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; class TagAllCommandTest extends WallabagCoreTestCase { /** - * @expectedException Symfony\Component\Console\Exception\RuntimeException + * @expectedException \Symfony\Component\Console\Exception\RuntimeException * @expectedExceptionMessage Not enough arguments (missing: "username") */ public function testRunTagAllCommandWithoutUsername() diff --git a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php index 77dfd5bf..44fca073 100644 --- a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php +++ b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php @@ -7,7 +7,6 @@ use Wallabag\CoreBundle\Helper\ContentProxy; use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Entity\Tag; use Wallabag\UserBundle\Entity\User; -use Wallabag\CoreBundle\Repository\TagRepository; use Wallabag\CoreBundle\Helper\RuleBasedTagger; class ContentProxyTest extends \PHPUnit_Framework_TestCase diff --git a/tests/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php b/tests/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php index 2e6fccfb..ca8e0d50 100644 --- a/tests/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php +++ b/tests/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php @@ -136,7 +136,7 @@ class UsernameRssTokenConverterTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException Symfony\Component\HttpKernel\Exception\NotFoundHttpException + * @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException * @expectedExceptionMessage User not found */ public function testApplyUserNotFound() -- cgit v1.2.3 From 31485bddb98a2a1b434e62e02ffd79614eca9db8 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Wed, 31 May 2017 11:11:02 +0200 Subject: Ensure retrieved data are fresh --- tests/Wallabag/CoreBundle/Controller/TagControllerTest.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php index e36d3924..80611a87 100644 --- a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php @@ -134,6 +134,12 @@ class TagControllerTest extends WallabagCoreTestCase $this->assertEquals(302, $client->getResponse()->getStatusCode()); $this->assertEquals($entryUri, $client->getResponse()->getTargetUrl()); + // re-retrieve the entry to be sure to get fresh data from database (mostly for tags) + $entry = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId()); + $this->assertNotContains($this->tagName, $entry->getTags()); $client->request('GET', '/remove-tag/'.$entry->getId().'/'.$tag->getId()); -- cgit v1.2.3 From 74a75f7d430eb7a69cd377194e52012db34d39b4 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 12 May 2017 07:53:21 +0200 Subject: Use graby ContentExtractor to clean html It might be better to re-use some graby functionalities to clean html instead of building a new system. --- .../CoreBundle/Helper/ContentProxyTest.php | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php index 44fca073..7a50b373 100644 --- a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php +++ b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php @@ -8,6 +8,7 @@ use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Entity\Tag; use Wallabag\UserBundle\Entity\User; use Wallabag\CoreBundle\Helper\RuleBasedTagger; +use Graby\Graby; class ContentProxyTest extends \PHPUnit_Framework_TestCase { @@ -253,6 +254,60 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase $this->assertCount(0, $entry->getTags()); } + public function dataForCrazyHtml() + { + return [ + 'script and comment' => [ + 'Script inside:
', + 'lol' + ], + 'script' => [ + 'Script inside:', + 'script' + ], + ]; + } + + /** + * @dataProvider dataForCrazyHtml + */ + public function testWithCrazyHtmlContent($html, $escapedString) + { + $tagger = $this->getTaggerMock(); + $tagger->expects($this->once()) + ->method('tag'); + + $graby = new Graby(); + + $proxy = new ContentProxy($graby, $tagger, $this->getTagRepositoryMock(), $this->getLogger(), $this->fetchingErrorMessage); + $entry = $proxy->updateEntry( + new Entry(new User()), + 'http://1.1.1.1', + [ + 'html' => $html, + 'title' => 'this is my title', + 'url' => 'http://1.1.1.1', + 'content_type' => 'text/html', + 'language' => 'fr', + 'status' => '200', + 'open_graph' => [ + 'og_title' => 'my OG title', + 'og_description' => 'OG desc', + 'og_image' => 'http://3.3.3.3/cover.jpg', + ], + ] + ); + + $this->assertEquals('http://1.1.1.1', $entry->getUrl()); + $this->assertEquals('this is my title', $entry->getTitle()); + $this->assertNotContains($escapedString, $entry->getContent()); + $this->assertEquals('http://3.3.3.3/cover.jpg', $entry->getPreviewPicture()); + $this->assertEquals('text/html', $entry->getMimetype()); + $this->assertEquals('fr', $entry->getLanguage()); + $this->assertEquals('200', $entry->getHttpStatus()); + $this->assertEquals('1.1.1.1', $entry->getDomainName()); + } + private function getTaggerMock() { return $this->getMockBuilder(RuleBasedTagger::class) -- cgit v1.2.3 From 0d6cfb884c8ef75e4dc5fd667fb9d29702523a2a Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Tue, 16 May 2017 23:11:20 +0200 Subject: Remove htmlawed and use graby instead Instead of using htmlawed (which is already used in graby) use graby directly (which require some refacto on graby side). Still needs some tests. --- .../CoreBundle/Helper/ContentProxyTest.php | 26 +++++++++++----------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php index 7a50b373..11f1d410 100644 --- a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php +++ b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php @@ -210,16 +210,18 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase $tagger->expects($this->once()) ->method('tag'); - $graby = $this->getMockBuilder('Graby\Graby')->getMock(); - - $proxy = new ContentProxy($graby, $tagger, $this->getLogger(), $this->fetchingErrorMessage); - $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0', [ - 'html' => str_repeat('this is my content', 325), - 'title' => 'this is my title', - 'url' => 'http://1.1.1.1', - 'content_type' => 'text/html', - 'language' => 'fr', - ]); + $proxy = new ContentProxy((new Graby()), $tagger, $this->getLogger(), $this->fetchingErrorMessage); + $entry = $proxy->updateEntry( + new Entry(new User()), + 'http://0.0.0.0', + [ + 'html' => str_repeat('this is my content', 325), + 'title' => 'this is my title', + 'url' => 'http://1.1.1.1', + 'content_type' => 'text/html', + 'language' => 'fr', + ] + ); $this->assertEquals('http://1.1.1.1', $entry->getUrl()); $this->assertEquals('this is my title', $entry->getTitle()); @@ -277,9 +279,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase $tagger->expects($this->once()) ->method('tag'); - $graby = new Graby(); - - $proxy = new ContentProxy($graby, $tagger, $this->getTagRepositoryMock(), $this->getLogger(), $this->fetchingErrorMessage); + $proxy = new ContentProxy((new Graby()), $tagger, $this->getLogger(), $this->fetchingErrorMessage); $entry = $proxy->updateEntry( new Entry(new User()), 'http://1.1.1.1', -- cgit v1.2.3 From f0378b4d7c7b8c971239445f3a2a1535abab7d00 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Wed, 24 May 2017 16:44:03 +0200 Subject: Forced date can now be a timestamp too Add adding more tests for forced content --- .../CoreBundle/Helper/ContentProxyTest.php | 81 ++++++++++++++++++++++ 1 file changed, 81 insertions(+) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php index 11f1d410..103acf50 100644 --- a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php +++ b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php @@ -9,6 +9,8 @@ use Wallabag\CoreBundle\Entity\Tag; use Wallabag\UserBundle\Entity\User; use Wallabag\CoreBundle\Helper\RuleBasedTagger; use Graby\Graby; +use Monolog\Handler\TestHandler; +use Monolog\Logger; class ContentProxyTest extends \PHPUnit_Framework_TestCase { @@ -220,6 +222,11 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase 'url' => 'http://1.1.1.1', 'content_type' => 'text/html', 'language' => 'fr', + 'date' => '1395635872', + 'authors' => ['Jeremy', 'Nico', 'Thomas'], + 'all_headers' => [ + 'Cache-Control' => 'no-cache', + ] ] ); @@ -230,6 +237,80 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase $this->assertEquals('fr', $entry->getLanguage()); $this->assertEquals(4.0, $entry->getReadingTime()); $this->assertEquals('1.1.1.1', $entry->getDomainName()); + $this->assertEquals('24/03/2014', $entry->getPublishedAt()->format('d/m/Y')); + $this->assertContains('Jeremy', $entry->getPublishedBy()); + $this->assertContains('Nico', $entry->getPublishedBy()); + $this->assertContains('Thomas', $entry->getPublishedBy()); + $this->assertContains('no-cache', $entry->getHeaders()); + } + + public function testWithForcedContentAndDatetime() + { + $tagger = $this->getTaggerMock(); + $tagger->expects($this->once()) + ->method('tag'); + + $proxy = new ContentProxy((new Graby()), $tagger, $this->getTagRepositoryMock(), $this->getLogger(), $this->fetchingErrorMessage); + $entry = $proxy->updateEntry( + new Entry(new User()), + 'http://0.0.0.0', + [ + 'html' => str_repeat('this is my content', 325), + 'title' => 'this is my title', + 'url' => 'http://1.1.1.1', + 'content_type' => 'text/html', + 'language' => 'fr', + 'date' => '2016-09-08T11:55:58+0200', + ] + ); + + $this->assertEquals('http://1.1.1.1', $entry->getUrl()); + $this->assertEquals('this is my title', $entry->getTitle()); + $this->assertContains('this is my content', $entry->getContent()); + $this->assertEquals('text/html', $entry->getMimetype()); + $this->assertEquals('fr', $entry->getLanguage()); + $this->assertEquals(4.0, $entry->getReadingTime()); + $this->assertEquals('1.1.1.1', $entry->getDomainName()); + $this->assertEquals('08/09/2016', $entry->getPublishedAt()->format('d/m/Y')); + } + + public function testWithForcedContentAndBadDate() + { + $tagger = $this->getTaggerMock(); + $tagger->expects($this->once()) + ->method('tag'); + + $logger = new Logger('foo'); + $handler = new TestHandler(); + $logger->pushHandler($handler); + + $proxy = new ContentProxy((new Graby()), $tagger, $this->getTagRepositoryMock(), $logger, $this->fetchingErrorMessage); + $entry = $proxy->updateEntry( + new Entry(new User()), + 'http://0.0.0.0', + [ + 'html' => str_repeat('this is my content', 325), + 'title' => 'this is my title', + 'url' => 'http://1.1.1.1', + 'content_type' => 'text/html', + 'language' => 'fr', + 'date' => '01 02 2012', + ] + ); + + $this->assertEquals('http://1.1.1.1', $entry->getUrl()); + $this->assertEquals('this is my title', $entry->getTitle()); + $this->assertContains('this is my content', $entry->getContent()); + $this->assertEquals('text/html', $entry->getMimetype()); + $this->assertEquals('fr', $entry->getLanguage()); + $this->assertEquals(4.0, $entry->getReadingTime()); + $this->assertEquals('1.1.1.1', $entry->getDomainName()); + $this->assertNull($entry->getPublishedAt()); + + $records = $handler->getRecords(); + + $this->assertCount(1, $records); + $this->assertContains('Error while defining date', $records[0]['message']); } public function testTaggerThrowException() -- cgit v1.2.3 From 38a04dee3459c040ff47aa5a62307efe72bcae00 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Mon, 29 May 2017 10:14:01 +0200 Subject: CS --- tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php index 103acf50..aba3bebc 100644 --- a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php +++ b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php @@ -226,7 +226,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase 'authors' => ['Jeremy', 'Nico', 'Thomas'], 'all_headers' => [ 'Cache-Control' => 'no-cache', - ] + ], ] ); @@ -342,11 +342,11 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase return [ 'script and comment' => [ 'Script inside:
', - 'lol' + 'lol', ], 'script' => [ 'Script inside:', - 'script' + 'script', ], ]; } -- cgit v1.2.3 From 695af5885702b5219ee4c7ac78c1b6c406263168 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Tue, 30 May 2017 10:08:50 +0200 Subject: Fix tests following rebase --- tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php index aba3bebc..0c715d90 100644 --- a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php +++ b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php @@ -250,7 +250,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase $tagger->expects($this->once()) ->method('tag'); - $proxy = new ContentProxy((new Graby()), $tagger, $this->getTagRepositoryMock(), $this->getLogger(), $this->fetchingErrorMessage); + $proxy = new ContentProxy((new Graby()), $tagger, $this->getLogger(), $this->fetchingErrorMessage); $entry = $proxy->updateEntry( new Entry(new User()), 'http://0.0.0.0', @@ -284,7 +284,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase $handler = new TestHandler(); $logger->pushHandler($handler); - $proxy = new ContentProxy((new Graby()), $tagger, $this->getTagRepositoryMock(), $logger, $this->fetchingErrorMessage); + $proxy = new ContentProxy((new Graby()), $tagger, $logger, $this->fetchingErrorMessage); $entry = $proxy->updateEntry( new Entry(new User()), 'http://0.0.0.0', -- cgit v1.2.3 From 7ab5eb9508921d84b4b4ec84a59135d536da748e Mon Sep 17 00:00:00 2001 From: adev Date: Mon, 15 May 2017 20:47:59 +0200 Subject: Isolated tests Use https://github.com/dmaicher/doctrine-test-bundle to have test isolation. --- .../CoreBundle/Command/ExportCommandTest.php | 2 +- .../CoreBundle/Command/InstallCommandTest.php | 67 ++-- .../CoreBundle/Controller/ConfigControllerTest.php | 11 + .../CoreBundle/Controller/EntryControllerTest.php | 359 ++++++++++++--------- .../CoreBundle/Controller/ExportControllerTest.php | 2 +- .../CoreBundle/Controller/TagControllerTest.php | 59 ++-- tests/Wallabag/CoreBundle/WallabagCoreTestCase.php | 76 ++++- 7 files changed, 357 insertions(+), 219 deletions(-) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Command/ExportCommandTest.php b/tests/Wallabag/CoreBundle/Command/ExportCommandTest.php index 284efac4..2eebf39b 100644 --- a/tests/Wallabag/CoreBundle/Command/ExportCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/ExportCommandTest.php @@ -55,7 +55,7 @@ class ExportCommandTest extends WallabagCoreTestCase 'username' => 'admin', ]); - $this->assertContains('Exporting 6 entrie(s) for user « admin »... Done', $tester->getDisplay()); + $this->assertContains('Exporting 5 entrie(s) for user « admin »... Done', $tester->getDisplay()); $this->assertFileExists('admin-export.json'); } diff --git a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php index 71c2ffc6..94fc0b94 100644 --- a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php @@ -2,8 +2,11 @@ namespace Tests\Wallabag\CoreBundle\Command; +use DAMA\DoctrineTestBundle\Doctrine\DBAL\StaticDriver; use Doctrine\Bundle\DoctrineBundle\Command\CreateDatabaseDoctrineCommand; use Doctrine\Bundle\DoctrineBundle\Command\DropDatabaseDoctrineCommand; +use Doctrine\DBAL\Platforms\PostgreSqlPlatform; +use Doctrine\DBAL\Platforms\SqlitePlatform; use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Output\NullOutput; @@ -18,7 +21,9 @@ class InstallCommandTest extends WallabagCoreTestCase { parent::setUp(); - if ($this->getClient()->getContainer()->get('doctrine')->getConnection()->getDriver() instanceof \Doctrine\DBAL\Driver\PDOPgSql\Driver) { + /** @var \Doctrine\DBAL\Connection $connection */ + $connection = $this->getClient()->getContainer()->get('doctrine')->getConnection(); + if ($connection->getDatabasePlatform() instanceof PostgreSqlPlatform) { /* * LOG: statement: CREATE DATABASE "wallabag" * ERROR: source database "template1" is being accessed by other users @@ -30,34 +35,44 @@ class InstallCommandTest extends WallabagCoreTestCase */ $this->markTestSkipped('PostgreSQL spotted: can\'t find a good way to drop current database, skipping.'); } - } - /** - * Ensure next tests will have a clean database. - */ - public static function tearDownAfterClass() - { - $application = new Application(static::$kernel); - $application->setAutoExit(false); + if ($connection->getDatabasePlatform() instanceof SqlitePlatform) { + // Environnement variable useful only for sqlite to avoid the error "attempt to write a readonly database" + // We can't define always this environnement variable because pdo_mysql seems to use it + // and we have the error: + // SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; + // check the manual that corresponds to your MariaDB server version for the right syntax to use + // near '/tmp/wallabag_testTYj1kp' at line 1 + $databasePath = tempnam(sys_get_temp_dir(), 'wallabag_test'); + putenv("TEST_DATABASE_PATH=$databasePath"); + + // The environnement has been changed, recreate the client in order to update connection + parent::setUp(); + } - $application->run(new ArrayInput([ - 'command' => 'doctrine:schema:drop', - '--no-interaction' => true, - '--force' => true, - '--env' => 'test', - ]), new NullOutput()); + // disable doctrine-test-bundle + StaticDriver::setKeepStaticConnections(false); - $application->run(new ArrayInput([ - 'command' => 'doctrine:schema:create', - '--no-interaction' => true, - '--env' => 'test', - ]), new NullOutput()); + $this->resetDatabase($this->getClient()); + } - $application->run(new ArrayInput([ - 'command' => 'doctrine:fixtures:load', - '--no-interaction' => true, - '--env' => 'test', - ]), new NullOutput()); + public function tearDown() + { + $databasePath = getenv('TEST_DATABASE_PATH'); + // Remove variable environnement + putenv('TEST_DATABASE_PATH'); + if ($databasePath && file_exists($databasePath)) { + unlink($databasePath); + } else { + // Create a new client to avoid the error: + // Transaction commit failed because the transaction has been marked for rollback only. + $client = static::createClient(); + $this->resetDatabase($client); + } + + // enable doctrine-test-bundle + StaticDriver::setKeepStaticConnections(true); + parent::tearDown(); } public function testRunInstallCommand() @@ -120,7 +135,7 @@ class InstallCommandTest extends WallabagCoreTestCase { // skipped SQLite check when database is removed because while testing for the connection, // the driver will create the file (so the database) before testing if database exist - if ($this->getClient()->getContainer()->get('doctrine')->getConnection()->getDriver() instanceof \Doctrine\DBAL\Driver\PDOSqlite\Driver) { + if ($this->getClient()->getContainer()->get('doctrine')->getConnection()->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\SqlitePlatform) { $this->markTestSkipped('SQLite spotted: can\'t test with database removed.'); } diff --git a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php index 35888f16..5bc815ee 100644 --- a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php @@ -67,8 +67,17 @@ class ConfigControllerTest extends WallabagCoreTestCase public function testChangeReadingSpeed() { $this->logInAs('admin'); + $this->useTheme('baggy'); $client = $this->getClient(); + $entry = new Entry($this->getLoggedInUser()); + $entry->setUrl('http://0.0.0.0/test-entry1') + ->setReadingTime(22); + $this->getEntityManager()->persist($entry); + + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); + $crawler = $client->request('GET', '/unread/list'); $form = $crawler->filter('button[id=submit-filter]')->form(); $dataFilters = [ @@ -409,6 +418,7 @@ class ConfigControllerTest extends WallabagCoreTestCase public function testTaggingRuleCreation() { $this->logInAs('admin'); + $this->useTheme('baggy'); $client = $this->getClient(); $crawler = $client->request('GET', '/config'); @@ -939,6 +949,7 @@ class ConfigControllerTest extends WallabagCoreTestCase public function testSwitchViewMode() { $this->logInAs('admin'); + $this->useTheme('baggy'); $client = $this->getClient(); $client->request('GET', '/unread/list'); diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index 116e5f32..cc7b3672 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php @@ -71,6 +71,7 @@ class EntryControllerTest extends WallabagCoreTestCase public function testGetNew() { $this->logInAs('admin'); + $this->useTheme('baggy'); $client = $this->getClient(); $crawler = $client->request('GET', '/new'); @@ -84,6 +85,7 @@ class EntryControllerTest extends WallabagCoreTestCase public function testPostNewViaBookmarklet() { $this->logInAs('admin'); + $this->useTheme('baggy'); $client = $this->getClient(); $crawler = $client->request('GET', '/'); @@ -195,6 +197,12 @@ class EntryControllerTest extends WallabagCoreTestCase public function testPostNewOkUrlExist() { $this->logInAs('admin'); + + $entry = new Entry($this->getLoggedInUser()); + $entry->setUrl($this->url); + $this->getEntityManager()->persist($entry); + $this->getEntityManager()->flush(); + $client = $this->getClient(); $crawler = $client->request('GET', '/new'); @@ -288,7 +296,7 @@ class EntryControllerTest extends WallabagCoreTestCase $tags = $entry->getTags(); $this->assertCount(2, $tags); - $this->assertEquals('wallabag', $tags[0]->getLabel()); + $this->assertContains('wallabag', $tags); $em->remove($entry); $em->flush(); @@ -317,7 +325,7 @@ class EntryControllerTest extends WallabagCoreTestCase $tags = $entry->getTags(); $this->assertCount(2, $tags); - $this->assertEquals('wallabag', $tags[1]->getLabel()); + $this->assertContains('wallabag', $tags); $em->remove($entry); $em->flush(); @@ -364,24 +372,23 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertEquals('/all/list', $client->getResponse()->getTargetUrl()); } - /** - * @depends testPostNewOk - */ public function testView() { $this->logInAs('admin'); $client = $this->getClient(); - $content = $client->getContainer() - ->get('doctrine.orm.entity_manager') - ->getRepository('WallabagCoreBundle:Entry') - ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); + $entry = new Entry($this->getLoggedInUser()); + $entry->setUrl('http://example.com/foo'); + $entry->setTitle('title foo'); + $entry->setContent('foo bar baz'); + $this->getEntityManager()->persist($entry); + $this->getEntityManager()->flush(); - $crawler = $client->request('GET', '/view/'.$content->getId()); + $crawler = $client->request('GET', '/view/'.$entry->getId()); $this->assertEquals(200, $client->getResponse()->getStatusCode()); $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); - $this->assertContains($content->getTitle(), $body[0]); + $this->assertContains($entry->getTitle(), $body[0]); } /** @@ -394,27 +401,23 @@ class EntryControllerTest extends WallabagCoreTestCase $this->logInAs('admin'); $client = $this->getClient(); - $em = $client->getContainer() - ->get('doctrine.orm.entity_manager'); + $entry = new Entry($this->getLoggedInUser()); + $entry->setUrl($this->url); + $entry->setTitle('title foo'); + $entry->setContent(''); + $this->getEntityManager()->persist($entry); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); - $content = $em - ->getRepository('WallabagCoreBundle:Entry') - ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); - - // empty content - $content->setContent(''); - $em->persist($content); - $em->flush(); - - $client->request('GET', '/reload/'.$content->getId()); + $client->request('GET', '/reload/'.$entry->getId()); $this->assertEquals(302, $client->getResponse()->getStatusCode()); - $content = $em + $entry = $this->getEntityManager() ->getRepository('WallabagCoreBundle:Entry') - ->find($content->getId()); + ->find($entry->getId()); - $this->assertNotEmpty($content->getContent()); + $this->assertNotEmpty($entry->getContent()); } /** @@ -425,32 +428,21 @@ class EntryControllerTest extends WallabagCoreTestCase $this->logInAs('admin'); $client = $this->getClient(); - $em = $client->getContainer() - ->get('doctrine.orm.entity_manager'); - - $content = $em - ->getRepository('WallabagCoreBundle:Entry') - ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); - - // put a known failed url - $content->setUrl('http://0.0.0.0/failed.html'); - $em->persist($content); - $em->flush(); + $entry = new Entry($this->getLoggedInUser()); + $entry->setUrl('http://0.0.0.0/failed.html'); + $this->getEntityManager()->persist($entry); + $this->getEntityManager()->flush(); - $client->request('GET', '/reload/'.$content->getId()); + $client->request('GET', '/reload/'.$entry->getId()); $this->assertEquals(302, $client->getResponse()->getStatusCode()); // force EntityManager to clear previous entity // otherwise, retrieve the same entity will retrieve change from the previous request :0 - $em->clear(); - $newContent = $em + $this->getEntityManager()->clear(); + $newContent = $this->getEntityManager() ->getRepository('WallabagCoreBundle:Entry') - ->find($content->getId()); - - $newContent->setUrl($this->url); - $em->persist($newContent); - $em->flush(); + ->find($entry->getId()); $this->assertNotEquals($client->getContainer()->getParameter('wallabag_core.fetching_error_message'), $newContent->getContent()); } @@ -460,12 +452,12 @@ class EntryControllerTest extends WallabagCoreTestCase $this->logInAs('admin'); $client = $this->getClient(); - $content = $client->getContainer() - ->get('doctrine.orm.entity_manager') - ->getRepository('WallabagCoreBundle:Entry') - ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); + $entry = new Entry($this->getLoggedInUser()); + $entry->setUrl($this->url); + $this->getEntityManager()->persist($entry); + $this->getEntityManager()->flush(); - $crawler = $client->request('GET', '/edit/'.$content->getId()); + $crawler = $client->request('GET', '/edit/'.$entry->getId()); $this->assertEquals(200, $client->getResponse()->getStatusCode()); @@ -478,12 +470,12 @@ class EntryControllerTest extends WallabagCoreTestCase $this->logInAs('admin'); $client = $this->getClient(); - $content = $client->getContainer() - ->get('doctrine.orm.entity_manager') - ->getRepository('WallabagCoreBundle:Entry') - ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); + $entry = new Entry($this->getLoggedInUser()); + $entry->setUrl($this->url); + $this->getEntityManager()->persist($entry); + $this->getEntityManager()->flush(); - $crawler = $client->request('GET', '/edit/'.$content->getId()); + $crawler = $client->request('GET', '/edit/'.$entry->getId()); $this->assertEquals(200, $client->getResponse()->getStatusCode()); @@ -508,19 +500,20 @@ class EntryControllerTest extends WallabagCoreTestCase $this->logInAs('admin'); $client = $this->getClient(); - $content = $client->getContainer() - ->get('doctrine.orm.entity_manager') - ->getRepository('WallabagCoreBundle:Entry') - ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); + $entry = new Entry($this->getLoggedInUser()); + $entry->setUrl($this->url); + $this->getEntityManager()->persist($entry); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); - $client->request('GET', '/archive/'.$content->getId()); + $client->request('GET', '/archive/'.$entry->getId()); $this->assertEquals(302, $client->getResponse()->getStatusCode()); $res = $client->getContainer() ->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') - ->find($content->getId()); + ->find($entry->getId()); $this->assertEquals($res->isArchived(), true); } @@ -530,19 +523,20 @@ class EntryControllerTest extends WallabagCoreTestCase $this->logInAs('admin'); $client = $this->getClient(); - $content = $client->getContainer() - ->get('doctrine.orm.entity_manager') - ->getRepository('WallabagCoreBundle:Entry') - ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); + $entry = new Entry($this->getLoggedInUser()); + $entry->setUrl($this->url); + $this->getEntityManager()->persist($entry); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); - $client->request('GET', '/star/'.$content->getId()); + $client->request('GET', '/star/'.$entry->getId()); $this->assertEquals(302, $client->getResponse()->getStatusCode()); $res = $client->getContainer() ->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') - ->findOneById($content->getId()); + ->findOneById($entry->getId()); $this->assertEquals($res->isStarred(), true); } @@ -552,16 +546,16 @@ class EntryControllerTest extends WallabagCoreTestCase $this->logInAs('admin'); $client = $this->getClient(); - $content = $client->getContainer() - ->get('doctrine.orm.entity_manager') - ->getRepository('WallabagCoreBundle:Entry') - ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); + $entry = new Entry($this->getLoggedInUser()); + $entry->setUrl($this->url); + $this->getEntityManager()->persist($entry); + $this->getEntityManager()->flush(); - $client->request('GET', '/delete/'.$content->getId()); + $client->request('GET', '/delete/'.$entry->getId()); $this->assertEquals(302, $client->getResponse()->getStatusCode()); - $client->request('GET', '/delete/'.$content->getId()); + $client->request('GET', '/delete/'.$entry->getId()); $this->assertEquals(404, $client->getResponse()->getStatusCode()); } @@ -627,7 +621,13 @@ class EntryControllerTest extends WallabagCoreTestCase public function testFilterOnReadingTime() { $this->logInAs('admin'); + $this->useTheme('baggy'); $client = $this->getClient(); + $entry = new Entry($this->getLoggedInUser()); + $entry->setUrl($this->url); + $entry->setReadingTime(22); + $this->getEntityManager()->persist($entry); + $this->getEntityManager()->flush(); $crawler = $client->request('GET', '/unread/list'); @@ -666,9 +666,20 @@ class EntryControllerTest extends WallabagCoreTestCase public function testFilterOnReadingTimeOnlyUpper() { $this->logInAs('admin'); + $this->useTheme('baggy'); $client = $this->getClient(); - $crawler = $client->request('GET', '/unread/list'); + $crawler = $client->request('GET', '/all/list'); + $this->assertCount(5, $crawler->filter('div[class=entry]')); + + $entry = new Entry($this->getLoggedInUser()); + $entry->setUrl($this->url); + $entry->setReadingTime(23); + $this->getEntityManager()->persist($entry); + $this->getEntityManager()->flush(); + + $crawler = $client->request('GET', '/all/list'); + $this->assertCount(6, $crawler->filter('div[class=entry]')); $form = $crawler->filter('button[id=submit-filter]')->form(); @@ -678,12 +689,13 @@ class EntryControllerTest extends WallabagCoreTestCase $crawler = $client->submit($form, $data); - $this->assertCount(3, $crawler->filter('div[class=entry]')); + $this->assertCount(5, $crawler->filter('div[class=entry]')); } public function testFilterOnReadingTimeOnlyLower() { $this->logInAs('admin'); + $this->useTheme('baggy'); $client = $this->getClient(); $crawler = $client->request('GET', '/unread/list'); @@ -696,12 +708,22 @@ class EntryControllerTest extends WallabagCoreTestCase $crawler = $client->submit($form, $data); - $this->assertCount(4, $crawler->filter('div[class=entry]')); + $this->assertCount(0, $crawler->filter('div[class=entry]')); + + $entry = new Entry($this->getLoggedInUser()); + $entry->setUrl($this->url); + $entry->setReadingTime(23); + $this->getEntityManager()->persist($entry); + $this->getEntityManager()->flush(); + + $crawler = $client->submit($form, $data); + $this->assertCount(1, $crawler->filter('div[class=entry]')); } public function testFilterOnUnreadStatus() { $this->logInAs('admin'); + $this->useTheme('baggy'); $client = $this->getClient(); $crawler = $client->request('GET', '/all/list'); @@ -714,12 +736,23 @@ class EntryControllerTest extends WallabagCoreTestCase $crawler = $client->submit($form, $data); + $this->assertCount(4, $crawler->filter('div[class=entry]')); + + $entry = new Entry($this->getLoggedInUser()); + $entry->setUrl($this->url); + $entry->setArchived(false); + $this->getEntityManager()->persist($entry); + $this->getEntityManager()->flush(); + + $crawler = $client->submit($form, $data); + $this->assertCount(5, $crawler->filter('div[class=entry]')); } public function testFilterOnCreationDate() { $this->logInAs('admin'); + $this->useTheme('baggy'); $client = $this->getClient(); $crawler = $client->request('GET', '/unread/list'); @@ -733,7 +766,7 @@ class EntryControllerTest extends WallabagCoreTestCase $crawler = $client->submit($form, $data); - $this->assertCount(6, $crawler->filter('div[class=entry]')); + $this->assertCount(5, $crawler->filter('div[class=entry]')); $data = [ 'entry_filter[createdAt][left_date]' => date('d/m/Y'), @@ -742,7 +775,7 @@ class EntryControllerTest extends WallabagCoreTestCase $crawler = $client->submit($form, $data); - $this->assertCount(6, $crawler->filter('div[class=entry]')); + $this->assertCount(5, $crawler->filter('div[class=entry]')); $data = [ 'entry_filter[createdAt][left_date]' => '01/01/1970', @@ -786,6 +819,7 @@ class EntryControllerTest extends WallabagCoreTestCase public function testFilterOnDomainName() { $this->logInAs('admin'); + $this->useTheme('baggy'); $client = $this->getClient(); $crawler = $client->request('GET', '/unread/list'); @@ -818,6 +852,7 @@ class EntryControllerTest extends WallabagCoreTestCase public function testFilterOnStatus() { $this->logInAs('admin'); + $this->useTheme('baggy'); $client = $this->getClient(); $crawler = $client->request('GET', '/unread/list'); @@ -839,6 +874,7 @@ class EntryControllerTest extends WallabagCoreTestCase public function testPreviewPictureFilter() { $this->logInAs('admin'); + $this->useTheme('baggy'); $client = $this->getClient(); $crawler = $client->request('GET', '/unread/list'); @@ -846,14 +882,21 @@ class EntryControllerTest extends WallabagCoreTestCase $form['entry_filter[previewPicture]']->tick(); $crawler = $client->submit($form); - $this->assertCount(2, $crawler->filter('div[class=entry]')); + $this->assertCount(1, $crawler->filter('div[class=entry]')); } public function testFilterOnLanguage() { $this->logInAs('admin'); + $this->useTheme('baggy'); $client = $this->getClient(); + $entry = new Entry($this->getLoggedInUser()); + $entry->setUrl($this->url); + $entry->setLanguage('fr'); + $this->getEntityManager()->persist($entry); + $this->getEntityManager()->flush(); + $crawler = $client->request('GET', '/unread/list'); $form = $crawler->filter('button[id=submit-filter]')->form(); $data = [ @@ -877,10 +920,14 @@ class EntryControllerTest extends WallabagCoreTestCase $this->logInAs('admin'); $client = $this->getClient(); - $content = $client->getContainer() - ->get('doctrine.orm.entity_manager') - ->getRepository('WallabagCoreBundle:Entry') - ->findOneByUser($this->getLoggedInUserId()); + // sharing is enabled + $client->getContainer()->get('craue_config')->set('share_public', 1); + + $content = new Entry($this->getLoggedInUser()); + $content->setUrl($this->url); + $this->getEntityManager()->persist($content); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); // no uid $client->request('GET', '/share/'.$content->getUid()); @@ -970,6 +1017,20 @@ class EntryControllerTest extends WallabagCoreTestCase $url = 'http://www.20minutes.fr/montpellier/1952003-20161030-video-car-tombe-panne-rugbymen-perpignan-improvisent-melee-route'; $client->getContainer()->get('craue_config')->set('download_images_enabled', 1); + $crawler = $client->request('GET', '/new'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + + $form = $crawler->filter('form[name=entry]')->form(); + + $data = [ + 'entry[url]' => $url, + ]; + + $client->submit($form, $data); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $content = $client->getContainer() ->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') @@ -987,28 +1048,19 @@ class EntryControllerTest extends WallabagCoreTestCase $this->logInAs('empty'); $client = $this->getClient(); - $em = $client->getContainer()->get('doctrine.orm.entity_manager'); - $user = $em - ->getRepository('WallabagUserBundle:User') - ->find($this->getLoggedInUserId()); - - if (!$user) { - $this->markTestSkipped('No user found in db.'); - } - // Redirect to homepage - $config = $user->getConfig(); + $config = $this->getLoggedInUser()->getConfig(); $config->setActionMarkAsRead(Config::REDIRECT_TO_HOMEPAGE); - $em->persist($config); - $em->flush(); + $this->getEntityManager()->persist($config); - $content = $client->getContainer() - ->get('doctrine.orm.entity_manager') - ->getRepository('WallabagCoreBundle:Entry') - ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); + $entry = new Entry($this->getLoggedInUser()); + $entry->setUrl($this->url); + $this->getEntityManager()->persist($entry); - $client->request('GET', '/view/'.$content->getId()); - $client->request('GET', '/archive/'.$content->getId()); + $this->getEntityManager()->flush(); + + $client->request('GET', '/view/'.$entry->getId()); + $client->request('GET', '/archive/'.$entry->getId()); $this->assertEquals(302, $client->getResponse()->getStatusCode()); $this->assertEquals('/', $client->getResponse()->headers->get('location')); @@ -1019,46 +1071,36 @@ class EntryControllerTest extends WallabagCoreTestCase $this->logInAs('empty'); $client = $this->getClient(); - $em = $client->getContainer()->get('doctrine.orm.entity_manager'); - $user = $em - ->getRepository('WallabagUserBundle:User') - ->find($this->getLoggedInUserId()); - - if (!$user) { - $this->markTestSkipped('No user found in db.'); - } - // Redirect to current page - $config = $user->getConfig(); + $config = $this->getLoggedInUser()->getConfig(); $config->setActionMarkAsRead(Config::REDIRECT_TO_CURRENT_PAGE); - $em->persist($config); - $em->flush(); + $this->getEntityManager()->persist($config); - $content = $client->getContainer() - ->get('doctrine.orm.entity_manager') - ->getRepository('WallabagCoreBundle:Entry') - ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); + $entry = new Entry($this->getLoggedInUser()); + $entry->setUrl($this->url); + $this->getEntityManager()->persist($entry); - $client->request('GET', '/view/'.$content->getId()); - $client->request('GET', '/archive/'.$content->getId()); + $this->getEntityManager()->flush(); + + $client->request('GET', '/view/'.$entry->getId()); + $client->request('GET', '/archive/'.$entry->getId()); $this->assertEquals(302, $client->getResponse()->getStatusCode()); - $this->assertContains('/view/'.$content->getId(), $client->getResponse()->headers->get('location')); + $this->assertContains('/view/'.$entry->getId(), $client->getResponse()->headers->get('location')); } public function testFilterOnHttpStatus() { $this->logInAs('admin'); + $this->useTheme('baggy'); $client = $this->getClient(); - $crawler = $client->request('GET', '/new'); - $form = $crawler->filter('form[name=entry]')->form(); + $entry = new Entry($this->getLoggedInUser()); + $entry->setUrl('http://www.lemonde.fr/incorrect-url/'); + $entry->setHttpStatus(404); + $this->getEntityManager()->persist($entry); - $data = [ - 'entry[url]' => 'http://www.lemonde.fr/incorrect-url/', - ]; - - $client->submit($form, $data); + $this->getEntityManager()->flush(); $crawler = $client->request('GET', '/all/list'); $form = $crawler->filter('button[id=submit-filter]')->form(); @@ -1071,14 +1113,17 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertCount(1, $crawler->filter('div[class=entry]')); - $crawler = $client->request('GET', '/new'); - $form = $crawler->filter('form[name=entry]')->form(); + $entry = new Entry($this->getLoggedInUser()); + $entry->setUrl($this->url); + $entry->setHttpStatus(200); + $this->getEntityManager()->persist($entry); - $data = [ - 'entry[url]' => 'http://www.nextinpact.com/news/101235-wallabag-alternative-libre-a-pocket-creuse-petit-a-petit-son-nid.htm', - ]; + $entry = new Entry($this->getLoggedInUser()); + $entry->setUrl('http://www.nextinpact.com/news/101235-wallabag-alternative-libre-a-pocket-creuse-petit-a-petit-son-nid.htm'); + $entry->setHttpStatus(200); + $this->getEntityManager()->persist($entry); - $client->submit($form, $data); + $this->getEntityManager()->flush(); $crawler = $client->request('GET', '/all/list'); $form = $crawler->filter('button[id=submit-filter]')->form(); @@ -1106,8 +1151,15 @@ class EntryControllerTest extends WallabagCoreTestCase public function testSearch() { $this->logInAs('admin'); + $this->useTheme('baggy'); $client = $this->getClient(); + $entry = new Entry($this->getLoggedInUser()); + $entry->setUrl($this->url); + $entry->setTitle('test'); + $this->getEntityManager()->persist($entry); + $this->getEntityManager()->flush(); + // Search on unread list $crawler = $client->request('GET', '/unread/list'); @@ -1118,35 +1170,37 @@ class EntryControllerTest extends WallabagCoreTestCase $crawler = $client->submit($form, $data); - $this->assertCount(5, $crawler->filter('div[class=entry]')); + $this->assertCount(4, $crawler->filter('div[class=entry]')); // Search on starred list $crawler = $client->request('GET', '/starred/list'); + $entry = new Entry($this->getLoggedInUser()); + $entry->setUrl('http://localhost/foo/bar'); + $entry->setTitle('testeur'); + $entry->setStarred(true); + $this->getEntityManager()->persist($entry); + $this->getEntityManager()->flush(); + $form = $crawler->filter('form[name=search]')->form(); $data = [ - 'search_entry[term]' => 'title', + 'search_entry[term]' => 'testeur', ]; $crawler = $client->submit($form, $data); $this->assertCount(1, $crawler->filter('div[class=entry]')); - // Added new article to test on archive list - $crawler = $client->request('GET', '/new'); - $form = $crawler->filter('form[name=entry]')->form(); - $data = [ - 'entry[url]' => $this->url, - ]; - $client->submit($form, $data); - $content = $client->getContainer() - ->get('doctrine.orm.entity_manager') - ->getRepository('WallabagCoreBundle:Entry') - ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); - $client->request('GET', '/archive/'.$content->getId()); - $crawler = $client->request('GET', '/archive/list'); + // Added new article to test on archive list + $entry = new Entry($this->getLoggedInUser()); + $entry->setUrl('http://0.0.0.0/foo/baz/qux'); + $entry->setTitle('Le manège'); + $entry->setArchived(true); + $this->getEntityManager()->persist($entry); + $this->getEntityManager()->flush(); + $form = $crawler->filter('form[name=search]')->form(); $data = [ 'search_entry[term]' => 'manège', @@ -1155,7 +1209,7 @@ class EntryControllerTest extends WallabagCoreTestCase $crawler = $client->submit($form, $data); $this->assertCount(1, $crawler->filter('div[class=entry]')); - $client->request('GET', '/delete/'.$content->getId()); + $client->request('GET', '/delete/'.$entry->getId()); // test on list of all articles $crawler = $client->request('GET', '/all/list'); @@ -1170,6 +1224,13 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertCount(0, $crawler->filter('div[class=entry]')); // test url search on list of all articles + $entry = new Entry($this->getLoggedInUser()); + $entry->setUrl('http://domain/qux'); + $entry->setTitle('Le manège'); + $entry->setArchived(true); + $this->getEntityManager()->persist($entry); + $this->getEntityManager()->flush(); + $crawler = $client->request('GET', '/all/list'); $form = $crawler->filter('form[name=search]')->form(); diff --git a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php index 63f2c829..b38961d3 100644 --- a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php @@ -239,7 +239,7 @@ class ExportControllerTest extends WallabagCoreTestCase $this->assertEquals($contentInDB->getLanguage(), $content[0]['language']); $this->assertEquals($contentInDB->getReadingtime(), $content[0]['reading_time']); $this->assertEquals($contentInDB->getDomainname(), $content[0]['domain_name']); - $this->assertEquals(['foo bar', 'baz', 'foot'], $content[0]['tags']); + $this->assertEquals(['foo bar', 'baz'], $content[0]['tags']); } public function testXmlExport() diff --git a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php index 80611a87..f9bf7b87 100644 --- a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php @@ -3,6 +3,7 @@ namespace Tests\Wallabag\CoreBundle\Controller; use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; +use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Entity\Tag; class TagControllerTest extends WallabagCoreTestCase @@ -24,10 +25,11 @@ class TagControllerTest extends WallabagCoreTestCase $this->logInAs('admin'); $client = $this->getClient(); - $entry = $client->getContainer() - ->get('doctrine.orm.entity_manager') - ->getRepository('WallabagCoreBundle:Entry') - ->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId()); + $entry = new Entry($this->getLoggedInUser()); + $entry->setUrl('http://0.0.0.0/foo'); + $this->getEntityManager()->persist($entry); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); $crawler = $client->request('GET', '/view/'.$entry->getId()); @@ -41,23 +43,15 @@ class TagControllerTest extends WallabagCoreTestCase $this->assertEquals(302, $client->getResponse()->getStatusCode()); // be sure to reload the entry - $entry = $client->getContainer() - ->get('doctrine.orm.entity_manager') - ->getRepository('WallabagCoreBundle:Entry') - ->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId()); - - $this->assertEquals(4, count($entry->getTags())); + $entry = $this->getEntityManager()->getRepository(Entry::class)->find($entry->getId()); + $this->assertCount(1, $entry->getTags()); // tag already exists and already assigned $client->submit($form, $data); $this->assertEquals(302, $client->getResponse()->getStatusCode()); - $newEntry = $client->getContainer() - ->get('doctrine.orm.entity_manager') - ->getRepository('WallabagCoreBundle:Entry') - ->find($entry->getId()); - - $this->assertEquals(4, count($newEntry->getTags())); + $entry = $this->getEntityManager()->getRepository(Entry::class)->find($entry->getId()); + $this->assertCount(1, $entry->getTags()); // tag already exists but still not assigned to this entry $data = [ @@ -67,12 +61,8 @@ class TagControllerTest extends WallabagCoreTestCase $client->submit($form, $data); $this->assertEquals(302, $client->getResponse()->getStatusCode()); - $newEntry = $client->getContainer() - ->get('doctrine.orm.entity_manager') - ->getRepository('WallabagCoreBundle:Entry') - ->find($entry->getId()); - - $this->assertEquals(4, count($newEntry->getTags())); + $entry = $this->getEntityManager()->getRepository(Entry::class)->find($entry->getId()); + $this->assertCount(2, $entry->getTags()); } public function testAddMultipleTagToEntry() @@ -116,15 +106,14 @@ class TagControllerTest extends WallabagCoreTestCase $this->logInAs('admin'); $client = $this->getClient(); - $entry = $client->getContainer() - ->get('doctrine.orm.entity_manager') - ->getRepository('WallabagCoreBundle:Entry') - ->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId()); - - $tag = $client->getContainer() - ->get('doctrine.orm.entity_manager') - ->getRepository('WallabagCoreBundle:Tag') - ->findOneByEntryAndTagLabel($entry, $this->tagName); + $tag = new Tag(); + $tag->setLabel($this->tagName); + $entry = new Entry($this->getLoggedInUser()); + $entry->setUrl('http://0.0.0.0/foo'); + $entry->addTag($tag); + $this->getEntityManager()->persist($entry); + $this->getEntityManager()->flush(); + $this->getEntityManager()->clear(); // We make a first request to set an history and test redirection after tag deletion $client->request('GET', '/view/'.$entry->getId()); @@ -134,12 +123,8 @@ class TagControllerTest extends WallabagCoreTestCase $this->assertEquals(302, $client->getResponse()->getStatusCode()); $this->assertEquals($entryUri, $client->getResponse()->getTargetUrl()); - // re-retrieve the entry to be sure to get fresh data from database (mostly for tags) - $entry = $client->getContainer() - ->get('doctrine.orm.entity_manager') - ->getRepository('WallabagCoreBundle:Entry') - ->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId()); - + // re-retrieve the entry to be sure to get fresh data from database (mostly for tags) + $entry = $this->getEntityManager()->getRepository(Entry::class)->find($entry->getId()); $this->assertNotContains($this->tagName, $entry->getTags()); $client->request('GET', '/remove-tag/'.$entry->getId().'/'.$tag->getId()); diff --git a/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php b/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php index 7bf4b43c..eec6939d 100644 --- a/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php +++ b/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php @@ -2,11 +2,20 @@ namespace Tests\Wallabag\CoreBundle; +use Symfony\Bundle\FrameworkBundle\Client; +use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; use Symfony\Component\BrowserKit\Cookie; +use Symfony\Component\Console\Input\ArrayInput; +use Symfony\Component\Console\Output\NullOutput; +use Wallabag\CoreBundle\Entity\Config; +use Wallabag\UserBundle\Entity\User; abstract class WallabagCoreTestCase extends WebTestCase { + /** + * @var Client|null + */ private $client = null; public function getClient() @@ -21,6 +30,44 @@ abstract class WallabagCoreTestCase extends WebTestCase $this->client = static::createClient(); } + public function resetDatabase(Client $client) + { + $application = new Application($client->getKernel()); + $application->setAutoExit(false); + + $application->run(new ArrayInput([ + 'command' => 'doctrine:schema:drop', + '--no-interaction' => true, + '--force' => true, + '--env' => 'test', + ]), new NullOutput()); + + $application->run(new ArrayInput([ + 'command' => 'doctrine:schema:create', + '--no-interaction' => true, + '--env' => 'test', + ]), new NullOutput()); + + $application->run(new ArrayInput([ + 'command' => 'doctrine:fixtures:load', + '--no-interaction' => true, + '--env' => 'test', + ]), new NullOutput()); + + /* + * Recreate client to avoid error: + * + * [Doctrine\DBAL\ConnectionException] + * Transaction commit failed because the transaction has been marked for rollback only. + */ + $this->client = static::createClient(); + } + + public function getEntityManager() + { + return $this->client->getContainer()->get('doctrine.orm.entity_manager'); + } + /** * Login a user without making a HTTP request. * If we make a HTTP request we lose ability to mock service in the container. @@ -37,7 +84,7 @@ abstract class WallabagCoreTestCase extends WebTestCase $firewallName = $container->getParameter('fos_user.firewall_name'); $user = $userManager->findUserBy(array('username' => $username)); - $loginManager->loginUser($firewallName, $user); + $loginManager->logInUser($firewallName, $user); $session->set('_security_'.$firewallName, serialize($container->get('security.token_storage')->getToken())); $session->save(); @@ -65,22 +112,41 @@ abstract class WallabagCoreTestCase extends WebTestCase } /** - * Return the user id of the logged in user. + * Return the user of the logged in user. * You should be sure that you called `logInAs` before. * - * @return int + * @return User */ - public function getLoggedInUserId() + public function getLoggedInUser() { $token = static::$kernel->getContainer()->get('security.token_storage')->getToken(); if (null !== $token) { - return $token->getUser()->getId(); + return $token->getUser(); } throw new \RuntimeException('No logged in User.'); } + /** + * Return the user id of the logged in user. + * You should be sure that you called `logInAs` before. + * + * @return int + */ + public function getLoggedInUserId() + { + return $this->getLoggedInUser()->getId(); + } + + public function useTheme($theme) + { + $config = $this->getEntityManager()->getRepository(Config::class)->findOneByUser($this->getLoggedInUser()); + $config->setTheme($theme); + $this->getEntityManager()->persist($config); + $this->getEntityManager()->flush(); + } + /** * Check if Redis is installed. * If not, mark test as skip. -- cgit v1.2.3 From 7aba665e484c5c36ee029219a999a427d864ff22 Mon Sep 17 00:00:00 2001 From: Jerome Charaoui Date: Tue, 6 Dec 2016 22:17:44 -0500 Subject: Avoid returning objects passed by reference. Objects are always passed by reference, so it doesn't make sense to return an object which is passed by reference as it will always be the same object. This change makes the code a bit more readable. --- .../CoreBundle/Helper/ContentProxyTest.php | 30 ++++++++++++++-------- 1 file changed, 19 insertions(+), 11 deletions(-) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php index 0c715d90..16643938 100644 --- a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php +++ b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php @@ -38,7 +38,8 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase ]); $proxy = new ContentProxy($graby, $tagger, $this->getLogger(), $this->fetchingErrorMessage); - $entry = $proxy->updateEntry(new Entry(new User()), 'http://user@:80'); + $entry = new Entry(new User()); + $proxy->updateEntry($entry, 'http://user@:80'); $this->assertEquals('http://user@:80', $entry->getUrl()); $this->assertEmpty($entry->getTitle()); @@ -72,7 +73,8 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase ]); $proxy = new ContentProxy($graby, $tagger, $this->getLogger(), $this->fetchingErrorMessage); - $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0'); + $entry = new Entry(new User()); + $proxy->updateEntry($entry, 'http://0.0.0.0'); $this->assertEquals('http://0.0.0.0', $entry->getUrl()); $this->assertEmpty($entry->getTitle()); @@ -111,7 +113,8 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase ]); $proxy = new ContentProxy($graby, $tagger, $this->getLogger(), $this->fetchingErrorMessage); - $entry = $proxy->updateEntry(new Entry(new User()), 'http://domain.io'); + $entry = new Entry(new User()); + $proxy->updateEntry($entry, 'http://domain.io'); $this->assertEquals('http://domain.io', $entry->getUrl()); $this->assertEquals('my title', $entry->getTitle()); @@ -152,7 +155,8 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase ]); $proxy = new ContentProxy($graby, $tagger, $this->getLogger(), $this->fetchingErrorMessage); - $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0'); + $entry = new Entry(new User()); + $proxy->updateEntry($entry, 'http://0.0.0.0'); $this->assertEquals('http://1.1.1.1', $entry->getUrl()); $this->assertEquals('this is my title', $entry->getTitle()); @@ -213,8 +217,9 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase ->method('tag'); $proxy = new ContentProxy((new Graby()), $tagger, $this->getLogger(), $this->fetchingErrorMessage); - $entry = $proxy->updateEntry( - new Entry(new User()), + $entry = new Entry(new User()); + $proxy->updateEntry( + $entry, 'http://0.0.0.0', [ 'html' => str_repeat('this is my content', 325), @@ -251,8 +256,9 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase ->method('tag'); $proxy = new ContentProxy((new Graby()), $tagger, $this->getLogger(), $this->fetchingErrorMessage); - $entry = $proxy->updateEntry( - new Entry(new User()), + $entry = new Entry(new User()); + $proxy->updateEntry( + $entry, 'http://0.0.0.0', [ 'html' => str_repeat('this is my content', 325), @@ -285,8 +291,9 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase $logger->pushHandler($handler); $proxy = new ContentProxy((new Graby()), $tagger, $logger, $this->fetchingErrorMessage); - $entry = $proxy->updateEntry( - new Entry(new User()), + $entry = new Entry(new User()); + $proxy->updateEntry( + $entry, 'http://0.0.0.0', [ 'html' => str_repeat('this is my content', 325), @@ -326,7 +333,8 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase $proxy = new ContentProxy($graby, $tagger, $this->getLogger(), $this->fetchingErrorMessage); - $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0', [ + $entry = new Entry(new User()); + $proxy->updateEntry($entry, 'http://0.0.0.0', [ 'html' => str_repeat('this is my content', 325), 'title' => 'this is my title', 'url' => 'http://1.1.1.1', -- cgit v1.2.3 From d0e9b3d640acce49068d1a2c5603b92c1bda363e Mon Sep 17 00:00:00 2001 From: Jerome Charaoui Date: Wed, 7 Dec 2016 15:16:49 -0500 Subject: Add disableContentUpdate import option This commit also decouples the "import" and "update" functions inside ContentProxy. If a content array is available, it must be passed to the new importEntry method. --- tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php index 16643938..1ad21d14 100644 --- a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php +++ b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php @@ -257,9 +257,8 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase $proxy = new ContentProxy((new Graby()), $tagger, $this->getLogger(), $this->fetchingErrorMessage); $entry = new Entry(new User()); - $proxy->updateEntry( + $proxy->importEntry( $entry, - 'http://0.0.0.0', [ 'html' => str_repeat('this is my content', 325), 'title' => 'this is my title', @@ -294,7 +293,6 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase $entry = new Entry(new User()); $proxy->updateEntry( $entry, - 'http://0.0.0.0', [ 'html' => str_repeat('this is my content', 325), 'title' => 'this is my title', @@ -334,13 +332,14 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase $proxy = new ContentProxy($graby, $tagger, $this->getLogger(), $this->fetchingErrorMessage); $entry = new Entry(new User()); - $proxy->updateEntry($entry, 'http://0.0.0.0', [ + $content = array( 'html' => str_repeat('this is my content', 325), 'title' => 'this is my title', 'url' => 'http://1.1.1.1', 'content_type' => 'text/html', 'language' => 'fr', - ]); + ); + $proxy->importEntry($entry, $content, true); $this->assertCount(0, $entry->getTags()); } -- cgit v1.2.3 From d5c2cc54b5490b0bec46f39d7706d5d46869e872 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Tue, 30 May 2017 17:48:24 +0200 Subject: Fix tests --- tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php index 1ad21d14..be287d84 100644 --- a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php +++ b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php @@ -3,6 +3,8 @@ namespace Tests\Wallabag\CoreBundle\Helper; use Psr\Log\NullLogger; +use Monolog\Logger; +use Monolog\Handler\TestHandler; use Wallabag\CoreBundle\Helper\ContentProxy; use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Entity\Tag; @@ -197,7 +199,8 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase ]); $proxy = new ContentProxy($graby, $tagger, $this->getLogger(), $this->fetchingErrorMessage); - $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0'); + $entry = new Entry(new User()); + $proxy->updateEntry($entry, 'http://0.0.0.0'); $this->assertEquals('http://1.1.1.1', $entry->getUrl()); $this->assertEquals('this is my title', $entry->getTitle()); @@ -255,7 +258,10 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase $tagger->expects($this->once()) ->method('tag'); - $proxy = new ContentProxy((new Graby()), $tagger, $this->getLogger(), $this->fetchingErrorMessage); + $logHandler = new TestHandler(); + $logger = new Logger('test', array($logHandler)); + + $proxy = new ContentProxy((new Graby()), $tagger, $logger, $this->fetchingErrorMessage); $entry = new Entry(new User()); $proxy->importEntry( $entry, -- cgit v1.2.3 From 6acadf8e98cf6021a9019773df75bdb151865687 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Thu, 1 Jun 2017 11:31:45 +0200 Subject: Rewrote code & fix tests --- .../CoreBundle/Controller/TagControllerTest.php | 2 +- .../CoreBundle/Helper/ContentProxyTest.php | 37 +++++++++++----------- 2 files changed, 19 insertions(+), 20 deletions(-) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php index f9bf7b87..af1ad7af 100644 --- a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php @@ -123,7 +123,7 @@ class TagControllerTest extends WallabagCoreTestCase $this->assertEquals(302, $client->getResponse()->getStatusCode()); $this->assertEquals($entryUri, $client->getResponse()->getTargetUrl()); - // re-retrieve the entry to be sure to get fresh data from database (mostly for tags) + // re-retrieve the entry to be sure to get fresh data from database (mostly for tags) $entry = $this->getEntityManager()->getRepository(Entry::class)->find($entry->getId()); $this->assertNotContains($this->tagName, $entry->getTags()); diff --git a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php index be287d84..a3570125 100644 --- a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php +++ b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php @@ -11,8 +11,6 @@ use Wallabag\CoreBundle\Entity\Tag; use Wallabag\UserBundle\Entity\User; use Wallabag\CoreBundle\Helper\RuleBasedTagger; use Graby\Graby; -use Monolog\Handler\TestHandler; -use Monolog\Logger; class ContentProxyTest extends \PHPUnit_Framework_TestCase { @@ -259,12 +257,13 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase ->method('tag'); $logHandler = new TestHandler(); - $logger = new Logger('test', array($logHandler)); + $logger = new Logger('test', [$logHandler]); $proxy = new ContentProxy((new Graby()), $tagger, $logger, $this->fetchingErrorMessage); $entry = new Entry(new User()); - $proxy->importEntry( + $proxy->updateEntry( $entry, + 'http://1.1.1.1', [ 'html' => str_repeat('this is my content', 325), 'title' => 'this is my title', @@ -299,6 +298,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase $entry = new Entry(new User()); $proxy->updateEntry( $entry, + 'http://1.1.1.1', [ 'html' => str_repeat('this is my content', 325), 'title' => 'this is my title', @@ -326,26 +326,24 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase public function testTaggerThrowException() { - $graby = $this->getMockBuilder('Graby\Graby') - ->disableOriginalConstructor() - ->getMock(); - $tagger = $this->getTaggerMock(); $tagger->expects($this->once()) ->method('tag') ->will($this->throwException(new \Exception())); - $proxy = new ContentProxy($graby, $tagger, $this->getLogger(), $this->fetchingErrorMessage); - + $proxy = new ContentProxy((new Graby()), $tagger, $this->getLogger(), $this->fetchingErrorMessage); $entry = new Entry(new User()); - $content = array( - 'html' => str_repeat('this is my content', 325), - 'title' => 'this is my title', - 'url' => 'http://1.1.1.1', - 'content_type' => 'text/html', - 'language' => 'fr', + $proxy->updateEntry( + $entry, + 'http://1.1.1.1', + [ + 'html' => str_repeat('this is my content', 325), + 'title' => 'this is my title', + 'url' => 'http://1.1.1.1', + 'content_type' => 'text/html', + 'language' => 'fr', + ] ); - $proxy->importEntry($entry, $content, true); $this->assertCount(0, $entry->getTags()); } @@ -374,8 +372,9 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase ->method('tag'); $proxy = new ContentProxy((new Graby()), $tagger, $this->getLogger(), $this->fetchingErrorMessage); - $entry = $proxy->updateEntry( - new Entry(new User()), + $entry = new Entry(new User()); + $proxy->updateEntry( + $entry, 'http://1.1.1.1', [ 'html' => $html, -- cgit v1.2.3 From fcad69a427de7ce4f65cbf53bcf778e561959807 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Thu, 1 Jun 2017 22:50:33 +0200 Subject: Replace images with & MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Images with `&` in the path weren’t well replaced because they might be with `&` in the html instead. Replacing `&` with `&` fix the problem. --- .../CoreBundle/Helper/DownloadImagesTest.php | 24 +++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php b/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php index 85f12d87..9125f8dc 100644 --- a/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php +++ b/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php @@ -12,7 +12,24 @@ use GuzzleHttp\Stream\Stream; class DownloadImagesTest extends \PHPUnit_Framework_TestCase { - public function testProcessHtml() + public function dataForSuccessImage() + { + return [ + 'imgur' => [ + '
', + 'http://imgur.com/gallery/WxtWY', + ], + 'image with &' => [ + '
', + 'https://www.tvaddons.ag/realdebrid-kodi-jarvis/', + ], + ]; + } + + /** + * @dataProvider dataForSuccessImage + */ + public function testProcessHtml($html, $url) { $client = new Client(); @@ -27,9 +44,10 @@ class DownloadImagesTest extends \PHPUnit_Framework_TestCase $download = new DownloadImages($client, sys_get_temp_dir().'/wallabag_test', 'http://wallabag.io/', $logger); - $res = $download->processHtml(123, '
', 'http://imgur.com/gallery/WxtWY'); + $res = $download->processHtml(123, $html, $url); - $this->assertContains('http://wallabag.io/assets/images/9/b/9b0ead26/c638b4c2.png', $res); + // this the base path of all image (since it's calculated using the entry id: 123) + $this->assertContains('http://wallabag.io/assets/images/9/b/9b0ead26/', $res); } public function testProcessHtmlWithBadImage() -- cgit v1.2.3 From d143fa243df6112c9df7c6e7e408b66da40c8fce Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Fri, 2 Jun 2017 16:53:03 +0200 Subject: Add show user command Signed-off-by: Thomas Citharel --- .../CoreBundle/Command/ShowUserCommandTest.php | 95 ++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php b/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php new file mode 100644 index 00000000..642327c3 --- /dev/null +++ b/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php @@ -0,0 +1,95 @@ +getClient()->getKernel()); + $application->add(new ShowUserCommand()); + + $command = $application->find('wallabag:user:show'); + + $tester = new CommandTester($command); + $tester->execute([ + 'command' => $command->getName(), + ]); + } + + public function testRunShowUserCommandWithBadUsername() + { + $application = new Application($this->getClient()->getKernel()); + $application->add(new ShowUserCommand()); + + $command = $application->find('wallabag:user:show'); + + $tester = new CommandTester($command); + $tester->execute([ + 'command' => $command->getName(), + 'username' => 'unknown', + ]); + + $this->assertContains('User "unknown" not found', $tester->getDisplay()); + } + + public function testRunShowUserCommandForUser() + { + $application = new Application($this->getClient()->getKernel()); + $application->add(new ShowUserCommand()); + + $command = $application->find('wallabag:user:show'); + + $tester = new CommandTester($command); + $tester->execute([ + 'command' => $command->getName(), + 'username' => 'admin', + ]); + + $this->assertContains('Username : admin', $tester->getDisplay()); + $this->assertContains('Email : bigboss@wallabag.org', $tester->getDisplay()); + $this->assertContains('Display name : Big boss', $tester->getDisplay()); + $this->assertContains('2FA activated: false', $tester->getDisplay()); + } + + public function testShowUser() + { + $client = $this->getClient(); + $em = $client->getContainer()->get('doctrine.orm.entity_manager'); + + $this->logInAs('admin'); + + /** @var User $user */ + $user = $em->getRepository('WallabagUserBundle:User')->findOneById($this->getLoggedInUserId()); + + $user->setName('Bug boss'); + $em->persist($user); + + $em->flush(); + + $application = new Application($this->getClient()->getKernel()); + $application->add(new ShowUserCommand()); + + $command = $application->find('wallabag:user:show'); + + $tester = new CommandTester($command); + $tester->execute([ + 'command' => $command->getName(), + 'username' => 'admin', + ]); + + $this->assertContains('Display name : Bug boss', $tester->getDisplay()); + } +} -- cgit v1.2.3 From 0d8ecb82a32fcb7e87d99316b00c827c8aa71eee Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Sun, 4 Jun 2017 17:57:40 +0200 Subject: Fix review Signed-off-by: Thomas Citharel --- tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php b/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php index 642327c3..3b928d1e 100644 --- a/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php @@ -61,7 +61,7 @@ class ShowUserCommandTest extends WallabagCoreTestCase $this->assertContains('Username : admin', $tester->getDisplay()); $this->assertContains('Email : bigboss@wallabag.org', $tester->getDisplay()); $this->assertContains('Display name : Big boss', $tester->getDisplay()); - $this->assertContains('2FA activated: false', $tester->getDisplay()); + $this->assertContains('2FA activated: no', $tester->getDisplay()); } public function testShowUser() -- cgit v1.2.3 From 577c0b6dd82c421c377c37295c59dee147068132 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Mon, 5 Jun 2017 22:54:02 +0200 Subject: Use an alternative way to detect image MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When parsing content to retrieve images to save locally, we only check for the content-type of the image response. In some case, that value is empty. Now we’re also checking for the first few bytes of the content as an alternative to detect if it’s an image wallabag can handle. We might get higher image supports using that alternative method. --- .../CoreBundle/Helper/DownloadImagesTest.php | 25 +++++++++++++++++++++ .../CoreBundle/fixtures/image-no-content-type.jpg | Bin 0 -> 354067 bytes 2 files changed, 25 insertions(+) create mode 100644 tests/Wallabag/CoreBundle/fixtures/image-no-content-type.jpg (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php b/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php index 9125f8dc..c02f9658 100644 --- a/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php +++ b/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php @@ -157,4 +157,29 @@ class DownloadImagesTest extends \PHPUnit_Framework_TestCase $this->assertFalse($res, 'Absolute image can not be determined, so it will not be replaced'); } + + public function testProcessRealImage() + { + $client = new Client(); + + $mock = new Mock([ + new Response(200, ['content-type' => null], Stream::factory(file_get_contents(__DIR__.'/../fixtures/image-no-content-type.jpg'))), + ]); + + $client->getEmitter()->attach($mock); + + $logHandler = new TestHandler(); + $logger = new Logger('test', array($logHandler)); + + $download = new DownloadImages($client, sys_get_temp_dir().'/wallabag_test', 'http://wallabag.io/', $logger); + + $res = $download->processSingleImage( + 123, + 'https://cdn.theconversation.com/files/157200/article/width926/gsj2rjp2-1487348607.jpg', + 'https://theconversation.com/conversation-avec-gerald-bronner-ce-nest-pas-la-post-verite-qui-nous-menace-mais-lextension-de-notre-credulite-73089' + ); + + $this->assertContains('http://wallabag.io/assets/images/9/b/9b0ead26/', $res, 'Content-Type was empty but data is ok for an image'); + $this->assertContains('DownloadImages: Checking extension (alternative)', $logHandler->getRecords()[3]['message']); + } } diff --git a/tests/Wallabag/CoreBundle/fixtures/image-no-content-type.jpg b/tests/Wallabag/CoreBundle/fixtures/image-no-content-type.jpg new file mode 100644 index 00000000..0c60e952 Binary files /dev/null and b/tests/Wallabag/CoreBundle/fixtures/image-no-content-type.jpg differ -- cgit v1.2.3 From eb570e49c8e3ba12638fac600bb5527191c2aaa2 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Wed, 7 Jun 2017 23:23:34 +0200 Subject: CS --- tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php | 2 -- 1 file changed, 2 deletions(-) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php b/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php index 3b928d1e..c0a4acfa 100644 --- a/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php @@ -4,10 +4,8 @@ namespace Tests\Wallabag\CoreBundle\Command; use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Component\Console\Tester\CommandTester; -use Wallabag\CoreBundle\Command\CleanDuplicatesCommand; use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; use Wallabag\CoreBundle\Command\ShowUserCommand; -use Wallabag\CoreBundle\Entity\Entry; use Wallabag\UserBundle\Entity\User; class ShowUserCommandTest extends WallabagCoreTestCase -- cgit v1.2.3 From 80f4d85ac92ab4dc490c51f2d831ac7fa3853826 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Thu, 8 Jun 2017 19:15:33 +0200 Subject: Review --- tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index cc7b3672..581ee952 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php @@ -1000,7 +1000,7 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertEquals($url, $entry->getUrl()); $this->assertContains('Perpignan', $entry->getTitle()); // instead of checking for the filename (which might change) check that the image is now local - $this->assertContains('http://v2.wallabag.org/assets/images/', $entry->getContent()); + $this->assertContains('http://your-wallabag-url-instance.com/assets/images/', $entry->getContent()); $client->getContainer()->get('craue_config')->set('download_images_enabled', 0); } -- cgit v1.2.3 From 0d349ea67073c535e1aa7f19f3cf842a54458bfe Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Thu, 8 Jun 2017 21:51:46 +0200 Subject: Validate language & preview picture fields Instead of saving the value of each field right into the content without any validation, it seems better to validate them. This might sounds obvious now we say that. --- .../CoreBundle/Helper/ContentProxyTest.php | 129 +++++++++++++++++++-- 1 file changed, 117 insertions(+), 12 deletions(-) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php index a3570125..95dd75ba 100644 --- a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php +++ b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php @@ -11,6 +11,9 @@ use Wallabag\CoreBundle\Entity\Tag; use Wallabag\UserBundle\Entity\User; use Wallabag\CoreBundle\Helper\RuleBasedTagger; use Graby\Graby; +use Symfony\Component\Validator\Validator\RecursiveValidator; +use Symfony\Component\Validator\ConstraintViolationList; +use Symfony\Component\Validator\ConstraintViolation; class ContentProxyTest extends \PHPUnit_Framework_TestCase { @@ -37,7 +40,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase 'language' => '', ]); - $proxy = new ContentProxy($graby, $tagger, $this->getLogger(), $this->fetchingErrorMessage); + $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); $entry = new Entry(new User()); $proxy->updateEntry($entry, 'http://user@:80'); @@ -72,7 +75,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase 'language' => '', ]); - $proxy = new ContentProxy($graby, $tagger, $this->getLogger(), $this->fetchingErrorMessage); + $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); $entry = new Entry(new User()); $proxy->updateEntry($entry, 'http://0.0.0.0'); @@ -112,7 +115,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase ], ]); - $proxy = new ContentProxy($graby, $tagger, $this->getLogger(), $this->fetchingErrorMessage); + $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); $entry = new Entry(new User()); $proxy->updateEntry($entry, 'http://domain.io'); @@ -154,7 +157,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase ], ]); - $proxy = new ContentProxy($graby, $tagger, $this->getLogger(), $this->fetchingErrorMessage); + $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); $entry = new Entry(new User()); $proxy->updateEntry($entry, 'http://0.0.0.0'); @@ -192,18 +195,112 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase 'open_graph' => [ 'og_title' => 'my OG title', 'og_description' => 'OG desc', - 'og_image' => false, + 'og_image' => null, ], ]); - $proxy = new ContentProxy($graby, $tagger, $this->getLogger(), $this->fetchingErrorMessage); + $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); $entry = new Entry(new User()); $proxy->updateEntry($entry, 'http://0.0.0.0'); $this->assertEquals('http://1.1.1.1', $entry->getUrl()); $this->assertEquals('this is my title', $entry->getTitle()); $this->assertContains('this is my content', $entry->getContent()); - $this->assertNull($entry->getPreviewPicture()); + $this->assertEmpty($entry->getPreviewPicture()); + $this->assertEquals('text/html', $entry->getMimetype()); + $this->assertEquals('fr', $entry->getLanguage()); + $this->assertEquals('200', $entry->getHttpStatus()); + $this->assertEquals(4.0, $entry->getReadingTime()); + $this->assertEquals('1.1.1.1', $entry->getDomainName()); + } + + public function testWithContentAndBadLanguage() + { + $tagger = $this->getTaggerMock(); + $tagger->expects($this->once()) + ->method('tag'); + + $validator = $this->getValidator(); + $validator->expects($this->exactly(2)) + ->method('validate') + ->will($this->onConsecutiveCalls( + new ConstraintViolationList([new ConstraintViolation('oops', 'oops', [], 'oops', 'language', 'dontexist')]), + new ConstraintViolationList() + )); + + $graby = $this->getMockBuilder('Graby\Graby') + ->setMethods(['fetchContent']) + ->disableOriginalConstructor() + ->getMock(); + + $graby->expects($this->any()) + ->method('fetchContent') + ->willReturn([ + 'html' => str_repeat('this is my content', 325), + 'title' => 'this is my title', + 'url' => 'http://1.1.1.1', + 'content_type' => 'text/html', + 'language' => 'dontexist', + 'status' => '200', + ]); + + $proxy = new ContentProxy($graby, $tagger, $validator, $this->getLogger(), $this->fetchingErrorMessage); + $entry = new Entry(new User()); + $proxy->updateEntry($entry, 'http://0.0.0.0'); + + $this->assertEquals('http://1.1.1.1', $entry->getUrl()); + $this->assertEquals('this is my title', $entry->getTitle()); + $this->assertContains('this is my content', $entry->getContent()); + $this->assertEquals('text/html', $entry->getMimetype()); + $this->assertEmpty($entry->getLanguage()); + $this->assertEquals('200', $entry->getHttpStatus()); + $this->assertEquals(4.0, $entry->getReadingTime()); + $this->assertEquals('1.1.1.1', $entry->getDomainName()); + } + + public function testWithContentAndBadOgImage() + { + $tagger = $this->getTaggerMock(); + $tagger->expects($this->once()) + ->method('tag'); + + $validator = $this->getValidator(); + $validator->expects($this->exactly(2)) + ->method('validate') + ->will($this->onConsecutiveCalls( + new ConstraintViolationList(), + new ConstraintViolationList([new ConstraintViolation('oops', 'oops', [], 'oops', 'url', 'https://')]) + )); + + $graby = $this->getMockBuilder('Graby\Graby') + ->setMethods(['fetchContent']) + ->disableOriginalConstructor() + ->getMock(); + + $graby->expects($this->any()) + ->method('fetchContent') + ->willReturn([ + 'html' => str_repeat('this is my content', 325), + 'title' => 'this is my title', + 'url' => 'http://1.1.1.1', + 'content_type' => 'text/html', + 'language' => 'fr', + 'status' => '200', + 'open_graph' => [ + 'og_title' => 'my OG title', + 'og_description' => 'OG desc', + 'og_image' => 'https://', + ], + ]); + + $proxy = new ContentProxy($graby, $tagger, $validator, $this->getLogger(), $this->fetchingErrorMessage); + $entry = new Entry(new User()); + $proxy->updateEntry($entry, 'http://0.0.0.0'); + + $this->assertEquals('http://1.1.1.1', $entry->getUrl()); + $this->assertEquals('this is my title', $entry->getTitle()); + $this->assertContains('this is my content', $entry->getContent()); + $this->assertEmpty($entry->getPreviewPicture()); $this->assertEquals('text/html', $entry->getMimetype()); $this->assertEquals('fr', $entry->getLanguage()); $this->assertEquals('200', $entry->getHttpStatus()); @@ -217,7 +314,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase $tagger->expects($this->once()) ->method('tag'); - $proxy = new ContentProxy((new Graby()), $tagger, $this->getLogger(), $this->fetchingErrorMessage); + $proxy = new ContentProxy((new Graby()), $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); $entry = new Entry(new User()); $proxy->updateEntry( $entry, @@ -259,7 +356,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase $logHandler = new TestHandler(); $logger = new Logger('test', [$logHandler]); - $proxy = new ContentProxy((new Graby()), $tagger, $logger, $this->fetchingErrorMessage); + $proxy = new ContentProxy((new Graby()), $tagger, $this->getValidator(), $logger, $this->fetchingErrorMessage); $entry = new Entry(new User()); $proxy->updateEntry( $entry, @@ -294,7 +391,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase $handler = new TestHandler(); $logger->pushHandler($handler); - $proxy = new ContentProxy((new Graby()), $tagger, $logger, $this->fetchingErrorMessage); + $proxy = new ContentProxy((new Graby()), $tagger, $this->getValidator(), $logger, $this->fetchingErrorMessage); $entry = new Entry(new User()); $proxy->updateEntry( $entry, @@ -331,7 +428,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase ->method('tag') ->will($this->throwException(new \Exception())); - $proxy = new ContentProxy((new Graby()), $tagger, $this->getLogger(), $this->fetchingErrorMessage); + $proxy = new ContentProxy((new Graby()), $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); $entry = new Entry(new User()); $proxy->updateEntry( $entry, @@ -371,7 +468,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase $tagger->expects($this->once()) ->method('tag'); - $proxy = new ContentProxy((new Graby()), $tagger, $this->getLogger(), $this->fetchingErrorMessage); + $proxy = new ContentProxy((new Graby()), $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); $entry = new Entry(new User()); $proxy->updateEntry( $entry, @@ -413,4 +510,12 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase { return new NullLogger(); } + + private function getValidator() + { + return $this->getMockBuilder(RecursiveValidator::class) + ->setMethods(['validate']) + ->disableOriginalConstructor() + ->getMock(); + } } -- cgit v1.2.3 From 1a94252831638cf41f0fe489939dee9dae1c1251 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 9 Jun 2017 10:07:27 +0200 Subject: Promote https --- tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index 581ee952..4ffe02de 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php @@ -1000,7 +1000,7 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertEquals($url, $entry->getUrl()); $this->assertContains('Perpignan', $entry->getTitle()); // instead of checking for the filename (which might change) check that the image is now local - $this->assertContains('http://your-wallabag-url-instance.com/assets/images/', $entry->getContent()); + $this->assertContains('https://your-wallabag-url-instance.com/assets/images/', $entry->getContent()); $client->getContainer()->get('craue_config')->set('download_images_enabled', 0); } -- cgit v1.2.3 From 42f3bb2c6346e04d2837f980bf685f7e32a61a21 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 9 Jun 2017 11:28:04 +0200 Subject: Use Locale instead of Language --- .../CoreBundle/Controller/EntryControllerTest.php | 92 ++++++++++++++++++---- 1 file changed, 78 insertions(+), 14 deletions(-) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index cc7b3672..b77e5ec1 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php @@ -158,6 +158,7 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); $this->assertEquals($this->url, $content->getUrl()); $this->assertContains('Google', $content->getTitle()); + $this->assertEquals('fr', $content->getLanguage()); $this->assertEquals('2015-03-28 15:37:39', $content->getPublishedAt()->format('Y-m-d H:i:s')); $this->assertEquals('Morgane Tual', $author[0]); $this->assertArrayHasKey('x-varnish1', $content->getHeaders()); @@ -190,6 +191,7 @@ class EntryControllerTest extends WallabagCoreTestCase $authors = $content->getPublishedBy(); $this->assertEquals('2017-04-05 19:26:13', $content->getPublishedAt()->format('Y-m-d H:i:s')); + $this->assertEquals('fr', $content->getLanguage()); $this->assertEquals('Raphaël Balenieri, correspondant à Pékin', $authors[0]); $this->assertEquals('Frédéric Autran, correspondant à New York', $authors[1]); } @@ -254,15 +256,6 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertEquals(302, $client->getResponse()->getStatusCode()); $this->assertContains('/view/', $client->getResponse()->getTargetUrl()); - - $em = $client->getContainer() - ->get('doctrine.orm.entity_manager'); - $entry = $em - ->getRepository('WallabagCoreBundle:Entry') - ->findOneByUrl(urldecode($url)); - - $em->remove($entry); - $em->flush(); } /** @@ -297,6 +290,7 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertCount(2, $tags); $this->assertContains('wallabag', $tags); + $this->assertEquals('en', $entry->getLanguage()); $em->remove($entry); $em->flush(); @@ -392,8 +386,6 @@ class EntryControllerTest extends WallabagCoreTestCase } /** - * @depends testPostNewOk - * * This test will require an internet connection. */ public function testReload() @@ -420,9 +412,6 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertNotEmpty($entry->getContent()); } - /** - * @depends testPostNewOk - */ public function testReloadWithFetchingFailed() { $this->logInAs('admin'); @@ -1001,6 +990,7 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertContains('Perpignan', $entry->getTitle()); // instead of checking for the filename (which might change) check that the image is now local $this->assertContains('http://v2.wallabag.org/assets/images/', $entry->getContent()); + $this->assertEquals('fr', $entry->getLanguage()); $client->getContainer()->get('craue_config')->set('download_images_enabled', 0); } @@ -1254,4 +1244,78 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertCount(1, $crawler->filter('div[class=entry]')); } + + public function dataForLanguage() + { + return [ + 'ru' => [ + 'https://www.pravda.ru/world/09-06-2017/1337283-qatar-0/', + 'ru', + ], + 'wrong fr-FR' => [ + 'http://www.zataz.com/fff-darknet/axzz4jUg2QJjH', + '', + ], + 'de' => [ + 'http://www.bild.de/politik/ausland/theresa-may/wahlbeben-grossbritannien-analyse-52108924.bild.html', + 'de', + ], + 'it' => [ + 'http://www.ansa.it/sito/notizie/mondo/europa/2017/06/08/voto-gb-seggi-aperti-misure-sicurezza-rafforzate_0cb71f7f-e23b-4d5f-95ca-bc12296419f0.html', + 'it', + ], + 'zh_CN' => [ + 'http://www.hao123.com/shequ?__noscript__-=1', + 'zh_CN', + ], + 'de_AT' => [ + 'https://buy.garmin.com/de-AT/AT/catalog/product/compareResult.ep?compareProduct=112885&compareProduct=36728', + 'de_AT', + ], + 'ru_RU' => [ + 'http://netler.ru/ikt/windows-error-reporting.htm', + 'ru_RU', + ], + 'pt_BR' => [ + 'http://precodoscombustiveis.com.br/postos/cidade/4121/pr/maringa', + 'pt_BR', + ], + 'fucked list of languages' => [ + 'http://geocatalog.webservice-energy.org/geonetwork/srv/eng/main.home', + '', + ], + ]; + } + + /** + * @dataProvider dataForLanguage + */ + public function testLanguageValidation($url, $expectedLanguage) + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/new'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + + $form = $crawler->filter('form[name=entry]')->form(); + + $data = [ + 'entry[url]' => $url, + ]; + + $client->submit($form, $data); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $content = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findByUrlAndUserId($url, $this->getLoggedInUserId()); + + $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); + $this->assertEquals($url, $content->getUrl()); + $this->assertEquals($expectedLanguage, $content->getLanguage()); + } } -- cgit v1.2.3 From 80e49ba7b0320a5c4278c01f3d7851a9218e0919 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 9 Jun 2017 11:42:04 +0200 Subject: Convert - to _ in language Mostly to increase language supports --- tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index b77e5ec1..84faf8d4 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php @@ -1252,9 +1252,9 @@ class EntryControllerTest extends WallabagCoreTestCase 'https://www.pravda.ru/world/09-06-2017/1337283-qatar-0/', 'ru', ], - 'wrong fr-FR' => [ - 'http://www.zataz.com/fff-darknet/axzz4jUg2QJjH', - '', + 'fr-FR' => [ + 'http://www.zataz.com/90-des-dossiers-medicaux-des-coreens-du-sud-vendus-a-des-entreprises-privees/', + 'fr_FR', ], 'de' => [ 'http://www.bild.de/politik/ausland/theresa-may/wahlbeben-grossbritannien-analyse-52108924.bild.html', @@ -1280,10 +1280,14 @@ class EntryControllerTest extends WallabagCoreTestCase 'http://precodoscombustiveis.com.br/postos/cidade/4121/pr/maringa', 'pt_BR', ], - 'fucked list of languages' => [ + 'fucked_list_of_languages' => [ 'http://geocatalog.webservice-energy.org/geonetwork/srv/eng/main.home', '', ], + 'es-ES' => [ + 'http://www.muylinux.com/2015/04/17/odf-reino-unido-microsoft-google', + 'es_ES', + ], ]; } -- cgit v1.2.3 From 1f7018e1fe369b326150c388b56b8b8c26017234 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 9 Jun 2017 11:52:40 +0200 Subject: Cleanup test Looks like we didn't ALWAYS get a value for language from 20minutes. Ahem. --- tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php | 1 - 1 file changed, 1 deletion(-) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index 84faf8d4..3babbaca 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php @@ -990,7 +990,6 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertContains('Perpignan', $entry->getTitle()); // instead of checking for the filename (which might change) check that the image is now local $this->assertContains('http://v2.wallabag.org/assets/images/', $entry->getContent()); - $this->assertEquals('fr', $entry->getLanguage()); $client->getContainer()->get('craue_config')->set('download_images_enabled', 0); } -- cgit v1.2.3 From e8911f7c09fa9d8009d7c7ee9fb0c181d2ffbc31 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 10 Jun 2017 15:00:52 +0200 Subject: Add isPublic filter on entries --- .../Wallabag/CoreBundle/Controller/EntryControllerTest.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index 8f5c372d..853f37f2 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php @@ -860,6 +860,20 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertCount(1, $crawler->filter('div[class=entry]')); } + public function testFilterOnIsPublic() + { + $this->logInAs('admin'); + $this->useTheme('baggy'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/unread/list'); + $form = $crawler->filter('button[id=submit-filter]')->form(); + $form['entry_filter[isPublic]']->tick(); + + $crawler = $client->submit($form); + $this->assertCount(0, $crawler->filter('div[class=entry]')); + } + public function testPreviewPictureFilter() { $this->logInAs('admin'); -- cgit v1.2.3 From 41d45c6122f61e01a370233d26a2633836094d5c Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Mon, 12 Jun 2017 16:46:33 +0200 Subject: Fix empty language and preview pics --- tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php index 95dd75ba..dbddbc5c 100644 --- a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php +++ b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php @@ -206,7 +206,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase $this->assertEquals('http://1.1.1.1', $entry->getUrl()); $this->assertEquals('this is my title', $entry->getTitle()); $this->assertContains('this is my content', $entry->getContent()); - $this->assertEmpty($entry->getPreviewPicture()); + $this->assertNull($entry->getPreviewPicture()); $this->assertEquals('text/html', $entry->getMimetype()); $this->assertEquals('fr', $entry->getLanguage()); $this->assertEquals('200', $entry->getHttpStatus()); @@ -252,7 +252,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase $this->assertEquals('this is my title', $entry->getTitle()); $this->assertContains('this is my content', $entry->getContent()); $this->assertEquals('text/html', $entry->getMimetype()); - $this->assertEmpty($entry->getLanguage()); + $this->assertNull($entry->getLanguage()); $this->assertEquals('200', $entry->getHttpStatus()); $this->assertEquals(4.0, $entry->getReadingTime()); $this->assertEquals('1.1.1.1', $entry->getDomainName()); @@ -300,7 +300,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase $this->assertEquals('http://1.1.1.1', $entry->getUrl()); $this->assertEquals('this is my title', $entry->getTitle()); $this->assertContains('this is my content', $entry->getContent()); - $this->assertEmpty($entry->getPreviewPicture()); + $this->assertNull($entry->getPreviewPicture()); $this->assertEquals('text/html', $entry->getMimetype()); $this->assertEquals('fr', $entry->getLanguage()); $this->assertEquals('200', $entry->getHttpStatus()); -- cgit v1.2.3 From b8427f22f06cab58383ec3080f09715c712c65ef Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Mon, 1 May 2017 22:13:35 +0200 Subject: Add menu access to site credentials CRUD --- .../Controller/SiteCredentialControllerTest.php | 140 +++++++++++++++++++++ .../GrabySiteConfigBuilderTest.php | 50 +++++++- 2 files changed, 187 insertions(+), 3 deletions(-) create mode 100644 tests/Wallabag/CoreBundle/Controller/SiteCredentialControllerTest.php (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Controller/SiteCredentialControllerTest.php b/tests/Wallabag/CoreBundle/Controller/SiteCredentialControllerTest.php new file mode 100644 index 00000000..47bf0907 --- /dev/null +++ b/tests/Wallabag/CoreBundle/Controller/SiteCredentialControllerTest.php @@ -0,0 +1,140 @@ +logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/site-credentials/'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + + $body = $crawler->filter('body')->extract(['_text'])[0]; + + $this->assertContains('site_credential.description', $body); + $this->assertContains('site_credential.list.create_new_one', $body); + } + + public function testNewSiteCredential() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/site-credentials/new'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + + $body = $crawler->filter('body')->extract(['_text'])[0]; + + $this->assertContains('site_credential.new_site_credential', $body); + $this->assertContains('site_credential.form.back_to_list', $body); + + $form = $crawler->filter('button[id=site_credential_save]')->form(); + + $data = [ + 'site_credential[host]' => 'google.io', + 'site_credential[username]' => 'sergei', + 'site_credential[password]' => 'microsoft', + ]; + + $client->submit($form, $data); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertContains('flashes.site_credential.notice.added', $crawler->filter('body')->extract(['_text'])[0]); + } + + /** + * @depends testNewSiteCredential + */ + public function testEditSiteCredential() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $credential = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:SiteCredential') + ->findOneByHost('google.io'); + + $crawler = $client->request('GET', '/site-credentials/'.$credential->getId().'/edit'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + + $body = $crawler->filter('body')->extract(['_text'])[0]; + + $this->assertContains('site_credential.edit_site_credential', $body); + $this->assertContains('site_credential.form.back_to_list', $body); + + $form = $crawler->filter('button[id=site_credential_save]')->form(); + + $data = [ + 'site_credential[host]' => 'google.io', + 'site_credential[username]' => 'larry', + 'site_credential[password]' => 'microsoft', + ]; + + $client->submit($form, $data); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertContains('flashes.site_credential.notice.updated', $crawler->filter('body')->extract(['_text'])[0]); + $this->assertContains('larry', $crawler->filter('input[id=site_credential_username]')->attr('value')); + } + + /** + * @depends testNewSiteCredential + */ + public function testEditFromADifferentUserSiteCredential() + { + $this->logInAs('bob'); + $client = $this->getClient(); + + $credential = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:SiteCredential') + ->findOneByHost('google.io'); + + $client->request('GET', '/site-credentials/'.$credential->getId().'/edit'); + + $this->assertEquals(403, $client->getResponse()->getStatusCode()); + } + + /** + * @depends testNewSiteCredential + */ + public function testDeleteSiteCredential() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $credential = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:SiteCredential') + ->findOneByHost('google.io'); + + $crawler = $client->request('GET', '/site-credentials/'.$credential->getId().'/edit'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + + $deleteForm = $crawler->filter('body')->selectButton('site_credential.form.delete')->form(); + + $client->submit($deleteForm, []); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertContains('flashes.site_credential.notice.deleted', $crawler->filter('body')->extract(['_text'])[0]); + } +} diff --git a/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php b/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php index 8b50bce9..980f7579 100644 --- a/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php +++ b/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php @@ -8,6 +8,8 @@ use BD\GuzzleSiteAuthenticator\SiteConfig\SiteConfig; use Graby\SiteConfig\SiteConfig as GrabySiteConfig; use PHPUnit_Framework_TestCase; use Wallabag\CoreBundle\GuzzleSiteAuthenticator\GrabySiteConfigBuilder; +use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; +use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; class GrabySiteConfigBuilderTest extends PHPUnit_Framework_TestCase { @@ -17,7 +19,7 @@ class GrabySiteConfigBuilderTest extends PHPUnit_Framework_TestCase public function testBuildConfigExists() { /* @var \Graby\SiteConfig\ConfigBuilder|\PHPUnit_Framework_MockObject_MockObject */ - $grabyConfigBuilderMock = $this->getMockBuilder('\Graby\SiteConfig\ConfigBuilder') + $grabyConfigBuilderMock = $this->getMockBuilder('Graby\SiteConfig\ConfigBuilder') ->disableOriginalConstructor() ->getMock(); @@ -38,9 +40,30 @@ class GrabySiteConfigBuilderTest extends PHPUnit_Framework_TestCase $handler = new TestHandler(); $logger->pushHandler($handler); + $siteCrentialRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\SiteCredentialRepository') + ->disableOriginalConstructor() + ->getMock(); + $siteCrentialRepo->expects($this->once()) + ->method('findOneByHostAndUser') + ->with('example.com', 1) + ->willReturn(['username' => 'foo', 'password' => 'bar']); + + $user = $this->getMockBuilder('Wallabag\UserBundle\Entity\User') + ->disableOriginalConstructor() + ->getMock(); + $user->expects($this->once()) + ->method('getId') + ->willReturn(1); + + $token = new UsernamePasswordToken($user, 'pass', 'provider'); + + $tokenStorage = new TokenStorage(); + $tokenStorage->setToken($token); + $this->builder = new GrabySiteConfigBuilder( $grabyConfigBuilderMock, - ['example.com' => ['username' => 'foo', 'password' => 'bar']], + $tokenStorage, + $siteCrentialRepo, $logger ); @@ -82,9 +105,30 @@ class GrabySiteConfigBuilderTest extends PHPUnit_Framework_TestCase $handler = new TestHandler(); $logger->pushHandler($handler); + $siteCrentialRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\SiteCredentialRepository') + ->disableOriginalConstructor() + ->getMock(); + $siteCrentialRepo->expects($this->once()) + ->method('findOneByHostAndUser') + ->with('unknown.com', 1) + ->willReturn(null); + + $user = $this->getMockBuilder('Wallabag\UserBundle\Entity\User') + ->disableOriginalConstructor() + ->getMock(); + $user->expects($this->once()) + ->method('getId') + ->willReturn(1); + + $token = new UsernamePasswordToken($user, 'pass', 'provider'); + + $tokenStorage = new TokenStorage(); + $tokenStorage->setToken($token); + $this->builder = new GrabySiteConfigBuilder( $grabyConfigBuilderMock, - [], + $tokenStorage, + $siteCrentialRepo, $logger ); -- cgit v1.2.3 From 9de9f1e5ceed4ac7ecd27e1cb808e630a831f94b Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Wed, 3 May 2017 10:23:49 +0200 Subject: Add a live test for restricted article MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It is not aimed to test if we can get the full article (since we aren't using real login/password) but mostly to test the full work (with authentication, etc.) Do not clean fixtured to avoid SQLite to re-use id for entry tag relation 😓 --- .../CoreBundle/Controller/EntryControllerTest.php | 53 ++++++++++++++++++++++ .../Controller/SiteCredentialControllerTest.php | 44 +++++++++--------- .../GrabySiteConfigBuilderTest.php | 6 +-- 3 files changed, 78 insertions(+), 25 deletions(-) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index 8f5c372d..104f60f1 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php @@ -5,6 +5,7 @@ namespace Tests\Wallabag\CoreBundle\Controller; use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; use Wallabag\CoreBundle\Entity\Config; use Wallabag\CoreBundle\Entity\Entry; +use Wallabag\CoreBundle\Entity\SiteCredential; class EntryControllerTest extends WallabagCoreTestCase { @@ -1321,4 +1322,56 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertEquals($url, $content->getUrl()); $this->assertEquals($expectedLanguage, $content->getLanguage()); } + + /** + * This test will require an internet connection. + */ + public function testRestrictedArticle() + { + $url = 'http://www.monde-diplomatique.fr/2017/05/BONNET/57475'; + $this->logInAs('admin'); + $client = $this->getClient(); + $em = $client->getContainer()->get('doctrine.orm.entity_manager'); + + // enable restricted access + $client->getContainer()->get('craue_config')->set('restricted_access', 1); + + // create a new site_credential + $user = $client->getContainer()->get('security.token_storage')->getToken()->getUser(); + $credential = new SiteCredential($user); + $credential->setHost('monde-diplomatique.fr'); + $credential->setUsername('foo'); + $credential->setPassword('bar'); + + $em->persist($credential); + $em->flush(); + + $crawler = $client->request('GET', '/new'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + + $form = $crawler->filter('form[name=entry]')->form(); + + $data = [ + 'entry[url]' => $url, + ]; + + $client->submit($form, $data); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertContains('flashes.entry.notice.entry_saved', $crawler->filter('body')->extract(['_text'])[0]); + + $content = $em + ->getRepository('WallabagCoreBundle:Entry') + ->findByUrlAndUserId($url, $this->getLoggedInUserId()); + + $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); + $this->assertSame('Crimes et réformes aux Philippines', $content->getTitle()); + + $client->getContainer()->get('craue_config')->set('restricted_access', 0); + } } diff --git a/tests/Wallabag/CoreBundle/Controller/SiteCredentialControllerTest.php b/tests/Wallabag/CoreBundle/Controller/SiteCredentialControllerTest.php index 47bf0907..7e6dafee 100644 --- a/tests/Wallabag/CoreBundle/Controller/SiteCredentialControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/SiteCredentialControllerTest.php @@ -2,7 +2,9 @@ namespace Tests\Wallabag\CoreBundle\Controller; +use Symfony\Bundle\FrameworkBundle\Client; use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; +use Wallabag\CoreBundle\Entity\SiteCredential; class SiteCredentialControllerTest extends WallabagCoreTestCase { @@ -52,18 +54,12 @@ class SiteCredentialControllerTest extends WallabagCoreTestCase $this->assertContains('flashes.site_credential.notice.added', $crawler->filter('body')->extract(['_text'])[0]); } - /** - * @depends testNewSiteCredential - */ public function testEditSiteCredential() { $this->logInAs('admin'); $client = $this->getClient(); - $credential = $client->getContainer() - ->get('doctrine.orm.entity_manager') - ->getRepository('WallabagCoreBundle:SiteCredential') - ->findOneByHost('google.io'); + $credential = $this->createSiteCredential($client); $crawler = $client->request('GET', '/site-credentials/'.$credential->getId().'/edit'); @@ -92,36 +88,26 @@ class SiteCredentialControllerTest extends WallabagCoreTestCase $this->assertContains('larry', $crawler->filter('input[id=site_credential_username]')->attr('value')); } - /** - * @depends testNewSiteCredential - */ public function testEditFromADifferentUserSiteCredential() { - $this->logInAs('bob'); + $this->logInAs('admin'); $client = $this->getClient(); - $credential = $client->getContainer() - ->get('doctrine.orm.entity_manager') - ->getRepository('WallabagCoreBundle:SiteCredential') - ->findOneByHost('google.io'); + $credential = $this->createSiteCredential($client); + + $this->logInAs('bob'); $client->request('GET', '/site-credentials/'.$credential->getId().'/edit'); $this->assertEquals(403, $client->getResponse()->getStatusCode()); } - /** - * @depends testNewSiteCredential - */ public function testDeleteSiteCredential() { $this->logInAs('admin'); $client = $this->getClient(); - $credential = $client->getContainer() - ->get('doctrine.orm.entity_manager') - ->getRepository('WallabagCoreBundle:SiteCredential') - ->findOneByHost('google.io'); + $credential = $this->createSiteCredential($client); $crawler = $client->request('GET', '/site-credentials/'.$credential->getId().'/edit'); @@ -137,4 +123,18 @@ class SiteCredentialControllerTest extends WallabagCoreTestCase $this->assertContains('flashes.site_credential.notice.deleted', $crawler->filter('body')->extract(['_text'])[0]); } + + private function createSiteCredential(Client $client) + { + $credential = new SiteCredential($this->getLoggedInUser()); + $credential->setHost('google.io'); + $credential->setUsername('sergei'); + $credential->setPassword('microsoft'); + + $em = $client->getContainer()->get('doctrine.orm.entity_manager'); + $em->persist($credential); + $em->flush(); + + return $credential; + } } diff --git a/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php b/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php index 980f7579..1e1e8989 100644 --- a/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php +++ b/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php @@ -25,7 +25,7 @@ class GrabySiteConfigBuilderTest extends PHPUnit_Framework_TestCase $grabySiteConfig = new GrabySiteConfig(); $grabySiteConfig->requires_login = true; - $grabySiteConfig->login_uri = 'http://example.com/login'; + $grabySiteConfig->login_uri = 'http://www.example.com/login'; $grabySiteConfig->login_username_field = 'login'; $grabySiteConfig->login_password_field = 'password'; $grabySiteConfig->login_extra_fields = ['field=value']; @@ -67,13 +67,13 @@ class GrabySiteConfigBuilderTest extends PHPUnit_Framework_TestCase $logger ); - $config = $this->builder->buildForHost('example.com'); + $config = $this->builder->buildForHost('www.example.com'); $this->assertEquals( new SiteConfig([ 'host' => 'example.com', 'requiresLogin' => true, - 'loginUri' => 'http://example.com/login', + 'loginUri' => 'http://www.example.com/login', 'usernameField' => 'login', 'passwordField' => 'password', 'extraFields' => ['field' => 'value'], -- cgit v1.2.3 From 906424c1b6fd884bf2081bfe6dd0b1f9651c2801 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 11 Jun 2017 23:05:19 +0200 Subject: Crypt site credential password --- .../CoreBundle/Controller/EntryControllerTest.php | 2 +- .../GrabySiteConfigBuilderTest.php | 3 +- .../Wallabag/CoreBundle/Helper/CryptoProxyTest.php | 40 ++++++++++++++++++++++ 3 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 tests/Wallabag/CoreBundle/Helper/CryptoProxyTest.php (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index 104f60f1..80380685 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php @@ -1341,7 +1341,7 @@ class EntryControllerTest extends WallabagCoreTestCase $credential = new SiteCredential($user); $credential->setHost('monde-diplomatique.fr'); $credential->setUsername('foo'); - $credential->setPassword('bar'); + $credential->setPassword($client->getContainer()->get('wallabag_core.helper.crypto_proxy')->crypt('bar')); $em->persist($credential); $em->flush(); diff --git a/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php b/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php index 1e1e8989..b0c81e7b 100644 --- a/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php +++ b/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php @@ -6,12 +6,11 @@ use Monolog\Handler\TestHandler; use Monolog\Logger; use BD\GuzzleSiteAuthenticator\SiteConfig\SiteConfig; use Graby\SiteConfig\SiteConfig as GrabySiteConfig; -use PHPUnit_Framework_TestCase; use Wallabag\CoreBundle\GuzzleSiteAuthenticator\GrabySiteConfigBuilder; use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; -class GrabySiteConfigBuilderTest extends PHPUnit_Framework_TestCase +class GrabySiteConfigBuilderTest extends \PHPUnit_Framework_TestCase { /** @var \Wallabag\CoreBundle\GuzzleSiteAuthenticator\GrabySiteConfigBuilder */ protected $builder; diff --git a/tests/Wallabag/CoreBundle/Helper/CryptoProxyTest.php b/tests/Wallabag/CoreBundle/Helper/CryptoProxyTest.php new file mode 100644 index 00000000..cede8696 --- /dev/null +++ b/tests/Wallabag/CoreBundle/Helper/CryptoProxyTest.php @@ -0,0 +1,40 @@ +crypt('test'); + $decrypted = $crypto->decrypt($crypted); + + $this->assertSame('test', $decrypted); + + $records = $logHandler->getRecords(); + $this->assertCount(2, $records); + $this->assertContains('Crypto: crypting value', $records[0]['message']); + $this->assertContains('Crypto: decrypting value', $records[1]['message']); + } + + /** + * @expectedException RuntimeException + * @expectedExceptionMessage Decrypt fail + * + * @return [type] [description] + */ + public function testDecryptBadValue() + { + $crypto = new CryptoProxy(sys_get_temp_dir().'/'.uniqid('', true).'.txt', new NullLogger()); + $crypto->decrypt('badvalue'); + } +} -- cgit v1.2.3 From bead8b42da4f17238dc0d5e0f90184b224ec5df7 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 14 Jun 2017 15:02:34 +0200 Subject: Fix reviews Encrypt username too Redirect to list after saving credentials Fix typos Signed-off-by: Thomas Citharel --- tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php | 2 +- tests/Wallabag/CoreBundle/Controller/SiteCredentialControllerTest.php | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index 80380685..f17dc97b 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php @@ -1340,7 +1340,7 @@ class EntryControllerTest extends WallabagCoreTestCase $user = $client->getContainer()->get('security.token_storage')->getToken()->getUser(); $credential = new SiteCredential($user); $credential->setHost('monde-diplomatique.fr'); - $credential->setUsername('foo'); + $credential->setUsername($client->getContainer()->get('wallabag_core.helper.crypto_proxy')->crypt('foo')); $credential->setPassword($client->getContainer()->get('wallabag_core.helper.crypto_proxy')->crypt('bar')); $em->persist($credential); diff --git a/tests/Wallabag/CoreBundle/Controller/SiteCredentialControllerTest.php b/tests/Wallabag/CoreBundle/Controller/SiteCredentialControllerTest.php index 7e6dafee..e73a9743 100644 --- a/tests/Wallabag/CoreBundle/Controller/SiteCredentialControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/SiteCredentialControllerTest.php @@ -85,7 +85,6 @@ class SiteCredentialControllerTest extends WallabagCoreTestCase $crawler = $client->followRedirect(); $this->assertContains('flashes.site_credential.notice.updated', $crawler->filter('body')->extract(['_text'])[0]); - $this->assertContains('larry', $crawler->filter('input[id=site_credential_username]')->attr('value')); } public function testEditFromADifferentUserSiteCredential() -- cgit v1.2.3 From 18c38dffc67d04e59a9cc26b6910d9b9a4a49cd6 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 10 Jun 2017 13:11:08 +0200 Subject: Add RSS tags feeds --- .../CoreBundle/Controller/RssControllerTest.php | 41 +++++++++++++++++----- 1 file changed, 33 insertions(+), 8 deletions(-) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php b/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php index 5a59654d..b46f3f9d 100644 --- a/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php @@ -6,7 +6,7 @@ use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; class RssControllerTest extends WallabagCoreTestCase { - public function validateDom($xml, $type, $nb = null) + public function validateDom($xml, $type, $urlPagination, $nb = null) { $doc = new \DOMDocument(); $doc->loadXML($xml); @@ -34,10 +34,10 @@ class RssControllerTest extends WallabagCoreTestCase $this->assertEquals('wallabag '.$type.' elements', $xpath->query('/rss/channel/description')->item(0)->nodeValue); $this->assertEquals(1, $xpath->query('/rss/channel/link[@rel="self"]')->length); - $this->assertContains($type.'.xml', $xpath->query('/rss/channel/link[@rel="self"]')->item(0)->getAttribute('href')); + $this->assertContains($urlPagination.'.xml', $xpath->query('/rss/channel/link[@rel="self"]')->item(0)->getAttribute('href')); $this->assertEquals(1, $xpath->query('/rss/channel/link[@rel="last"]')->length); - $this->assertContains($type.'.xml?page=', $xpath->query('/rss/channel/link[@rel="last"]')->item(0)->getAttribute('href')); + $this->assertContains($urlPagination.'.xml?page=', $xpath->query('/rss/channel/link[@rel="last"]')->item(0)->getAttribute('href')); foreach ($xpath->query('//item') as $item) { $this->assertEquals(1, $xpath->query('title', $item)->length); @@ -94,7 +94,7 @@ class RssControllerTest extends WallabagCoreTestCase $this->assertEquals(200, $client->getResponse()->getStatusCode()); - $this->validateDom($client->getResponse()->getContent(), 'unread', 2); + $this->validateDom($client->getResponse()->getContent(), 'unread', 'unread', 2); } public function testStarred() @@ -116,7 +116,7 @@ class RssControllerTest extends WallabagCoreTestCase $this->assertEquals(200, $client->getResponse()->getStatusCode(), 1); - $this->validateDom($client->getResponse()->getContent(), 'starred'); + $this->validateDom($client->getResponse()->getContent(), 'starred', 'starred'); } public function testArchives() @@ -138,7 +138,7 @@ class RssControllerTest extends WallabagCoreTestCase $this->assertEquals(200, $client->getResponse()->getStatusCode()); - $this->validateDom($client->getResponse()->getContent(), 'archive'); + $this->validateDom($client->getResponse()->getContent(), 'archive', 'archive'); } public function testPagination() @@ -159,13 +159,38 @@ class RssControllerTest extends WallabagCoreTestCase $client->request('GET', '/admin/SUPERTOKEN/unread.xml'); $this->assertEquals(200, $client->getResponse()->getStatusCode()); - $this->validateDom($client->getResponse()->getContent(), 'unread'); + $this->validateDom($client->getResponse()->getContent(), 'unread', 'unread'); $client->request('GET', '/admin/SUPERTOKEN/unread.xml?page=2'); $this->assertEquals(200, $client->getResponse()->getStatusCode()); - $this->validateDom($client->getResponse()->getContent(), 'unread'); + $this->validateDom($client->getResponse()->getContent(), 'unread', 'unread'); $client->request('GET', '/admin/SUPERTOKEN/unread.xml?page=3000'); $this->assertEquals(302, $client->getResponse()->getStatusCode()); } + + public function testTags() + { + $client = $this->getClient(); + $em = $client->getContainer()->get('doctrine.orm.entity_manager'); + $user = $em + ->getRepository('WallabagUserBundle:User') + ->findOneByUsername('admin'); + + $config = $user->getConfig(); + $config->setRssToken('SUPERTOKEN'); + $config->setRssLimit(null); + $em->persist($config); + $em->flush(); + + $client = $this->getClient(); + $client->request('GET', '/admin/SUPERTOKEN/tags/foo-bar.xml'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + + $this->validateDom($client->getResponse()->getContent(), 'tag (foo bar)', 'tags/foo-bar'); + + $client->request('GET', '/admin/SUPERTOKEN/tags/foo-bar.xml?page=3000'); + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + } } -- cgit v1.2.3 From 11b8695663b3a649a452b8a4d2ee3ccd70202e9e Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 10 Jun 2017 14:24:42 +0200 Subject: Fix tests --- tests/Wallabag/CoreBundle/Controller/RssControllerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php b/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php index b46f3f9d..530c8bbf 100644 --- a/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php @@ -23,7 +23,7 @@ class RssControllerTest extends WallabagCoreTestCase $this->assertEquals(1, $xpath->query('/rss/channel')->length); $this->assertEquals(1, $xpath->query('/rss/channel/title')->length); - $this->assertEquals('wallabag — '.$type.' feed', $xpath->query('/rss/channel/title')->item(0)->nodeValue); + $this->assertEquals('wallabag - '.$type.' feed', $xpath->query('/rss/channel/title')->item(0)->nodeValue); $this->assertEquals(1, $xpath->query('/rss/channel/pubDate')->length); -- cgit v1.2.3 From f808b01692a835673f328d7221ba8c212caa9b61 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 1 Jul 2017 09:52:38 +0200 Subject: Add a real configuration for CS-Fixer --- .../Command/CleanDuplicatesCommandTest.php | 2 +- .../CoreBundle/Command/ExportCommandTest.php | 2 +- .../CoreBundle/Command/InstallCommandTest.php | 20 +- .../CoreBundle/Command/TagAllCommandTest.php | 2 +- .../CoreBundle/Controller/ConfigControllerTest.php | 116 ++++++------ .../CoreBundle/Controller/EntryControllerTest.php | 202 ++++++++++----------- .../CoreBundle/Controller/ExportControllerTest.php | 108 +++++------ .../CoreBundle/Controller/RssControllerTest.php | 58 +++--- .../Controller/SettingsControllerTest.php | 4 +- .../Controller/SiteCredentialControllerTest.php | 22 +-- .../CoreBundle/Controller/StaticControllerTest.php | 4 +- .../CoreBundle/Controller/TagControllerTest.php | 36 ++-- .../Event/Listener/LocaleListenerTest.php | 28 +-- .../Event/Listener/UserLocaleListenerTest.php | 4 +- .../Event/Subscriber/TablePrefixSubscriberTest.php | 18 +- .../GrabySiteConfigBuilderTest.php | 10 +- .../CoreBundle/Helper/ContentProxyTest.php | 152 ++++++++-------- .../Wallabag/CoreBundle/Helper/CryptoProxyTest.php | 10 +- .../CoreBundle/Helper/DownloadImagesTest.php | 46 ++--- tests/Wallabag/CoreBundle/Helper/RedirectTest.php | 20 +- .../CoreBundle/Helper/RuleBasedTaggerTest.php | 2 +- .../CoreBundle/Helper/TagsAssignerTest.php | 16 +- .../UsernameRssTokenConverterTest.php | 2 +- tests/Wallabag/CoreBundle/Tools/UtilsTest.php | 2 +- .../CoreBundle/Twig/WallabagExtensionTest.php | 6 +- tests/Wallabag/CoreBundle/WallabagCoreTestCase.php | 14 +- 26 files changed, 453 insertions(+), 453 deletions(-) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Command/CleanDuplicatesCommandTest.php b/tests/Wallabag/CoreBundle/Command/CleanDuplicatesCommandTest.php index e6e57f30..38e8dd07 100644 --- a/tests/Wallabag/CoreBundle/Command/CleanDuplicatesCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/CleanDuplicatesCommandTest.php @@ -4,8 +4,8 @@ namespace Tests\Wallabag\CoreBundle\Command; use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Component\Console\Tester\CommandTester; -use Wallabag\CoreBundle\Command\CleanDuplicatesCommand; use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; +use Wallabag\CoreBundle\Command\CleanDuplicatesCommand; use Wallabag\CoreBundle\Entity\Entry; class CleanDuplicatesCommandTest extends WallabagCoreTestCase diff --git a/tests/Wallabag/CoreBundle/Command/ExportCommandTest.php b/tests/Wallabag/CoreBundle/Command/ExportCommandTest.php index 2eebf39b..25de2730 100644 --- a/tests/Wallabag/CoreBundle/Command/ExportCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/ExportCommandTest.php @@ -4,8 +4,8 @@ namespace Tests\Wallabag\CoreBundle\Command; use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Component\Console\Tester\CommandTester; -use Wallabag\CoreBundle\Command\ExportCommand; use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; +use Wallabag\CoreBundle\Command\ExportCommand; class ExportCommandTest extends WallabagCoreTestCase { diff --git a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php index 94fc0b94..f684a206 100644 --- a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php @@ -11,9 +11,9 @@ use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Output\NullOutput; use Symfony\Component\Console\Tester\CommandTester; -use Wallabag\CoreBundle\Command\InstallCommand; use Tests\Wallabag\CoreBundle\Mock\InstallCommandMock; use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; +use Wallabag\CoreBundle\Command\InstallCommand; class InstallCommandTest extends WallabagCoreTestCase { @@ -86,9 +86,9 @@ class InstallCommandTest extends WallabagCoreTestCase $tester->setInputs([ 'y', // dropping database 'y', // create super admin - 'username_'.uniqid('', true), // username - 'password_'.uniqid('', true), // password - 'email_'.uniqid('', true).'@wallabag.it', // email + 'username_' . uniqid('', true), // username + 'password_' . uniqid('', true), // password + 'email_' . uniqid('', true) . '@wallabag.it', // email ]); $tester->execute([ 'command' => $command->getName(), @@ -111,9 +111,9 @@ class InstallCommandTest extends WallabagCoreTestCase $tester = new CommandTester($command); $tester->setInputs([ 'y', // create super admin - 'username_'.uniqid('', true), // username - 'password_'.uniqid('', true), // password - 'email_'.uniqid('', true).'@wallabag.it', // email + 'username_' . uniqid('', true), // username + 'password_' . uniqid('', true), // password + 'email_' . uniqid('', true) . '@wallabag.it', // email ]); $tester->execute([ 'command' => $command->getName(), @@ -159,9 +159,9 @@ class InstallCommandTest extends WallabagCoreTestCase $tester = new CommandTester($command); $tester->setInputs([ 'y', // create super admin - 'username_'.uniqid('', true), // username - 'password_'.uniqid('', true), // password - 'email_'.uniqid('', true).'@wallabag.it', // email + 'username_' . uniqid('', true), // username + 'password_' . uniqid('', true), // password + 'email_' . uniqid('', true) . '@wallabag.it', // email ]); $tester->execute([ 'command' => $command->getName(), diff --git a/tests/Wallabag/CoreBundle/Command/TagAllCommandTest.php b/tests/Wallabag/CoreBundle/Command/TagAllCommandTest.php index 4cde3679..96d0e91f 100644 --- a/tests/Wallabag/CoreBundle/Command/TagAllCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/TagAllCommandTest.php @@ -4,8 +4,8 @@ namespace Tests\Wallabag\CoreBundle\Command; use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Component\Console\Tester\CommandTester; -use Wallabag\CoreBundle\Command\TagAllCommand; use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; +use Wallabag\CoreBundle\Command\TagAllCommand; class TagAllCommandTest extends WallabagCoreTestCase { diff --git a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php index 5bc815ee..e4bf0998 100644 --- a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php @@ -3,11 +3,11 @@ namespace tests\Wallabag\CoreBundle\Controller; use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; +use Wallabag\AnnotationBundle\Entity\Annotation; use Wallabag\CoreBundle\Entity\Config; -use Wallabag\UserBundle\Entity\User; use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Entity\Tag; -use Wallabag\AnnotationBundle\Entity\Annotation; +use Wallabag\UserBundle\Entity\User; class ConfigControllerTest extends WallabagCoreTestCase { @@ -17,7 +17,7 @@ class ConfigControllerTest extends WallabagCoreTestCase $client->request('GET', '/new'); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertSame(302, $client->getResponse()->getStatusCode()); $this->assertContains('login', $client->getResponse()->headers->get('location')); } @@ -28,7 +28,7 @@ class ConfigControllerTest extends WallabagCoreTestCase $crawler = $client->request('GET', '/config'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $this->assertCount(1, $crawler->filter('button[id=config_save]')); $this->assertCount(1, $crawler->filter('button[id=change_passwd_save]')); @@ -43,7 +43,7 @@ class ConfigControllerTest extends WallabagCoreTestCase $crawler = $client->request('GET', '/config'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $form = $crawler->filter('button[id=config_save]')->form(); @@ -57,7 +57,7 @@ class ConfigControllerTest extends WallabagCoreTestCase $client->submit($form, $data); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertSame(302, $client->getResponse()->getStatusCode()); $crawler = $client->followRedirect(); @@ -131,13 +131,13 @@ class ConfigControllerTest extends WallabagCoreTestCase $crawler = $client->request('GET', '/config'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $form = $crawler->filter('button[id=config_save]')->form(); $crawler = $client->submit($form, $data); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text'])); $this->assertContains('This value should not be blank', $alert[0]); @@ -191,13 +191,13 @@ class ConfigControllerTest extends WallabagCoreTestCase $crawler = $client->request('GET', '/config'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $form = $crawler->filter('button[id=change_passwd_save]')->form(); $crawler = $client->submit($form, $data); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text'])); $this->assertContains($expectedMessage, $alert[0]); @@ -210,7 +210,7 @@ class ConfigControllerTest extends WallabagCoreTestCase $crawler = $client->request('GET', '/config'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $form = $crawler->filter('button[id=change_passwd_save]')->form(); @@ -222,7 +222,7 @@ class ConfigControllerTest extends WallabagCoreTestCase $client->submit($form, $data); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertSame(302, $client->getResponse()->getStatusCode()); $crawler = $client->followRedirect(); @@ -259,13 +259,13 @@ class ConfigControllerTest extends WallabagCoreTestCase $crawler = $client->request('GET', '/config'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $form = $crawler->filter('button[id=update_user_save]')->form(); $crawler = $client->submit($form, $data); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text'])); $this->assertContains($expectedMessage, $alert[0]); @@ -278,7 +278,7 @@ class ConfigControllerTest extends WallabagCoreTestCase $crawler = $client->request('GET', '/config'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $form = $crawler->filter('button[id=update_user_save]')->form(); @@ -289,7 +289,7 @@ class ConfigControllerTest extends WallabagCoreTestCase $client->submit($form, $data); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertSame(302, $client->getResponse()->getStatusCode()); $crawler = $client->followRedirect(); @@ -319,13 +319,13 @@ class ConfigControllerTest extends WallabagCoreTestCase $crawler = $client->request('GET', '/config'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); $this->assertContains('config.form_rss.no_token', $body[0]); $client->request('GET', '/generate-token'); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertSame(302, $client->getResponse()->getStatusCode()); $crawler = $client->followRedirect(); @@ -346,7 +346,7 @@ class ConfigControllerTest extends WallabagCoreTestCase ['HTTP_X-Requested-With' => 'XMLHttpRequest'] ); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $content = json_decode($client->getResponse()->getContent(), true); $this->assertArrayHasKey('token', $content); } @@ -358,7 +358,7 @@ class ConfigControllerTest extends WallabagCoreTestCase $crawler = $client->request('GET', '/config'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $form = $crawler->filter('button[id=rss_config_save]')->form(); @@ -368,7 +368,7 @@ class ConfigControllerTest extends WallabagCoreTestCase $client->submit($form, $data); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertSame(302, $client->getResponse()->getStatusCode()); $crawler = $client->followRedirect(); @@ -403,13 +403,13 @@ class ConfigControllerTest extends WallabagCoreTestCase $crawler = $client->request('GET', '/config'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $form = $crawler->filter('button[id=rss_config_save]')->form(); $crawler = $client->submit($form, $data); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text'])); $this->assertContains($expectedMessage, $alert[0]); @@ -423,7 +423,7 @@ class ConfigControllerTest extends WallabagCoreTestCase $crawler = $client->request('GET', '/config'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $form = $crawler->filter('button[id=tagging_rule_save]')->form(); @@ -434,7 +434,7 @@ class ConfigControllerTest extends WallabagCoreTestCase $client->submit($form, $data); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertSame(302, $client->getResponse()->getStatusCode()); $crawler = $client->followRedirect(); @@ -443,7 +443,7 @@ class ConfigControllerTest extends WallabagCoreTestCase $editLink = $crawler->filter('.mode_edit')->last()->link(); $crawler = $client->click($editLink); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertSame(302, $client->getResponse()->getStatusCode()); $this->assertContains('?tagging-rule=', $client->getResponse()->headers->get('location')); $crawler = $client->followRedirect(); @@ -457,7 +457,7 @@ class ConfigControllerTest extends WallabagCoreTestCase $client->submit($form, $data); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertSame(302, $client->getResponse()->getStatusCode()); $crawler = $client->followRedirect(); @@ -468,7 +468,7 @@ class ConfigControllerTest extends WallabagCoreTestCase $deleteLink = $crawler->filter('.delete')->last()->link(); $crawler = $client->click($deleteLink); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertSame(302, $client->getResponse()->getStatusCode()); $crawler = $client->followRedirect(); $this->assertContains('flashes.config.notice.tagging_rules_deleted', $crawler->filter('body')->extract(['_text'])[0]); @@ -510,13 +510,13 @@ class ConfigControllerTest extends WallabagCoreTestCase $crawler = $client->request('GET', '/config'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $form = $crawler->filter('button[id=tagging_rule_save]')->form(); $crawler = $client->submit($form, $data); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); @@ -532,7 +532,7 @@ class ConfigControllerTest extends WallabagCoreTestCase $crawler = $client->request('GET', '/config'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $form = $crawler->filter('button[id=tagging_rule_save]')->form(); @@ -541,7 +541,7 @@ class ConfigControllerTest extends WallabagCoreTestCase 'tagging_rule[tags]' => 'cool tag', ]); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); @@ -557,9 +557,9 @@ class ConfigControllerTest extends WallabagCoreTestCase ->getRepository('WallabagCoreBundle:TaggingRule') ->findAll()[0]; - $crawler = $client->request('GET', '/tagging-rule/edit/'.$rule->getId()); + $crawler = $client->request('GET', '/tagging-rule/edit/' . $rule->getId()); - $this->assertEquals(403, $client->getResponse()->getStatusCode()); + $this->assertSame(403, $client->getResponse()->getStatusCode()); $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); $this->assertContains('You can not access this tagging rule', $body[0]); } @@ -573,9 +573,9 @@ class ConfigControllerTest extends WallabagCoreTestCase ->getRepository('WallabagCoreBundle:TaggingRule') ->findAll()[0]; - $crawler = $client->request('GET', '/tagging-rule/edit/'.$rule->getId()); + $crawler = $client->request('GET', '/tagging-rule/edit/' . $rule->getId()); - $this->assertEquals(403, $client->getResponse()->getStatusCode()); + $this->assertSame(403, $client->getResponse()->getStatusCode()); $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); $this->assertContains('You can not access this tagging rule', $body[0]); } @@ -591,7 +591,7 @@ class ConfigControllerTest extends WallabagCoreTestCase $crawler = $client->request('GET', '/config'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $form = $crawler->filter('button[id=change_passwd_save]')->form(); @@ -603,7 +603,7 @@ class ConfigControllerTest extends WallabagCoreTestCase $client->submit($form, $data); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertSame(302, $client->getResponse()->getStatusCode()); $this->assertContains('flashes.config.notice.password_not_updated_demo', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]); $config->set('demo_mode_enabled', 0); @@ -642,7 +642,7 @@ class ConfigControllerTest extends WallabagCoreTestCase $this->assertNotContains('config.form_user.delete.button', $body[0]); $client->request('GET', '/account/delete'); - $this->assertEquals(403, $client->getResponse()->getStatusCode()); + $this->assertSame(403, $client->getResponse()->getStatusCode()); $user = $em ->getRepository('WallabagUserBundle:User') @@ -692,7 +692,7 @@ class ConfigControllerTest extends WallabagCoreTestCase // that this entry is also deleted $crawler = $client->request('GET', '/new'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $form = $crawler->filter('form[name=entry]')->form(); $data = [ @@ -700,14 +700,14 @@ class ConfigControllerTest extends WallabagCoreTestCase ]; $client->submit($form, $data); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertSame(302, $client->getResponse()->getStatusCode()); $crawler = $client->request('GET', '/config'); $deleteLink = $crawler->filter('.delete-account')->last()->link(); $client->click($deleteLink); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertSame(302, $client->getResponse()->getStatusCode()); $em = $client->getContainer()->get('doctrine.orm.entity_manager'); $user = $em @@ -767,11 +767,11 @@ class ConfigControllerTest extends WallabagCoreTestCase // reset annotations $crawler = $client->request('GET', '/config#set3'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $crawler = $client->click($crawler->selectLink('config.reset.annotations')->link()); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertSame(302, $client->getResponse()->getStatusCode()); $this->assertContains('flashes.config.notice.annotations_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]); $annotationsReset = $em @@ -783,34 +783,34 @@ class ConfigControllerTest extends WallabagCoreTestCase // reset tags $crawler = $client->request('GET', '/config#set3'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $crawler = $client->click($crawler->selectLink('config.reset.tags')->link()); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertSame(302, $client->getResponse()->getStatusCode()); $this->assertContains('flashes.config.notice.tags_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]); $tagReset = $em ->getRepository('WallabagCoreBundle:Tag') ->countAllTags($user->getId()); - $this->assertEquals(0, $tagReset, 'Tags were reset'); + $this->assertSame(0, $tagReset, 'Tags were reset'); // reset entries $crawler = $client->request('GET', '/config#set3'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $crawler = $client->click($crawler->selectLink('config.reset.entries')->link()); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertSame(302, $client->getResponse()->getStatusCode()); $this->assertContains('flashes.config.notice.entries_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]); $entryReset = $em ->getRepository('WallabagCoreBundle:Entry') ->countAllEntriesByUser($user->getId()); - $this->assertEquals(0, $entryReset, 'Entries were reset'); + $this->assertSame(0, $entryReset, 'Entries were reset'); } public function testResetArchivedEntries() @@ -863,24 +863,24 @@ class ConfigControllerTest extends WallabagCoreTestCase $crawler = $client->request('GET', '/config#set3'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $crawler = $client->click($crawler->selectLink('config.reset.archived')->link()); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertSame(302, $client->getResponse()->getStatusCode()); $this->assertContains('flashes.config.notice.archived_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]); $entryReset = $em ->getRepository('WallabagCoreBundle:Entry') ->countAllEntriesByUser($user->getId()); - $this->assertEquals(1, $entryReset, 'Entries were reset'); + $this->assertSame(1, $entryReset, 'Entries were reset'); $tagReset = $em ->getRepository('WallabagCoreBundle:Tag') ->countAllTags($user->getId()); - $this->assertEquals(1, $tagReset, 'Tags were reset'); + $this->assertSame(1, $tagReset, 'Tags were reset'); $annotationsReset = $em ->getRepository('WallabagAnnotationBundle:Annotation') @@ -920,24 +920,24 @@ class ConfigControllerTest extends WallabagCoreTestCase $crawler = $client->request('GET', '/config#set3'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $crawler = $client->click($crawler->selectLink('config.reset.entries')->link()); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertSame(302, $client->getResponse()->getStatusCode()); $this->assertContains('flashes.config.notice.entries_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]); $entryReset = $em ->getRepository('WallabagCoreBundle:Entry') ->countAllEntriesByUser($user->getId()); - $this->assertEquals(0, $entryReset, 'Entries were reset'); + $this->assertSame(0, $entryReset, 'Entries were reset'); $tagReset = $em ->getRepository('WallabagCoreBundle:Tag') ->countAllTags($user->getId()); - $this->assertEquals(0, $tagReset, 'Tags were reset'); + $this->assertSame(0, $tagReset, 'Tags were reset'); $annotationsReset = $em ->getRepository('WallabagAnnotationBundle:Annotation') diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index 7cf28bfe..b528bcdb 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php @@ -33,7 +33,7 @@ class EntryControllerTest extends WallabagCoreTestCase $client->request('GET', '/new'); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertSame(302, $client->getResponse()->getStatusCode()); $this->assertContains('login', $client->getResponse()->headers->get('location')); } @@ -45,14 +45,14 @@ class EntryControllerTest extends WallabagCoreTestCase $client->request('GET', '/unread/list'); $crawler = $client->followRedirect(); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); $this->assertContains('quickstart.intro.title', $body[0]); // Test if quickstart is disabled when user has 1 entry $crawler = $client->request('GET', '/new'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $form = $crawler->filter('form[name=entry]')->form(); @@ -61,7 +61,7 @@ class EntryControllerTest extends WallabagCoreTestCase ]; $client->submit($form, $data); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertSame(302, $client->getResponse()->getStatusCode()); $client->followRedirect(); $crawler = $client->request('GET', '/unread/list'); @@ -77,7 +77,7 @@ class EntryControllerTest extends WallabagCoreTestCase $crawler = $client->request('GET', '/new'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $this->assertCount(1, $crawler->filter('input[type=url]')); $this->assertCount(1, $crawler->filter('form[name=entry]')); @@ -95,7 +95,7 @@ class EntryControllerTest extends WallabagCoreTestCase // Good URL $client->request('GET', '/bookmarklet', ['url' => $this->url]); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertSame(302, $client->getResponse()->getStatusCode()); $client->followRedirect(); $crawler = $client->request('GET', '/'); $this->assertCount(5, $crawler->filter('div[class=entry]')); @@ -116,15 +116,15 @@ class EntryControllerTest extends WallabagCoreTestCase $crawler = $client->request('GET', '/new'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $form = $crawler->filter('form[name=entry]')->form(); $crawler = $client->submit($form); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $this->assertCount(1, $alert = $crawler->filter('form ul li')->extract(['_text'])); - $this->assertEquals('This value should not be blank.', $alert[0]); + $this->assertSame('This value should not be blank.', $alert[0]); } /** @@ -137,7 +137,7 @@ class EntryControllerTest extends WallabagCoreTestCase $crawler = $client->request('GET', '/new'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $form = $crawler->filter('form[name=entry]')->form(); @@ -147,7 +147,7 @@ class EntryControllerTest extends WallabagCoreTestCase $client->submit($form, $data); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertSame(302, $client->getResponse()->getStatusCode()); $content = $client->getContainer() ->get('doctrine.orm.entity_manager') @@ -157,11 +157,11 @@ class EntryControllerTest extends WallabagCoreTestCase $author = $content->getPublishedBy(); $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); - $this->assertEquals($this->url, $content->getUrl()); + $this->assertSame($this->url, $content->getUrl()); $this->assertContains('Google', $content->getTitle()); - $this->assertEquals('fr', $content->getLanguage()); - $this->assertEquals('2015-03-28 15:37:39', $content->getPublishedAt()->format('Y-m-d H:i:s')); - $this->assertEquals('Morgane Tual', $author[0]); + $this->assertSame('fr', $content->getLanguage()); + $this->assertSame('2015-03-28 15:37:39', $content->getPublishedAt()->format('Y-m-d H:i:s')); + $this->assertSame('Morgane Tual', $author[0]); $this->assertArrayHasKey('x-varnish1', $content->getHeaders()); } @@ -173,7 +173,7 @@ class EntryControllerTest extends WallabagCoreTestCase $crawler = $client->request('GET', '/new'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $form = $crawler->filter('form[name=entry]')->form(); @@ -183,7 +183,7 @@ class EntryControllerTest extends WallabagCoreTestCase $client->submit($form, $data); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertSame(302, $client->getResponse()->getStatusCode()); $content = $client->getContainer() ->get('doctrine.orm.entity_manager') @@ -191,10 +191,10 @@ class EntryControllerTest extends WallabagCoreTestCase ->findByUrlAndUserId($url, $this->getLoggedInUserId()); $authors = $content->getPublishedBy(); - $this->assertEquals('2017-04-05 19:26:13', $content->getPublishedAt()->format('Y-m-d H:i:s')); - $this->assertEquals('fr', $content->getLanguage()); - $this->assertEquals('Raphaël Balenieri, correspondant à Pékin', $authors[0]); - $this->assertEquals('Frédéric Autran, correspondant à New York', $authors[1]); + $this->assertSame('2017-04-05 19:26:13', $content->getPublishedAt()->format('Y-m-d H:i:s')); + $this->assertSame('fr', $content->getLanguage()); + $this->assertSame('Raphaël Balenieri, correspondant à Pékin', $authors[0]); + $this->assertSame('Frédéric Autran, correspondant à New York', $authors[1]); } public function testPostNewOkUrlExist() @@ -210,7 +210,7 @@ class EntryControllerTest extends WallabagCoreTestCase $crawler = $client->request('GET', '/new'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $form = $crawler->filter('form[name=entry]')->form(); @@ -220,7 +220,7 @@ class EntryControllerTest extends WallabagCoreTestCase $client->submit($form, $data); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertSame(302, $client->getResponse()->getStatusCode()); $this->assertContains('/view/', $client->getResponse()->getTargetUrl()); } @@ -233,7 +233,7 @@ class EntryControllerTest extends WallabagCoreTestCase $crawler = $client->request('GET', '/new'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $form = $crawler->filter('form[name=entry]')->form(); @@ -245,7 +245,7 @@ class EntryControllerTest extends WallabagCoreTestCase $crawler = $client->request('GET', '/new'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $form = $crawler->filter('form[name=entry]')->form(); @@ -255,7 +255,7 @@ class EntryControllerTest extends WallabagCoreTestCase $client->submit($form, $data); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertSame(302, $client->getResponse()->getStatusCode()); $this->assertContains('/view/', $client->getResponse()->getTargetUrl()); } @@ -269,7 +269,7 @@ class EntryControllerTest extends WallabagCoreTestCase $crawler = $client->request('GET', '/new'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $form = $crawler->filter('form[name=entry]')->form(); @@ -279,7 +279,7 @@ class EntryControllerTest extends WallabagCoreTestCase $client->submit($form, $data); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertSame(302, $client->getResponse()->getStatusCode()); $this->assertContains('/', $client->getResponse()->getTargetUrl()); $em = $client->getContainer() @@ -291,7 +291,7 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertCount(2, $tags); $this->assertContains('wallabag', $tags); - $this->assertEquals('en', $entry->getLanguage()); + $this->assertSame('en', $entry->getLanguage()); $em->remove($entry); $em->flush(); @@ -300,7 +300,7 @@ class EntryControllerTest extends WallabagCoreTestCase // related https://github.com/wallabag/wallabag/issues/2121 $crawler = $client->request('GET', '/new'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $form = $crawler->filter('form[name=entry]')->form(); @@ -310,7 +310,7 @@ class EntryControllerTest extends WallabagCoreTestCase $client->submit($form, $data); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertSame(302, $client->getResponse()->getStatusCode()); $this->assertContains('/', $client->getResponse()->getTargetUrl()); $entry = $em @@ -333,7 +333,7 @@ class EntryControllerTest extends WallabagCoreTestCase $client->request('GET', '/archive/list'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); } public function testUntagged() @@ -343,7 +343,7 @@ class EntryControllerTest extends WallabagCoreTestCase $client->request('GET', '/untagged/list'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); } public function testStarred() @@ -353,7 +353,7 @@ class EntryControllerTest extends WallabagCoreTestCase $client->request('GET', '/starred/list'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); } public function testRangeException() @@ -363,8 +363,8 @@ class EntryControllerTest extends WallabagCoreTestCase $client->request('GET', '/all/list/900'); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); - $this->assertEquals('/all/list', $client->getResponse()->getTargetUrl()); + $this->assertSame(302, $client->getResponse()->getStatusCode()); + $this->assertSame('/all/list', $client->getResponse()->getTargetUrl()); } public function testView() @@ -379,9 +379,9 @@ class EntryControllerTest extends WallabagCoreTestCase $this->getEntityManager()->persist($entry); $this->getEntityManager()->flush(); - $crawler = $client->request('GET', '/view/'.$entry->getId()); + $crawler = $client->request('GET', '/view/' . $entry->getId()); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); $this->assertContains($entry->getTitle(), $body[0]); } @@ -402,9 +402,9 @@ class EntryControllerTest extends WallabagCoreTestCase $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); - $client->request('GET', '/reload/'.$entry->getId()); + $client->request('GET', '/reload/' . $entry->getId()); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertSame(302, $client->getResponse()->getStatusCode()); $entry = $this->getEntityManager() ->getRepository('WallabagCoreBundle:Entry') @@ -423,9 +423,9 @@ class EntryControllerTest extends WallabagCoreTestCase $this->getEntityManager()->persist($entry); $this->getEntityManager()->flush(); - $client->request('GET', '/reload/'.$entry->getId()); + $client->request('GET', '/reload/' . $entry->getId()); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertSame(302, $client->getResponse()->getStatusCode()); // force EntityManager to clear previous entity // otherwise, retrieve the same entity will retrieve change from the previous request :0 @@ -434,7 +434,7 @@ class EntryControllerTest extends WallabagCoreTestCase ->getRepository('WallabagCoreBundle:Entry') ->find($entry->getId()); - $this->assertNotEquals($client->getContainer()->getParameter('wallabag_core.fetching_error_message'), $newContent->getContent()); + $this->assertNotSame($client->getContainer()->getParameter('wallabag_core.fetching_error_message'), $newContent->getContent()); } public function testEdit() @@ -447,9 +447,9 @@ class EntryControllerTest extends WallabagCoreTestCase $this->getEntityManager()->persist($entry); $this->getEntityManager()->flush(); - $crawler = $client->request('GET', '/edit/'.$entry->getId()); + $crawler = $client->request('GET', '/edit/' . $entry->getId()); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $this->assertCount(1, $crawler->filter('input[id=entry_title]')); $this->assertCount(1, $crawler->filter('button[id=entry_save]')); @@ -465,9 +465,9 @@ class EntryControllerTest extends WallabagCoreTestCase $this->getEntityManager()->persist($entry); $this->getEntityManager()->flush(); - $crawler = $client->request('GET', '/edit/'.$entry->getId()); + $crawler = $client->request('GET', '/edit/' . $entry->getId()); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $form = $crawler->filter('button[type=submit]')->form(); @@ -477,7 +477,7 @@ class EntryControllerTest extends WallabagCoreTestCase $client->submit($form, $data); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertSame(302, $client->getResponse()->getStatusCode()); $crawler = $client->followRedirect(); @@ -496,16 +496,16 @@ class EntryControllerTest extends WallabagCoreTestCase $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); - $client->request('GET', '/archive/'.$entry->getId()); + $client->request('GET', '/archive/' . $entry->getId()); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertSame(302, $client->getResponse()->getStatusCode()); $res = $client->getContainer() ->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') ->find($entry->getId()); - $this->assertEquals($res->isArchived(), true); + $this->assertSame($res->isArchived(), true); } public function testToggleStar() @@ -519,16 +519,16 @@ class EntryControllerTest extends WallabagCoreTestCase $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); - $client->request('GET', '/star/'.$entry->getId()); + $client->request('GET', '/star/' . $entry->getId()); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertSame(302, $client->getResponse()->getStatusCode()); $res = $client->getContainer() ->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') ->findOneById($entry->getId()); - $this->assertEquals($res->isStarred(), true); + $this->assertSame($res->isStarred(), true); } public function testDelete() @@ -541,13 +541,13 @@ class EntryControllerTest extends WallabagCoreTestCase $this->getEntityManager()->persist($entry); $this->getEntityManager()->flush(); - $client->request('GET', '/delete/'.$entry->getId()); + $client->request('GET', '/delete/' . $entry->getId()); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertSame(302, $client->getResponse()->getStatusCode()); - $client->request('GET', '/delete/'.$entry->getId()); + $client->request('GET', '/delete/' . $entry->getId()); - $this->assertEquals(404, $client->getResponse()->getStatusCode()); + $this->assertSame(404, $client->getResponse()->getStatusCode()); } /** @@ -583,14 +583,14 @@ class EntryControllerTest extends WallabagCoreTestCase $em->persist($content); $em->flush(); - $client->request('GET', '/view/'.$content->getId()); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $client->request('GET', '/view/' . $content->getId()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); - $client->request('GET', '/delete/'.$content->getId()); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $client->request('GET', '/delete/' . $content->getId()); + $this->assertSame(302, $client->getResponse()->getStatusCode()); $client->followRedirect(); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); } public function testViewOtherUserEntry() @@ -603,9 +603,9 @@ class EntryControllerTest extends WallabagCoreTestCase ->getRepository('WallabagCoreBundle:Entry') ->findOneByUsernameAndNotArchived('bob'); - $client->request('GET', '/view/'.$content->getId()); + $client->request('GET', '/view/' . $content->getId()); - $this->assertEquals(403, $client->getResponse()->getStatusCode()); + $this->assertSame(403, $client->getResponse()->getStatusCode()); } public function testFilterOnReadingTime() @@ -793,7 +793,7 @@ class EntryControllerTest extends WallabagCoreTestCase $parameters = '?entry_filter%5BreadingTime%5D%5Bleft_number%5D=&entry_filter%5BreadingTime%5D%5Bright_number%5D='; - $client->request('GET', 'unread/list'.$parameters); + $client->request('GET', 'unread/list' . $parameters); $this->assertContains($parameters, $client->getResponse()->getContent()); @@ -934,16 +934,16 @@ class EntryControllerTest extends WallabagCoreTestCase $this->getEntityManager()->clear(); // no uid - $client->request('GET', '/share/'.$content->getUid()); - $this->assertEquals(404, $client->getResponse()->getStatusCode()); + $client->request('GET', '/share/' . $content->getUid()); + $this->assertSame(404, $client->getResponse()->getStatusCode()); // generating the uid - $client->request('GET', '/share/'.$content->getId()); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $client->request('GET', '/share/' . $content->getId()); + $this->assertSame(302, $client->getResponse()->getStatusCode()); // follow link with uid $crawler = $client->followRedirect(); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $this->assertContains('max-age=25200', $client->getResponse()->headers->get('cache-control')); $this->assertContains('public', $client->getResponse()->headers->get('cache-control')); $this->assertContains('s-maxage=25200', $client->getResponse()->headers->get('cache-control')); @@ -955,19 +955,19 @@ class EntryControllerTest extends WallabagCoreTestCase // sharing is now disabled $client->getContainer()->get('craue_config')->set('share_public', 0); - $client->request('GET', '/share/'.$content->getUid()); - $this->assertEquals(404, $client->getResponse()->getStatusCode()); + $client->request('GET', '/share/' . $content->getUid()); + $this->assertSame(404, $client->getResponse()->getStatusCode()); - $client->request('GET', '/view/'.$content->getId()); + $client->request('GET', '/view/' . $content->getId()); $this->assertContains('no-cache', $client->getResponse()->headers->get('cache-control')); // removing the share - $client->request('GET', '/share/delete/'.$content->getId()); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $client->request('GET', '/share/delete/' . $content->getId()); + $this->assertSame(302, $client->getResponse()->getStatusCode()); // share is now disable - $client->request('GET', '/share/'.$content->getUid()); - $this->assertEquals(404, $client->getResponse()->getStatusCode()); + $client->request('GET', '/share/' . $content->getUid()); + $this->assertSame(404, $client->getResponse()->getStatusCode()); } public function testNewEntryWithDownloadImagesEnabled() @@ -981,7 +981,7 @@ class EntryControllerTest extends WallabagCoreTestCase $crawler = $client->request('GET', '/new'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $form = $crawler->filter('form[name=entry]')->form(); @@ -991,7 +991,7 @@ class EntryControllerTest extends WallabagCoreTestCase $client->submit($form, $data); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertSame(302, $client->getResponse()->getStatusCode()); $em = $client->getContainer() ->get('doctrine.orm.entity_manager'); @@ -1001,7 +1001,7 @@ class EntryControllerTest extends WallabagCoreTestCase ->findByUrlAndUserId($url, $this->getLoggedInUserId()); $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $entry); - $this->assertEquals($url, $entry->getUrl()); + $this->assertSame($url, $entry->getUrl()); $this->assertContains('Perpignan', $entry->getTitle()); // instead of checking for the filename (which might change) check that the image is now local $this->assertContains('https://your-wallabag-url-instance.com/assets/images/', $entry->getContent()); @@ -1023,7 +1023,7 @@ class EntryControllerTest extends WallabagCoreTestCase $crawler = $client->request('GET', '/new'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $form = $crawler->filter('form[name=entry]')->form(); @@ -1033,16 +1033,16 @@ class EntryControllerTest extends WallabagCoreTestCase $client->submit($form, $data); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertSame(302, $client->getResponse()->getStatusCode()); $content = $client->getContainer() ->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') ->findByUrlAndUserId($url, $this->getLoggedInUserId()); - $client->request('GET', '/delete/'.$content->getId()); + $client->request('GET', '/delete/' . $content->getId()); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertSame(302, $client->getResponse()->getStatusCode()); $client->getContainer()->get('craue_config')->set('download_images_enabled', 0); } @@ -1063,11 +1063,11 @@ class EntryControllerTest extends WallabagCoreTestCase $this->getEntityManager()->flush(); - $client->request('GET', '/view/'.$entry->getId()); - $client->request('GET', '/archive/'.$entry->getId()); + $client->request('GET', '/view/' . $entry->getId()); + $client->request('GET', '/archive/' . $entry->getId()); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); - $this->assertEquals('/', $client->getResponse()->headers->get('location')); + $this->assertSame(302, $client->getResponse()->getStatusCode()); + $this->assertSame('/', $client->getResponse()->headers->get('location')); } public function testRedirectToCurrentPage() @@ -1086,11 +1086,11 @@ class EntryControllerTest extends WallabagCoreTestCase $this->getEntityManager()->flush(); - $client->request('GET', '/view/'.$entry->getId()); - $client->request('GET', '/archive/'.$entry->getId()); + $client->request('GET', '/view/' . $entry->getId()); + $client->request('GET', '/archive/' . $entry->getId()); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); - $this->assertContains('/view/'.$entry->getId(), $client->getResponse()->headers->get('location')); + $this->assertSame(302, $client->getResponse()->getStatusCode()); + $this->assertContains('/view/' . $entry->getId(), $client->getResponse()->headers->get('location')); } public function testFilterOnHttpStatus() @@ -1213,7 +1213,7 @@ class EntryControllerTest extends WallabagCoreTestCase $crawler = $client->submit($form, $data); $this->assertCount(1, $crawler->filter('div[class=entry]')); - $client->request('GET', '/delete/'.$entry->getId()); + $client->request('GET', '/delete/' . $entry->getId()); // test on list of all articles $crawler = $client->request('GET', '/all/list'); @@ -1315,7 +1315,7 @@ class EntryControllerTest extends WallabagCoreTestCase $crawler = $client->request('GET', '/new'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $form = $crawler->filter('form[name=entry]')->form(); @@ -1325,7 +1325,7 @@ class EntryControllerTest extends WallabagCoreTestCase $client->submit($form, $data); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertSame(302, $client->getResponse()->getStatusCode()); $content = $client->getContainer() ->get('doctrine.orm.entity_manager') @@ -1333,8 +1333,8 @@ class EntryControllerTest extends WallabagCoreTestCase ->findByUrlAndUserId($url, $this->getLoggedInUserId()); $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); - $this->assertEquals($url, $content->getUrl()); - $this->assertEquals($expectedLanguage, $content->getLanguage()); + $this->assertSame($url, $content->getUrl()); + $this->assertSame($expectedLanguage, $content->getLanguage()); } /** @@ -1362,7 +1362,7 @@ class EntryControllerTest extends WallabagCoreTestCase $crawler = $client->request('GET', '/new'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $form = $crawler->filter('form[name=entry]')->form(); @@ -1372,11 +1372,11 @@ class EntryControllerTest extends WallabagCoreTestCase $client->submit($form, $data); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertSame(302, $client->getResponse()->getStatusCode()); $crawler = $client->followRedirect(); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $this->assertContains('flashes.entry.notice.entry_saved', $crawler->filter('body')->extract(['_text'])[0]); $content = $em diff --git a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php index b38961d3..ba9296af 100644 --- a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php @@ -12,7 +12,7 @@ class ExportControllerTest extends WallabagCoreTestCase $client->request('GET', '/export/unread.csv'); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertSame(302, $client->getResponse()->getStatusCode()); $this->assertContains('login', $client->getResponse()->headers->get('location')); } @@ -23,7 +23,7 @@ class ExportControllerTest extends WallabagCoreTestCase $client->request('GET', '/export/awesomeness.epub'); - $this->assertEquals(404, $client->getResponse()->getStatusCode()); + $this->assertSame(404, $client->getResponse()->getStatusCode()); } public function testUnknownFormatExport() @@ -33,7 +33,7 @@ class ExportControllerTest extends WallabagCoreTestCase $client->request('GET', '/export/unread.xslx'); - $this->assertEquals(404, $client->getResponse()->getStatusCode()); + $this->assertSame(404, $client->getResponse()->getStatusCode()); } public function testUnsupportedFormatExport() @@ -42,15 +42,15 @@ class ExportControllerTest extends WallabagCoreTestCase $client = $this->getClient(); $client->request('GET', '/export/unread.doc'); - $this->assertEquals(404, $client->getResponse()->getStatusCode()); + $this->assertSame(404, $client->getResponse()->getStatusCode()); $content = $client->getContainer() ->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') ->findOneByUsernameAndNotArchived('admin'); - $client->request('GET', '/export/'.$content->getId().'.doc'); - $this->assertEquals(404, $client->getResponse()->getStatusCode()); + $client->request('GET', '/export/' . $content->getId() . '.doc'); + $this->assertSame(404, $client->getResponse()->getStatusCode()); } public function testBadEntryId() @@ -60,7 +60,7 @@ class ExportControllerTest extends WallabagCoreTestCase $client->request('GET', '/export/0.mobi'); - $this->assertEquals(404, $client->getResponse()->getStatusCode()); + $this->assertSame(404, $client->getResponse()->getStatusCode()); } public function testEpubExport() @@ -72,12 +72,12 @@ class ExportControllerTest extends WallabagCoreTestCase $crawler = $client->request('GET', '/export/archive.epub'); ob_end_clean(); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $headers = $client->getResponse()->headers; - $this->assertEquals('application/epub+zip', $headers->get('content-type')); - $this->assertEquals('attachment; filename="Archive articles.epub"', $headers->get('content-disposition')); - $this->assertEquals('binary', $headers->get('content-transfer-encoding')); + $this->assertSame('application/epub+zip', $headers->get('content-type')); + $this->assertSame('attachment; filename="Archive articles.epub"', $headers->get('content-disposition')); + $this->assertSame('binary', $headers->get('content-transfer-encoding')); } public function testMobiExport() @@ -91,15 +91,15 @@ class ExportControllerTest extends WallabagCoreTestCase ->findOneByUsernameAndNotArchived('admin'); ob_start(); - $crawler = $client->request('GET', '/export/'.$content->getId().'.mobi'); + $crawler = $client->request('GET', '/export/' . $content->getId() . '.mobi'); ob_end_clean(); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $headers = $client->getResponse()->headers; - $this->assertEquals('application/x-mobipocket-ebook', $headers->get('content-type')); - $this->assertEquals('attachment; filename="'.preg_replace('/[^A-Za-z0-9\-]/', '', $content->getTitle()).'.mobi"', $headers->get('content-disposition')); - $this->assertEquals('binary', $headers->get('content-transfer-encoding')); + $this->assertSame('application/x-mobipocket-ebook', $headers->get('content-type')); + $this->assertSame('attachment; filename="' . preg_replace('/[^A-Za-z0-9\-]/', '', $content->getTitle()) . '.mobi"', $headers->get('content-disposition')); + $this->assertSame('binary', $headers->get('content-transfer-encoding')); } public function testPdfExport() @@ -111,23 +111,23 @@ class ExportControllerTest extends WallabagCoreTestCase $crawler = $client->request('GET', '/export/all.pdf'); ob_end_clean(); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $headers = $client->getResponse()->headers; - $this->assertEquals('application/pdf', $headers->get('content-type')); - $this->assertEquals('attachment; filename="All articles.pdf"', $headers->get('content-disposition')); - $this->assertEquals('binary', $headers->get('content-transfer-encoding')); + $this->assertSame('application/pdf', $headers->get('content-type')); + $this->assertSame('attachment; filename="All articles.pdf"', $headers->get('content-disposition')); + $this->assertSame('binary', $headers->get('content-transfer-encoding')); ob_start(); $crawler = $client->request('GET', '/export/tag_entries.pdf?tag=foo-bar'); ob_end_clean(); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $headers = $client->getResponse()->headers; - $this->assertEquals('application/pdf', $headers->get('content-type')); - $this->assertEquals('attachment; filename="Tag_entries articles.pdf"', $headers->get('content-disposition')); - $this->assertEquals('binary', $headers->get('content-transfer-encoding')); + $this->assertSame('application/pdf', $headers->get('content-type')); + $this->assertSame('attachment; filename="Tag_entries articles.pdf"', $headers->get('content-disposition')); + $this->assertSame('binary', $headers->get('content-transfer-encoding')); } public function testTxtExport() @@ -139,12 +139,12 @@ class ExportControllerTest extends WallabagCoreTestCase $crawler = $client->request('GET', '/export/all.txt'); ob_end_clean(); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $headers = $client->getResponse()->headers; - $this->assertEquals('text/plain; charset=UTF-8', $headers->get('content-type')); - $this->assertEquals('attachment; filename="All articles.txt"', $headers->get('content-disposition')); - $this->assertEquals('UTF-8', $headers->get('content-transfer-encoding')); + $this->assertSame('text/plain; charset=UTF-8', $headers->get('content-type')); + $this->assertSame('attachment; filename="All articles.txt"', $headers->get('content-disposition')); + $this->assertSame('UTF-8', $headers->get('content-transfer-encoding')); } public function testCsvExport() @@ -169,19 +169,19 @@ class ExportControllerTest extends WallabagCoreTestCase $crawler = $client->request('GET', '/export/archive.csv'); ob_end_clean(); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $headers = $client->getResponse()->headers; - $this->assertEquals('application/csv', $headers->get('content-type')); - $this->assertEquals('attachment; filename="Archive articles.csv"', $headers->get('content-disposition')); - $this->assertEquals('UTF-8', $headers->get('content-transfer-encoding')); + $this->assertSame('application/csv', $headers->get('content-type')); + $this->assertSame('attachment; filename="Archive articles.csv"', $headers->get('content-disposition')); + $this->assertSame('UTF-8', $headers->get('content-transfer-encoding')); $csv = str_getcsv($client->getResponse()->getContent(), "\n"); $this->assertGreaterThan(1, $csv); // +1 for title line - $this->assertEquals(count($contentInDB) + 1, count($csv)); - $this->assertEquals('Title;URL;Content;Tags;"MIME Type";Language;"Creation date"', $csv[0]); + $this->assertSame(count($contentInDB) + 1, count($csv)); + $this->assertSame('Title;URL;Content;Tags;"MIME Type";Language;"Creation date"', $csv[0]); $this->assertContains($contentInDB[0]['title'], $csv[1]); $this->assertContains($contentInDB[0]['url'], $csv[1]); $this->assertContains($contentInDB[0]['content'], $csv[1]); @@ -205,15 +205,15 @@ class ExportControllerTest extends WallabagCoreTestCase ->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId()); ob_start(); - $crawler = $client->request('GET', '/export/'.$contentInDB->getId().'.json'); + $crawler = $client->request('GET', '/export/' . $contentInDB->getId() . '.json'); ob_end_clean(); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $headers = $client->getResponse()->headers; - $this->assertEquals('application/json', $headers->get('content-type')); - $this->assertEquals('attachment; filename="'.$contentInDB->getTitle().'.json"', $headers->get('content-disposition')); - $this->assertEquals('UTF-8', $headers->get('content-transfer-encoding')); + $this->assertSame('application/json', $headers->get('content-type')); + $this->assertSame('attachment; filename="' . $contentInDB->getTitle() . '.json"', $headers->get('content-disposition')); + $this->assertSame('UTF-8', $headers->get('content-transfer-encoding')); $content = json_decode($client->getResponse()->getContent(), true); $this->assertArrayHasKey('id', $content[0]); @@ -230,16 +230,16 @@ class ExportControllerTest extends WallabagCoreTestCase $this->assertArrayHasKey('created_at', $content[0]); $this->assertArrayHasKey('updated_at', $content[0]); - $this->assertEquals($contentInDB->isArchived(), $content[0]['is_archived']); - $this->assertEquals($contentInDB->isStarred(), $content[0]['is_starred']); - $this->assertEquals($contentInDB->getTitle(), $content[0]['title']); - $this->assertEquals($contentInDB->getUrl(), $content[0]['url']); - $this->assertEquals([['text' => 'This is my annotation /o/', 'quote' => 'content']], $content[0]['annotations']); - $this->assertEquals($contentInDB->getMimetype(), $content[0]['mimetype']); - $this->assertEquals($contentInDB->getLanguage(), $content[0]['language']); - $this->assertEquals($contentInDB->getReadingtime(), $content[0]['reading_time']); - $this->assertEquals($contentInDB->getDomainname(), $content[0]['domain_name']); - $this->assertEquals(['foo bar', 'baz'], $content[0]['tags']); + $this->assertSame($contentInDB->isArchived(), $content[0]['is_archived']); + $this->assertSame($contentInDB->isStarred(), $content[0]['is_starred']); + $this->assertSame($contentInDB->getTitle(), $content[0]['title']); + $this->assertSame($contentInDB->getUrl(), $content[0]['url']); + $this->assertSame([['text' => 'This is my annotation /o/', 'quote' => 'content']], $content[0]['annotations']); + $this->assertSame($contentInDB->getMimetype(), $content[0]['mimetype']); + $this->assertSame($contentInDB->getLanguage(), $content[0]['language']); + $this->assertSame($contentInDB->getReadingtime(), $content[0]['reading_time']); + $this->assertSame($contentInDB->getDomainname(), $content[0]['domain_name']); + $this->assertSame(['foo bar', 'baz'], $content[0]['tags']); } public function testXmlExport() @@ -262,16 +262,16 @@ class ExportControllerTest extends WallabagCoreTestCase $crawler = $client->request('GET', '/export/unread.xml'); ob_end_clean(); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $headers = $client->getResponse()->headers; - $this->assertEquals('application/xml', $headers->get('content-type')); - $this->assertEquals('attachment; filename="Unread articles.xml"', $headers->get('content-disposition')); - $this->assertEquals('UTF-8', $headers->get('content-transfer-encoding')); + $this->assertSame('application/xml', $headers->get('content-type')); + $this->assertSame('attachment; filename="Unread articles.xml"', $headers->get('content-disposition')); + $this->assertSame('UTF-8', $headers->get('content-transfer-encoding')); $content = new \SimpleXMLElement($client->getResponse()->getContent()); $this->assertGreaterThan(0, $content->count()); - $this->assertEquals(count($contentInDB), $content->count()); + $this->assertSame(count($contentInDB), $content->count()); $this->assertNotEmpty('id', (string) $content->entry[0]->id); $this->assertNotEmpty('title', (string) $content->entry[0]->title); $this->assertNotEmpty('url', (string) $content->entry[0]->url); diff --git a/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php b/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php index 530c8bbf..6167fe2d 100644 --- a/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php @@ -16,36 +16,36 @@ class RssControllerTest extends WallabagCoreTestCase if (null === $nb) { $this->assertGreaterThan(0, $xpath->query('//item')->length); } else { - $this->assertEquals($nb, $xpath->query('//item')->length); + $this->assertSame($nb, $xpath->query('//item')->length); } - $this->assertEquals(1, $xpath->query('/rss')->length); - $this->assertEquals(1, $xpath->query('/rss/channel')->length); + $this->assertSame(1, $xpath->query('/rss')->length); + $this->assertSame(1, $xpath->query('/rss/channel')->length); - $this->assertEquals(1, $xpath->query('/rss/channel/title')->length); - $this->assertEquals('wallabag - '.$type.' feed', $xpath->query('/rss/channel/title')->item(0)->nodeValue); + $this->assertSame(1, $xpath->query('/rss/channel/title')->length); + $this->assertSame('wallabag - ' . $type . ' feed', $xpath->query('/rss/channel/title')->item(0)->nodeValue); - $this->assertEquals(1, $xpath->query('/rss/channel/pubDate')->length); + $this->assertSame(1, $xpath->query('/rss/channel/pubDate')->length); - $this->assertEquals(1, $xpath->query('/rss/channel/generator')->length); - $this->assertEquals('wallabag', $xpath->query('/rss/channel/generator')->item(0)->nodeValue); + $this->assertSame(1, $xpath->query('/rss/channel/generator')->length); + $this->assertSame('wallabag', $xpath->query('/rss/channel/generator')->item(0)->nodeValue); - $this->assertEquals(1, $xpath->query('/rss/channel/description')->length); - $this->assertEquals('wallabag '.$type.' elements', $xpath->query('/rss/channel/description')->item(0)->nodeValue); + $this->assertSame(1, $xpath->query('/rss/channel/description')->length); + $this->assertSame('wallabag ' . $type . ' elements', $xpath->query('/rss/channel/description')->item(0)->nodeValue); - $this->assertEquals(1, $xpath->query('/rss/channel/link[@rel="self"]')->length); - $this->assertContains($urlPagination.'.xml', $xpath->query('/rss/channel/link[@rel="self"]')->item(0)->getAttribute('href')); + $this->assertSame(1, $xpath->query('/rss/channel/link[@rel="self"]')->length); + $this->assertContains($urlPagination . '.xml', $xpath->query('/rss/channel/link[@rel="self"]')->item(0)->getAttribute('href')); - $this->assertEquals(1, $xpath->query('/rss/channel/link[@rel="last"]')->length); - $this->assertContains($urlPagination.'.xml?page=', $xpath->query('/rss/channel/link[@rel="last"]')->item(0)->getAttribute('href')); + $this->assertSame(1, $xpath->query('/rss/channel/link[@rel="last"]')->length); + $this->assertContains($urlPagination . '.xml?page=', $xpath->query('/rss/channel/link[@rel="last"]')->item(0)->getAttribute('href')); foreach ($xpath->query('//item') as $item) { - $this->assertEquals(1, $xpath->query('title', $item)->length); - $this->assertEquals(1, $xpath->query('source', $item)->length); - $this->assertEquals(1, $xpath->query('link', $item)->length); - $this->assertEquals(1, $xpath->query('guid', $item)->length); - $this->assertEquals(1, $xpath->query('pubDate', $item)->length); - $this->assertEquals(1, $xpath->query('description', $item)->length); + $this->assertSame(1, $xpath->query('title', $item)->length); + $this->assertSame(1, $xpath->query('source', $item)->length); + $this->assertSame(1, $xpath->query('link', $item)->length); + $this->assertSame(1, $xpath->query('guid', $item)->length); + $this->assertSame(1, $xpath->query('pubDate', $item)->length); + $this->assertSame(1, $xpath->query('description', $item)->length); } } @@ -73,7 +73,7 @@ class RssControllerTest extends WallabagCoreTestCase $client->request('GET', $url); - $this->assertEquals(404, $client->getResponse()->getStatusCode()); + $this->assertSame(404, $client->getResponse()->getStatusCode()); } public function testUnread() @@ -92,7 +92,7 @@ class RssControllerTest extends WallabagCoreTestCase $client->request('GET', '/admin/SUPERTOKEN/unread.xml'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $this->validateDom($client->getResponse()->getContent(), 'unread', 'unread', 2); } @@ -114,7 +114,7 @@ class RssControllerTest extends WallabagCoreTestCase $client = $this->getClient(); $client->request('GET', '/admin/SUPERTOKEN/starred.xml'); - $this->assertEquals(200, $client->getResponse()->getStatusCode(), 1); + $this->assertSame(200, $client->getResponse()->getStatusCode(), 1); $this->validateDom($client->getResponse()->getContent(), 'starred', 'starred'); } @@ -136,7 +136,7 @@ class RssControllerTest extends WallabagCoreTestCase $client = $this->getClient(); $client->request('GET', '/admin/SUPERTOKEN/archive.xml'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $this->validateDom($client->getResponse()->getContent(), 'archive', 'archive'); } @@ -158,15 +158,15 @@ class RssControllerTest extends WallabagCoreTestCase $client = $this->getClient(); $client->request('GET', '/admin/SUPERTOKEN/unread.xml'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $this->validateDom($client->getResponse()->getContent(), 'unread', 'unread'); $client->request('GET', '/admin/SUPERTOKEN/unread.xml?page=2'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $this->validateDom($client->getResponse()->getContent(), 'unread', 'unread'); $client->request('GET', '/admin/SUPERTOKEN/unread.xml?page=3000'); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertSame(302, $client->getResponse()->getStatusCode()); } public function testTags() @@ -186,11 +186,11 @@ class RssControllerTest extends WallabagCoreTestCase $client = $this->getClient(); $client->request('GET', '/admin/SUPERTOKEN/tags/foo-bar.xml'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $this->validateDom($client->getResponse()->getContent(), 'tag (foo bar)', 'tags/foo-bar'); $client->request('GET', '/admin/SUPERTOKEN/tags/foo-bar.xml?page=3000'); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertSame(302, $client->getResponse()->getStatusCode()); } } diff --git a/tests/Wallabag/CoreBundle/Controller/SettingsControllerTest.php b/tests/Wallabag/CoreBundle/Controller/SettingsControllerTest.php index 9b8b5702..6005c0df 100644 --- a/tests/Wallabag/CoreBundle/Controller/SettingsControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/SettingsControllerTest.php @@ -17,7 +17,7 @@ class SettingsControllerTest extends WallabagCoreTestCase $crawler = $client->request('GET', '/settings'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); } public function testSettingsWithNormalUser() @@ -27,6 +27,6 @@ class SettingsControllerTest extends WallabagCoreTestCase $crawler = $client->request('GET', '/settings'); - $this->assertEquals(403, $client->getResponse()->getStatusCode()); + $this->assertSame(403, $client->getResponse()->getStatusCode()); } } diff --git a/tests/Wallabag/CoreBundle/Controller/SiteCredentialControllerTest.php b/tests/Wallabag/CoreBundle/Controller/SiteCredentialControllerTest.php index e73a9743..87ea2867 100644 --- a/tests/Wallabag/CoreBundle/Controller/SiteCredentialControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/SiteCredentialControllerTest.php @@ -15,7 +15,7 @@ class SiteCredentialControllerTest extends WallabagCoreTestCase $crawler = $client->request('GET', '/site-credentials/'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $body = $crawler->filter('body')->extract(['_text'])[0]; @@ -30,7 +30,7 @@ class SiteCredentialControllerTest extends WallabagCoreTestCase $crawler = $client->request('GET', '/site-credentials/new'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $body = $crawler->filter('body')->extract(['_text'])[0]; @@ -47,7 +47,7 @@ class SiteCredentialControllerTest extends WallabagCoreTestCase $client->submit($form, $data); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertSame(302, $client->getResponse()->getStatusCode()); $crawler = $client->followRedirect(); @@ -61,9 +61,9 @@ class SiteCredentialControllerTest extends WallabagCoreTestCase $credential = $this->createSiteCredential($client); - $crawler = $client->request('GET', '/site-credentials/'.$credential->getId().'/edit'); + $crawler = $client->request('GET', '/site-credentials/' . $credential->getId() . '/edit'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $body = $crawler->filter('body')->extract(['_text'])[0]; @@ -80,7 +80,7 @@ class SiteCredentialControllerTest extends WallabagCoreTestCase $client->submit($form, $data); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertSame(302, $client->getResponse()->getStatusCode()); $crawler = $client->followRedirect(); @@ -96,9 +96,9 @@ class SiteCredentialControllerTest extends WallabagCoreTestCase $this->logInAs('bob'); - $client->request('GET', '/site-credentials/'.$credential->getId().'/edit'); + $client->request('GET', '/site-credentials/' . $credential->getId() . '/edit'); - $this->assertEquals(403, $client->getResponse()->getStatusCode()); + $this->assertSame(403, $client->getResponse()->getStatusCode()); } public function testDeleteSiteCredential() @@ -108,15 +108,15 @@ class SiteCredentialControllerTest extends WallabagCoreTestCase $credential = $this->createSiteCredential($client); - $crawler = $client->request('GET', '/site-credentials/'.$credential->getId().'/edit'); + $crawler = $client->request('GET', '/site-credentials/' . $credential->getId() . '/edit'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $deleteForm = $crawler->filter('body')->selectButton('site_credential.form.delete')->form(); $client->submit($deleteForm, []); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertSame(302, $client->getResponse()->getStatusCode()); $crawler = $client->followRedirect(); diff --git a/tests/Wallabag/CoreBundle/Controller/StaticControllerTest.php b/tests/Wallabag/CoreBundle/Controller/StaticControllerTest.php index 98a37b50..17847937 100644 --- a/tests/Wallabag/CoreBundle/Controller/StaticControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/StaticControllerTest.php @@ -13,7 +13,7 @@ class StaticControllerTest extends WallabagCoreTestCase $client->request('GET', '/about'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); } public function testHowto() @@ -23,6 +23,6 @@ class StaticControllerTest extends WallabagCoreTestCase $client->request('GET', '/howto'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); } } diff --git a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php index af1ad7af..be25a8b5 100644 --- a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php @@ -17,7 +17,7 @@ class TagControllerTest extends WallabagCoreTestCase $client->request('GET', '/tag/list'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); } public function testAddTagToEntry() @@ -31,7 +31,7 @@ class TagControllerTest extends WallabagCoreTestCase $this->getEntityManager()->flush(); $this->getEntityManager()->clear(); - $crawler = $client->request('GET', '/view/'.$entry->getId()); + $crawler = $client->request('GET', '/view/' . $entry->getId()); $form = $crawler->filter('form[name=tag]')->form(); @@ -40,7 +40,7 @@ class TagControllerTest extends WallabagCoreTestCase ]; $client->submit($form, $data); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertSame(302, $client->getResponse()->getStatusCode()); // be sure to reload the entry $entry = $this->getEntityManager()->getRepository(Entry::class)->find($entry->getId()); @@ -48,7 +48,7 @@ class TagControllerTest extends WallabagCoreTestCase // tag already exists and already assigned $client->submit($form, $data); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertSame(302, $client->getResponse()->getStatusCode()); $entry = $this->getEntityManager()->getRepository(Entry::class)->find($entry->getId()); $this->assertCount(1, $entry->getTags()); @@ -59,7 +59,7 @@ class TagControllerTest extends WallabagCoreTestCase ]; $client->submit($form, $data); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertSame(302, $client->getResponse()->getStatusCode()); $entry = $this->getEntityManager()->getRepository(Entry::class)->find($entry->getId()); $this->assertCount(2, $entry->getTags()); @@ -75,7 +75,7 @@ class TagControllerTest extends WallabagCoreTestCase ->getRepository('WallabagCoreBundle:Entry') ->findByUrlAndUserId('http://0.0.0.0/entry2', $this->getLoggedInUserId()); - $crawler = $client->request('GET', '/view/'.$entry->getId()); + $crawler = $client->request('GET', '/view/' . $entry->getId()); $form = $crawler->filter('form[name=tag]')->form(); @@ -84,7 +84,7 @@ class TagControllerTest extends WallabagCoreTestCase ]; $client->submit($form, $data); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); + $this->assertSame(302, $client->getResponse()->getStatusCode()); $newEntry = $client->getContainer() ->get('doctrine.orm.entity_manager') @@ -97,8 +97,8 @@ class TagControllerTest extends WallabagCoreTestCase } $this->assertGreaterThanOrEqual(2, count($tags)); - $this->assertNotFalse(array_search('foo2', $tags), 'Tag foo2 is assigned to the entry'); - $this->assertNotFalse(array_search('bar2', $tags), 'Tag bar2 is assigned to the entry'); + $this->assertNotFalse(array_search('foo2', $tags, true), 'Tag foo2 is assigned to the entry'); + $this->assertNotFalse(array_search('bar2', $tags, true), 'Tag bar2 is assigned to the entry'); } public function testRemoveTagFromEntry() @@ -116,27 +116,27 @@ class TagControllerTest extends WallabagCoreTestCase $this->getEntityManager()->clear(); // We make a first request to set an history and test redirection after tag deletion - $client->request('GET', '/view/'.$entry->getId()); + $client->request('GET', '/view/' . $entry->getId()); $entryUri = $client->getRequest()->getUri(); - $client->request('GET', '/remove-tag/'.$entry->getId().'/'.$tag->getId()); + $client->request('GET', '/remove-tag/' . $entry->getId() . '/' . $tag->getId()); - $this->assertEquals(302, $client->getResponse()->getStatusCode()); - $this->assertEquals($entryUri, $client->getResponse()->getTargetUrl()); + $this->assertSame(302, $client->getResponse()->getStatusCode()); + $this->assertSame($entryUri, $client->getResponse()->getTargetUrl()); // re-retrieve the entry to be sure to get fresh data from database (mostly for tags) $entry = $this->getEntityManager()->getRepository(Entry::class)->find($entry->getId()); $this->assertNotContains($this->tagName, $entry->getTags()); - $client->request('GET', '/remove-tag/'.$entry->getId().'/'.$tag->getId()); + $client->request('GET', '/remove-tag/' . $entry->getId() . '/' . $tag->getId()); - $this->assertEquals(404, $client->getResponse()->getStatusCode()); + $this->assertSame(404, $client->getResponse()->getStatusCode()); $tag = $client->getContainer() ->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Tag') ->findOneByLabel($this->tagName); - $this->assertNull($tag, $this->tagName.' was removed because it begun an orphan tag'); + $this->assertNull($tag, $this->tagName . ' was removed because it begun an orphan tag'); } public function testShowEntriesForTagAction() @@ -165,9 +165,9 @@ class TagControllerTest extends WallabagCoreTestCase ->getRepository('WallabagCoreBundle:Tag') ->findOneByEntryAndTagLabel($entry, $this->tagName); - $crawler = $client->request('GET', '/tag/list/'.$tag->getSlug()); + $crawler = $client->request('GET', '/tag/list/' . $tag->getSlug()); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertSame(200, $client->getResponse()->getStatusCode()); $this->assertCount(1, $crawler->filter('[id*="entry-"]')); $entry->removeTag($tag); diff --git a/tests/Wallabag/CoreBundle/Event/Listener/LocaleListenerTest.php b/tests/Wallabag/CoreBundle/Event/Listener/LocaleListenerTest.php index 84a54d3a..0dbd9f70 100644 --- a/tests/Wallabag/CoreBundle/Event/Listener/LocaleListenerTest.php +++ b/tests/Wallabag/CoreBundle/Event/Listener/LocaleListenerTest.php @@ -13,15 +13,6 @@ use Wallabag\CoreBundle\Event\Listener\LocaleListener; class LocaleListenerTest extends \PHPUnit_Framework_TestCase { - private function getEvent(Request $request) - { - $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface') - ->disableOriginalConstructor() - ->getMock(); - - return new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); - } - public function testWithoutSession() { $request = Request::create('/'); @@ -30,7 +21,7 @@ class LocaleListenerTest extends \PHPUnit_Framework_TestCase $event = $this->getEvent($request); $listener->onKernelRequest($event); - $this->assertEquals('en', $request->getLocale()); + $this->assertSame('en', $request->getLocale()); } public function testWithPreviousSession() @@ -44,7 +35,7 @@ class LocaleListenerTest extends \PHPUnit_Framework_TestCase $event = $this->getEvent($request); $listener->onKernelRequest($event); - $this->assertEquals('fr', $request->getLocale()); + $this->assertSame('fr', $request->getLocale()); } public function testLocaleFromRequestAttribute() @@ -59,8 +50,8 @@ class LocaleListenerTest extends \PHPUnit_Framework_TestCase $event = $this->getEvent($request); $listener->onKernelRequest($event); - $this->assertEquals('en', $request->getLocale()); - $this->assertEquals('es', $request->getSession()->get('_locale')); + $this->assertSame('en', $request->getLocale()); + $this->assertSame('es', $request->getSession()->get('_locale')); } public function testSubscribedEvents() @@ -81,6 +72,15 @@ class LocaleListenerTest extends \PHPUnit_Framework_TestCase $event ); - $this->assertEquals('fr', $request->getLocale()); + $this->assertSame('fr', $request->getLocale()); + } + + private function getEvent(Request $request) + { + $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface') + ->disableOriginalConstructor() + ->getMock(); + + return new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); } } diff --git a/tests/Wallabag/CoreBundle/Event/Listener/UserLocaleListenerTest.php b/tests/Wallabag/CoreBundle/Event/Listener/UserLocaleListenerTest.php index 45aecc63..91ce0102 100644 --- a/tests/Wallabag/CoreBundle/Event/Listener/UserLocaleListenerTest.php +++ b/tests/Wallabag/CoreBundle/Event/Listener/UserLocaleListenerTest.php @@ -32,7 +32,7 @@ class UserLocaleListenerTest extends \PHPUnit_Framework_TestCase $listener->onInteractiveLogin($event); - $this->assertEquals('fr', $session->get('_locale')); + $this->assertSame('fr', $session->get('_locale')); } public function testWithoutLanguage() @@ -53,6 +53,6 @@ class UserLocaleListenerTest extends \PHPUnit_Framework_TestCase $listener->onInteractiveLogin($event); - $this->assertEquals('', $session->get('_locale')); + $this->assertSame('', $session->get('_locale')); } } diff --git a/tests/Wallabag/CoreBundle/Event/Subscriber/TablePrefixSubscriberTest.php b/tests/Wallabag/CoreBundle/Event/Subscriber/TablePrefixSubscriberTest.php index b8cd0fad..64e3c6d9 100644 --- a/tests/Wallabag/CoreBundle/Event/Subscriber/TablePrefixSubscriberTest.php +++ b/tests/Wallabag/CoreBundle/Event/Subscriber/TablePrefixSubscriberTest.php @@ -46,12 +46,12 @@ class TablePrefixSubscriberTest extends \PHPUnit_Framework_TestCase $metaDataEvent = new LoadClassMetadataEventArgs($metaClass, $em); - $this->assertEquals($tableNameExpected, $metaDataEvent->getClassMetadata()->getTableName()); + $this->assertSame($tableNameExpected, $metaDataEvent->getClassMetadata()->getTableName()); $subscriber->loadClassMetadata($metaDataEvent); - $this->assertEquals($finalTableName, $metaDataEvent->getClassMetadata()->getTableName()); - $this->assertEquals($finalTableNameQuoted, $metaDataEvent->getClassMetadata()->getQuotedTableName($platform)); + $this->assertSame($finalTableName, $metaDataEvent->getClassMetadata()->getTableName()); + $this->assertSame($finalTableNameQuoted, $metaDataEvent->getClassMetadata()->getQuotedTableName($platform)); } /** @@ -75,8 +75,8 @@ class TablePrefixSubscriberTest extends \PHPUnit_Framework_TestCase $evm->dispatchEvent('loadClassMetadata', $metaDataEvent); - $this->assertEquals($finalTableName, $metaDataEvent->getClassMetadata()->getTableName()); - $this->assertEquals($finalTableNameQuoted, $metaDataEvent->getClassMetadata()->getQuotedTableName($platform)); + $this->assertSame($finalTableName, $metaDataEvent->getClassMetadata()->getTableName()); + $this->assertSame($finalTableNameQuoted, $metaDataEvent->getClassMetadata()->getQuotedTableName($platform)); } public function testPrefixManyToMany() @@ -103,12 +103,12 @@ class TablePrefixSubscriberTest extends \PHPUnit_Framework_TestCase $metaDataEvent = new LoadClassMetadataEventArgs($metaClass, $em); - $this->assertEquals('entry', $metaDataEvent->getClassMetadata()->getTableName()); + $this->assertSame('entry', $metaDataEvent->getClassMetadata()->getTableName()); $subscriber->loadClassMetadata($metaDataEvent); - $this->assertEquals('yo_entry', $metaDataEvent->getClassMetadata()->getTableName()); - $this->assertEquals('yo_entry_tag', $metaDataEvent->getClassMetadata()->associationMappings['tags']['joinTable']['name']); - $this->assertEquals('yo_entry', $metaDataEvent->getClassMetadata()->getQuotedTableName(new \Doctrine\DBAL\Platforms\MySqlPlatform())); + $this->assertSame('yo_entry', $metaDataEvent->getClassMetadata()->getTableName()); + $this->assertSame('yo_entry_tag', $metaDataEvent->getClassMetadata()->associationMappings['tags']['joinTable']['name']); + $this->assertSame('yo_entry', $metaDataEvent->getClassMetadata()->getQuotedTableName(new \Doctrine\DBAL\Platforms\MySqlPlatform())); } } diff --git a/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php b/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php index b0c81e7b..85036e35 100644 --- a/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php +++ b/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php @@ -2,13 +2,13 @@ namespace Tests\Wallabag\CoreBundle\GuzzleSiteAuthenticator; -use Monolog\Handler\TestHandler; -use Monolog\Logger; use BD\GuzzleSiteAuthenticator\SiteConfig\SiteConfig; use Graby\SiteConfig\SiteConfig as GrabySiteConfig; -use Wallabag\CoreBundle\GuzzleSiteAuthenticator\GrabySiteConfigBuilder; -use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; +use Monolog\Handler\TestHandler; +use Monolog\Logger; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; +use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; +use Wallabag\CoreBundle\GuzzleSiteAuthenticator\GrabySiteConfigBuilder; class GrabySiteConfigBuilderTest extends \PHPUnit_Framework_TestCase { @@ -68,7 +68,7 @@ class GrabySiteConfigBuilderTest extends \PHPUnit_Framework_TestCase $config = $this->builder->buildForHost('www.example.com'); - $this->assertEquals( + $this->assertSame( new SiteConfig([ 'host' => 'example.com', 'requiresLogin' => true, diff --git a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php index dbddbc5c..7e19631b 100644 --- a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php +++ b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php @@ -2,18 +2,18 @@ namespace Tests\Wallabag\CoreBundle\Helper; -use Psr\Log\NullLogger; -use Monolog\Logger; +use Graby\Graby; use Monolog\Handler\TestHandler; -use Wallabag\CoreBundle\Helper\ContentProxy; +use Monolog\Logger; +use Psr\Log\NullLogger; +use Symfony\Component\Validator\ConstraintViolation; +use Symfony\Component\Validator\ConstraintViolationList; +use Symfony\Component\Validator\Validator\RecursiveValidator; use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Entity\Tag; -use Wallabag\UserBundle\Entity\User; +use Wallabag\CoreBundle\Helper\ContentProxy; use Wallabag\CoreBundle\Helper\RuleBasedTagger; -use Graby\Graby; -use Symfony\Component\Validator\Validator\RecursiveValidator; -use Symfony\Component\Validator\ConstraintViolationList; -use Symfony\Component\Validator\ConstraintViolation; +use Wallabag\UserBundle\Entity\User; class ContentProxyTest extends \PHPUnit_Framework_TestCase { @@ -44,14 +44,14 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase $entry = new Entry(new User()); $proxy->updateEntry($entry, 'http://user@:80'); - $this->assertEquals('http://user@:80', $entry->getUrl()); + $this->assertSame('http://user@:80', $entry->getUrl()); $this->assertEmpty($entry->getTitle()); - $this->assertEquals($this->fetchingErrorMessage, $entry->getContent()); + $this->assertSame($this->fetchingErrorMessage, $entry->getContent()); $this->assertEmpty($entry->getPreviewPicture()); $this->assertEmpty($entry->getMimetype()); $this->assertEmpty($entry->getLanguage()); - $this->assertEquals(0.0, $entry->getReadingTime()); - $this->assertEquals(false, $entry->getDomainName()); + $this->assertSame(0.0, $entry->getReadingTime()); + $this->assertSame(false, $entry->getDomainName()); } public function testWithEmptyContent() @@ -79,14 +79,14 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase $entry = new Entry(new User()); $proxy->updateEntry($entry, 'http://0.0.0.0'); - $this->assertEquals('http://0.0.0.0', $entry->getUrl()); + $this->assertSame('http://0.0.0.0', $entry->getUrl()); $this->assertEmpty($entry->getTitle()); - $this->assertEquals($this->fetchingErrorMessage, $entry->getContent()); + $this->assertSame($this->fetchingErrorMessage, $entry->getContent()); $this->assertEmpty($entry->getPreviewPicture()); $this->assertEmpty($entry->getMimetype()); $this->assertEmpty($entry->getLanguage()); - $this->assertEquals(0.0, $entry->getReadingTime()); - $this->assertEquals('0.0.0.0', $entry->getDomainName()); + $this->assertSame(0.0, $entry->getReadingTime()); + $this->assertSame('0.0.0.0', $entry->getDomainName()); } public function testWithEmptyContentButOG() @@ -119,15 +119,15 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase $entry = new Entry(new User()); $proxy->updateEntry($entry, 'http://domain.io'); - $this->assertEquals('http://domain.io', $entry->getUrl()); - $this->assertEquals('my title', $entry->getTitle()); - $this->assertEquals($this->fetchingErrorMessage.'

But we found a short description:

desc', $entry->getContent()); + $this->assertSame('http://domain.io', $entry->getUrl()); + $this->assertSame('my title', $entry->getTitle()); + $this->assertSame($this->fetchingErrorMessage . '

But we found a short description:

desc', $entry->getContent()); $this->assertEmpty($entry->getPreviewPicture()); $this->assertEmpty($entry->getLanguage()); $this->assertEmpty($entry->getHttpStatus()); $this->assertEmpty($entry->getMimetype()); - $this->assertEquals(0.0, $entry->getReadingTime()); - $this->assertEquals('domain.io', $entry->getDomainName()); + $this->assertSame(0.0, $entry->getReadingTime()); + $this->assertSame('domain.io', $entry->getDomainName()); } public function testWithContent() @@ -161,15 +161,15 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase $entry = new Entry(new User()); $proxy->updateEntry($entry, 'http://0.0.0.0'); - $this->assertEquals('http://1.1.1.1', $entry->getUrl()); - $this->assertEquals('this is my title', $entry->getTitle()); + $this->assertSame('http://1.1.1.1', $entry->getUrl()); + $this->assertSame('this is my title', $entry->getTitle()); $this->assertContains('this is my content', $entry->getContent()); - $this->assertEquals('http://3.3.3.3/cover.jpg', $entry->getPreviewPicture()); - $this->assertEquals('text/html', $entry->getMimetype()); - $this->assertEquals('fr', $entry->getLanguage()); - $this->assertEquals('200', $entry->getHttpStatus()); - $this->assertEquals(4.0, $entry->getReadingTime()); - $this->assertEquals('1.1.1.1', $entry->getDomainName()); + $this->assertSame('http://3.3.3.3/cover.jpg', $entry->getPreviewPicture()); + $this->assertSame('text/html', $entry->getMimetype()); + $this->assertSame('fr', $entry->getLanguage()); + $this->assertSame('200', $entry->getHttpStatus()); + $this->assertSame(4.0, $entry->getReadingTime()); + $this->assertSame('1.1.1.1', $entry->getDomainName()); } public function testWithContentAndNoOgImage() @@ -203,15 +203,15 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase $entry = new Entry(new User()); $proxy->updateEntry($entry, 'http://0.0.0.0'); - $this->assertEquals('http://1.1.1.1', $entry->getUrl()); - $this->assertEquals('this is my title', $entry->getTitle()); + $this->assertSame('http://1.1.1.1', $entry->getUrl()); + $this->assertSame('this is my title', $entry->getTitle()); $this->assertContains('this is my content', $entry->getContent()); $this->assertNull($entry->getPreviewPicture()); - $this->assertEquals('text/html', $entry->getMimetype()); - $this->assertEquals('fr', $entry->getLanguage()); - $this->assertEquals('200', $entry->getHttpStatus()); - $this->assertEquals(4.0, $entry->getReadingTime()); - $this->assertEquals('1.1.1.1', $entry->getDomainName()); + $this->assertSame('text/html', $entry->getMimetype()); + $this->assertSame('fr', $entry->getLanguage()); + $this->assertSame('200', $entry->getHttpStatus()); + $this->assertSame(4.0, $entry->getReadingTime()); + $this->assertSame('1.1.1.1', $entry->getDomainName()); } public function testWithContentAndBadLanguage() @@ -248,14 +248,14 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase $entry = new Entry(new User()); $proxy->updateEntry($entry, 'http://0.0.0.0'); - $this->assertEquals('http://1.1.1.1', $entry->getUrl()); - $this->assertEquals('this is my title', $entry->getTitle()); + $this->assertSame('http://1.1.1.1', $entry->getUrl()); + $this->assertSame('this is my title', $entry->getTitle()); $this->assertContains('this is my content', $entry->getContent()); - $this->assertEquals('text/html', $entry->getMimetype()); + $this->assertSame('text/html', $entry->getMimetype()); $this->assertNull($entry->getLanguage()); - $this->assertEquals('200', $entry->getHttpStatus()); - $this->assertEquals(4.0, $entry->getReadingTime()); - $this->assertEquals('1.1.1.1', $entry->getDomainName()); + $this->assertSame('200', $entry->getHttpStatus()); + $this->assertSame(4.0, $entry->getReadingTime()); + $this->assertSame('1.1.1.1', $entry->getDomainName()); } public function testWithContentAndBadOgImage() @@ -297,15 +297,15 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase $entry = new Entry(new User()); $proxy->updateEntry($entry, 'http://0.0.0.0'); - $this->assertEquals('http://1.1.1.1', $entry->getUrl()); - $this->assertEquals('this is my title', $entry->getTitle()); + $this->assertSame('http://1.1.1.1', $entry->getUrl()); + $this->assertSame('this is my title', $entry->getTitle()); $this->assertContains('this is my content', $entry->getContent()); $this->assertNull($entry->getPreviewPicture()); - $this->assertEquals('text/html', $entry->getMimetype()); - $this->assertEquals('fr', $entry->getLanguage()); - $this->assertEquals('200', $entry->getHttpStatus()); - $this->assertEquals(4.0, $entry->getReadingTime()); - $this->assertEquals('1.1.1.1', $entry->getDomainName()); + $this->assertSame('text/html', $entry->getMimetype()); + $this->assertSame('fr', $entry->getLanguage()); + $this->assertSame('200', $entry->getHttpStatus()); + $this->assertSame(4.0, $entry->getReadingTime()); + $this->assertSame('1.1.1.1', $entry->getDomainName()); } public function testWithForcedContent() @@ -333,14 +333,14 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase ] ); - $this->assertEquals('http://1.1.1.1', $entry->getUrl()); - $this->assertEquals('this is my title', $entry->getTitle()); + $this->assertSame('http://1.1.1.1', $entry->getUrl()); + $this->assertSame('this is my title', $entry->getTitle()); $this->assertContains('this is my content', $entry->getContent()); - $this->assertEquals('text/html', $entry->getMimetype()); - $this->assertEquals('fr', $entry->getLanguage()); - $this->assertEquals(4.0, $entry->getReadingTime()); - $this->assertEquals('1.1.1.1', $entry->getDomainName()); - $this->assertEquals('24/03/2014', $entry->getPublishedAt()->format('d/m/Y')); + $this->assertSame('text/html', $entry->getMimetype()); + $this->assertSame('fr', $entry->getLanguage()); + $this->assertSame(4.0, $entry->getReadingTime()); + $this->assertSame('1.1.1.1', $entry->getDomainName()); + $this->assertSame('24/03/2014', $entry->getPublishedAt()->format('d/m/Y')); $this->assertContains('Jeremy', $entry->getPublishedBy()); $this->assertContains('Nico', $entry->getPublishedBy()); $this->assertContains('Thomas', $entry->getPublishedBy()); @@ -371,14 +371,14 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase ] ); - $this->assertEquals('http://1.1.1.1', $entry->getUrl()); - $this->assertEquals('this is my title', $entry->getTitle()); + $this->assertSame('http://1.1.1.1', $entry->getUrl()); + $this->assertSame('this is my title', $entry->getTitle()); $this->assertContains('this is my content', $entry->getContent()); - $this->assertEquals('text/html', $entry->getMimetype()); - $this->assertEquals('fr', $entry->getLanguage()); - $this->assertEquals(4.0, $entry->getReadingTime()); - $this->assertEquals('1.1.1.1', $entry->getDomainName()); - $this->assertEquals('08/09/2016', $entry->getPublishedAt()->format('d/m/Y')); + $this->assertSame('text/html', $entry->getMimetype()); + $this->assertSame('fr', $entry->getLanguage()); + $this->assertSame(4.0, $entry->getReadingTime()); + $this->assertSame('1.1.1.1', $entry->getDomainName()); + $this->assertSame('08/09/2016', $entry->getPublishedAt()->format('d/m/Y')); } public function testWithForcedContentAndBadDate() @@ -406,13 +406,13 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase ] ); - $this->assertEquals('http://1.1.1.1', $entry->getUrl()); - $this->assertEquals('this is my title', $entry->getTitle()); + $this->assertSame('http://1.1.1.1', $entry->getUrl()); + $this->assertSame('this is my title', $entry->getTitle()); $this->assertContains('this is my content', $entry->getContent()); - $this->assertEquals('text/html', $entry->getMimetype()); - $this->assertEquals('fr', $entry->getLanguage()); - $this->assertEquals(4.0, $entry->getReadingTime()); - $this->assertEquals('1.1.1.1', $entry->getDomainName()); + $this->assertSame('text/html', $entry->getMimetype()); + $this->assertSame('fr', $entry->getLanguage()); + $this->assertSame(4.0, $entry->getReadingTime()); + $this->assertSame('1.1.1.1', $entry->getDomainName()); $this->assertNull($entry->getPublishedAt()); $records = $handler->getRecords(); @@ -488,14 +488,14 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase ] ); - $this->assertEquals('http://1.1.1.1', $entry->getUrl()); - $this->assertEquals('this is my title', $entry->getTitle()); + $this->assertSame('http://1.1.1.1', $entry->getUrl()); + $this->assertSame('this is my title', $entry->getTitle()); $this->assertNotContains($escapedString, $entry->getContent()); - $this->assertEquals('http://3.3.3.3/cover.jpg', $entry->getPreviewPicture()); - $this->assertEquals('text/html', $entry->getMimetype()); - $this->assertEquals('fr', $entry->getLanguage()); - $this->assertEquals('200', $entry->getHttpStatus()); - $this->assertEquals('1.1.1.1', $entry->getDomainName()); + $this->assertSame('http://3.3.3.3/cover.jpg', $entry->getPreviewPicture()); + $this->assertSame('text/html', $entry->getMimetype()); + $this->assertSame('fr', $entry->getLanguage()); + $this->assertSame('200', $entry->getHttpStatus()); + $this->assertSame('1.1.1.1', $entry->getDomainName()); } private function getTaggerMock() diff --git a/tests/Wallabag/CoreBundle/Helper/CryptoProxyTest.php b/tests/Wallabag/CoreBundle/Helper/CryptoProxyTest.php index cede8696..782c29c3 100644 --- a/tests/Wallabag/CoreBundle/Helper/CryptoProxyTest.php +++ b/tests/Wallabag/CoreBundle/Helper/CryptoProxyTest.php @@ -2,9 +2,9 @@ namespace Tests\Wallabag\CoreBundle\Helper; -use Psr\Log\NullLogger; -use Monolog\Logger; use Monolog\Handler\TestHandler; +use Monolog\Logger; +use Psr\Log\NullLogger; use Wallabag\CoreBundle\Helper\CryptoProxy; class CryptoProxyTest extends \PHPUnit_Framework_TestCase @@ -14,7 +14,7 @@ class CryptoProxyTest extends \PHPUnit_Framework_TestCase $logHandler = new TestHandler(); $logger = new Logger('test', [$logHandler]); - $crypto = new CryptoProxy(sys_get_temp_dir().'/'.uniqid('', true).'.txt', $logger); + $crypto = new CryptoProxy(sys_get_temp_dir() . '/' . uniqid('', true) . '.txt', $logger); $crypted = $crypto->crypt('test'); $decrypted = $crypto->decrypt($crypted); @@ -27,14 +27,14 @@ class CryptoProxyTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException RuntimeException + * @expectedException \RuntimeException * @expectedExceptionMessage Decrypt fail * * @return [type] [description] */ public function testDecryptBadValue() { - $crypto = new CryptoProxy(sys_get_temp_dir().'/'.uniqid('', true).'.txt', new NullLogger()); + $crypto = new CryptoProxy(sys_get_temp_dir() . '/' . uniqid('', true) . '.txt', new NullLogger()); $crypto->decrypt('badvalue'); } } diff --git a/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php b/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php index c02f9658..c61f65d0 100644 --- a/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php +++ b/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php @@ -2,13 +2,13 @@ namespace Tests\Wallabag\CoreBundle\Helper; -use Wallabag\CoreBundle\Helper\DownloadImages; -use Monolog\Logger; -use Monolog\Handler\TestHandler; use GuzzleHttp\Client; -use GuzzleHttp\Subscriber\Mock; use GuzzleHttp\Message\Response; use GuzzleHttp\Stream\Stream; +use GuzzleHttp\Subscriber\Mock; +use Monolog\Handler\TestHandler; +use Monolog\Logger; +use Wallabag\CoreBundle\Helper\DownloadImages; class DownloadImagesTest extends \PHPUnit_Framework_TestCase { @@ -34,15 +34,15 @@ class DownloadImagesTest extends \PHPUnit_Framework_TestCase $client = new Client(); $mock = new Mock([ - new Response(200, ['content-type' => 'image/png'], Stream::factory(file_get_contents(__DIR__.'/../fixtures/unnamed.png'))), + new Response(200, ['content-type' => 'image/png'], Stream::factory(file_get_contents(__DIR__ . '/../fixtures/unnamed.png'))), ]); $client->getEmitter()->attach($mock); $logHandler = new TestHandler(); - $logger = new Logger('test', array($logHandler)); + $logger = new Logger('test', [$logHandler]); - $download = new DownloadImages($client, sys_get_temp_dir().'/wallabag_test', 'http://wallabag.io/', $logger); + $download = new DownloadImages($client, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); $res = $download->processHtml(123, $html, $url); @@ -61,9 +61,9 @@ class DownloadImagesTest extends \PHPUnit_Framework_TestCase $client->getEmitter()->attach($mock); $logHandler = new TestHandler(); - $logger = new Logger('test', array($logHandler)); + $logger = new Logger('test', [$logHandler]); - $download = new DownloadImages($client, sys_get_temp_dir().'/wallabag_test', 'http://wallabag.io/', $logger); + $download = new DownloadImages($client, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); $res = $download->processHtml(123, '
', 'http://imgur.com/gallery/WxtWY'); $this->assertContains('http://i.imgur.com/T9qgcHc.jpg', $res, 'Image were not replace because of content-type'); @@ -87,18 +87,18 @@ class DownloadImagesTest extends \PHPUnit_Framework_TestCase $client = new Client(); $mock = new Mock([ - new Response(200, ['content-type' => $header], Stream::factory(file_get_contents(__DIR__.'/../fixtures/unnamed.png'))), + new Response(200, ['content-type' => $header], Stream::factory(file_get_contents(__DIR__ . '/../fixtures/unnamed.png'))), ]); $client->getEmitter()->attach($mock); $logHandler = new TestHandler(); - $logger = new Logger('test', array($logHandler)); + $logger = new Logger('test', [$logHandler]); - $download = new DownloadImages($client, sys_get_temp_dir().'/wallabag_test', 'http://wallabag.io/', $logger); + $download = new DownloadImages($client, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); $res = $download->processSingleImage(123, 'T9qgcHc.jpg', 'http://imgur.com/gallery/WxtWY'); - $this->assertContains('/assets/images/9/b/9b0ead26/ebe60399.'.$extension, $res); + $this->assertContains('/assets/images/9/b/9b0ead26/ebe60399.' . $extension, $res); } public function testProcessSingleImageWithBadUrl() @@ -112,9 +112,9 @@ class DownloadImagesTest extends \PHPUnit_Framework_TestCase $client->getEmitter()->attach($mock); $logHandler = new TestHandler(); - $logger = new Logger('test', array($logHandler)); + $logger = new Logger('test', [$logHandler]); - $download = new DownloadImages($client, sys_get_temp_dir().'/wallabag_test', 'http://wallabag.io/', $logger); + $download = new DownloadImages($client, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); $res = $download->processSingleImage(123, 'T9qgcHc.jpg', 'http://imgur.com/gallery/WxtWY'); $this->assertFalse($res, 'Image can not be found, so it will not be replaced'); @@ -131,9 +131,9 @@ class DownloadImagesTest extends \PHPUnit_Framework_TestCase $client->getEmitter()->attach($mock); $logHandler = new TestHandler(); - $logger = new Logger('test', array($logHandler)); + $logger = new Logger('test', [$logHandler]); - $download = new DownloadImages($client, sys_get_temp_dir().'/wallabag_test', 'http://wallabag.io/', $logger); + $download = new DownloadImages($client, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); $res = $download->processSingleImage(123, 'http://i.imgur.com/T9qgcHc.jpg', 'http://imgur.com/gallery/WxtWY'); $this->assertFalse($res, 'Image can not be loaded, so it will not be replaced'); @@ -144,15 +144,15 @@ class DownloadImagesTest extends \PHPUnit_Framework_TestCase $client = new Client(); $mock = new Mock([ - new Response(200, ['content-type' => 'image/png'], Stream::factory(file_get_contents(__DIR__.'/../fixtures/unnamed.png'))), + new Response(200, ['content-type' => 'image/png'], Stream::factory(file_get_contents(__DIR__ . '/../fixtures/unnamed.png'))), ]); $client->getEmitter()->attach($mock); $logHandler = new TestHandler(); - $logger = new Logger('test', array($logHandler)); + $logger = new Logger('test', [$logHandler]); - $download = new DownloadImages($client, sys_get_temp_dir().'/wallabag_test', 'http://wallabag.io/', $logger); + $download = new DownloadImages($client, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); $res = $download->processSingleImage(123, '/i.imgur.com/T9qgcHc.jpg', 'imgur.com/gallery/WxtWY'); $this->assertFalse($res, 'Absolute image can not be determined, so it will not be replaced'); @@ -163,15 +163,15 @@ class DownloadImagesTest extends \PHPUnit_Framework_TestCase $client = new Client(); $mock = new Mock([ - new Response(200, ['content-type' => null], Stream::factory(file_get_contents(__DIR__.'/../fixtures/image-no-content-type.jpg'))), + new Response(200, ['content-type' => null], Stream::factory(file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))), ]); $client->getEmitter()->attach($mock); $logHandler = new TestHandler(); - $logger = new Logger('test', array($logHandler)); + $logger = new Logger('test', [$logHandler]); - $download = new DownloadImages($client, sys_get_temp_dir().'/wallabag_test', 'http://wallabag.io/', $logger); + $download = new DownloadImages($client, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); $res = $download->processSingleImage( 123, diff --git a/tests/Wallabag/CoreBundle/Helper/RedirectTest.php b/tests/Wallabag/CoreBundle/Helper/RedirectTest.php index f420d06a..7fd2ea2b 100644 --- a/tests/Wallabag/CoreBundle/Helper/RedirectTest.php +++ b/tests/Wallabag/CoreBundle/Helper/RedirectTest.php @@ -2,11 +2,11 @@ namespace Tests\Wallabag\CoreBundle\Helper; +use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; +use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; use Wallabag\CoreBundle\Entity\Config; -use Wallabag\UserBundle\Entity\User; use Wallabag\CoreBundle\Helper\Redirect; -use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; -use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; +use Wallabag\UserBundle\Entity\User; class RedirectTest extends \PHPUnit_Framework_TestCase { @@ -56,21 +56,21 @@ class RedirectTest extends \PHPUnit_Framework_TestCase { $redirectUrl = $this->redirect->to(null, 'fallback'); - $this->assertEquals('fallback', $redirectUrl); + $this->assertSame('fallback', $redirectUrl); } public function testRedirectToNullWithoutFallback() { $redirectUrl = $this->redirect->to(null); - $this->assertEquals($this->routerMock->generate('homepage'), $redirectUrl); + $this->assertSame($this->routerMock->generate('homepage'), $redirectUrl); } public function testRedirectToValidUrl() { $redirectUrl = $this->redirect->to('/unread/list'); - $this->assertEquals('/unread/list', $redirectUrl); + $this->assertSame('/unread/list', $redirectUrl); } public function testWithNotLoggedUser() @@ -78,7 +78,7 @@ class RedirectTest extends \PHPUnit_Framework_TestCase $redirect = new Redirect($this->routerMock, new TokenStorage()); $redirectUrl = $redirect->to('/unread/list'); - $this->assertEquals('/unread/list', $redirectUrl); + $this->assertSame('/unread/list', $redirectUrl); } public function testUserForRedirectToHomepage() @@ -87,7 +87,7 @@ class RedirectTest extends \PHPUnit_Framework_TestCase $redirectUrl = $this->redirect->to('/unread/list'); - $this->assertEquals($this->routerMock->generate('homepage'), $redirectUrl); + $this->assertSame($this->routerMock->generate('homepage'), $redirectUrl); } public function testUserForRedirectWithIgnoreActionMarkAsRead() @@ -96,7 +96,7 @@ class RedirectTest extends \PHPUnit_Framework_TestCase $redirectUrl = $this->redirect->to('/unread/list', '', true); - $this->assertEquals('/unread/list', $redirectUrl); + $this->assertSame('/unread/list', $redirectUrl); } public function testUserForRedirectNullWithFallbackWithIgnoreActionMarkAsRead() @@ -105,6 +105,6 @@ class RedirectTest extends \PHPUnit_Framework_TestCase $redirectUrl = $this->redirect->to(null, 'fallback', true); - $this->assertEquals('fallback', $redirectUrl); + $this->assertSame('fallback', $redirectUrl); } } diff --git a/tests/Wallabag/CoreBundle/Helper/RuleBasedTaggerTest.php b/tests/Wallabag/CoreBundle/Helper/RuleBasedTaggerTest.php index 1e21f400..c31af680 100644 --- a/tests/Wallabag/CoreBundle/Helper/RuleBasedTaggerTest.php +++ b/tests/Wallabag/CoreBundle/Helper/RuleBasedTaggerTest.php @@ -182,7 +182,7 @@ class RuleBasedTaggerTest extends \PHPUnit_Framework_TestCase $tags = $entry->getTags(); $this->assertCount(1, $tags); - $this->assertEquals('hey', $tags[0]->getLabel()); + $this->assertSame('hey', $tags[0]->getLabel()); } } diff --git a/tests/Wallabag/CoreBundle/Helper/TagsAssignerTest.php b/tests/Wallabag/CoreBundle/Helper/TagsAssignerTest.php index 6d6d6484..475cd349 100644 --- a/tests/Wallabag/CoreBundle/Helper/TagsAssignerTest.php +++ b/tests/Wallabag/CoreBundle/Helper/TagsAssignerTest.php @@ -5,8 +5,8 @@ namespace Tests\Wallabag\CoreBundle\Helper; use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Entity\Tag; use Wallabag\CoreBundle\Helper\TagsAssigner; -use Wallabag\UserBundle\Entity\User; use Wallabag\CoreBundle\Repository\TagRepository; +use Wallabag\UserBundle\Entity\User; class TagsAssignerTest extends \PHPUnit_Framework_TestCase { @@ -20,8 +20,8 @@ class TagsAssignerTest extends \PHPUnit_Framework_TestCase $tagsAssigner->assignTagsToEntry($entry, [' tag1', 'tag2 ']); $this->assertCount(2, $entry->getTags()); - $this->assertEquals('tag1', $entry->getTags()[0]->getLabel()); - $this->assertEquals('tag2', $entry->getTags()[1]->getLabel()); + $this->assertSame('tag1', $entry->getTags()[0]->getLabel()); + $this->assertSame('tag2', $entry->getTags()[1]->getLabel()); } public function testAssignTagsWithString() @@ -34,8 +34,8 @@ class TagsAssignerTest extends \PHPUnit_Framework_TestCase $tagsAssigner->assignTagsToEntry($entry, 'tag1, tag2'); $this->assertCount(2, $entry->getTags()); - $this->assertEquals('tag1', $entry->getTags()[0]->getLabel()); - $this->assertEquals('tag2', $entry->getTags()[1]->getLabel()); + $this->assertSame('tag1', $entry->getTags()[0]->getLabel()); + $this->assertSame('tag2', $entry->getTags()[1]->getLabel()); } public function testAssignTagsWithEmptyArray() @@ -76,8 +76,8 @@ class TagsAssignerTest extends \PHPUnit_Framework_TestCase $tagsAssigner->assignTagsToEntry($entry, 'tag1, tag2'); $this->assertCount(2, $entry->getTags()); - $this->assertEquals('tag1', $entry->getTags()[0]->getLabel()); - $this->assertEquals('tag2', $entry->getTags()[1]->getLabel()); + $this->assertSame('tag1', $entry->getTags()[0]->getLabel()); + $this->assertSame('tag2', $entry->getTags()[1]->getLabel()); } public function testAssignTagsNotFlushed() @@ -96,7 +96,7 @@ class TagsAssignerTest extends \PHPUnit_Framework_TestCase $tagsAssigner->assignTagsToEntry($entry, 'tag1', [$tagEntity]); $this->assertCount(1, $entry->getTags()); - $this->assertEquals('tag1', $entry->getTags()[0]->getLabel()); + $this->assertSame('tag1', $entry->getTags()[0]->getLabel()); } private function getTagRepositoryMock() diff --git a/tests/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php b/tests/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php index ca8e0d50..74c645ef 100644 --- a/tests/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php +++ b/tests/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php @@ -212,6 +212,6 @@ class UsernameRssTokenConverterTest extends \PHPUnit_Framework_TestCase $converter->apply($request, $params); - $this->assertEquals($user, $request->attributes->get('user')); + $this->assertSame($user, $request->attributes->get('user')); } } diff --git a/tests/Wallabag/CoreBundle/Tools/UtilsTest.php b/tests/Wallabag/CoreBundle/Tools/UtilsTest.php index 435c25ca..4521e485 100644 --- a/tests/Wallabag/CoreBundle/Tools/UtilsTest.php +++ b/tests/Wallabag/CoreBundle/Tools/UtilsTest.php @@ -18,7 +18,7 @@ class UtilsTest extends \PHPUnit_Framework_TestCase public function examples() { $examples = []; - $finder = (new Finder())->in(__DIR__.'/samples'); + $finder = (new Finder())->in(__DIR__ . '/samples'); foreach ($finder->getIterator() as $file) { $examples[] = [$file->getContents(), 1]; } diff --git a/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php b/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php index b1c8c946..ceec4b37 100644 --- a/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php +++ b/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php @@ -26,8 +26,8 @@ class WallabagExtensionTest extends \PHPUnit_Framework_TestCase $extension = new WallabagExtension($entryRepository, $tagRepository, $tokenStorage, 0, $translator); - $this->assertEquals('lemonde.fr', $extension->removeWww('www.lemonde.fr')); - $this->assertEquals('lemonde.fr', $extension->removeWww('lemonde.fr')); - $this->assertEquals('gist.github.com', $extension->removeWww('gist.github.com')); + $this->assertSame('lemonde.fr', $extension->removeWww('www.lemonde.fr')); + $this->assertSame('lemonde.fr', $extension->removeWww('lemonde.fr')); + $this->assertSame('gist.github.com', $extension->removeWww('gist.github.com')); } } diff --git a/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php b/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php index eec6939d..1eda5199 100644 --- a/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php +++ b/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php @@ -18,11 +18,6 @@ abstract class WallabagCoreTestCase extends WebTestCase */ private $client = null; - public function getClient() - { - return $this->client; - } - public function setUp() { parent::setUp(); @@ -30,6 +25,11 @@ abstract class WallabagCoreTestCase extends WebTestCase $this->client = static::createClient(); } + public function getClient() + { + return $this->client; + } + public function resetDatabase(Client $client) { $application = new Application($client->getKernel()); @@ -83,10 +83,10 @@ abstract class WallabagCoreTestCase extends WebTestCase $loginManager = $container->get('fos_user.security.login_manager'); $firewallName = $container->getParameter('fos_user.firewall_name'); - $user = $userManager->findUserBy(array('username' => $username)); + $user = $userManager->findUserBy(['username' => $username]); $loginManager->logInUser($firewallName, $user); - $session->set('_security_'.$firewallName, serialize($container->get('security.token_storage')->getToken())); + $session->set('_security_' . $firewallName, serialize($container->get('security.token_storage')->getToken())); $session->save(); $cookie = new Cookie($session->getName(), $session->getId()); -- cgit v1.2.3 From 38520658addc217f127b0627ea28dcf8d6e6178c Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Mon, 3 Jul 2017 07:30:54 +0200 Subject: Fix tests --- .../CoreBundle/Controller/EntryControllerTest.php | 9 ++++---- .../CoreBundle/Controller/ExportControllerTest.php | 4 ++-- .../Event/Listener/UserLocaleListenerTest.php | 2 +- .../GrabySiteConfigBuilderTest.php | 24 ++++++++-------------- .../CoreBundle/Helper/ContentProxyTest.php | 2 +- 5 files changed, 18 insertions(+), 23 deletions(-) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index b528bcdb..b1c6d53c 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php @@ -43,6 +43,7 @@ class EntryControllerTest extends WallabagCoreTestCase $client = $this->getClient(); $client->request('GET', '/unread/list'); + $this->assertSame(302, $client->getResponse()->getStatusCode()); $crawler = $client->followRedirect(); $this->assertSame(200, $client->getResponse()->getStatusCode()); @@ -505,7 +506,7 @@ class EntryControllerTest extends WallabagCoreTestCase ->getRepository('WallabagCoreBundle:Entry') ->find($entry->getId()); - $this->assertSame($res->isArchived(), true); + $this->assertSame(1, $res->isArchived()); } public function testToggleStar() @@ -528,7 +529,7 @@ class EntryControllerTest extends WallabagCoreTestCase ->getRepository('WallabagCoreBundle:Entry') ->findOneById($entry->getId()); - $this->assertSame($res->isStarred(), true); + $this->assertSame(1, $res->isStarred()); } public function testDelete() @@ -1004,7 +1005,7 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertSame($url, $entry->getUrl()); $this->assertContains('Perpignan', $entry->getTitle()); // instead of checking for the filename (which might change) check that the image is now local - $this->assertContains('https://your-wallabag-url-instance.com/assets/images/', $entry->getContent()); + $this->assertContains($client->getContainer()->getParameter('domain_name') . '/assets/images/', $entry->getContent()); $client->getContainer()->get('craue_config')->set('download_images_enabled', 0); } @@ -1296,7 +1297,7 @@ class EntryControllerTest extends WallabagCoreTestCase ], 'fucked_list_of_languages' => [ 'http://geocatalog.webservice-energy.org/geonetwork/srv/eng/main.home', - '', + null, ], 'es-ES' => [ 'http://www.muylinux.com/2015/04/17/odf-reino-unido-microsoft-google', diff --git a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php index ba9296af..3e216381 100644 --- a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php @@ -230,8 +230,8 @@ class ExportControllerTest extends WallabagCoreTestCase $this->assertArrayHasKey('created_at', $content[0]); $this->assertArrayHasKey('updated_at', $content[0]); - $this->assertSame($contentInDB->isArchived(), $content[0]['is_archived']); - $this->assertSame($contentInDB->isStarred(), $content[0]['is_starred']); + $this->assertSame((int) $contentInDB->isArchived(), $content[0]['is_archived']); + $this->assertSame((int) $contentInDB->isStarred(), $content[0]['is_starred']); $this->assertSame($contentInDB->getTitle(), $content[0]['title']); $this->assertSame($contentInDB->getUrl(), $content[0]['url']); $this->assertSame([['text' => 'This is my annotation /o/', 'quote' => 'content']], $content[0]['annotations']); diff --git a/tests/Wallabag/CoreBundle/Event/Listener/UserLocaleListenerTest.php b/tests/Wallabag/CoreBundle/Event/Listener/UserLocaleListenerTest.php index 91ce0102..5ffe1ca6 100644 --- a/tests/Wallabag/CoreBundle/Event/Listener/UserLocaleListenerTest.php +++ b/tests/Wallabag/CoreBundle/Event/Listener/UserLocaleListenerTest.php @@ -53,6 +53,6 @@ class UserLocaleListenerTest extends \PHPUnit_Framework_TestCase $listener->onInteractiveLogin($event); - $this->assertSame('', $session->get('_locale')); + $this->assertNull($session->get('_locale')); } } diff --git a/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php b/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php index 85036e35..5d6a29fe 100644 --- a/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php +++ b/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php @@ -2,7 +2,6 @@ namespace Tests\Wallabag\CoreBundle\GuzzleSiteAuthenticator; -use BD\GuzzleSiteAuthenticator\SiteConfig\SiteConfig; use Graby\SiteConfig\SiteConfig as GrabySiteConfig; use Monolog\Handler\TestHandler; use Monolog\Logger; @@ -68,20 +67,15 @@ class GrabySiteConfigBuilderTest extends \PHPUnit_Framework_TestCase $config = $this->builder->buildForHost('www.example.com'); - $this->assertSame( - new SiteConfig([ - 'host' => 'example.com', - 'requiresLogin' => true, - 'loginUri' => 'http://www.example.com/login', - 'usernameField' => 'login', - 'passwordField' => 'password', - 'extraFields' => ['field' => 'value'], - 'notLoggedInXpath' => '//div[@class="need-login"]', - 'username' => 'foo', - 'password' => 'bar', - ]), - $config - ); + $this->assertSame('example.com', $config->getHost()); + $this->assertSame(true, $config->requiresLogin()); + $this->assertSame('http://www.example.com/login', $config->getLoginUri()); + $this->assertSame('login', $config->getUsernameField()); + $this->assertSame('password', $config->getPasswordField()); + $this->assertSame(['field' => 'value'], $config->getExtraFields()); + $this->assertSame('//div[@class="need-login"]', $config->getNotLoggedInXpath()); + $this->assertSame('foo', $config->getUsername()); + $this->assertSame('bar', $config->getPassword()); $records = $handler->getRecords(); diff --git a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php index 7e19631b..c63671c4 100644 --- a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php +++ b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php @@ -51,7 +51,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase $this->assertEmpty($entry->getMimetype()); $this->assertEmpty($entry->getLanguage()); $this->assertSame(0.0, $entry->getReadingTime()); - $this->assertSame(false, $entry->getDomainName()); + $this->assertSame(null, $entry->getDomainName()); } public function testWithEmptyContent() -- cgit v1.2.3 From a05b61159e147776f63baee731b5026796e5f7ae Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 30 Jun 2017 16:54:26 +0200 Subject: Fix PATCH method The PATCH method for the entry should only update what user sent to us and not the whole entry as it was before. Also, sending tags when patching an entry will now remove all current tags & assocatied new ones. --- tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php index c63671c4..f394b947 100644 --- a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php +++ b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php @@ -221,12 +221,9 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase ->method('tag'); $validator = $this->getValidator(); - $validator->expects($this->exactly(2)) + $validator->expects($this->once()) ->method('validate') - ->will($this->onConsecutiveCalls( - new ConstraintViolationList([new ConstraintViolation('oops', 'oops', [], 'oops', 'language', 'dontexist')]), - new ConstraintViolationList() - )); + ->willReturn(new ConstraintViolationList([new ConstraintViolation('oops', 'oops', [], 'oops', 'language', 'dontexist')])); $graby = $this->getMockBuilder('Graby\Graby') ->setMethods(['fetchContent']) -- cgit v1.2.3 From d0ec2ddd2354e39badd947c2214f47193784b1c7 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Fri, 30 Jun 2017 17:04:40 +0200 Subject: Fix validateAndSetPreviewPicture Which wasn't covered by a test! --- .../CoreBundle/Helper/ContentProxyTest.php | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php index f394b947..c0b68d53 100644 --- a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php +++ b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php @@ -495,6 +495,41 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase $this->assertSame('1.1.1.1', $entry->getDomainName()); } + public function testWithImageAsContent() + { + $tagger = $this->getTaggerMock(); + $tagger->expects($this->once()) + ->method('tag'); + + $graby = $this->getMockBuilder('Graby\Graby') + ->setMethods(['fetchContent']) + ->disableOriginalConstructor() + ->getMock(); + + $graby->expects($this->any()) + ->method('fetchContent') + ->willReturn([ + 'html' => '

', + 'title' => 'this is my title', + 'url' => 'http://1.1.1.1/image.jpg', + 'content_type' => 'image/jpeg', + 'status' => '200', + 'open_graph' => [], + ]); + + $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); + $entry = new Entry(new User()); + $proxy->updateEntry($entry, 'http://0.0.0.0'); + + $this->assertEquals('http://1.1.1.1/image.jpg', $entry->getUrl()); + $this->assertEquals('this is my title', $entry->getTitle()); + $this->assertContains('http://1.1.1.1/image.jpg', $entry->getContent()); + $this->assertSame('http://1.1.1.1/image.jpg', $entry->getPreviewPicture()); + $this->assertEquals('image/jpeg', $entry->getMimetype()); + $this->assertEquals('200', $entry->getHttpStatus()); + $this->assertEquals('1.1.1.1', $entry->getDomainName()); + } + private function getTaggerMock() { return $this->getMockBuilder(RuleBasedTagger::class) -- cgit v1.2.3 From c18a2476b601bc6b9893462d9be680c2e13c89e8 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Mon, 3 Jul 2017 13:56:39 +0200 Subject: CS --- tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php index c0b68d53..f94c2137 100644 --- a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php +++ b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php @@ -521,13 +521,13 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase $entry = new Entry(new User()); $proxy->updateEntry($entry, 'http://0.0.0.0'); - $this->assertEquals('http://1.1.1.1/image.jpg', $entry->getUrl()); - $this->assertEquals('this is my title', $entry->getTitle()); + $this->assertSame('http://1.1.1.1/image.jpg', $entry->getUrl()); + $this->assertSame('this is my title', $entry->getTitle()); $this->assertContains('http://1.1.1.1/image.jpg', $entry->getContent()); $this->assertSame('http://1.1.1.1/image.jpg', $entry->getPreviewPicture()); - $this->assertEquals('image/jpeg', $entry->getMimetype()); - $this->assertEquals('200', $entry->getHttpStatus()); - $this->assertEquals('1.1.1.1', $entry->getDomainName()); + $this->assertSame('image/jpeg', $entry->getMimetype()); + $this->assertSame('200', $entry->getHttpStatus()); + $this->assertSame('1.1.1.1', $entry->getDomainName()); } private function getTaggerMock() -- cgit v1.2.3 From c6c45673af62ca7d888d1e30d8b63fe15a388a9c Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Mon, 24 Jul 2017 11:12:54 +0200 Subject: Put the final URL in data test --- tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index b1c6d53c..33bfa71e 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php @@ -1300,7 +1300,7 @@ class EntryControllerTest extends WallabagCoreTestCase null, ], 'es-ES' => [ - 'http://www.muylinux.com/2015/04/17/odf-reino-unido-microsoft-google', + 'http://www.muylinux.com/2015/04/17/odf-reino-unido-microsoft-google/', 'es_ES', ], ]; -- cgit v1.2.3 From e1b33efb3dd7c9ebb4dcfb23a2ca5efbda0a05f6 Mon Sep 17 00:00:00 2001 From: Nicolas Hart Date: Sat, 29 Jul 2017 00:30:22 +0200 Subject: Better rendering for all core commands --- tests/Wallabag/CoreBundle/Command/ExportCommandTest.php | 3 ++- tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php | 8 ++++---- tests/Wallabag/CoreBundle/Command/TagAllCommandTest.php | 3 ++- 3 files changed, 8 insertions(+), 6 deletions(-) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Command/ExportCommandTest.php b/tests/Wallabag/CoreBundle/Command/ExportCommandTest.php index 25de2730..210b2ab6 100644 --- a/tests/Wallabag/CoreBundle/Command/ExportCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/ExportCommandTest.php @@ -55,7 +55,8 @@ class ExportCommandTest extends WallabagCoreTestCase 'username' => 'admin', ]); - $this->assertContains('Exporting 5 entrie(s) for user « admin »... Done', $tester->getDisplay()); + $this->assertContains('Exporting 5 entrie(s) for user admin...', $tester->getDisplay()); + $this->assertContains('Done', $tester->getDisplay()); $this->assertFileExists('admin-export.json'); } diff --git a/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php b/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php index c0a4acfa..9b34f2a0 100644 --- a/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php @@ -56,9 +56,9 @@ class ShowUserCommandTest extends WallabagCoreTestCase 'username' => 'admin', ]); - $this->assertContains('Username : admin', $tester->getDisplay()); - $this->assertContains('Email : bigboss@wallabag.org', $tester->getDisplay()); - $this->assertContains('Display name : Big boss', $tester->getDisplay()); + $this->assertContains('Username: admin', $tester->getDisplay()); + $this->assertContains('Email: bigboss@wallabag.org', $tester->getDisplay()); + $this->assertContains('Display name: Big boss', $tester->getDisplay()); $this->assertContains('2FA activated: no', $tester->getDisplay()); } @@ -88,6 +88,6 @@ class ShowUserCommandTest extends WallabagCoreTestCase 'username' => 'admin', ]); - $this->assertContains('Display name : Bug boss', $tester->getDisplay()); + $this->assertContains('Display name: Bug boss', $tester->getDisplay()); } } diff --git a/tests/Wallabag/CoreBundle/Command/TagAllCommandTest.php b/tests/Wallabag/CoreBundle/Command/TagAllCommandTest.php index 96d0e91f..b1e56a10 100644 --- a/tests/Wallabag/CoreBundle/Command/TagAllCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/TagAllCommandTest.php @@ -55,6 +55,7 @@ class TagAllCommandTest extends WallabagCoreTestCase 'username' => 'admin', ]); - $this->assertContains('Tagging entries for user « admin »... Done', $tester->getDisplay()); + $this->assertContains('Tagging entries for user admin...', $tester->getDisplay()); + $this->assertContains('Done', $tester->getDisplay()); } } -- cgit v1.2.3 From af31cfed769538fcb7d283cb1fad80ac8d07b663 Mon Sep 17 00:00:00 2001 From: Nicolas Hart Date: Sun, 30 Jul 2017 22:04:29 +0200 Subject: Add list user command --- .../CoreBundle/Command/ListUserCommandTest.php | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 tests/Wallabag/CoreBundle/Command/ListUserCommandTest.php (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Command/ListUserCommandTest.php b/tests/Wallabag/CoreBundle/Command/ListUserCommandTest.php new file mode 100644 index 00000000..5e644247 --- /dev/null +++ b/tests/Wallabag/CoreBundle/Command/ListUserCommandTest.php @@ -0,0 +1,26 @@ +getClient()->getKernel()); + $application->add(new ListUserCommand()); + + $command = $application->find('wallabag:user:list'); + + $tester = new CommandTester($command); + $tester->execute([ + 'command' => $command->getName(), + ]); + + $this->assertContains('3 user(s) displayed.', $tester->getDisplay()); + } +} -- cgit v1.2.3 From f7a4b441361404b378c30b7788b3699c208537ad Mon Sep 17 00:00:00 2001 From: Nicolas Hart Date: Mon, 31 Jul 2017 23:20:41 +0200 Subject: add search argument and limit option to list users command --- .../CoreBundle/Command/ListUserCommandTest.php | 51 +++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Command/ListUserCommandTest.php b/tests/Wallabag/CoreBundle/Command/ListUserCommandTest.php index 5e644247..9068cf59 100644 --- a/tests/Wallabag/CoreBundle/Command/ListUserCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/ListUserCommandTest.php @@ -21,6 +21,55 @@ class ListUserCommandTest extends WallabagCoreTestCase 'command' => $command->getName(), ]); - $this->assertContains('3 user(s) displayed.', $tester->getDisplay()); + $this->assertContains('3/3 user(s) displayed.', $tester->getDisplay()); + } + + public function testRunListUserCommandWithLimit() + { + $application = new Application($this->getClient()->getKernel()); + $application->add(new ListUserCommand()); + + $command = $application->find('wallabag:user:list'); + + $tester = new CommandTester($command); + $tester->execute([ + 'command' => $command->getName(), + '--limit' => 2, + ]); + + $this->assertContains('2/3 user(s) displayed.', $tester->getDisplay()); + } + + public function testRunListUserCommandWithSearch() + { + $application = new Application($this->getClient()->getKernel()); + $application->add(new ListUserCommand()); + + $command = $application->find('wallabag:user:list'); + + $tester = new CommandTester($command); + $tester->execute([ + 'command' => $command->getName(), + 'search' => 'boss', + ]); + + $this->assertContains('1/3 (filtered) user(s) displayed.', $tester->getDisplay()); + } + + public function testRunListUserCommandWithSearchAndLimit() + { + $application = new Application($this->getClient()->getKernel()); + $application->add(new ListUserCommand()); + + $command = $application->find('wallabag:user:list'); + + $tester = new CommandTester($command); + $tester->execute([ + 'command' => $command->getName(), + 'search' => 'bo', + '--limit' => 1, + ]); + + $this->assertContains('1/3 (filtered) user(s) displayed.', $tester->getDisplay()); } } -- cgit v1.2.3 From 511f1ce1e87e0f30a455ca6ed73e008bfd557f83 Mon Sep 17 00:00:00 2001 From: Nicolas Hart Date: Mon, 21 Aug 2017 10:36:56 +0200 Subject: Add reload entry command --- .../CoreBundle/Command/ReloadEntryCommandTest.php | 115 +++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php b/tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php new file mode 100644 index 00000000..63c068b4 --- /dev/null +++ b/tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php @@ -0,0 +1,115 @@ +getClient()->getContainer()->get('wallabag_user.user_repository'); + + $user = $userRepository->findOneByUserName('admin'); + $this->adminEntry = new Entry($user); + $this->adminEntry->setUrl($this->url); + $this->adminEntry->setTitle('title foo'); + $this->adminEntry->setContent(''); + $this->getEntityManager()->persist($this->adminEntry); + + $user = $userRepository->findOneByUserName('bob'); + $this->bobEntry = new Entry($user); + $this->bobEntry->setUrl($this->url); + $this->bobEntry->setTitle('title foo'); + $this->bobEntry->setContent(''); + $this->getEntityManager()->persist($this->bobEntry); + + $this->getEntityManager()->flush(); + } + + public function testRunReloadEntryCommand() + { + $application = new Application($this->getClient()->getKernel()); + $application->add(new ReloadEntryCommand()); + + $command = $application->find('wallabag:entry:reload'); + $tester = new CommandTester($command); + $tester->execute([ + 'command' => $command->getName(), + ], [ + 'interactive' => false, + ]); + + $reloadedEntries = $this->getClient() + ->getContainer() + ->get('wallabag_core.entry_repository') + ->findById([$this->adminEntry->getId(), $this->bobEntry->getId()]); + + foreach ($reloadedEntries as $reloadedEntry) { + $this->assertNotEmpty($reloadedEntry->getContent()); + } + + $this->assertContains('Done', $tester->getDisplay()); + } + + public function testRunReloadEntryWithUsernameCommand() + { + $application = new Application($this->getClient()->getKernel()); + $application->add(new ReloadEntryCommand()); + + $command = $application->find('wallabag:entry:reload'); + $tester = new CommandTester($command); + $tester->execute([ + 'command' => $command->getName(), + 'username' => 'admin', + ], [ + 'interactive' => false, + ]); + + $entryRepository = $this->getClient()->getContainer()->get('wallabag_core.entry_repository'); + + $reloadedAdminEntry = $entryRepository->find($this->adminEntry->getId()); + $this->assertNotEmpty($reloadedAdminEntry->getContent()); + + $reloadedBobEntry = $entryRepository->find($this->bobEntry->getId()); + $this->assertEmpty($reloadedBobEntry->getContent()); + + $this->assertContains('Done', $tester->getDisplay()); + } + + public function testRunReloadEntryWithoutEntryCommand() + { + $application = new Application($this->getClient()->getKernel()); + $application->add(new ReloadEntryCommand()); + + $command = $application->find('wallabag:entry:reload'); + $tester = new CommandTester($command); + $tester->execute([ + 'command' => $command->getName(), + 'username' => 'empty', + ], [ + 'interactive' => false, + ]); + + $this->assertContains('No entry to reload', $tester->getDisplay()); + $this->assertNotContains('Done', $tester->getDisplay()); + } +} -- cgit v1.2.3 From 7036d91fe7332a797bf5cbccec8790bcef8437d4 Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Sun, 21 May 2017 17:01:59 +0200 Subject: Tag: render tags case-insensitive by storing them in lowercase Fixes #2502 Signed-off-by: Kevin Decherf --- tests/Wallabag/CoreBundle/Controller/TagControllerTest.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php index be25a8b5..5a973a7e 100644 --- a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php @@ -9,6 +9,7 @@ use Wallabag\CoreBundle\Entity\Tag; class TagControllerTest extends WallabagCoreTestCase { public $tagName = 'opensource'; + public $caseTagName = 'OpenSource'; public function testList() { @@ -36,7 +37,7 @@ class TagControllerTest extends WallabagCoreTestCase $form = $crawler->filter('form[name=tag]')->form(); $data = [ - 'tag[label]' => $this->tagName, + 'tag[label]' => $this->caseTagName, ]; $client->submit($form, $data); @@ -45,6 +46,7 @@ class TagControllerTest extends WallabagCoreTestCase // be sure to reload the entry $entry = $this->getEntityManager()->getRepository(Entry::class)->find($entry->getId()); $this->assertCount(1, $entry->getTags()); + $this->assertContains($this->tagName, $entry->getTags()); // tag already exists and already assigned $client->submit($form, $data); @@ -80,7 +82,7 @@ class TagControllerTest extends WallabagCoreTestCase $form = $crawler->filter('form[name=tag]')->form(); $data = [ - 'tag[label]' => 'foo2, bar2', + 'tag[label]' => 'foo2, Bar2', ]; $client->submit($form, $data); -- cgit v1.2.3 From 7c04b7396a296e31bb11beadc19550396ee728a8 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Thu, 3 Aug 2017 12:46:20 +0200 Subject: Multiple tag search was broken from API First, the setParameter() were done on the same parameter which in fact just duplicated the condition in the SQL query (like `where t.label = 'test' and t.label = 'test'`. Changed the parameter doesn't help because the query was then wrong. Changing the way to match associated tags for an entry and it worked. --- tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php | 2 +- tests/Wallabag/CoreBundle/Controller/RssControllerTest.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php index 3e216381..02ad26ae 100644 --- a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php @@ -239,7 +239,7 @@ class ExportControllerTest extends WallabagCoreTestCase $this->assertSame($contentInDB->getLanguage(), $content[0]['language']); $this->assertSame($contentInDB->getReadingtime(), $content[0]['reading_time']); $this->assertSame($contentInDB->getDomainname(), $content[0]['domain_name']); - $this->assertSame(['foo bar', 'baz'], $content[0]['tags']); + $this->assertSame(['baz', 'foo'], $content[0]['tags']); } public function testXmlExport() diff --git a/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php b/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php index 6167fe2d..c6ca4937 100644 --- a/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php @@ -184,13 +184,13 @@ class RssControllerTest extends WallabagCoreTestCase $em->flush(); $client = $this->getClient(); - $client->request('GET', '/admin/SUPERTOKEN/tags/foo-bar.xml'); + $client->request('GET', '/admin/SUPERTOKEN/tags/foo.xml'); $this->assertSame(200, $client->getResponse()->getStatusCode()); - $this->validateDom($client->getResponse()->getContent(), 'tag (foo bar)', 'tags/foo-bar'); + $this->validateDom($client->getResponse()->getContent(), 'tag (foo)', 'tags/foo'); - $client->request('GET', '/admin/SUPERTOKEN/tags/foo-bar.xml?page=3000'); + $client->request('GET', '/admin/SUPERTOKEN/tags/foo.xml?page=3000'); $this->assertSame(302, $client->getResponse()->getStatusCode()); } } -- cgit v1.2.3 From 33264c2d02fdfe6e8321096491b9c7398cd10e9a Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Thu, 3 Aug 2017 16:20:49 +0200 Subject: Fix tests --- tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php index 02ad26ae..ab7f23cc 100644 --- a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php @@ -239,7 +239,8 @@ class ExportControllerTest extends WallabagCoreTestCase $this->assertSame($contentInDB->getLanguage(), $content[0]['language']); $this->assertSame($contentInDB->getReadingtime(), $content[0]['reading_time']); $this->assertSame($contentInDB->getDomainname(), $content[0]['domain_name']); - $this->assertSame(['baz', 'foo'], $content[0]['tags']); + $this->assertContains('baz', $content[0]['tags']); + $this->assertContains('foo', $content[0]['tags']); } public function testXmlExport() -- cgit v1.2.3 From f40c88eb1fa349aab600f9c1c94364f317fe62dd Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Mon, 9 Oct 2017 16:45:09 +0200 Subject: Jump to Symfony 3.3 & update others deps Also update tests urls --- tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index 33bfa71e..907814df 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php @@ -1268,7 +1268,7 @@ class EntryControllerTest extends WallabagCoreTestCase 'ru', ], 'fr-FR' => [ - 'http://www.zataz.com/90-des-dossiers-medicaux-des-coreens-du-sud-vendus-a-des-entreprises-privees/', + 'https://www.zataz.com/90-des-dossiers-medicaux-des-coreens-du-sud-vendus-a-des-entreprises-privees/', 'fr_FR', ], 'de' => [ @@ -1300,7 +1300,7 @@ class EntryControllerTest extends WallabagCoreTestCase null, ], 'es-ES' => [ - 'http://www.muylinux.com/2015/04/17/odf-reino-unido-microsoft-google/', + 'https://www.muylinux.com/2015/04/17/odf-reino-unido-microsoft-google/', 'es_ES', ], ]; -- cgit v1.2.3 From f645d371ce55e9c2a45712df34244318742b0d74 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Tue, 10 Oct 2017 10:20:57 +0200 Subject: Fix MondeDiplo https url --- tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index 907814df..ca275b32 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php @@ -1343,7 +1343,7 @@ class EntryControllerTest extends WallabagCoreTestCase */ public function testRestrictedArticle() { - $url = 'http://www.monde-diplomatique.fr/2017/05/BONNET/57475'; + $url = 'https://www.monde-diplomatique.fr/2017/05/BONNET/57475'; $this->logInAs('admin'); $client = $this->getClient(); $em = $client->getContainer()->get('doctrine.orm.entity_manager'); -- cgit v1.2.3