3 namespace Tests\Wallabag\CoreBundle\Command
;
5 use Symfony\Bundle\FrameworkBundle\Console\Application
;
6 use Symfony\Component\Console\Tester\CommandTester
;
7 use Tests\Wallabag\CoreBundle\WallabagCoreTestCase
;
8 use Wallabag\CoreBundle\Command\CleanDuplicatesCommand
;
9 use Wallabag\CoreBundle\Entity\Entry
;
11 class CleanDuplicatesCommandTest
extends WallabagCoreTestCase
13 public function testRunCleanDuplicates()
15 $application = new Application($this->getClient()->getKernel());
16 $application->add(new CleanDuplicatesCommand());
18 $command = $application->find('wallabag:clean-duplicates');
20 $tester = new CommandTester($command);
22 'command' => $command->getName(),
25 $this->assertContains('Cleaning through 3 user accounts', $tester->getDisplay());
26 $this->assertContains('Finished cleaning. 0 duplicates found in total', $tester->getDisplay());
29 public function testRunCleanDuplicatesCommandWithBadUsername()
31 $application = new Application($this->getClient()->getKernel());
32 $application->add(new CleanDuplicatesCommand());
34 $command = $application->find('wallabag:clean-duplicates');
36 $tester = new CommandTester($command);
38 'command' => $command->getName(),
39 'username' => 'unknown',
42 $this->assertContains('User "unknown" not found', $tester->getDisplay());
45 public function testRunCleanDuplicatesCommandForUser()
47 $application = new Application($this->getClient()->getKernel());
48 $application->add(new CleanDuplicatesCommand());
50 $command = $application->find('wallabag:clean-duplicates');
52 $tester = new CommandTester($command);
54 'command' => $command->getName(),
55 'username' => 'admin',
58 $this->assertContains('Cleaned 0 duplicates for user admin', $tester->getDisplay());
61 public function testDuplicate()
63 $url = 'https://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');
67 $this->logInAs('admin');
69 $nbEntries = $em->getRepository('WallabagCoreBundle:Entry')->findAllByUrlAndUserId($url, $this->getLoggedInUserId());
70 $this->assertCount(0, $nbEntries);
72 $user = $em->getRepository('WallabagUserBundle:User')->findOneById($this->getLoggedInUserId());
74 $entry1 = new Entry($user);
75 $entry1->setUrl($url);
77 $entry2 = new Entry($user);
78 $entry2->setUrl($url);
80 $em->persist($entry1);
81 $em->persist($entry2);
85 $nbEntries = $em->getRepository('WallabagCoreBundle:Entry')->findAllByUrlAndUserId($url, $this->getLoggedInUserId());
86 $this->assertCount(2, $nbEntries);
88 $application = new Application($this->getClient()->getKernel());
89 $application->add(new CleanDuplicatesCommand());
91 $command = $application->find('wallabag:clean-duplicates');
93 $tester = new CommandTester($command);
95 'command' => $command->getName(),
96 'username' => 'admin',
99 $this->assertContains('Cleaned 1 duplicates for user admin', $tester->getDisplay());
101 $nbEntries = $em->getRepository('WallabagCoreBundle:Entry')->findAllByUrlAndUserId($url, $this->getLoggedInUserId());
102 $this->assertCount(1, $nbEntries);
104 $query = $em->createQuery('DELETE FROM Wallabag\CoreBundle\Entity\Entry e WHERE e.url = :url');
105 $query->setParameter('url', $url);