diff options
Diffstat (limited to 'tests/Wallabag/CoreBundle')
13 files changed, 331 insertions, 338 deletions
diff --git a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php index 83f5bf24..1bfd41d5 100644 --- a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php | |||
@@ -33,7 +33,7 @@ class InstallCommandTest extends WallabagCoreTestCase | |||
33 | } | 33 | } |
34 | 34 | ||
35 | /** | 35 | /** |
36 | * Ensure next tests will have a clean database | 36 | * Ensure next tests will have a clean database. |
37 | */ | 37 | */ |
38 | public static function tearDownAfterClass() | 38 | public static function tearDownAfterClass() |
39 | { | 39 | { |
@@ -87,7 +87,6 @@ class InstallCommandTest extends WallabagCoreTestCase | |||
87 | $this->assertContains('Setting up database.', $tester->getDisplay()); | 87 | $this->assertContains('Setting up database.', $tester->getDisplay()); |
88 | $this->assertContains('Administration setup.', $tester->getDisplay()); | 88 | $this->assertContains('Administration setup.', $tester->getDisplay()); |
89 | $this->assertContains('Config setup.', $tester->getDisplay()); | 89 | $this->assertContains('Config setup.', $tester->getDisplay()); |
90 | $this->assertContains('Installing assets.', $tester->getDisplay()); | ||
91 | } | 90 | } |
92 | 91 | ||
93 | public function testRunInstallCommandWithReset() | 92 | public function testRunInstallCommandWithReset() |
@@ -119,7 +118,6 @@ class InstallCommandTest extends WallabagCoreTestCase | |||
119 | $this->assertContains('Droping database, creating database and schema, clearing the cache', $tester->getDisplay()); | 118 | $this->assertContains('Droping database, creating database and schema, clearing the cache', $tester->getDisplay()); |
120 | $this->assertContains('Administration setup.', $tester->getDisplay()); | 119 | $this->assertContains('Administration setup.', $tester->getDisplay()); |
121 | $this->assertContains('Config setup.', $tester->getDisplay()); | 120 | $this->assertContains('Config setup.', $tester->getDisplay()); |
122 | $this->assertContains('Installing assets.', $tester->getDisplay()); | ||
123 | 121 | ||
124 | // we force to reset everything | 122 | // we force to reset everything |
125 | $this->assertContains('Droping database, creating database and schema, clearing the cache', $tester->getDisplay()); | 123 | $this->assertContains('Droping database, creating database and schema, clearing the cache', $tester->getDisplay()); |
@@ -170,7 +168,6 @@ class InstallCommandTest extends WallabagCoreTestCase | |||
170 | $this->assertContains('Setting up database.', $tester->getDisplay()); | 168 | $this->assertContains('Setting up database.', $tester->getDisplay()); |
171 | $this->assertContains('Administration setup.', $tester->getDisplay()); | 169 | $this->assertContains('Administration setup.', $tester->getDisplay()); |
172 | $this->assertContains('Config setup.', $tester->getDisplay()); | 170 | $this->assertContains('Config setup.', $tester->getDisplay()); |
173 | $this->assertContains('Installing assets.', $tester->getDisplay()); | ||
174 | 171 | ||
175 | // the current database doesn't already exist | 172 | // the current database doesn't already exist |
176 | $this->assertContains('Creating database and schema, clearing the cache', $tester->getDisplay()); | 173 | $this->assertContains('Creating database and schema, clearing the cache', $tester->getDisplay()); |
@@ -208,7 +205,6 @@ class InstallCommandTest extends WallabagCoreTestCase | |||
208 | $this->assertContains('Setting up database.', $tester->getDisplay()); | 205 | $this->assertContains('Setting up database.', $tester->getDisplay()); |
209 | $this->assertContains('Administration setup.', $tester->getDisplay()); | 206 | $this->assertContains('Administration setup.', $tester->getDisplay()); |
210 | $this->assertContains('Config setup.', $tester->getDisplay()); | 207 | $this->assertContains('Config setup.', $tester->getDisplay()); |
211 | $this->assertContains('Installing assets.', $tester->getDisplay()); | ||
212 | 208 | ||
213 | $this->assertContains('Droping schema and creating schema', $tester->getDisplay()); | 209 | $this->assertContains('Droping schema and creating schema', $tester->getDisplay()); |
214 | } | 210 | } |
@@ -263,7 +259,6 @@ class InstallCommandTest extends WallabagCoreTestCase | |||
263 | $this->assertContains('Setting up database.', $tester->getDisplay()); | 259 | $this->assertContains('Setting up database.', $tester->getDisplay()); |
264 | $this->assertContains('Administration setup.', $tester->getDisplay()); | 260 | $this->assertContains('Administration setup.', $tester->getDisplay()); |
265 | $this->assertContains('Config setup.', $tester->getDisplay()); | 261 | $this->assertContains('Config setup.', $tester->getDisplay()); |
266 | $this->assertContains('Installing assets.', $tester->getDisplay()); | ||
267 | 262 | ||
268 | $this->assertContains('Creating schema', $tester->getDisplay()); | 263 | $this->assertContains('Creating schema', $tester->getDisplay()); |
269 | } | 264 | } |
@@ -296,6 +291,5 @@ class InstallCommandTest extends WallabagCoreTestCase | |||
296 | $this->assertContains('Setting up database.', $tester->getDisplay()); | 291 | $this->assertContains('Setting up database.', $tester->getDisplay()); |
297 | $this->assertContains('Administration setup.', $tester->getDisplay()); | 292 | $this->assertContains('Administration setup.', $tester->getDisplay()); |
298 | $this->assertContains('Config setup.', $tester->getDisplay()); | 293 | $this->assertContains('Config setup.', $tester->getDisplay()); |
299 | $this->assertContains('Installing assets.', $tester->getDisplay()); | ||
300 | } | 294 | } |
301 | } | 295 | } |
diff --git a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php index 7193f9b0..1954c654 100644 --- a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php | |||
@@ -28,7 +28,6 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
28 | $this->assertCount(1, $crawler->filter('button[id=config_save]')); | 28 | $this->assertCount(1, $crawler->filter('button[id=config_save]')); |
29 | $this->assertCount(1, $crawler->filter('button[id=change_passwd_save]')); | 29 | $this->assertCount(1, $crawler->filter('button[id=change_passwd_save]')); |
30 | $this->assertCount(1, $crawler->filter('button[id=update_user_save]')); | 30 | $this->assertCount(1, $crawler->filter('button[id=update_user_save]')); |
31 | $this->assertCount(1, $crawler->filter('button[id=new_user_save]')); | ||
32 | $this->assertCount(1, $crawler->filter('button[id=rss_config_save]')); | 31 | $this->assertCount(1, $crawler->filter('button[id=rss_config_save]')); |
33 | } | 32 | } |
34 | 33 | ||
@@ -56,8 +55,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
56 | 55 | ||
57 | $crawler = $client->followRedirect(); | 56 | $crawler = $client->followRedirect(); |
58 | 57 | ||
59 | $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(['_text'])); | 58 | $this->assertContains('flashes.config.notice.config_saved', $crawler->filter('body')->extract(['_text'])[0]); |
60 | $this->assertContains('flashes.config.notice.config_saved', $alert[0]); | ||
61 | } | 59 | } |
62 | 60 | ||
63 | public function testChangeReadingSpeed() | 61 | public function testChangeReadingSpeed() |
@@ -213,8 +211,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
213 | 211 | ||
214 | $crawler = $client->followRedirect(); | 212 | $crawler = $client->followRedirect(); |
215 | 213 | ||
216 | $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(['_text'])); | 214 | $this->assertContains('flashes.config.notice.password_updated', $crawler->filter('body')->extract(['_text'])[0]); |
217 | $this->assertContains('flashes.config.notice.password_updated', $alert[0]); | ||
218 | } | 215 | } |
219 | 216 | ||
220 | public function dataForUserFailed() | 217 | public function dataForUserFailed() |
@@ -285,120 +282,6 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
285 | $this->assertContains('flashes.config.notice.user_updated', $alert[0]); | 282 | $this->assertContains('flashes.config.notice.user_updated', $alert[0]); |
286 | } | 283 | } |
287 | 284 | ||
288 | public function dataForNewUserFailed() | ||
289 | { | ||
290 | return [ | ||
291 | [ | ||
292 | [ | ||
293 | 'new_user[username]' => '', | ||
294 | 'new_user[plainPassword][first]' => '', | ||
295 | 'new_user[plainPassword][second]' => '', | ||
296 | 'new_user[email]' => '', | ||
297 | ], | ||
298 | 'fos_user.username.blank', | ||
299 | ], | ||
300 | [ | ||
301 | [ | ||
302 | 'new_user[username]' => 'a', | ||
303 | 'new_user[plainPassword][first]' => 'mypassword', | ||
304 | 'new_user[plainPassword][second]' => 'mypassword', | ||
305 | 'new_user[email]' => '', | ||
306 | ], | ||
307 | 'fos_user.username.short', | ||
308 | ], | ||
309 | [ | ||
310 | [ | ||
311 | 'new_user[username]' => 'wallace', | ||
312 | 'new_user[plainPassword][first]' => 'mypassword', | ||
313 | 'new_user[plainPassword][second]' => 'mypassword', | ||
314 | 'new_user[email]' => 'test', | ||
315 | ], | ||
316 | 'fos_user.email.invalid', | ||
317 | ], | ||
318 | [ | ||
319 | [ | ||
320 | 'new_user[username]' => 'admin', | ||
321 | 'new_user[plainPassword][first]' => 'wallacewallace', | ||
322 | 'new_user[plainPassword][second]' => 'wallacewallace', | ||
323 | 'new_user[email]' => 'wallace@wallace.me', | ||
324 | ], | ||
325 | 'fos_user.username.already_used', | ||
326 | ], | ||
327 | [ | ||
328 | [ | ||
329 | 'new_user[username]' => 'wallace', | ||
330 | 'new_user[plainPassword][first]' => 'mypassword1', | ||
331 | 'new_user[plainPassword][second]' => 'mypassword2', | ||
332 | 'new_user[email]' => 'wallace@wallace.me', | ||
333 | ], | ||
334 | 'validator.password_must_match', | ||
335 | ], | ||
336 | ]; | ||
337 | } | ||
338 | |||
339 | /** | ||
340 | * @dataProvider dataForNewUserFailed | ||
341 | */ | ||
342 | public function testNewUserFailed($data, $expectedMessage) | ||
343 | { | ||
344 | $this->logInAs('admin'); | ||
345 | $client = $this->getClient(); | ||
346 | |||
347 | $crawler = $client->request('GET', '/config'); | ||
348 | |||
349 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
350 | |||
351 | $form = $crawler->filter('button[id=new_user_save]')->form(); | ||
352 | |||
353 | $crawler = $client->submit($form, $data); | ||
354 | |||
355 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
356 | |||
357 | $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text'])); | ||
358 | $this->assertContains($expectedMessage, $alert[0]); | ||
359 | } | ||
360 | |||
361 | public function testNewUserCreated() | ||
362 | { | ||
363 | $this->logInAs('admin'); | ||
364 | $client = $this->getClient(); | ||
365 | |||
366 | $crawler = $client->request('GET', '/config'); | ||
367 | |||
368 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
369 | |||
370 | $form = $crawler->filter('button[id=new_user_save]')->form(); | ||
371 | |||
372 | $data = [ | ||
373 | 'new_user[username]' => 'wallace', | ||
374 | 'new_user[plainPassword][first]' => 'wallace1', | ||
375 | 'new_user[plainPassword][second]' => 'wallace1', | ||
376 | 'new_user[email]' => 'wallace@wallace.me', | ||
377 | ]; | ||
378 | |||
379 | $client->submit($form, $data); | ||
380 | |||
381 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
382 | |||
383 | $crawler = $client->followRedirect(); | ||
384 | |||
385 | $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(['_text'])); | ||
386 | $this->assertContains('flashes.config.notice.user_added', $alert[0]); | ||
387 | |||
388 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
389 | $user = $em | ||
390 | ->getRepository('WallabagUserBundle:User') | ||
391 | ->findOneByUsername('wallace'); | ||
392 | |||
393 | $this->assertTrue(false !== $user); | ||
394 | $this->assertTrue($user->isEnabled()); | ||
395 | $this->assertEquals('material', $user->getConfig()->getTheme()); | ||
396 | $this->assertEquals(12, $user->getConfig()->getItemsPerPage()); | ||
397 | $this->assertEquals(50, $user->getConfig()->getRssLimit()); | ||
398 | $this->assertEquals('en', $user->getConfig()->getLanguage()); | ||
399 | $this->assertEquals(1, $user->getConfig()->getReadingSpeed()); | ||
400 | } | ||
401 | |||
402 | public function testRssUpdateResetToken() | 285 | public function testRssUpdateResetToken() |
403 | { | 286 | { |
404 | $this->logInAs('admin'); | 287 | $this->logInAs('admin'); |
@@ -474,8 +357,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
474 | 357 | ||
475 | $crawler = $client->followRedirect(); | 358 | $crawler = $client->followRedirect(); |
476 | 359 | ||
477 | $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(['_text'])); | 360 | $this->assertContains('flashes.config.notice.rss_updated', $crawler->filter('body')->extract(['_text'])[0]); |
478 | $this->assertContains('flashes.config.notice.rss_updated', $alert[0]); | ||
479 | } | 361 | } |
480 | 362 | ||
481 | public function dataForRssFailed() | 363 | public function dataForRssFailed() |
@@ -540,8 +422,32 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
540 | 422 | ||
541 | $crawler = $client->followRedirect(); | 423 | $crawler = $client->followRedirect(); |
542 | 424 | ||
543 | $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(['_text'])); | 425 | $this->assertContains('flashes.config.notice.tagging_rules_updated', $crawler->filter('body')->extract(['_text'])[0]); |
544 | $this->assertContains('flashes.config.notice.tagging_rules_updated', $alert[0]); | 426 | |
427 | $editLink = $crawler->filter('.mode_edit')->last()->link(); | ||
428 | |||
429 | $crawler = $client->click($editLink); | ||
430 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
431 | $this->assertContains('?tagging-rule=', $client->getResponse()->headers->get('location')); | ||
432 | |||
433 | $crawler = $client->followRedirect(); | ||
434 | |||
435 | $form = $crawler->filter('button[id=tagging_rule_save]')->form(); | ||
436 | |||
437 | $data = [ | ||
438 | 'tagging_rule[rule]' => 'readingTime <= 30', | ||
439 | 'tagging_rule[tags]' => 'short reading', | ||
440 | ]; | ||
441 | |||
442 | $client->submit($form, $data); | ||
443 | |||
444 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
445 | |||
446 | $crawler = $client->followRedirect(); | ||
447 | |||
448 | $this->assertContains('flashes.config.notice.tagging_rules_updated', $crawler->filter('body')->extract(['_text'])[0]); | ||
449 | |||
450 | $this->assertContains('readingTime <= 30', $crawler->filter('body')->extract(['_text'])[0]); | ||
545 | 451 | ||
546 | $deleteLink = $crawler->filter('.delete')->last()->link(); | 452 | $deleteLink = $crawler->filter('.delete')->last()->link(); |
547 | 453 | ||
@@ -549,8 +455,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
549 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 455 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
550 | 456 | ||
551 | $crawler = $client->followRedirect(); | 457 | $crawler = $client->followRedirect(); |
552 | $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(['_text'])); | 458 | $this->assertContains('flashes.config.notice.tagging_rules_deleted', $crawler->filter('body')->extract(['_text'])[0]); |
553 | $this->assertContains('flashes.config.notice.tagging_rules_deleted', $alert[0]); | ||
554 | } | 459 | } |
555 | 460 | ||
556 | public function dataForTaggingRuleFailed() | 461 | public function dataForTaggingRuleFailed() |
@@ -613,7 +518,23 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
613 | ->getRepository('WallabagCoreBundle:TaggingRule') | 518 | ->getRepository('WallabagCoreBundle:TaggingRule') |
614 | ->findAll()[0]; | 519 | ->findAll()[0]; |
615 | 520 | ||
616 | $crawler = $client->request('GET', '/tagging-rule/delete/'.$rule->getId()); | 521 | $crawler = $client->request('GET', '/tagging-rule/edit/'.$rule->getId()); |
522 | |||
523 | $this->assertEquals(403, $client->getResponse()->getStatusCode()); | ||
524 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | ||
525 | $this->assertContains('You can not access this tagging rule', $body[0]); | ||
526 | } | ||
527 | |||
528 | public function testEditingTaggingRuleFromAnOtherUser() | ||
529 | { | ||
530 | $this->logInAs('bob'); | ||
531 | $client = $this->getClient(); | ||
532 | |||
533 | $rule = $client->getContainer()->get('doctrine.orm.entity_manager') | ||
534 | ->getRepository('WallabagCoreBundle:TaggingRule') | ||
535 | ->findAll()[0]; | ||
536 | |||
537 | $crawler = $client->request('GET', '/tagging-rule/edit/'.$rule->getId()); | ||
617 | 538 | ||
618 | $this->assertEquals(403, $client->getResponse()->getStatusCode()); | 539 | $this->assertEquals(403, $client->getResponse()->getStatusCode()); |
619 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | 540 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); |
diff --git a/tests/Wallabag/CoreBundle/Controller/DeveloperControllerTest.php b/tests/Wallabag/CoreBundle/Controller/DeveloperControllerTest.php deleted file mode 100644 index 79452ace..00000000 --- a/tests/Wallabag/CoreBundle/Controller/DeveloperControllerTest.php +++ /dev/null | |||
@@ -1,71 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Tests\Wallabag\CoreBundle\Controller; | ||
4 | |||
5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | ||
6 | |||
7 | class DeveloperControllerTest extends WallabagCoreTestCase | ||
8 | { | ||
9 | public function testCreateClient() | ||
10 | { | ||
11 | $this->logInAs('admin'); | ||
12 | $client = $this->getClient(); | ||
13 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
14 | $nbClients = $em->getRepository('WallabagApiBundle:Client')->findAll(); | ||
15 | |||
16 | $crawler = $client->request('GET', '/developer/client/create'); | ||
17 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
18 | |||
19 | $form = $crawler->filter('button[type=submit]')->form(); | ||
20 | |||
21 | $client->submit($form); | ||
22 | |||
23 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
24 | |||
25 | $newNbClients = $em->getRepository('WallabagApiBundle:Client')->findAll(); | ||
26 | $this->assertGreaterThan(count($nbClients), count($newNbClients)); | ||
27 | } | ||
28 | |||
29 | public function testListingClient() | ||
30 | { | ||
31 | $this->logInAs('admin'); | ||
32 | $client = $this->getClient(); | ||
33 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
34 | $nbClients = $em->getRepository('WallabagApiBundle:Client')->findAll(); | ||
35 | |||
36 | $crawler = $client->request('GET', '/developer'); | ||
37 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
38 | $this->assertEquals(count($nbClients), $crawler->filter('ul[class=collapsible] li')->count()); | ||
39 | } | ||
40 | |||
41 | public function testDeveloperHowto() | ||
42 | { | ||
43 | $this->logInAs('admin'); | ||
44 | $client = $this->getClient(); | ||
45 | |||
46 | $crawler = $client->request('GET', '/developer/howto/first-app'); | ||
47 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
48 | } | ||
49 | |||
50 | public function testRemoveClient() | ||
51 | { | ||
52 | $this->logInAs('admin'); | ||
53 | $client = $this->getClient(); | ||
54 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
55 | $nbClients = $em->getRepository('WallabagApiBundle:Client')->findAll(); | ||
56 | |||
57 | $crawler = $client->request('GET', '/developer'); | ||
58 | |||
59 | $link = $crawler | ||
60 | ->filter('div[class=collapsible-body] p a') | ||
61 | ->eq(0) | ||
62 | ->link() | ||
63 | ; | ||
64 | |||
65 | $client->click($link); | ||
66 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
67 | |||
68 | $newNbClients = $em->getRepository('WallabagApiBundle:Client')->findAll(); | ||
69 | $this->assertGreaterThan(count($newNbClients), count($nbClients)); | ||
70 | } | ||
71 | } | ||
diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index 5c739c78..9b03a519 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php | |||
@@ -29,7 +29,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
29 | 29 | ||
30 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 30 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); |
31 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | 31 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); |
32 | $this->assertContains('quickstart.intro.paragraph_1', $body[0]); | 32 | $this->assertContains('quickstart.intro.title', $body[0]); |
33 | 33 | ||
34 | // Test if quickstart is disabled when user has 1 entry | 34 | // Test if quickstart is disabled when user has 1 entry |
35 | $crawler = $client->request('GET', '/new'); | 35 | $crawler = $client->request('GET', '/new'); |
@@ -160,6 +160,50 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
160 | $this->assertContains('/view/', $client->getResponse()->getTargetUrl()); | 160 | $this->assertContains('/view/', $client->getResponse()->getTargetUrl()); |
161 | } | 161 | } |
162 | 162 | ||
163 | public function testPostNewOkUrlExistWithAccent() | ||
164 | { | ||
165 | $this->logInAs('admin'); | ||
166 | $client = $this->getClient(); | ||
167 | |||
168 | $url = 'http://www.aritylabs.com/post/106091708292/des-contr%C3%B4leurs-optionnels-gr%C3%A2ce-%C3%A0-constmissing'; | ||
169 | |||
170 | $crawler = $client->request('GET', '/new'); | ||
171 | |||
172 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
173 | |||
174 | $form = $crawler->filter('form[name=entry]')->form(); | ||
175 | |||
176 | $data = [ | ||
177 | 'entry[url]' => $url, | ||
178 | ]; | ||
179 | |||
180 | $client->submit($form, $data); | ||
181 | |||
182 | $crawler = $client->request('GET', '/new'); | ||
183 | |||
184 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
185 | |||
186 | $form = $crawler->filter('form[name=entry]')->form(); | ||
187 | |||
188 | $data = [ | ||
189 | 'entry[url]' => $url, | ||
190 | ]; | ||
191 | |||
192 | $client->submit($form, $data); | ||
193 | |||
194 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
195 | $this->assertContains('/view/', $client->getResponse()->getTargetUrl()); | ||
196 | |||
197 | $em = $client->getContainer() | ||
198 | ->get('doctrine.orm.entity_manager'); | ||
199 | $entry = $em | ||
200 | ->getRepository('WallabagCoreBundle:Entry') | ||
201 | ->findOneByUrl(urldecode($url)); | ||
202 | |||
203 | $em->remove($entry); | ||
204 | $em->flush(); | ||
205 | } | ||
206 | |||
163 | /** | 207 | /** |
164 | * This test will require an internet connection. | 208 | * This test will require an internet connection. |
165 | */ | 209 | */ |
@@ -236,6 +280,16 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
236 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 280 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); |
237 | } | 281 | } |
238 | 282 | ||
283 | public function testUntagged() | ||
284 | { | ||
285 | $this->logInAs('admin'); | ||
286 | $client = $this->getClient(); | ||
287 | |||
288 | $client->request('GET', '/untagged/list'); | ||
289 | |||
290 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
291 | } | ||
292 | |||
239 | public function testStarred() | 293 | public function testStarred() |
240 | { | 294 | { |
241 | $this->logInAs('admin'); | 295 | $this->logInAs('admin'); |
@@ -287,22 +341,23 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
287 | $this->logInAs('admin'); | 341 | $this->logInAs('admin'); |
288 | $client = $this->getClient(); | 342 | $client = $this->getClient(); |
289 | 343 | ||
290 | $content = $client->getContainer() | 344 | $em = $client->getContainer() |
291 | ->get('doctrine.orm.entity_manager') | 345 | ->get('doctrine.orm.entity_manager'); |
346 | |||
347 | $content = $em | ||
292 | ->getRepository('WallabagCoreBundle:Entry') | 348 | ->getRepository('WallabagCoreBundle:Entry') |
293 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | 349 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); |
294 | 350 | ||
295 | // empty content | 351 | // empty content |
296 | $content->setContent(''); | 352 | $content->setContent(''); |
297 | $client->getContainer()->get('doctrine.orm.entity_manager')->persist($content); | 353 | $em->persist($content); |
298 | $client->getContainer()->get('doctrine.orm.entity_manager')->flush(); | 354 | $em->flush(); |
299 | 355 | ||
300 | $client->request('GET', '/reload/'.$content->getId()); | 356 | $client->request('GET', '/reload/'.$content->getId()); |
301 | 357 | ||
302 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 358 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
303 | 359 | ||
304 | $content = $client->getContainer() | 360 | $content = $em |
305 | ->get('doctrine.orm.entity_manager') | ||
306 | ->getRepository('WallabagCoreBundle:Entry') | 361 | ->getRepository('WallabagCoreBundle:Entry') |
307 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | 362 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); |
308 | 363 | ||
@@ -432,9 +487,11 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
432 | $this->logInAs('admin'); | 487 | $this->logInAs('admin'); |
433 | $client = $this->getClient(); | 488 | $client = $this->getClient(); |
434 | 489 | ||
490 | $em = $client->getContainer() | ||
491 | ->get('doctrine.orm.entity_manager'); | ||
492 | |||
435 | // add a new content to be removed later | 493 | // add a new content to be removed later |
436 | $user = $client->getContainer() | 494 | $user = $em |
437 | ->get('doctrine.orm.entity_manager') | ||
438 | ->getRepository('WallabagUserBundle:User') | 495 | ->getRepository('WallabagUserBundle:User') |
439 | ->findOneByUserName('admin'); | 496 | ->findOneByUserName('admin'); |
440 | 497 | ||
@@ -448,12 +505,8 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
448 | $content->setArchived(true); | 505 | $content->setArchived(true); |
449 | $content->setLanguage('fr'); | 506 | $content->setLanguage('fr'); |
450 | 507 | ||
451 | $client->getContainer() | 508 | $em->persist($content); |
452 | ->get('doctrine.orm.entity_manager') | 509 | $em->flush(); |
453 | ->persist($content); | ||
454 | $client->getContainer() | ||
455 | ->get('doctrine.orm.entity_manager') | ||
456 | ->flush(); | ||
457 | 510 | ||
458 | $client->request('GET', '/view/'.$content->getId()); | 511 | $client->request('GET', '/view/'.$content->getId()); |
459 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 512 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); |
@@ -698,4 +751,51 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
698 | $crawler = $client->submit($form, $data); | 751 | $crawler = $client->submit($form, $data); |
699 | $this->assertCount(2, $crawler->filter('div[class=entry]')); | 752 | $this->assertCount(2, $crawler->filter('div[class=entry]')); |
700 | } | 753 | } |
754 | |||
755 | public function testShareEntryPublicly() | ||
756 | { | ||
757 | $this->logInAs('admin'); | ||
758 | $client = $this->getClient(); | ||
759 | |||
760 | $content = $client->getContainer() | ||
761 | ->get('doctrine.orm.entity_manager') | ||
762 | ->getRepository('WallabagCoreBundle:Entry') | ||
763 | ->findOneByUser($this->getLoggedInUserId()); | ||
764 | |||
765 | // no uuid | ||
766 | $client->request('GET', '/share/'.$content->getUuid()); | ||
767 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | ||
768 | |||
769 | // generating the uuid | ||
770 | $client->request('GET', '/share/'.$content->getId()); | ||
771 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
772 | |||
773 | // follow link with uuid | ||
774 | $crawler = $client->followRedirect(); | ||
775 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
776 | $this->assertContains('max-age=25200', $client->getResponse()->headers->get('cache-control')); | ||
777 | $this->assertContains('public', $client->getResponse()->headers->get('cache-control')); | ||
778 | $this->assertContains('s-maxage=25200', $client->getResponse()->headers->get('cache-control')); | ||
779 | $this->assertNotContains('no-cache', $client->getResponse()->headers->get('cache-control')); | ||
780 | $this->assertContains('og:title', $client->getResponse()->getContent()); | ||
781 | $this->assertContains('og:type', $client->getResponse()->getContent()); | ||
782 | $this->assertContains('og:url', $client->getResponse()->getContent()); | ||
783 | $this->assertContains('og:image', $client->getResponse()->getContent()); | ||
784 | |||
785 | // sharing is now disabled | ||
786 | $client->getContainer()->get('craue_config')->set('share_public', 0); | ||
787 | $client->request('GET', '/share/'.$content->getUuid()); | ||
788 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | ||
789 | |||
790 | $client->request('GET', '/view/'.$content->getId()); | ||
791 | $this->assertContains('no-cache', $client->getResponse()->headers->get('cache-control')); | ||
792 | |||
793 | // removing the share | ||
794 | $client->request('GET', '/share/delete/'.$content->getId()); | ||
795 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
796 | |||
797 | // share is now disable | ||
798 | $client->request('GET', '/share/'.$content->getUuid()); | ||
799 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | ||
800 | } | ||
701 | } | 801 | } |
diff --git a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php index b22156c3..9ecd8bc4 100644 --- a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php | |||
@@ -146,7 +146,9 @@ class ExportControllerTest extends WallabagCoreTestCase | |||
146 | ->get('doctrine.orm.entity_manager') | 146 | ->get('doctrine.orm.entity_manager') |
147 | ->getRepository('WallabagCoreBundle:Entry') | 147 | ->getRepository('WallabagCoreBundle:Entry') |
148 | ->createQueryBuilder('e') | 148 | ->createQueryBuilder('e') |
149 | ->select('e, t') | ||
149 | ->leftJoin('e.user', 'u') | 150 | ->leftJoin('e.user', 'u') |
151 | ->leftJoin('e.tags', 't') | ||
150 | ->where('u.username = :username')->setParameter('username', 'admin') | 152 | ->where('u.username = :username')->setParameter('username', 'admin') |
151 | ->andWhere('e.isArchived = true') | 153 | ->andWhere('e.isArchived = true') |
152 | ->getQuery() | 154 | ->getQuery() |
@@ -168,7 +170,19 @@ class ExportControllerTest extends WallabagCoreTestCase | |||
168 | $this->assertGreaterThan(1, $csv); | 170 | $this->assertGreaterThan(1, $csv); |
169 | // +1 for title line | 171 | // +1 for title line |
170 | $this->assertEquals(count($contentInDB) + 1, count($csv)); | 172 | $this->assertEquals(count($contentInDB) + 1, count($csv)); |
171 | $this->assertEquals('Title;URL;Content;Tags;"MIME Type";Language', $csv[0]); | 173 | $this->assertEquals('Title;URL;Content;Tags;"MIME Type";Language;"Creation date"', $csv[0]); |
174 | $this->assertContains($contentInDB[0]['title'], $csv[1]); | ||
175 | $this->assertContains($contentInDB[0]['url'], $csv[1]); | ||
176 | $this->assertContains($contentInDB[0]['content'], $csv[1]); | ||
177 | $this->assertContains($contentInDB[0]['mimetype'], $csv[1]); | ||
178 | $this->assertContains($contentInDB[0]['language'], $csv[1]); | ||
179 | $this->assertContains($contentInDB[0]['createdAt']->format('d/m/Y h:i:s'), $csv[1]); | ||
180 | |||
181 | $expectedTag = []; | ||
182 | foreach ($contentInDB[0]['tags'] as $tag) { | ||
183 | $expectedTag[] = $tag['label']; | ||
184 | } | ||
185 | $this->assertContains(implode(', ', $expectedTag), $csv[1]); | ||
172 | } | 186 | } |
173 | 187 | ||
174 | public function testJsonExport() | 188 | public function testJsonExport() |
@@ -176,29 +190,23 @@ class ExportControllerTest extends WallabagCoreTestCase | |||
176 | $this->logInAs('admin'); | 190 | $this->logInAs('admin'); |
177 | $client = $this->getClient(); | 191 | $client = $this->getClient(); |
178 | 192 | ||
179 | // to be sure results are the same | ||
180 | $contentInDB = $client->getContainer() | 193 | $contentInDB = $client->getContainer() |
181 | ->get('doctrine.orm.entity_manager') | 194 | ->get('doctrine.orm.entity_manager') |
182 | ->getRepository('WallabagCoreBundle:Entry') | 195 | ->getRepository('WallabagCoreBundle:Entry') |
183 | ->createQueryBuilder('e') | 196 | ->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId()); |
184 | ->leftJoin('e.user', 'u') | ||
185 | ->where('u.username = :username')->setParameter('username', 'admin') | ||
186 | ->getQuery() | ||
187 | ->getArrayResult(); | ||
188 | 197 | ||
189 | ob_start(); | 198 | ob_start(); |
190 | $crawler = $client->request('GET', '/export/all.json'); | 199 | $crawler = $client->request('GET', '/export/'.$contentInDB->getId().'.json'); |
191 | ob_end_clean(); | 200 | ob_end_clean(); |
192 | 201 | ||
193 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 202 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); |
194 | 203 | ||
195 | $headers = $client->getResponse()->headers; | 204 | $headers = $client->getResponse()->headers; |
196 | $this->assertEquals('application/json', $headers->get('content-type')); | 205 | $this->assertEquals('application/json', $headers->get('content-type')); |
197 | $this->assertEquals('attachment; filename="All articles.json"', $headers->get('content-disposition')); | 206 | $this->assertEquals('attachment; filename="'.$contentInDB->getTitle().'.json"', $headers->get('content-disposition')); |
198 | $this->assertEquals('UTF-8', $headers->get('content-transfer-encoding')); | 207 | $this->assertEquals('UTF-8', $headers->get('content-transfer-encoding')); |
199 | 208 | ||
200 | $content = json_decode($client->getResponse()->getContent(), true); | 209 | $content = json_decode($client->getResponse()->getContent(), true); |
201 | $this->assertEquals(count($contentInDB), count($content)); | ||
202 | $this->assertArrayHasKey('id', $content[0]); | 210 | $this->assertArrayHasKey('id', $content[0]); |
203 | $this->assertArrayHasKey('title', $content[0]); | 211 | $this->assertArrayHasKey('title', $content[0]); |
204 | $this->assertArrayHasKey('url', $content[0]); | 212 | $this->assertArrayHasKey('url', $content[0]); |
@@ -210,6 +218,19 @@ class ExportControllerTest extends WallabagCoreTestCase | |||
210 | $this->assertArrayHasKey('reading_time', $content[0]); | 218 | $this->assertArrayHasKey('reading_time', $content[0]); |
211 | $this->assertArrayHasKey('domain_name', $content[0]); | 219 | $this->assertArrayHasKey('domain_name', $content[0]); |
212 | $this->assertArrayHasKey('tags', $content[0]); | 220 | $this->assertArrayHasKey('tags', $content[0]); |
221 | $this->assertArrayHasKey('created_at', $content[0]); | ||
222 | $this->assertArrayHasKey('updated_at', $content[0]); | ||
223 | |||
224 | $this->assertEquals($contentInDB->isArchived(), $content[0]['is_archived']); | ||
225 | $this->assertEquals($contentInDB->isStarred(), $content[0]['is_starred']); | ||
226 | $this->assertEquals($contentInDB->getTitle(), $content[0]['title']); | ||
227 | $this->assertEquals($contentInDB->getUrl(), $content[0]['url']); | ||
228 | $this->assertEquals([['text' => 'This is my annotation /o/', 'quote' => 'content']], $content[0]['annotations']); | ||
229 | $this->assertEquals($contentInDB->getMimetype(), $content[0]['mimetype']); | ||
230 | $this->assertEquals($contentInDB->getLanguage(), $content[0]['language']); | ||
231 | $this->assertEquals($contentInDB->getReadingtime(), $content[0]['reading_time']); | ||
232 | $this->assertEquals($contentInDB->getDomainname(), $content[0]['domain_name']); | ||
233 | $this->assertEquals(['foo', 'baz'], $content[0]['tags']); | ||
213 | } | 234 | } |
214 | 235 | ||
215 | public function testXmlExport() | 236 | public function testXmlExport() |
@@ -247,5 +268,7 @@ class ExportControllerTest extends WallabagCoreTestCase | |||
247 | $this->assertNotEmpty('url', (string) $content->entry[0]->url); | 268 | $this->assertNotEmpty('url', (string) $content->entry[0]->url); |
248 | $this->assertNotEmpty('content', (string) $content->entry[0]->content); | 269 | $this->assertNotEmpty('content', (string) $content->entry[0]->content); |
249 | $this->assertNotEmpty('domain_name', (string) $content->entry[0]->domain_name); | 270 | $this->assertNotEmpty('domain_name', (string) $content->entry[0]->domain_name); |
271 | $this->assertNotEmpty('created_at', (string) $content->entry[0]->created_at); | ||
272 | $this->assertNotEmpty('updated_at', (string) $content->entry[0]->updated_at); | ||
250 | } | 273 | } |
251 | } | 274 | } |
diff --git a/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php b/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php index 03355f5a..08f4676e 100644 --- a/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php | |||
@@ -69,4 +69,19 @@ class SecurityControllerTest extends WallabagCoreTestCase | |||
69 | $this->assertTrue($user->isTrustedComputer('ABCDEF')); | 69 | $this->assertTrue($user->isTrustedComputer('ABCDEF')); |
70 | $this->assertFalse($user->isTrustedComputer('FEDCBA')); | 70 | $this->assertFalse($user->isTrustedComputer('FEDCBA')); |
71 | } | 71 | } |
72 | |||
73 | public function testEnabledRegistration() | ||
74 | { | ||
75 | $client = $this->getClient(); | ||
76 | |||
77 | if (!$client->getContainer()->getParameter('fosuser_registration')) { | ||
78 | $this->markTestSkipped('fosuser_registration is not enabled.'); | ||
79 | |||
80 | return; | ||
81 | } | ||
82 | |||
83 | $client->followRedirects(); | ||
84 | $crawler = $client->request('GET', '/register'); | ||
85 | $this->assertContains('registration.submit', $crawler->filter('body')->extract(['_text'])[0]); | ||
86 | } | ||
72 | } | 87 | } |
diff --git a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php index 58450e5f..769ce66e 100644 --- a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php | |||
@@ -3,6 +3,7 @@ | |||
3 | namespace Tests\Wallabag\CoreBundle\Controller; | 3 | namespace Tests\Wallabag\CoreBundle\Controller; |
4 | 4 | ||
5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | 5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; |
6 | use Wallabag\CoreBundle\Entity\Tag; | ||
6 | 7 | ||
7 | class TagControllerTest extends WallabagCoreTestCase | 8 | class TagControllerTest extends WallabagCoreTestCase |
8 | { | 9 | { |
@@ -26,7 +27,7 @@ class TagControllerTest extends WallabagCoreTestCase | |||
26 | $entry = $client->getContainer() | 27 | $entry = $client->getContainer() |
27 | ->get('doctrine.orm.entity_manager') | 28 | ->get('doctrine.orm.entity_manager') |
28 | ->getRepository('WallabagCoreBundle:Entry') | 29 | ->getRepository('WallabagCoreBundle:Entry') |
29 | ->findOneByUsernameAndNotArchived('admin'); | 30 | ->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId()); |
30 | 31 | ||
31 | $crawler = $client->request('GET', '/view/'.$entry->getId()); | 32 | $crawler = $client->request('GET', '/view/'.$entry->getId()); |
32 | 33 | ||
@@ -43,11 +44,11 @@ class TagControllerTest extends WallabagCoreTestCase | |||
43 | $entry = $client->getContainer() | 44 | $entry = $client->getContainer() |
44 | ->get('doctrine.orm.entity_manager') | 45 | ->get('doctrine.orm.entity_manager') |
45 | ->getRepository('WallabagCoreBundle:Entry') | 46 | ->getRepository('WallabagCoreBundle:Entry') |
46 | ->findOneByUsernameAndNotArchived('admin'); | 47 | ->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId()); |
47 | 48 | ||
48 | $this->assertEquals(1, count($entry->getTags())); | 49 | $this->assertEquals(3, count($entry->getTags())); |
49 | 50 | ||
50 | # tag already exists and already assigned | 51 | // tag already exists and already assigned |
51 | $client->submit($form, $data); | 52 | $client->submit($form, $data); |
52 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 53 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
53 | 54 | ||
@@ -56,9 +57,9 @@ class TagControllerTest extends WallabagCoreTestCase | |||
56 | ->getRepository('WallabagCoreBundle:Entry') | 57 | ->getRepository('WallabagCoreBundle:Entry') |
57 | ->find($entry->getId()); | 58 | ->find($entry->getId()); |
58 | 59 | ||
59 | $this->assertEquals(1, count($newEntry->getTags())); | 60 | $this->assertEquals(3, count($newEntry->getTags())); |
60 | 61 | ||
61 | # tag already exists but still not assigned to this entry | 62 | // tag already exists but still not assigned to this entry |
62 | $data = [ | 63 | $data = [ |
63 | 'tag[label]' => 'foo', | 64 | 'tag[label]' => 'foo', |
64 | ]; | 65 | ]; |
@@ -71,7 +72,7 @@ class TagControllerTest extends WallabagCoreTestCase | |||
71 | ->getRepository('WallabagCoreBundle:Entry') | 72 | ->getRepository('WallabagCoreBundle:Entry') |
72 | ->find($entry->getId()); | 73 | ->find($entry->getId()); |
73 | 74 | ||
74 | $this->assertEquals(2, count($newEntry->getTags())); | 75 | $this->assertEquals(3, count($newEntry->getTags())); |
75 | } | 76 | } |
76 | 77 | ||
77 | public function testAddMultipleTagToEntry() | 78 | public function testAddMultipleTagToEntry() |
@@ -82,7 +83,7 @@ class TagControllerTest extends WallabagCoreTestCase | |||
82 | $entry = $client->getContainer() | 83 | $entry = $client->getContainer() |
83 | ->get('doctrine.orm.entity_manager') | 84 | ->get('doctrine.orm.entity_manager') |
84 | ->getRepository('WallabagCoreBundle:Entry') | 85 | ->getRepository('WallabagCoreBundle:Entry') |
85 | ->findOneByUsernameAndNotArchived('admin'); | 86 | ->findByUrlAndUserId('http://0.0.0.0/entry2', $this->getLoggedInUserId()); |
86 | 87 | ||
87 | $crawler = $client->request('GET', '/view/'.$entry->getId()); | 88 | $crawler = $client->request('GET', '/view/'.$entry->getId()); |
88 | 89 | ||
@@ -101,9 +102,13 @@ class TagControllerTest extends WallabagCoreTestCase | |||
101 | ->find($entry->getId()); | 102 | ->find($entry->getId()); |
102 | 103 | ||
103 | $tags = $newEntry->getTags()->toArray(); | 104 | $tags = $newEntry->getTags()->toArray(); |
105 | foreach ($tags as $key => $tag) { | ||
106 | $tags[$key] = $tag->getLabel(); | ||
107 | } | ||
108 | |||
104 | $this->assertGreaterThanOrEqual(2, count($tags)); | 109 | $this->assertGreaterThanOrEqual(2, count($tags)); |
105 | $this->assertNotEquals(false, array_search('foo2', $tags), 'Tag foo2 is assigned to the entry'); | 110 | $this->assertNotFalse(array_search('foo2', $tags), 'Tag foo2 is assigned to the entry'); |
106 | $this->assertNotEquals(false, array_search('bar2', $tags), 'Tag bar2 is assigned to the entry'); | 111 | $this->assertNotFalse(array_search('bar2', $tags), 'Tag bar2 is assigned to the entry'); |
107 | } | 112 | } |
108 | 113 | ||
109 | public function testRemoveTagFromEntry() | 114 | public function testRemoveTagFromEntry() |
@@ -114,7 +119,7 @@ class TagControllerTest extends WallabagCoreTestCase | |||
114 | $entry = $client->getContainer() | 119 | $entry = $client->getContainer() |
115 | ->get('doctrine.orm.entity_manager') | 120 | ->get('doctrine.orm.entity_manager') |
116 | ->getRepository('WallabagCoreBundle:Entry') | 121 | ->getRepository('WallabagCoreBundle:Entry') |
117 | ->findOneByUsernameAndNotArchived('admin'); | 122 | ->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId()); |
118 | 123 | ||
119 | $tag = $client->getContainer() | 124 | $tag = $client->getContainer() |
120 | ->get('doctrine.orm.entity_manager') | 125 | ->get('doctrine.orm.entity_manager') |
@@ -130,5 +135,48 @@ class TagControllerTest extends WallabagCoreTestCase | |||
130 | $client->request('GET', '/remove-tag/'.$entry->getId().'/'.$tag->getId()); | 135 | $client->request('GET', '/remove-tag/'.$entry->getId().'/'.$tag->getId()); |
131 | 136 | ||
132 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | 137 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); |
138 | |||
139 | $tag = $client->getContainer() | ||
140 | ->get('doctrine.orm.entity_manager') | ||
141 | ->getRepository('WallabagCoreBundle:Tag') | ||
142 | ->findOneByLabel($this->tagName); | ||
143 | |||
144 | $this->assertNull($tag, $this->tagName.' was removed because it begun an orphan tag'); | ||
145 | } | ||
146 | |||
147 | public function testShowEntriesForTagAction() | ||
148 | { | ||
149 | $this->logInAs('admin'); | ||
150 | $client = $this->getClient(); | ||
151 | $em = $client->getContainer() | ||
152 | ->get('doctrine.orm.entity_manager'); | ||
153 | |||
154 | $tag = new Tag(); | ||
155 | $tag->setLabel($this->tagName); | ||
156 | |||
157 | $entry = $client->getContainer() | ||
158 | ->get('doctrine.orm.entity_manager') | ||
159 | ->getRepository('WallabagCoreBundle:Entry') | ||
160 | ->findByUrlAndUserId('http://0.0.0.0/entry4', $this->getLoggedInUserId()); | ||
161 | |||
162 | $tag->addEntry($entry); | ||
163 | |||
164 | $em->persist($entry); | ||
165 | $em->persist($tag); | ||
166 | $em->flush(); | ||
167 | |||
168 | $tag = $client->getContainer() | ||
169 | ->get('doctrine.orm.entity_manager') | ||
170 | ->getRepository('WallabagCoreBundle:Tag') | ||
171 | ->findOneByEntryAndTagLabel($entry, $this->tagName); | ||
172 | |||
173 | $crawler = $client->request('GET', '/tag/list/'.$tag->getSlug()); | ||
174 | |||
175 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
176 | $this->assertCount(1, $crawler->filter('[id*="entry-"]')); | ||
177 | |||
178 | $entry->removeTag($tag); | ||
179 | $em->remove($tag); | ||
180 | $em->flush(); | ||
133 | } | 181 | } |
134 | } | 182 | } |
diff --git a/tests/Wallabag/CoreBundle/EventListener/LocaleListenerTest.php b/tests/Wallabag/CoreBundle/EventListener/LocaleListenerTest.php index 2a7f9390..078bb69a 100644 --- a/tests/Wallabag/CoreBundle/EventListener/LocaleListenerTest.php +++ b/tests/Wallabag/CoreBundle/EventListener/LocaleListenerTest.php | |||
@@ -15,7 +15,11 @@ class LocaleListenerTest extends \PHPUnit_Framework_TestCase | |||
15 | { | 15 | { |
16 | private function getEvent(Request $request) | 16 | private function getEvent(Request $request) |
17 | { | 17 | { |
18 | return new GetResponseEvent($this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface'), $request, HttpKernelInterface::MASTER_REQUEST); | 18 | $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface') |
19 | ->disableOriginalConstructor() | ||
20 | ->getMock(); | ||
21 | |||
22 | return new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); | ||
19 | } | 23 | } |
20 | 24 | ||
21 | public function testWithoutSession() | 25 | public function testWithoutSession() |
diff --git a/tests/Wallabag/CoreBundle/EventListener/RegistrationConfirmedListenerTest.php b/tests/Wallabag/CoreBundle/EventListener/RegistrationConfirmedListenerTest.php deleted file mode 100644 index e45722fa..00000000 --- a/tests/Wallabag/CoreBundle/EventListener/RegistrationConfirmedListenerTest.php +++ /dev/null | |||
@@ -1,91 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Tests\Wallabag\CoreBundle\EventListener; | ||
4 | |||
5 | use FOS\UserBundle\Event\FilterUserResponseEvent; | ||
6 | use FOS\UserBundle\FOSUserEvents; | ||
7 | use Symfony\Component\EventDispatcher\EventDispatcher; | ||
8 | use Symfony\Component\HttpFoundation\Request; | ||
9 | use Symfony\Component\HttpFoundation\Response; | ||
10 | use Wallabag\CoreBundle\Entity\Config; | ||
11 | use Wallabag\CoreBundle\EventListener\RegistrationConfirmedListener; | ||
12 | use Wallabag\UserBundle\Entity\User; | ||
13 | |||
14 | class RegistrationConfirmedListenerTest extends \PHPUnit_Framework_TestCase | ||
15 | { | ||
16 | private $em; | ||
17 | private $listener; | ||
18 | private $dispatcher; | ||
19 | private $request; | ||
20 | private $response; | ||
21 | |||
22 | protected function setUp() | ||
23 | { | ||
24 | $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') | ||
25 | ->disableOriginalConstructor() | ||
26 | ->getMock(); | ||
27 | |||
28 | $this->listener = new RegistrationConfirmedListener( | ||
29 | $this->em, | ||
30 | 'baggy', | ||
31 | 20, | ||
32 | 50, | ||
33 | 'fr' | ||
34 | ); | ||
35 | |||
36 | $this->dispatcher = new EventDispatcher(); | ||
37 | $this->dispatcher->addSubscriber($this->listener); | ||
38 | |||
39 | $this->request = Request::create('/'); | ||
40 | $this->response = Response::create(); | ||
41 | } | ||
42 | |||
43 | public function testWithInvalidUser() | ||
44 | { | ||
45 | $user = new User(); | ||
46 | $user->setEnabled(false); | ||
47 | |||
48 | $event = new FilterUserResponseEvent( | ||
49 | $user, | ||
50 | $this->request, | ||
51 | $this->response | ||
52 | ); | ||
53 | |||
54 | $this->em->expects($this->never())->method('persist'); | ||
55 | $this->em->expects($this->never())->method('flush'); | ||
56 | |||
57 | $this->dispatcher->dispatch( | ||
58 | FOSUserEvents::REGISTRATION_CONFIRMED, | ||
59 | $event | ||
60 | ); | ||
61 | } | ||
62 | |||
63 | public function testWithValidUser() | ||
64 | { | ||
65 | $user = new User(); | ||
66 | $user->setEnabled(true); | ||
67 | |||
68 | $event = new FilterUserResponseEvent( | ||
69 | $user, | ||
70 | $this->request, | ||
71 | $this->response | ||
72 | ); | ||
73 | |||
74 | $config = new Config($user); | ||
75 | $config->setTheme('baggy'); | ||
76 | $config->setItemsPerPage(20); | ||
77 | $config->setRssLimit(50); | ||
78 | $config->setLanguage('fr'); | ||
79 | |||
80 | $this->em->expects($this->once()) | ||
81 | ->method('persist') | ||
82 | ->will($this->returnValue($config)); | ||
83 | $this->em->expects($this->once()) | ||
84 | ->method('flush'); | ||
85 | |||
86 | $this->dispatcher->dispatch( | ||
87 | FOSUserEvents::REGISTRATION_CONFIRMED, | ||
88 | $event | ||
89 | ); | ||
90 | } | ||
91 | } | ||
diff --git a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php index 7abb0737..5d772602 100644 --- a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php +++ b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php | |||
@@ -296,6 +296,29 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase | |||
296 | $this->assertEquals('tag2', $entry->getTags()[1]->getLabel()); | 296 | $this->assertEquals('tag2', $entry->getTags()[1]->getLabel()); |
297 | } | 297 | } |
298 | 298 | ||
299 | public function testAssignTagsNotFlushed() | ||
300 | { | ||
301 | $graby = $this->getMockBuilder('Graby\Graby') | ||
302 | ->disableOriginalConstructor() | ||
303 | ->getMock(); | ||
304 | |||
305 | $tagRepo = $this->getTagRepositoryMock(); | ||
306 | $tagRepo->expects($this->never()) | ||
307 | ->method('__call'); | ||
308 | |||
309 | $proxy = new ContentProxy($graby, $this->getTaggerMock(), $tagRepo, $this->getLogger()); | ||
310 | |||
311 | $tagEntity = new Tag(); | ||
312 | $tagEntity->setLabel('tag1'); | ||
313 | |||
314 | $entry = new Entry(new User()); | ||
315 | |||
316 | $proxy->assignTagsToEntry($entry, 'tag1', [$tagEntity]); | ||
317 | |||
318 | $this->assertCount(1, $entry->getTags()); | ||
319 | $this->assertEquals('tag1', $entry->getTags()[0]->getLabel()); | ||
320 | } | ||
321 | |||
299 | private function getTaggerMock() | 322 | private function getTaggerMock() |
300 | { | 323 | { |
301 | return $this->getMockBuilder('Wallabag\CoreBundle\Helper\RuleBasedTagger') | 324 | return $this->getMockBuilder('Wallabag\CoreBundle\Helper\RuleBasedTagger') |
diff --git a/tests/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php b/tests/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php index e29b58b5..2e6fccfb 100644 --- a/tests/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php +++ b/tests/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php | |||
@@ -125,16 +125,14 @@ class UsernameRssTokenConverterTest extends \PHPUnit_Framework_TestCase | |||
125 | $this->assertTrue($converter->supports($params)); | 125 | $this->assertTrue($converter->supports($params)); |
126 | } | 126 | } |
127 | 127 | ||
128 | /** | ||
129 | * @expectedException InvalidArgumentException | ||
130 | * @expectedExceptionMessage Route attribute is missing | ||
131 | */ | ||
132 | public function testApplyEmptyRequest() | 128 | public function testApplyEmptyRequest() |
133 | { | 129 | { |
134 | $params = new ParamConverter([]); | 130 | $params = new ParamConverter([]); |
135 | $converter = new UsernameRssTokenConverter(); | 131 | $converter = new UsernameRssTokenConverter(); |
136 | 132 | ||
137 | $converter->apply(new Request(), $params); | 133 | $res = $converter->apply(new Request(), $params); |
134 | |||
135 | $this->assertFalse($res); | ||
138 | } | 136 | } |
139 | 137 | ||
140 | /** | 138 | /** |
diff --git a/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php b/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php index 8ec2a75a..b1c8c946 100644 --- a/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php +++ b/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php | |||
@@ -8,7 +8,23 @@ class WallabagExtensionTest extends \PHPUnit_Framework_TestCase | |||
8 | { | 8 | { |
9 | public function testRemoveWww() | 9 | public function testRemoveWww() |
10 | { | 10 | { |
11 | $extension = new WallabagExtension(); | 11 | $entryRepository = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') |
12 | ->disableOriginalConstructor() | ||
13 | ->getMock(); | ||
14 | |||
15 | $tagRepository = $this->getMockBuilder('Wallabag\CoreBundle\Repository\TagRepository') | ||
16 | ->disableOriginalConstructor() | ||
17 | ->getMock(); | ||
18 | |||
19 | $tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface') | ||
20 | ->disableOriginalConstructor() | ||
21 | ->getMock(); | ||
22 | |||
23 | $translator = $this->getMockBuilder('Symfony\Component\Translation\TranslatorInterface') | ||
24 | ->disableOriginalConstructor() | ||
25 | ->getMock(); | ||
26 | |||
27 | $extension = new WallabagExtension($entryRepository, $tagRepository, $tokenStorage, 0, $translator); | ||
12 | 28 | ||
13 | $this->assertEquals('lemonde.fr', $extension->removeWww('www.lemonde.fr')); | 29 | $this->assertEquals('lemonde.fr', $extension->removeWww('www.lemonde.fr')); |
14 | $this->assertEquals('lemonde.fr', $extension->removeWww('lemonde.fr')); | 30 | $this->assertEquals('lemonde.fr', $extension->removeWww('lemonde.fr')); |
diff --git a/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php b/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php index c0055888..7bf4b43c 100644 --- a/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php +++ b/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php | |||
@@ -80,4 +80,17 @@ abstract class WallabagCoreTestCase extends WebTestCase | |||
80 | 80 | ||
81 | throw new \RuntimeException('No logged in User.'); | 81 | throw new \RuntimeException('No logged in User.'); |
82 | } | 82 | } |
83 | |||
84 | /** | ||
85 | * Check if Redis is installed. | ||
86 | * If not, mark test as skip. | ||
87 | */ | ||
88 | protected function checkRedis() | ||
89 | { | ||
90 | try { | ||
91 | $this->client->getContainer()->get('wallabag_core.redis.client')->connect(); | ||
92 | } catch (\Exception $e) { | ||
93 | $this->markTestSkipped('Redis is not installed/activated'); | ||
94 | } | ||
95 | } | ||
83 | } | 96 | } |