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') 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 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') 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') 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 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') 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