diff options
Diffstat (limited to 'tests/Wallabag/CoreBundle/Command')
4 files changed, 116 insertions, 9 deletions
diff --git a/tests/Wallabag/CoreBundle/Command/GenerateUrlHashesCommandTest.php b/tests/Wallabag/CoreBundle/Command/GenerateUrlHashesCommandTest.php new file mode 100644 index 00000000..17eed210 --- /dev/null +++ b/tests/Wallabag/CoreBundle/Command/GenerateUrlHashesCommandTest.php | |||
@@ -0,0 +1,98 @@ | |||
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 "3" users', $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 | $em->flush(); | ||
76 | |||
77 | $application = new Application($this->getClient()->getKernel()); | ||
78 | $application->add(new GenerateUrlHashesCommand()); | ||
79 | |||
80 | $command = $application->find('wallabag:generate-hashed-urls'); | ||
81 | |||
82 | $tester = new CommandTester($command); | ||
83 | $tester->execute([ | ||
84 | 'command' => $command->getName(), | ||
85 | 'username' => 'admin', | ||
86 | ]); | ||
87 | |||
88 | $this->assertContains('Generated hashed urls for user: admin', $tester->getDisplay()); | ||
89 | |||
90 | $entry = $em->getRepository('WallabagCoreBundle:Entry')->findOneByUrl($url); | ||
91 | |||
92 | $this->assertSame($entry->getHashedUrl(), hash('sha1', $url)); | ||
93 | |||
94 | $query = $em->createQuery('DELETE FROM Wallabag\CoreBundle\Entity\Entry e WHERE e.url = :url'); | ||
95 | $query->setParameter('url', $url); | ||
96 | $query->execute(); | ||
97 | } | ||
98 | } | ||
diff --git a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php index bd351b18..d8928451 100644 --- a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php | |||
@@ -18,6 +18,18 @@ use Wallabag\CoreBundle\Command\InstallCommand; | |||
18 | 18 | ||
19 | class InstallCommandTest extends WallabagCoreTestCase | 19 | class InstallCommandTest extends WallabagCoreTestCase |
20 | { | 20 | { |
21 | public static function setUpBeforeClass() | ||
22 | { | ||
23 | // disable doctrine-test-bundle | ||
24 | StaticDriver::setKeepStaticConnections(false); | ||
25 | } | ||
26 | |||
27 | public static function tearDownAfterClass() | ||
28 | { | ||
29 | // enable doctrine-test-bundle | ||
30 | StaticDriver::setKeepStaticConnections(true); | ||
31 | } | ||
32 | |||
21 | public function setUp() | 33 | public function setUp() |
22 | { | 34 | { |
23 | parent::setUp(); | 35 | parent::setUp(); |
@@ -51,9 +63,6 @@ class InstallCommandTest extends WallabagCoreTestCase | |||
51 | parent::setUp(); | 63 | parent::setUp(); |
52 | } | 64 | } |
53 | 65 | ||
54 | // disable doctrine-test-bundle | ||
55 | StaticDriver::setKeepStaticConnections(false); | ||
56 | |||
57 | $this->resetDatabase($this->getClient()); | 66 | $this->resetDatabase($this->getClient()); |
58 | } | 67 | } |
59 | 68 | ||
@@ -62,6 +71,7 @@ class InstallCommandTest extends WallabagCoreTestCase | |||
62 | $databasePath = getenv('TEST_DATABASE_PATH'); | 71 | $databasePath = getenv('TEST_DATABASE_PATH'); |
63 | // Remove variable environnement | 72 | // Remove variable environnement |
64 | putenv('TEST_DATABASE_PATH'); | 73 | putenv('TEST_DATABASE_PATH'); |
74 | |||
65 | if ($databasePath && file_exists($databasePath)) { | 75 | if ($databasePath && file_exists($databasePath)) { |
66 | unlink($databasePath); | 76 | unlink($databasePath); |
67 | } else { | 77 | } else { |
@@ -71,8 +81,6 @@ class InstallCommandTest extends WallabagCoreTestCase | |||
71 | $this->resetDatabase($client); | 81 | $this->resetDatabase($client); |
72 | } | 82 | } |
73 | 83 | ||
74 | // enable doctrine-test-bundle | ||
75 | StaticDriver::setKeepStaticConnections(true); | ||
76 | parent::tearDown(); | 84 | parent::tearDown(); |
77 | } | 85 | } |
78 | 86 | ||
diff --git a/tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php b/tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php index b13f6519..c4bd6dac 100644 --- a/tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php | |||
@@ -26,7 +26,7 @@ class ReloadEntryCommandTest extends WallabagCoreTestCase | |||
26 | { | 26 | { |
27 | parent::setUp(); | 27 | parent::setUp(); |
28 | 28 | ||
29 | $userRepository = $this->getClient()->getContainer()->get('wallabag_user.user_repository'); | 29 | $userRepository = $this->getClient()->getContainer()->get('wallabag_user.user_repository.test'); |
30 | 30 | ||
31 | $user = $userRepository->findOneByUserName('admin'); | 31 | $user = $userRepository->findOneByUserName('admin'); |
32 | $this->adminEntry = new Entry($user); | 32 | $this->adminEntry = new Entry($user); |
@@ -60,7 +60,7 @@ class ReloadEntryCommandTest extends WallabagCoreTestCase | |||
60 | 60 | ||
61 | $reloadedEntries = $this->getClient() | 61 | $reloadedEntries = $this->getClient() |
62 | ->getContainer() | 62 | ->getContainer() |
63 | ->get('wallabag_core.entry_repository') | 63 | ->get('wallabag_core.entry_repository.test') |
64 | ->findById([$this->adminEntry->getId(), $this->bobEntry->getId()]); | 64 | ->findById([$this->adminEntry->getId(), $this->bobEntry->getId()]); |
65 | 65 | ||
66 | foreach ($reloadedEntries as $reloadedEntry) { | 66 | foreach ($reloadedEntries as $reloadedEntry) { |
@@ -84,7 +84,7 @@ class ReloadEntryCommandTest extends WallabagCoreTestCase | |||
84 | 'interactive' => false, | 84 | 'interactive' => false, |
85 | ]); | 85 | ]); |
86 | 86 | ||
87 | $entryRepository = $this->getClient()->getContainer()->get('wallabag_core.entry_repository'); | 87 | $entryRepository = $this->getClient()->getContainer()->get('wallabag_core.entry_repository.test'); |
88 | 88 | ||
89 | $reloadedAdminEntry = $entryRepository->find($this->adminEntry->getId()); | 89 | $reloadedAdminEntry = $entryRepository->find($this->adminEntry->getId()); |
90 | $this->assertNotEmpty($reloadedAdminEntry->getContent()); | 90 | $this->assertNotEmpty($reloadedAdminEntry->getContent()); |
diff --git a/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php b/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php index 9b34f2a0..ed383a2c 100644 --- a/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php | |||
@@ -59,7 +59,8 @@ class ShowUserCommandTest extends WallabagCoreTestCase | |||
59 | $this->assertContains('Username: admin', $tester->getDisplay()); | 59 | $this->assertContains('Username: admin', $tester->getDisplay()); |
60 | $this->assertContains('Email: bigboss@wallabag.org', $tester->getDisplay()); | 60 | $this->assertContains('Email: bigboss@wallabag.org', $tester->getDisplay()); |
61 | $this->assertContains('Display name: Big boss', $tester->getDisplay()); | 61 | $this->assertContains('Display name: Big boss', $tester->getDisplay()); |
62 | $this->assertContains('2FA activated: no', $tester->getDisplay()); | 62 | $this->assertContains('2FA (email) activated', $tester->getDisplay()); |
63 | $this->assertContains('2FA (OTP) activated', $tester->getDisplay()); | ||
63 | } | 64 | } |
64 | 65 | ||
65 | public function testShowUser() | 66 | public function testShowUser() |