aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/CoreBundle/Command
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Wallabag/CoreBundle/Command')
-rw-r--r--tests/Wallabag/CoreBundle/Command/InstallCommandTest.php273
-rw-r--r--tests/Wallabag/CoreBundle/Command/TagAllCommandTest.php60
2 files changed, 333 insertions, 0 deletions
diff --git a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php
new file mode 100644
index 00000000..2413d735
--- /dev/null
+++ b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php
@@ -0,0 +1,273 @@
1<?php
2
3namespace Tests\Wallabag\CoreBundle\Command;
4
5use Doctrine\Bundle\DoctrineBundle\Command\CreateDatabaseDoctrineCommand;
6use Doctrine\Bundle\DoctrineBundle\Command\DropDatabaseDoctrineCommand;
7use Symfony\Bundle\FrameworkBundle\Console\Application;
8use Symfony\Component\Console\Input\ArrayInput;
9use Symfony\Component\Console\Output\NullOutput;
10use Symfony\Component\Console\Tester\CommandTester;
11use Wallabag\CoreBundle\Command\InstallCommand;
12use Tests\Wallabag\CoreBundle\Mock\InstallCommandMock;
13use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
14
15class InstallCommandTest extends WallabagCoreTestCase
16{
17 public function setUp()
18 {
19 parent::setUp();
20
21 if ($this->getClient()->getContainer()->get('doctrine')->getConnection()->getDriver() instanceof \Doctrine\DBAL\Driver\PDOPgSql\Driver) {
22 /*
23 * LOG: statement: CREATE DATABASE "wallabag"
24 * ERROR: source database "template1" is being accessed by other users
25 * DETAIL: There is 1 other session using the database.
26 * STATEMENT: CREATE DATABASE "wallabag"
27 * FATAL: database "wallabag" does not exist
28 *
29 * http://stackoverflow.com/a/14374832/569101
30 */
31 $this->markTestSkipped('PostgreSQL spotted: can find a good way to drop current database, skipping.');
32 }
33 }
34
35 public static function tearDownAfterClass()
36 {
37 $application = new Application(static::$kernel);
38 $application->setAutoExit(false);
39
40 $code = $application->run(new ArrayInput([
41 'command' => 'doctrine:fixtures:load',
42 '--no-interaction' => true,
43 '--env' => 'test',
44 ]), new NullOutput());
45 }
46
47 public function testRunInstallCommand()
48 {
49 $application = new Application($this->getClient()->getKernel());
50 $application->add(new InstallCommandMock());
51
52 $command = $application->find('wallabag:install');
53
54 // We mock the QuestionHelper
55 $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')
56 ->disableOriginalConstructor()
57 ->getMock();
58 $question->expects($this->any())
59 ->method('ask')
60 ->will($this->returnValue('yes_'.uniqid('', true)));
61
62 // We override the standard helper with our mock
63 $command->getHelperSet()->set($question, 'question');
64
65 $tester = new CommandTester($command);
66 $tester->execute([
67 'command' => $command->getName(),
68 ]);
69
70 $this->assertContains('Checking system requirements.', $tester->getDisplay());
71 $this->assertContains('Setting up database.', $tester->getDisplay());
72 $this->assertContains('Administration setup.', $tester->getDisplay());
73 $this->assertContains('Config setup.', $tester->getDisplay());
74 }
75
76 public function testRunInstallCommandWithReset()
77 {
78 $application = new Application($this->getClient()->getKernel());
79 $application->add(new InstallCommandMock());
80
81 $command = $application->find('wallabag:install');
82
83 // We mock the QuestionHelper
84 $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')
85 ->disableOriginalConstructor()
86 ->getMock();
87 $question->expects($this->any())
88 ->method('ask')
89 ->will($this->returnValue('yes_'.uniqid('', true)));
90
91 // We override the standard helper with our mock
92 $command->getHelperSet()->set($question, 'question');
93
94 $tester = new CommandTester($command);
95 $tester->execute([
96 'command' => $command->getName(),
97 '--reset' => true,
98 ]);
99
100 $this->assertContains('Checking system requirements.', $tester->getDisplay());
101 $this->assertContains('Setting up database.', $tester->getDisplay());
102 $this->assertContains('Droping database, creating database and schema, clearing the cache', $tester->getDisplay());
103 $this->assertContains('Administration setup.', $tester->getDisplay());
104 $this->assertContains('Config setup.', $tester->getDisplay());
105
106 // we force to reset everything
107 $this->assertContains('Droping database, creating database and schema, clearing the cache', $tester->getDisplay());
108 }
109
110 public function testRunInstallCommandWithDatabaseRemoved()
111 {
112 $application = new Application($this->getClient()->getKernel());
113 $application->add(new DropDatabaseDoctrineCommand());
114
115 // drop database first, so the install command won't ask to reset things
116 $command = $application->find('doctrine:database:drop');
117 $command->run(new ArrayInput([
118 'command' => 'doctrine:database:drop',
119 '--force' => true,
120 ]), new NullOutput());
121
122 // start a new application to avoid lagging connexion to pgsql
123 $client = static::createClient();
124 $application = new Application($client->getKernel());
125 $application->add(new InstallCommand());
126
127 $command = $application->find('wallabag:install');
128
129 // We mock the QuestionHelper
130 $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')
131 ->disableOriginalConstructor()
132 ->getMock();
133 $question->expects($this->any())
134 ->method('ask')
135 ->will($this->returnValue('yes_'.uniqid('', true)));
136
137 // We override the standard helper with our mock
138 $command->getHelperSet()->set($question, 'question');
139
140 $tester = new CommandTester($command);
141 $tester->execute([
142 'command' => $command->getName(),
143 ]);
144
145 $this->assertContains('Checking system requirements.', $tester->getDisplay());
146 $this->assertContains('Setting up database.', $tester->getDisplay());
147 $this->assertContains('Administration setup.', $tester->getDisplay());
148 $this->assertContains('Config setup.', $tester->getDisplay());
149
150 // the current database doesn't already exist
151 $this->assertContains('Creating database and schema, clearing the cache', $tester->getDisplay());
152 }
153
154 public function testRunInstallCommandChooseResetSchema()
155 {
156 $application = new Application($this->getClient()->getKernel());
157 $application->add(new InstallCommandMock());
158
159 $command = $application->find('wallabag:install');
160
161 // We mock the QuestionHelper
162 $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')
163 ->disableOriginalConstructor()
164 ->getMock();
165
166 $question->expects($this->exactly(3))
167 ->method('ask')
168 ->will($this->onConsecutiveCalls(
169 false, // don't want to reset the entire database
170 true, // do want to reset the schema
171 false // don't want to create a new user
172 ));
173
174 // We override the standard helper with our mock
175 $command->getHelperSet()->set($question, 'question');
176
177 $tester = new CommandTester($command);
178 $tester->execute([
179 'command' => $command->getName(),
180 ]);
181
182 $this->assertContains('Checking system requirements.', $tester->getDisplay());
183 $this->assertContains('Setting up database.', $tester->getDisplay());
184 $this->assertContains('Administration setup.', $tester->getDisplay());
185 $this->assertContains('Config setup.', $tester->getDisplay());
186
187 $this->assertContains('Droping schema and creating schema', $tester->getDisplay());
188 }
189
190 public function testRunInstallCommandChooseNothing()
191 {
192 $application = new Application($this->getClient()->getKernel());
193 $application->add(new InstallCommand());
194 $application->add(new DropDatabaseDoctrineCommand());
195 $application->add(new CreateDatabaseDoctrineCommand());
196
197 // drop database first, so the install command won't ask to reset things
198 $command = new DropDatabaseDoctrineCommand();
199 $command->setApplication($application);
200 $command->run(new ArrayInput([
201 'command' => 'doctrine:database:drop',
202 '--force' => true,
203 ]), new NullOutput());
204
205 $this->getClient()->getContainer()->get('doctrine')->getConnection()->close();
206
207 $command = new CreateDatabaseDoctrineCommand();
208 $command->setApplication($application);
209 $command->run(new ArrayInput([
210 'command' => 'doctrine:database:create',
211 '--env' => 'test',
212 ]), new NullOutput());
213
214 $command = $application->find('wallabag:install');
215
216 // We mock the QuestionHelper
217 $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')
218 ->disableOriginalConstructor()
219 ->getMock();
220
221 $question->expects($this->exactly(2))
222 ->method('ask')
223 ->will($this->onConsecutiveCalls(
224 false, // don't want to reset the entire database
225 false // don't want to create a new user
226 ));
227
228 // We override the standard helper with our mock
229 $command->getHelperSet()->set($question, 'question');
230
231 $tester = new CommandTester($command);
232 $tester->execute([
233 'command' => $command->getName(),
234 ]);
235
236 $this->assertContains('Checking system requirements.', $tester->getDisplay());
237 $this->assertContains('Setting up database.', $tester->getDisplay());
238 $this->assertContains('Administration setup.', $tester->getDisplay());
239 $this->assertContains('Config setup.', $tester->getDisplay());
240
241 $this->assertContains('Creating schema', $tester->getDisplay());
242 }
243
244 public function testRunInstallCommandNoInteraction()
245 {
246 $application = new Application($this->getClient()->getKernel());
247 $application->add(new InstallCommandMock());
248
249 $command = $application->find('wallabag:install');
250
251 // We mock the QuestionHelper
252 $question = $this->getMockBuilder('Symfony\Component\Console\Helper\QuestionHelper')
253 ->disableOriginalConstructor()
254 ->getMock();
255 $question->expects($this->any())
256 ->method('ask')
257 ->will($this->returnValue('yes_'.uniqid('', true)));
258
259 // We override the standard helper with our mock
260 $command->getHelperSet()->set($question, 'question');
261
262 $tester = new CommandTester($command);
263 $tester->execute([
264 'command' => $command->getName(),
265 '--no-interaction' => true,
266 ]);
267
268 $this->assertContains('Checking system requirements.', $tester->getDisplay());
269 $this->assertContains('Setting up database.', $tester->getDisplay());
270 $this->assertContains('Administration setup.', $tester->getDisplay());
271 $this->assertContains('Config setup.', $tester->getDisplay());
272 }
273}
diff --git a/tests/Wallabag/CoreBundle/Command/TagAllCommandTest.php b/tests/Wallabag/CoreBundle/Command/TagAllCommandTest.php
new file mode 100644
index 00000000..ec31708f
--- /dev/null
+++ b/tests/Wallabag/CoreBundle/Command/TagAllCommandTest.php
@@ -0,0 +1,60 @@
1<?php
2
3namespace Tests\Wallabag\CoreBundle\Command;
4
5use Symfony\Bundle\FrameworkBundle\Console\Application;
6use Symfony\Component\Console\Tester\CommandTester;
7use Wallabag\CoreBundle\Command\TagAllCommand;
8use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
9
10class TagAllCommandTest extends WallabagCoreTestCase
11{
12 /**
13 * @expectedException Symfony\Component\Console\Exception\RuntimeException
14 * @expectedExceptionMessage Not enough arguments (missing: "username")
15 */
16 public function testRunTagAllCommandWithoutUsername()
17 {
18 $application = new Application($this->getClient()->getKernel());
19 $application->add(new TagAllCommand());
20
21 $command = $application->find('wallabag:tag:all');
22
23 $tester = new CommandTester($command);
24 $tester->execute([
25 'command' => $command->getName(),
26 ]);
27 }
28
29 public function testRunTagAllCommandWithBadUsername()
30 {
31 $application = new Application($this->getClient()->getKernel());
32 $application->add(new TagAllCommand());
33
34 $command = $application->find('wallabag:tag:all');
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 testRunTagAllCommand()
46 {
47 $application = new Application($this->getClient()->getKernel());
48 $application->add(new TagAllCommand());
49
50 $command = $application->find('wallabag:tag:all');
51
52 $tester = new CommandTester($command);
53 $tester->execute([
54 'command' => $command->getName(),
55 'username' => 'admin',
56 ]);
57
58 $this->assertContains('Tagging entries for user « admin »... Done', $tester->getDisplay());
59 }
60}