aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/CoreBundle/Command/CleanDuplicatesCommandTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Wallabag/CoreBundle/Command/CleanDuplicatesCommandTest.php')
-rw-r--r--tests/Wallabag/CoreBundle/Command/CleanDuplicatesCommandTest.php47
1 files changed, 46 insertions, 1 deletions
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;
6use Symfony\Component\Console\Tester\CommandTester; 6use Symfony\Component\Console\Tester\CommandTester;
7use Wallabag\CoreBundle\Command\CleanDuplicatesCommand; 7use Wallabag\CoreBundle\Command\CleanDuplicatesCommand;
8use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; 8use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
9use Wallabag\CoreBundle\Entity\Entry;
9 10
10class CleanDuplicatesCommandTest extends WallabagCoreTestCase 11class CleanDuplicatesCommandTest extends WallabagCoreTestCase
11{ 12{
12 public function testRunTagAllCommandForAll() 13 public function testTagAll()
13 { 14 {
14 $application = new Application($this->getClient()->getKernel()); 15 $application = new Application($this->getClient()->getKernel());
15 $application->add(new CleanDuplicatesCommand()); 16 $application->add(new CleanDuplicatesCommand());
@@ -56,4 +57,48 @@ class CleanDuplicatesCommandTest extends WallabagCoreTestCase
56 57
57 $this->assertContains('Cleaned 0 duplicates for user admin', $tester->getDisplay()); 58 $this->assertContains('Cleaned 0 duplicates for user admin', $tester->getDisplay());
58 } 59 }
60
61 public function testDuplicate()
62 {
63 $url = 'http://www.lemonde.fr/sport/visuel/2017/05/05/rondelle-prison-blanchissage-comprendre-le-hockey-sur-glace_5122587_3242.html';
64 $client = $this->getClient();
65 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
66
67 $this->logInAs('admin');
68
69 $nbEntries = $em->getRepository('WallabagCoreBundle:Entry')->findAllByUrlAndUserId($url, $this->getLoggedInUserId());
70 $this->assertCount(0, $nbEntries);
71
72 $user = $em->getRepository('WallabagUserBundle:User')->findOneById($this->getLoggedInUserId());
73
74 $entry1 = new Entry($user);
75 $entry1->setUrl($url);
76
77 $entry2 = new Entry($user);
78 $entry2->setUrl($url);
79
80 $em->persist($entry1);
81 $em->persist($entry2);
82
83 $em->flush();
84
85 $nbEntries = $em->getRepository('WallabagCoreBundle:Entry')->findAllByUrlAndUserId($url, $this->getLoggedInUserId());
86 $this->assertCount(2, $nbEntries);
87
88 $application = new Application($this->getClient()->getKernel());
89 $application->add(new CleanDuplicatesCommand());
90
91 $command = $application->find('wallabag:clean-duplicates');
92
93 $tester = new CommandTester($command);
94 $tester->execute([
95 'command' => $command->getName(),
96 'username' => 'admin',
97 ]);
98
99 $this->assertContains('Cleaned 1 duplicates for user admin', $tester->getDisplay());
100
101 $nbEntries = $em->getRepository('WallabagCoreBundle:Entry')->findAllByUrlAndUserId($url, $this->getLoggedInUserId());
102 $this->assertCount(1, $nbEntries);
103 }
59} 104}