3 namespace Tests\Wallabag\CoreBundle\Controller
;
5 use Tests\Wallabag\CoreBundle\WallabagCoreTestCase
;
6 use Wallabag\AnnotationBundle\Entity\Annotation
;
7 use Wallabag\CoreBundle\Entity\Config
;
8 use Wallabag\CoreBundle\Entity\Entry
;
9 use Wallabag\CoreBundle\Entity\Tag
;
10 use Wallabag\UserBundle\Entity\User
;
12 class ConfigControllerTest
extends WallabagCoreTestCase
14 public function testLogin()
16 $client = $this->getClient();
18 $client->request('GET', '/new');
20 $this->assertSame(302, $client->getResponse()->getStatusCode());
21 $this->assertContains('login', $client->getResponse()->headers
->get('location'));
24 public function testIndex()
26 $this->logInAs('admin');
27 $client = $this->getClient();
29 $crawler = $client->request('GET', '/config');
31 $this->assertSame(200, $client->getResponse()->getStatusCode());
33 $this->assertCount(1, $crawler->filter('button[id=config_save]'));
34 $this->assertCount(1, $crawler->filter('button[id=change_passwd_save]'));
35 $this->assertCount(1, $crawler->filter('button[id=update_user_save]'));
36 $this->assertCount(1, $crawler->filter('button[id=rss_config_save]'));
39 public function testUpdate()
41 $this->logInAs('admin');
42 $client = $this->getClient();
44 $crawler = $client->request('GET', '/config');
46 $this->assertSame(200, $client->getResponse()->getStatusCode());
48 $form = $crawler->filter('button[id=config_save]')->form();
51 'config[theme]' => 'baggy',
52 'config[items_per_page]' => '30',
53 'config[reading_speed]' => '0.5',
54 'config[action_mark_as_read]' => '0',
55 'config[language]' => 'en',
58 $client->submit($form, $data);
60 $this->assertSame(302, $client->getResponse()->getStatusCode());
62 $crawler = $client->followRedirect();
64 $this->assertContains('flashes.config.notice.config_saved', $crawler->filter('body')->extract(['_text'])[0]);
67 public function testChangeReadingSpeed()
69 $this->logInAs('admin');
70 $this->useTheme('baggy');
71 $client = $this->getClient();
73 $entry = new Entry($this->getLoggedInUser());
74 $entry->setUrl('http://0.0.0.0/test-entry1')
76 $this->getEntityManager()->persist($entry);
78 $this->getEntityManager()->flush();
79 $this->getEntityManager()->clear();
81 $crawler = $client->request('GET', '/unread/list');
82 $form = $crawler->filter('button[id=submit-filter]')->form();
84 'entry_filter[readingTime][right_number]' => 22,
85 'entry_filter[readingTime][left_number]' => 22,
87 $crawler = $client->submit($form, $dataFilters);
88 $this->assertCount(1, $crawler->filter('div[class=entry]'));
90 // Change reading speed
91 $crawler = $client->request('GET', '/config');
92 $form = $crawler->filter('button[id=config_save]')->form();
94 'config[reading_speed]' => '2',
96 $client->submit($form, $data);
98 // Is the entry still available via filters?
99 $crawler = $client->request('GET', '/unread/list');
100 $form = $crawler->filter('button[id=submit-filter]')->form();
101 $crawler = $client->submit($form, $dataFilters);
102 $this->assertCount(0, $crawler->filter('div[class=entry]'));
104 // Restore old configuration
105 $crawler = $client->request('GET', '/config');
106 $form = $crawler->filter('button[id=config_save]')->form();
108 'config[reading_speed]' => '0.5',
110 $client->submit($form, $data);
113 public function dataForUpdateFailed()
117 'config[theme]' => 'baggy',
118 'config[items_per_page]' => '',
119 'config[language]' => 'en',
125 * @dataProvider dataForUpdateFailed
127 public function testUpdateFailed($data)
129 $this->logInAs('admin');
130 $client = $this->getClient();
132 $crawler = $client->request('GET', '/config');
134 $this->assertSame(200, $client->getResponse()->getStatusCode());
136 $form = $crawler->filter('button[id=config_save]')->form();
138 $crawler = $client->submit($form, $data);
140 $this->assertSame(200, $client->getResponse()->getStatusCode());
142 $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text']));
143 $this->assertContains('This value should not be blank', $alert[0]);
146 public function dataForChangePasswordFailed()
151 'change_passwd[old_password]' => 'material',
152 'change_passwd[new_password][first]' => '',
153 'change_passwd[new_password][second]' => '',
155 'validator.password_wrong_value',
159 'change_passwd[old_password]' => 'mypassword',
160 'change_passwd[new_password][first]' => '',
161 'change_passwd[new_password][second]' => '',
163 'This value should not be blank',
167 'change_passwd[old_password]' => 'mypassword',
168 'change_passwd[new_password][first]' => 'hop',
169 'change_passwd[new_password][second]' => '',
171 'validator.password_must_match',
175 'change_passwd[old_password]' => 'mypassword',
176 'change_passwd[new_password][first]' => 'hop',
177 'change_passwd[new_password][second]' => 'hop',
179 'validator.password_too_short',
185 * @dataProvider dataForChangePasswordFailed
187 public function testChangePasswordFailed($data, $expectedMessage)
189 $this->logInAs('admin');
190 $client = $this->getClient();
192 $crawler = $client->request('GET', '/config');
194 $this->assertSame(200, $client->getResponse()->getStatusCode());
196 $form = $crawler->filter('button[id=change_passwd_save]')->form();
198 $crawler = $client->submit($form, $data);
200 $this->assertSame(200, $client->getResponse()->getStatusCode());
202 $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text']));
203 $this->assertContains($expectedMessage, $alert[0]);
206 public function testChangePassword()
208 $this->logInAs('admin');
209 $client = $this->getClient();
211 $crawler = $client->request('GET', '/config');
213 $this->assertSame(200, $client->getResponse()->getStatusCode());
215 $form = $crawler->filter('button[id=change_passwd_save]')->form();
218 'change_passwd[old_password]' => 'mypassword',
219 'change_passwd[new_password][first]' => 'mypassword',
220 'change_passwd[new_password][second]' => 'mypassword',
223 $client->submit($form, $data);
225 $this->assertSame(302, $client->getResponse()->getStatusCode());
227 $crawler = $client->followRedirect();
229 $this->assertContains('flashes.config.notice.password_updated', $crawler->filter('body')->extract(['_text'])[0]);
232 public function dataForUserFailed()
237 'update_user[name]' => '',
238 'update_user[email]' => '',
240 'fos_user.email.blank',
244 'update_user[name]' => '',
245 'update_user[email]' => 'test',
247 'fos_user.email.invalid',
253 * @dataProvider dataForUserFailed
255 public function testUserFailed($data, $expectedMessage)
257 $this->logInAs('admin');
258 $client = $this->getClient();
260 $crawler = $client->request('GET', '/config');
262 $this->assertSame(200, $client->getResponse()->getStatusCode());
264 $form = $crawler->filter('button[id=update_user_save]')->form();
266 $crawler = $client->submit($form, $data);
268 $this->assertSame(200, $client->getResponse()->getStatusCode());
270 $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text']));
271 $this->assertContains($expectedMessage, $alert[0]);
274 public function testUserUpdate()
276 $this->logInAs('admin');
277 $client = $this->getClient();
279 $crawler = $client->request('GET', '/config');
281 $this->assertSame(200, $client->getResponse()->getStatusCode());
283 $form = $crawler->filter('button[id=update_user_save]')->form();
286 'update_user[name]' => 'new name',
287 'update_user[email]' => 'admin@wallabag.io',
290 $client->submit($form, $data);
292 $this->assertSame(302, $client->getResponse()->getStatusCode());
294 $crawler = $client->followRedirect();
296 $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text']));
297 $this->assertContains('flashes.config.notice.user_updated', $alert[0]);
300 public function testUserEnable2faEmail()
302 $this->logInAs('admin');
303 $client = $this->getClient();
305 $crawler = $client->request('GET', '/config');
307 $this->assertSame(200, $client->getResponse()->getStatusCode());
309 $form = $crawler->filter('button[id=update_user_save]')->form();
312 'update_user[emailTwoFactor]' => '1',
315 $client->submit($form, $data);
317 $this->assertSame(302, $client->getResponse()->getStatusCode());
319 $crawler = $client->followRedirect();
321 $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text']));
322 $this->assertContains('flashes.config.notice.user_updated', $alert[0]);
325 $em = $this->getEntityManager();
327 ->getRepository('WallabagUserBundle:User')
328 ->findOneByUsername('admin');
330 $this->assertTrue($user->isEmailTwoFactor());
332 $user->setEmailTwoFactor(false);
337 public function testUserEnable2faGoogle()
339 $this->logInAs('admin');
340 $client = $this->getClient();
342 $crawler = $client->request('GET', '/config');
344 $this->assertSame(200, $client->getResponse()->getStatusCode());
346 $form = $crawler->filter('button[id=update_user_save]')->form();
349 'update_user[googleTwoFactor]' => '1',
352 $client->submit($form, $data);
354 $this->assertSame(302, $client->getResponse()->getStatusCode());
356 $crawler = $client->followRedirect();
358 $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text']));
359 $this->assertContains('flashes.config.notice.user_updated', $alert[0]);
362 $em = $this->getEntityManager();
364 ->getRepository('WallabagUserBundle:User')
365 ->findOneByUsername('admin');
367 $this->assertTrue($user->isGoogleAuthenticatorEnabled());
369 $user->setGoogleAuthenticatorSecret(null);
374 public function testUserEnable2faBoth()
376 $this->logInAs('admin');
377 $client = $this->getClient();
379 $crawler = $client->request('GET', '/config');
381 $this->assertSame(200, $client->getResponse()->getStatusCode());
383 $form = $crawler->filter('button[id=update_user_save]')->form();
386 'update_user[googleTwoFactor]' => '1',
387 'update_user[emailTwoFactor]' => '1',
390 $client->submit($form, $data);
392 $this->assertSame(302, $client->getResponse()->getStatusCode());
394 $crawler = $client->followRedirect();
396 $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text']));
397 $this->assertContains('flashes.config.notice.user_updated', $alert[0]);
400 $em = $this->getEntityManager();
402 ->getRepository('WallabagUserBundle:User')
403 ->findOneByUsername('admin');
405 $this->assertTrue($user->isGoogleAuthenticatorEnabled());
406 $this->assertFalse($user->isEmailTwoFactor());
408 $user->setGoogleAuthenticatorSecret(null);
413 public function testRssUpdateResetToken()
415 $this->logInAs('admin');
416 $client = $this->getClient();
419 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
421 ->getRepository('WallabagUserBundle:User')
422 ->findOneByUsername('admin');
425 $this->markTestSkipped('No user found in db.');
428 $config = $user->getConfig();
429 $config->setRssToken(null);
430 $em->persist($config);
433 $crawler = $client->request('GET', '/config');
435 $this->assertSame(200, $client->getResponse()->getStatusCode());
437 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
438 $this->assertContains('config.form_rss.no_token', $body[0]);
440 $client->request('GET', '/generate-token');
441 $this->assertSame(302, $client->getResponse()->getStatusCode());
443 $crawler = $client->followRedirect();
445 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
446 $this->assertNotContains('config.form_rss.no_token', $body[0]);
449 public function testGenerateTokenAjax()
451 $this->logInAs('admin');
452 $client = $this->getClient();
459 ['HTTP_X-Requested-With' => 'XMLHttpRequest']
462 $this->assertSame(200, $client->getResponse()->getStatusCode());
463 $content = json_decode($client->getResponse()->getContent(), true);
464 $this->assertArrayHasKey('token', $content);
467 public function testRssUpdate()
469 $this->logInAs('admin');
470 $client = $this->getClient();
472 $crawler = $client->request('GET', '/config');
474 $this->assertSame(200, $client->getResponse()->getStatusCode());
476 $form = $crawler->filter('button[id=rss_config_save]')->form();
479 'rss_config[rss_limit]' => 12,
482 $client->submit($form, $data);
484 $this->assertSame(302, $client->getResponse()->getStatusCode());
486 $crawler = $client->followRedirect();
488 $this->assertContains('flashes.config.notice.rss_updated', $crawler->filter('body')->extract(['_text'])[0]);
491 public function dataForRssFailed()
496 'rss_config[rss_limit]' => 0,
498 'This value should be 1 or more.',
502 'rss_config[rss_limit]' => 1000000000000,
504 'validator.rss_limit_too_high',
510 * @dataProvider dataForRssFailed
512 public function testRssFailed($data, $expectedMessage)
514 $this->logInAs('admin');
515 $client = $this->getClient();
517 $crawler = $client->request('GET', '/config');
519 $this->assertSame(200, $client->getResponse()->getStatusCode());
521 $form = $crawler->filter('button[id=rss_config_save]')->form();
523 $crawler = $client->submit($form, $data);
525 $this->assertSame(200, $client->getResponse()->getStatusCode());
527 $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text']));
528 $this->assertContains($expectedMessage, $alert[0]);
531 public function testTaggingRuleCreation()
533 $this->logInAs('admin');
534 $this->useTheme('baggy');
535 $client = $this->getClient();
537 $crawler = $client->request('GET', '/config');
539 $this->assertSame(200, $client->getResponse()->getStatusCode());
541 $form = $crawler->filter('button[id=tagging_rule_save]')->form();
544 'tagging_rule[rule]' => 'readingTime <= 3',
545 'tagging_rule[tags]' => 'short reading',
548 $client->submit($form, $data);
550 $this->assertSame(302, $client->getResponse()->getStatusCode());
552 $crawler = $client->followRedirect();
554 $this->assertContains('flashes.config.notice.tagging_rules_updated', $crawler->filter('body')->extract(['_text'])[0]);
556 $editLink = $crawler->filter('.mode_edit')->last()->link();
558 $crawler = $client->click($editLink);
559 $this->assertSame(302, $client->getResponse()->getStatusCode());
560 $this->assertContains('?tagging-rule=', $client->getResponse()->headers
->get('location'));
562 $crawler = $client->followRedirect();
564 $form = $crawler->filter('button[id=tagging_rule_save]')->form();
567 'tagging_rule[rule]' => 'readingTime <= 30',
568 'tagging_rule[tags]' => 'short reading',
571 $client->submit($form, $data);
573 $this->assertSame(302, $client->getResponse()->getStatusCode());
575 $crawler = $client->followRedirect();
577 $this->assertContains('flashes.config.notice.tagging_rules_updated', $crawler->filter('body')->extract(['_text'])[0]);
579 $this->assertContains('readingTime <= 30', $crawler->filter('body')->extract(['_text'])[0]);
581 $deleteLink = $crawler->filter('.delete')->last()->link();
583 $crawler = $client->click($deleteLink);
584 $this->assertSame(302, $client->getResponse()->getStatusCode());
586 $crawler = $client->followRedirect();
587 $this->assertContains('flashes.config.notice.tagging_rules_deleted', $crawler->filter('body')->extract(['_text'])[0]);
590 public function dataForTaggingRuleFailed()
595 'tagging_rule[rule]' => 'unknownVar <= 3',
596 'tagging_rule[tags]' => 'cool tag',
605 'tagging_rule[rule]' => 'length(domainName) <= 42',
606 'tagging_rule[tags]' => 'cool tag',
617 * @dataProvider dataForTaggingRuleFailed
619 public function testTaggingRuleCreationFail($data, $messages)
621 $this->logInAs('admin');
622 $client = $this->getClient();
624 $crawler = $client->request('GET', '/config');
626 $this->assertSame(200, $client->getResponse()->getStatusCode());
628 $form = $crawler->filter('button[id=tagging_rule_save]')->form();
630 $crawler = $client->submit($form, $data);
632 $this->assertSame(200, $client->getResponse()->getStatusCode());
634 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
636 foreach ($messages as $message) {
637 $this->assertContains($message, $body[0]);
641 public function testTaggingRuleTooLong()
643 $this->logInAs('admin');
644 $client = $this->getClient();
646 $crawler = $client->request('GET', '/config');
648 $this->assertSame(200, $client->getResponse()->getStatusCode());
650 $form = $crawler->filter('button[id=tagging_rule_save]')->form();
652 $crawler = $client->submit($form, [
653 'tagging_rule[rule]' => str_repeat('title', 60),
654 'tagging_rule[tags]' => 'cool tag',
657 $this->assertSame(200, $client->getResponse()->getStatusCode());
659 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
661 $this->assertContains('255 characters', $body[0]);
664 public function testDeletingTaggingRuleFromAnOtherUser()
666 $this->logInAs('bob');
667 $client = $this->getClient();
669 $rule = $client->getContainer()->get('doctrine.orm.entity_manager')
670 ->getRepository('WallabagCoreBundle:TaggingRule')
673 $crawler = $client->request('GET', '/tagging-rule/edit/' . $rule->getId());
675 $this->assertSame(403, $client->getResponse()->getStatusCode());
676 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
677 $this->assertContains('You can not access this tagging rule', $body[0]);
680 public function testEditingTaggingRuleFromAnOtherUser()
682 $this->logInAs('bob');
683 $client = $this->getClient();
685 $rule = $client->getContainer()->get('doctrine.orm.entity_manager')
686 ->getRepository('WallabagCoreBundle:TaggingRule')
689 $crawler = $client->request('GET', '/tagging-rule/edit/' . $rule->getId());
691 $this->assertSame(403, $client->getResponse()->getStatusCode());
692 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
693 $this->assertContains('You can not access this tagging rule', $body[0]);
696 public function testDemoMode()
698 $this->logInAs('admin');
699 $client = $this->getClient();
701 $config = $client->getContainer()->get('craue_config');
702 $config->set('demo_mode_enabled', 1);
703 $config->set('demo_mode_username', 'admin');
705 $crawler = $client->request('GET', '/config');
707 $this->assertSame(200, $client->getResponse()->getStatusCode());
709 $form = $crawler->filter('button[id=change_passwd_save]')->form();
712 'change_passwd[old_password]' => 'mypassword',
713 'change_passwd[new_password][first]' => 'mypassword',
714 'change_passwd[new_password][second]' => 'mypassword',
717 $client->submit($form, $data);
719 $this->assertSame(302, $client->getResponse()->getStatusCode());
720 $this->assertContains('flashes.config.notice.password_not_updated_demo', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]);
722 $config->set('demo_mode_enabled', 0);
723 $config->set('demo_mode_username', 'wallabag');
726 public function testDeleteUserButtonVisibility()
728 $this->logInAs('admin');
729 $client = $this->getClient();
731 $crawler = $client->request('GET', '/config');
733 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
734 $this->assertContains('config.form_user.delete.button', $body[0]);
736 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
739 ->getRepository('WallabagUserBundle:User')
740 ->findOneByUsername('empty');
741 $user->setEnabled(false);
745 ->getRepository('WallabagUserBundle:User')
746 ->findOneByUsername('bob');
747 $user->setEnabled(false);
752 $crawler = $client->request('GET', '/config');
754 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
755 $this->assertNotContains('config.form_user.delete.button', $body[0]);
757 $client->request('GET', '/account/delete');
758 $this->assertSame(403, $client->getResponse()->getStatusCode());
761 ->getRepository('WallabagUserBundle:User')
762 ->findOneByUsername('empty');
763 $user->setEnabled(true);
767 ->getRepository('WallabagUserBundle:User')
768 ->findOneByUsername('bob');
769 $user->setEnabled(true);
775 public function testDeleteAccount()
777 $client = $this->getClient();
778 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
781 $user->setName('Wallace');
782 $user->setEmail('wallace@wallabag.org');
783 $user->setUsername('wallace');
784 $user->setPlainPassword('wallace');
785 $user->setEnabled(true);
786 $user->addRole('ROLE_SUPER_ADMIN');
790 $config = new Config($user);
792 $config->setTheme('material');
793 $config->setItemsPerPage(30);
794 $config->setReadingSpeed(1);
795 $config->setLanguage('en');
796 $config->setPocketConsumerKey('xxxxx');
798 $em->persist($config);
801 $this->logInAs('wallace');
802 $loggedInUserId = $this->getLoggedInUserId();
804 // create entry to check after user deletion
805 // that this entry is also deleted
806 $crawler = $client->request('GET', '/new');
808 $this->assertSame(200, $client->getResponse()->getStatusCode());
810 $form = $crawler->filter('form[name=entry]')->form();
812 'entry[url]' => $url = 'https://github.com/wallabag/wallabag',
815 $client->submit($form, $data);
816 $this->assertSame(302, $client->getResponse()->getStatusCode());
818 $crawler = $client->request('GET', '/config');
820 $deleteLink = $crawler->filter('.delete-account')->last()->link();
822 $client->click($deleteLink);
823 $this->assertSame(302, $client->getResponse()->getStatusCode());
825 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
827 ->getRepository('WallabagUserBundle:User')
828 ->createQueryBuilder('u')
829 ->where('u.username = :username')->setParameter('username', 'wallace')
831 ->getOneOrNullResult()
834 $this->assertNull($user);
836 $entries = $client->getContainer()
837 ->get('doctrine.orm.entity_manager')
838 ->getRepository('WallabagCoreBundle:Entry')
839 ->findByUser($loggedInUserId);
841 $this->assertEmpty($entries);
844 public function testReset()
846 $this->logInAs('empty');
847 $client = $this->getClient();
849 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
851 $user = static::$kernel->getContainer()->get('security.token_storage')->getToken()->getUser();
854 $tag->setLabel('super');
857 $entry = new Entry($user);
858 $entry->setUrl('https://www.lemonde.fr/europe/article/2016/10/01/pour-le-psoe-chaque-election-s-est-transformee-en-une-agonie_5006476_3214.html');
859 $entry->setContent('Youhou');
860 $entry->setTitle('Youhou');
861 $entry->addTag($tag);
862 $em->persist($entry);
864 $entry2 = new Entry($user);
865 $entry2->setUrl('http://www.lemonde.de/europe/article/2016/10/01/pour-le-psoe-chaque-election-s-est-transformee-en-une-agonie_5006476_3214.html');
866 $entry2->setContent('Youhou');
867 $entry2->setTitle('Youhou');
868 $entry2->addTag($tag);
869 $em->persist($entry2);
871 $annotation = new Annotation($user);
872 $annotation->setText('annotated');
873 $annotation->setQuote('annotated');
874 $annotation->setRanges([]);
875 $annotation->setEntry($entry);
876 $em->persist($annotation);
881 $crawler = $client->request('GET', '/config#set3');
883 $this->assertSame(200, $client->getResponse()->getStatusCode());
885 $crawler = $client->click($crawler->selectLink('config.reset.annotations')->link());
887 $this->assertSame(302, $client->getResponse()->getStatusCode());
888 $this->assertContains('flashes.config.notice.annotations_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]);
890 $annotationsReset = $em
891 ->getRepository('WallabagAnnotationBundle:Annotation')
892 ->findAnnotationsByPageId($entry->getId(), $user->getId());
894 $this->assertEmpty($annotationsReset, 'Annotations were reset');
897 $crawler = $client->request('GET', '/config#set3');
899 $this->assertSame(200, $client->getResponse()->getStatusCode());
901 $crawler = $client->click($crawler->selectLink('config.reset.tags')->link());
903 $this->assertSame(302, $client->getResponse()->getStatusCode());
904 $this->assertContains('flashes.config.notice.tags_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]);
907 ->getRepository('WallabagCoreBundle:Tag')
908 ->countAllTags($user->getId());
910 $this->assertSame(0, $tagReset, 'Tags were reset');
913 $crawler = $client->request('GET', '/config#set3');
915 $this->assertSame(200, $client->getResponse()->getStatusCode());
917 $crawler = $client->click($crawler->selectLink('config.reset.entries')->link());
919 $this->assertSame(302, $client->getResponse()->getStatusCode());
920 $this->assertContains('flashes.config.notice.entries_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]);
923 ->getRepository('WallabagCoreBundle:Entry')
924 ->countAllEntriesByUser($user->getId());
926 $this->assertSame(0, $entryReset, 'Entries were reset');
929 public function testResetArchivedEntries()
931 $this->logInAs('empty');
932 $client = $this->getClient();
934 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
936 $user = static::$kernel->getContainer()->get('security.token_storage')->getToken()->getUser();
939 $tag->setLabel('super');
942 $entry = new Entry($user);
943 $entry->setUrl('https://www.lemonde.fr/europe/article/2016/10/01/pour-le-psoe-chaque-election-s-est-transformee-en-une-agonie_5006476_3214.html');
944 $entry->setContent('Youhou');
945 $entry->setTitle('Youhou');
946 $entry->addTag($tag);
947 $em->persist($entry);
949 $annotation = new Annotation($user);
950 $annotation->setText('annotated');
951 $annotation->setQuote('annotated');
952 $annotation->setRanges([]);
953 $annotation->setEntry($entry);
954 $em->persist($annotation);
956 $tagArchived = new Tag();
957 $tagArchived->setLabel('super');
958 $em->persist($tagArchived);
960 $entryArchived = new Entry($user);
961 $entryArchived->setUrl('https://www.lemonde.fr/europe/article/2016/10/01/pour-le-psoe-chaque-election-s-est-transformee-en-une-agonie_5006476_3214.html');
962 $entryArchived->setContent('Youhou');
963 $entryArchived->setTitle('Youhou');
964 $entryArchived->addTag($tagArchived);
965 $entryArchived->updateArchived(true);
966 $em->persist($entryArchived);
968 $annotationArchived = new Annotation($user);
969 $annotationArchived->setText('annotated');
970 $annotationArchived->setQuote('annotated');
971 $annotationArchived->setRanges([]);
972 $annotationArchived->setEntry($entryArchived);
973 $em->persist($annotationArchived);
977 $crawler = $client->request('GET', '/config#set3');
979 $this->assertSame(200, $client->getResponse()->getStatusCode());
981 $crawler = $client->click($crawler->selectLink('config.reset.archived')->link());
983 $this->assertSame(302, $client->getResponse()->getStatusCode());
984 $this->assertContains('flashes.config.notice.archived_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]);
987 ->getRepository('WallabagCoreBundle:Entry')
988 ->countAllEntriesByUser($user->getId());
990 $this->assertSame(1, $entryReset, 'Entries were reset');
993 ->getRepository('WallabagCoreBundle:Tag')
994 ->countAllTags($user->getId());
996 $this->assertSame(1, $tagReset, 'Tags were reset');
998 $annotationsReset = $em
999 ->getRepository('WallabagAnnotationBundle:Annotation')
1000 ->findAnnotationsByPageId($annotationArchived->getId(), $user->getId());
1002 $this->assertEmpty($annotationsReset, 'Annotations were reset');
1005 public function testResetEntriesCascade()
1007 $this->logInAs('empty');
1008 $client = $this->getClient();
1010 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
1012 $user = static::$kernel->getContainer()->get('security.token_storage')->getToken()->getUser();
1015 $tag->setLabel('super');
1018 $entry = new Entry($user);
1019 $entry->setUrl('https://www.lemonde.fr/europe/article/2016/10/01/pour-le-psoe-chaque-election-s-est-transformee-en-une-agonie_5006476_3214.html');
1020 $entry->setContent('Youhou');
1021 $entry->setTitle('Youhou');
1022 $entry->addTag($tag);
1023 $em->persist($entry);
1025 $annotation = new Annotation($user);
1026 $annotation->setText('annotated');
1027 $annotation->setQuote('annotated');
1028 $annotation->setRanges([]);
1029 $annotation->setEntry($entry);
1030 $em->persist($annotation);
1034 $crawler = $client->request('GET', '/config#set3');
1036 $this->assertSame(200, $client->getResponse()->getStatusCode());
1038 $crawler = $client->click($crawler->selectLink('config.reset.entries')->link());
1040 $this->assertSame(302, $client->getResponse()->getStatusCode());
1041 $this->assertContains('flashes.config.notice.entries_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]);
1044 ->getRepository('WallabagCoreBundle:Entry')
1045 ->countAllEntriesByUser($user->getId());
1047 $this->assertSame(0, $entryReset, 'Entries were reset');
1050 ->getRepository('WallabagCoreBundle:Tag')
1051 ->countAllTags($user->getId());
1053 $this->assertSame(0, $tagReset, 'Tags were reset');
1055 $annotationsReset = $em
1056 ->getRepository('WallabagAnnotationBundle:Annotation')
1057 ->findAnnotationsByPageId($entry->getId(), $user->getId());
1059 $this->assertEmpty($annotationsReset, 'Annotations were reset');
1062 public function testSwitchViewMode()
1064 $this->logInAs('admin');
1065 $this->useTheme('baggy');
1066 $client = $this->getClient();
1068 $client->request('GET', '/unread/list');
1070 $this->assertNotContains('listmode', $client->getResponse()->getContent());
1072 $client->request('GET', '/config/view-mode');
1073 $crawler = $client->followRedirect();
1075 $client->request('GET', '/unread/list');
1077 $this->assertContains('listmode', $client->getResponse()->getContent());
1079 $client->request('GET', '/config/view-mode');
1082 public function testChangeLocaleWithoutReferer()
1084 $client = $this->getClient();
1086 $client->request('GET', '/locale/de');
1087 $client->followRedirect();
1089 $this->assertSame('de', $client->getRequest()->getLocale());
1090 $this->assertSame('de', $client->getContainer()->get('session')->get('_locale'));
1093 public function testChangeLocaleWithReferer()
1095 $client = $this->getClient();
1097 $client->request('GET', '/login');
1098 $client->request('GET', '/locale/de');
1099 $client->followRedirect();
1101 $this->assertSame('de', $client->getRequest()->getLocale());
1102 $this->assertSame('de', $client->getContainer()->get('session')->get('_locale'));
1105 public function testChangeLocaleToBadLocale()
1107 $client = $this->getClient();
1109 $client->request('GET', '/login');
1110 $client->request('GET', '/locale/yuyuyuyu');
1111 $client->followRedirect();
1113 $this->assertNotSame('yuyuyuyu', $client->getRequest()->getLocale());
1114 $this->assertNotSame('yuyuyuyu', $client->getContainer()->get('session')->get('_locale'));