diff options
author | Thomas Citharel <tcit@tcit.fr> | 2017-05-28 15:04:39 +0200 |
---|---|---|
committer | Thomas Citharel <tcit@tcit.fr> | 2017-05-28 15:04:39 +0200 |
commit | 642528bb15293405ccf0160f06aff342f165714f (patch) | |
tree | cfdc06362ef9166dbafce977de99dc4cfe7f0130 /tests | |
parent | d5fbb570c974fe8b6f64356772f7cd60b96419da (diff) | |
download | wallabag-642528bb15293405ccf0160f06aff342f165714f.tar.gz wallabag-642528bb15293405ccf0160f06aff342f165714f.tar.zst wallabag-642528bb15293405ccf0160f06aff342f165714f.zip |
add command testhash-exist-url
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Wallabag/CoreBundle/Command/GenerateUrlHashesCommandTest.php | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/tests/Wallabag/CoreBundle/Command/GenerateUrlHashesCommandTest.php b/tests/Wallabag/CoreBundle/Command/GenerateUrlHashesCommandTest.php new file mode 100644 index 00000000..8ca772cb --- /dev/null +++ b/tests/Wallabag/CoreBundle/Command/GenerateUrlHashesCommandTest.php | |||
@@ -0,0 +1,101 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Tests\Wallabag\CoreBundle\Command; | ||
4 | |||
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; | ||
10 | |||
11 | class GenerateUrlHashesCommandTest extends WallabagCoreTestCase | ||
12 | { | ||
13 | public function testRunGenerateUrlHashesCommand() | ||
14 | { | ||
15 | $application = new Application($this->getClient()->getKernel()); | ||
16 | $application->add(new GenerateUrlHashesCommand()); | ||
17 | |||
18 | $command = $application->find('wallabag:generate-hashed-urls'); | ||
19 | |||
20 | $tester = new CommandTester($command); | ||
21 | $tester->execute([ | ||
22 | 'command' => $command->getName(), | ||
23 | ]); | ||
24 | |||
25 | $this->assertContains('Generating hashed urls for the 3 user account entries', $tester->getDisplay()); | ||
26 | $this->assertContains('Finished generated hashed urls', $tester->getDisplay()); | ||
27 | } | ||
28 | |||
29 | public function testRunGenerateUrlHashesCommandWithBadUsername() | ||
30 | { | ||
31 | $application = new Application($this->getClient()->getKernel()); | ||
32 | $application->add(new GenerateUrlHashesCommand()); | ||
33 | |||
34 | $command = $application->find('wallabag:generate-hashed-urls'); | ||
35 | |||
36 | $tester = new CommandTester($command); | ||
37 | $tester->execute([ | ||
38 | 'command' => $command->getName(), | ||
39 | 'username' => 'unknown', | ||
40 | ]); | ||
41 | |||
42 | $this->assertContains('User "unknown" not found', $tester->getDisplay()); | ||
43 | } | ||
44 | |||
45 | public function testRunGenerateUrlHashesCommandForUser() | ||
46 | { | ||
47 | $application = new Application($this->getClient()->getKernel()); | ||
48 | $application->add(new GenerateUrlHashesCommand()); | ||
49 | |||
50 | $command = $application->find('wallabag:generate-hashed-urls'); | ||
51 | |||
52 | $tester = new CommandTester($command); | ||
53 | $tester->execute([ | ||
54 | 'command' => $command->getName(), | ||
55 | 'username' => 'admin', | ||
56 | ]); | ||
57 | |||
58 | $this->assertContains('Generated hashed urls for user admin', $tester->getDisplay()); | ||
59 | } | ||
60 | |||
61 | public function testGenerateUrls() | ||
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 | $user = $em->getRepository('WallabagUserBundle:User')->findOneById($this->getLoggedInUserId()); | ||
70 | |||
71 | $entry1 = new Entry($user); | ||
72 | $entry1->setUrl($url); | ||
73 | |||
74 | $em->persist($entry1); | ||
75 | |||
76 | $em->flush(); | ||
77 | |||
78 | $this->assertNull($entry1->getHashedUrl()); | ||
79 | |||
80 | $application = new Application($this->getClient()->getKernel()); | ||
81 | $application->add(new GenerateUrlHashesCommand()); | ||
82 | |||
83 | $command = $application->find('wallabag:generate-hashed-urls'); | ||
84 | |||
85 | $tester = new CommandTester($command); | ||
86 | $tester->execute([ | ||
87 | 'command' => $command->getName(), | ||
88 | 'username' => 'admin', | ||
89 | ]); | ||
90 | |||
91 | $this->assertContains('Generated hashed urls for user admin', $tester->getDisplay()); | ||
92 | |||
93 | $entry = $em->getRepository('WallabagCoreBundle:Entry')->findOneByUrl($url); | ||
94 | |||
95 | $this->assertEquals($entry->getHashedUrl(), hash('sha512', $url)); | ||
96 | |||
97 | $query = $em->createQuery('DELETE FROM Wallabag\CoreBundle\Entity\Entry e WHERE e.url = :url'); | ||
98 | $query->setParameter('url', $url); | ||
99 | $query->execute(); | ||
100 | } | ||
101 | } | ||