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\GenerateUrlHashesCommand
;
9 use Wallabag\CoreBundle\Entity\Entry
;
11 class GenerateUrlHashesCommandTest
extends WallabagCoreTestCase
13 public function testRunGenerateUrlHashesCommand()
15 $application = new Application($this->getClient()->getKernel());
16 $application->add(new GenerateUrlHashesCommand());
18 $command = $application->find('wallabag:generate-hashed-urls');
20 $tester = new CommandTester($command);
22 'command' => $command->getName(),
25 $this->assertContains('Generating hashed urls for "3" users', $tester->getDisplay());
26 $this->assertContains('Finished generated hashed urls', $tester->getDisplay());
29 public function testRunGenerateUrlHashesCommandWithBadUsername()
31 $application = new Application($this->getClient()->getKernel());
32 $application->add(new GenerateUrlHashesCommand());
34 $command = $application->find('wallabag:generate-hashed-urls');
36 $tester = new CommandTester($command);
38 'command' => $command->getName(),
39 'username' => 'unknown',
42 $this->assertContains('User "unknown" not found', $tester->getDisplay());
45 public function testRunGenerateUrlHashesCommandForUser()
47 $application = new Application($this->getClient()->getKernel());
48 $application->add(new GenerateUrlHashesCommand());
50 $command = $application->find('wallabag:generate-hashed-urls');
52 $tester = new CommandTester($command);
54 'command' => $command->getName(),
55 'username' => 'admin',
58 $this->assertContains('Generated hashed urls for user: admin', $tester->getDisplay());
61 public function testGenerateUrls()
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');
67 $this->logInAs('admin');
69 $user = $em->getRepository('WallabagUserBundle:User')->findOneById($this->getLoggedInUserId());
71 $entry1 = new Entry($user);
72 $entry1->setUrl($url);
74 $em->persist($entry1);
77 $application = new Application($this->getClient()->getKernel());
78 $application->add(new GenerateUrlHashesCommand());
80 $command = $application->find('wallabag:generate-hashed-urls');
82 $tester = new CommandTester($command);
84 'command' => $command->getName(),
85 'username' => 'admin',
88 $this->assertContains('Generated hashed urls for user: admin', $tester->getDisplay());
90 $entry = $em->getRepository('WallabagCoreBundle:Entry')->findOneByUrl($url);
92 $this->assertSame($entry->getHashedUrl(), hash('sha1', $url));
94 $query = $em->createQuery('DELETE FROM Wallabag\CoreBundle\Entity\Entry e WHERE e.url = :url');
95 $query->setParameter('url', $url);