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 testRssUpdateResetToken()
302 $this->logInAs('admin');
303 $client = $this->getClient();
306 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
308 ->getRepository('WallabagUserBundle:User')
309 ->findOneByUsername('admin');
312 $this->markTestSkipped('No user found in db.');
315 $config = $user->getConfig();
316 $config->setRssToken(null);
317 $em->persist($config);
320 $crawler = $client->request('GET', '/config');
322 $this->assertSame(200, $client->getResponse()->getStatusCode());
324 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
325 $this->assertContains('config.form_rss.no_token', $body[0]);
327 $client->request('GET', '/generate-token');
328 $this->assertSame(302, $client->getResponse()->getStatusCode());
330 $crawler = $client->followRedirect();
332 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
333 $this->assertNotContains('config.form_rss.no_token', $body[0]);
336 public function testGenerateTokenAjax()
338 $this->logInAs('admin');
339 $client = $this->getClient();
346 ['HTTP_X-Requested-With' => 'XMLHttpRequest']
349 $this->assertSame(200, $client->getResponse()->getStatusCode());
350 $content = json_decode($client->getResponse()->getContent(), true);
351 $this->assertArrayHasKey('token', $content);
354 public function testRssUpdate()
356 $this->logInAs('admin');
357 $client = $this->getClient();
359 $crawler = $client->request('GET', '/config');
361 $this->assertSame(200, $client->getResponse()->getStatusCode());
363 $form = $crawler->filter('button[id=rss_config_save]')->form();
366 'rss_config[rss_limit]' => 12,
369 $client->submit($form, $data);
371 $this->assertSame(302, $client->getResponse()->getStatusCode());
373 $crawler = $client->followRedirect();
375 $this->assertContains('flashes.config.notice.rss_updated', $crawler->filter('body')->extract(['_text'])[0]);
378 public function dataForRssFailed()
383 'rss_config[rss_limit]' => 0,
385 'This value should be 1 or more.',
389 'rss_config[rss_limit]' => 1000000000000,
391 'validator.rss_limit_too_high',
397 * @dataProvider dataForRssFailed
399 public function testRssFailed($data, $expectedMessage)
401 $this->logInAs('admin');
402 $client = $this->getClient();
404 $crawler = $client->request('GET', '/config');
406 $this->assertSame(200, $client->getResponse()->getStatusCode());
408 $form = $crawler->filter('button[id=rss_config_save]')->form();
410 $crawler = $client->submit($form, $data);
412 $this->assertSame(200, $client->getResponse()->getStatusCode());
414 $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text']));
415 $this->assertContains($expectedMessage, $alert[0]);
418 public function testTaggingRuleCreation()
420 $this->logInAs('admin');
421 $this->useTheme('baggy');
422 $client = $this->getClient();
424 $crawler = $client->request('GET', '/config');
426 $this->assertSame(200, $client->getResponse()->getStatusCode());
428 $form = $crawler->filter('button[id=tagging_rule_save]')->form();
431 'tagging_rule[rule]' => 'readingTime <= 3',
432 'tagging_rule[tags]' => 'short reading',
435 $client->submit($form, $data);
437 $this->assertSame(302, $client->getResponse()->getStatusCode());
439 $crawler = $client->followRedirect();
441 $this->assertContains('flashes.config.notice.tagging_rules_updated', $crawler->filter('body')->extract(['_text'])[0]);
443 $editLink = $crawler->filter('.mode_edit')->last()->link();
445 $crawler = $client->click($editLink);
446 $this->assertSame(302, $client->getResponse()->getStatusCode());
447 $this->assertContains('?tagging-rule=', $client->getResponse()->headers
->get('location'));
449 $crawler = $client->followRedirect();
451 $form = $crawler->filter('button[id=tagging_rule_save]')->form();
454 'tagging_rule[rule]' => 'readingTime <= 30',
455 'tagging_rule[tags]' => 'short reading',
458 $client->submit($form, $data);
460 $this->assertSame(302, $client->getResponse()->getStatusCode());
462 $crawler = $client->followRedirect();
464 $this->assertContains('flashes.config.notice.tagging_rules_updated', $crawler->filter('body')->extract(['_text'])[0]);
466 $this->assertContains('readingTime <= 30', $crawler->filter('body')->extract(['_text'])[0]);
468 $deleteLink = $crawler->filter('.delete')->last()->link();
470 $crawler = $client->click($deleteLink);
471 $this->assertSame(302, $client->getResponse()->getStatusCode());
473 $crawler = $client->followRedirect();
474 $this->assertContains('flashes.config.notice.tagging_rules_deleted', $crawler->filter('body')->extract(['_text'])[0]);
477 public function dataForTaggingRuleFailed()
482 'tagging_rule[rule]' => 'unknownVar <= 3',
483 'tagging_rule[tags]' => 'cool tag',
492 'tagging_rule[rule]' => 'length(domainName) <= 42',
493 'tagging_rule[tags]' => 'cool tag',
504 * @dataProvider dataForTaggingRuleFailed
506 public function testTaggingRuleCreationFail($data, $messages)
508 $this->logInAs('admin');
509 $client = $this->getClient();
511 $crawler = $client->request('GET', '/config');
513 $this->assertSame(200, $client->getResponse()->getStatusCode());
515 $form = $crawler->filter('button[id=tagging_rule_save]')->form();
517 $crawler = $client->submit($form, $data);
519 $this->assertSame(200, $client->getResponse()->getStatusCode());
521 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
523 foreach ($messages as $message) {
524 $this->assertContains($message, $body[0]);
528 public function testTaggingRuleTooLong()
530 $this->logInAs('admin');
531 $client = $this->getClient();
533 $crawler = $client->request('GET', '/config');
535 $this->assertSame(200, $client->getResponse()->getStatusCode());
537 $form = $crawler->filter('button[id=tagging_rule_save]')->form();
539 $crawler = $client->submit($form, [
540 'tagging_rule[rule]' => str_repeat('title', 60),
541 'tagging_rule[tags]' => 'cool tag',
544 $this->assertSame(200, $client->getResponse()->getStatusCode());
546 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
548 $this->assertContains('255 characters', $body[0]);
551 public function testDeletingTaggingRuleFromAnOtherUser()
553 $this->logInAs('bob');
554 $client = $this->getClient();
556 $rule = $client->getContainer()->get('doctrine.orm.entity_manager')
557 ->getRepository('WallabagCoreBundle:TaggingRule')
560 $crawler = $client->request('GET', '/tagging-rule/edit/' . $rule->getId());
562 $this->assertSame(403, $client->getResponse()->getStatusCode());
563 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
564 $this->assertContains('You can not access this tagging rule', $body[0]);
567 public function testEditingTaggingRuleFromAnOtherUser()
569 $this->logInAs('bob');
570 $client = $this->getClient();
572 $rule = $client->getContainer()->get('doctrine.orm.entity_manager')
573 ->getRepository('WallabagCoreBundle:TaggingRule')
576 $crawler = $client->request('GET', '/tagging-rule/edit/' . $rule->getId());
578 $this->assertSame(403, $client->getResponse()->getStatusCode());
579 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
580 $this->assertContains('You can not access this tagging rule', $body[0]);
583 public function testDemoMode()
585 $this->logInAs('admin');
586 $client = $this->getClient();
588 $config = $client->getContainer()->get('craue_config');
589 $config->set('demo_mode_enabled', 1);
590 $config->set('demo_mode_username', 'admin');
592 $crawler = $client->request('GET', '/config');
594 $this->assertSame(200, $client->getResponse()->getStatusCode());
596 $form = $crawler->filter('button[id=change_passwd_save]')->form();
599 'change_passwd[old_password]' => 'mypassword',
600 'change_passwd[new_password][first]' => 'mypassword',
601 'change_passwd[new_password][second]' => 'mypassword',
604 $client->submit($form, $data);
606 $this->assertSame(302, $client->getResponse()->getStatusCode());
607 $this->assertContains('flashes.config.notice.password_not_updated_demo', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]);
609 $config->set('demo_mode_enabled', 0);
610 $config->set('demo_mode_username', 'wallabag');
613 public function testDeleteUserButtonVisibility()
615 $this->logInAs('admin');
616 $client = $this->getClient();
618 $crawler = $client->request('GET', '/config');
620 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
621 $this->assertContains('config.form_user.delete.button', $body[0]);
623 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
626 ->getRepository('WallabagUserBundle:User')
627 ->findOneByUsername('empty');
628 $user->setEnabled(false);
632 ->getRepository('WallabagUserBundle:User')
633 ->findOneByUsername('bob');
634 $user->setEnabled(false);
639 $crawler = $client->request('GET', '/config');
641 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
642 $this->assertNotContains('config.form_user.delete.button', $body[0]);
644 $client->request('GET', '/account/delete');
645 $this->assertSame(403, $client->getResponse()->getStatusCode());
648 ->getRepository('WallabagUserBundle:User')
649 ->findOneByUsername('empty');
650 $user->setEnabled(true);
654 ->getRepository('WallabagUserBundle:User')
655 ->findOneByUsername('bob');
656 $user->setEnabled(true);
662 public function testDeleteAccount()
664 $client = $this->getClient();
665 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
668 $user->setName('Wallace');
669 $user->setEmail('wallace@wallabag.org');
670 $user->setUsername('wallace');
671 $user->setPlainPassword('wallace');
672 $user->setEnabled(true);
673 $user->addRole('ROLE_SUPER_ADMIN');
677 $config = new Config($user);
679 $config->setTheme('material');
680 $config->setItemsPerPage(30);
681 $config->setReadingSpeed(1);
682 $config->setLanguage('en');
683 $config->setPocketConsumerKey('xxxxx');
685 $em->persist($config);
688 $this->logInAs('wallace');
689 $loggedInUserId = $this->getLoggedInUserId();
691 // create entry to check after user deletion
692 // that this entry is also deleted
693 $crawler = $client->request('GET', '/new');
695 $this->assertSame(200, $client->getResponse()->getStatusCode());
697 $form = $crawler->filter('form[name=entry]')->form();
699 'entry[url]' => $url = 'https://github.com/wallabag/wallabag',
702 $client->submit($form, $data);
703 $this->assertSame(302, $client->getResponse()->getStatusCode());
705 $crawler = $client->request('GET', '/config');
707 $deleteLink = $crawler->filter('.delete-account')->last()->link();
709 $client->click($deleteLink);
710 $this->assertSame(302, $client->getResponse()->getStatusCode());
712 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
714 ->getRepository('WallabagUserBundle:User')
715 ->createQueryBuilder('u')
716 ->where('u.username = :username')->setParameter('username', 'wallace')
718 ->getOneOrNullResult()
721 $this->assertNull($user);
723 $entries = $client->getContainer()
724 ->get('doctrine.orm.entity_manager')
725 ->getRepository('WallabagCoreBundle:Entry')
726 ->findByUser($loggedInUserId);
728 $this->assertEmpty($entries);
731 public function testReset()
733 $this->logInAs('empty');
734 $client = $this->getClient();
736 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
738 $user = static::$kernel->getContainer()->get('security.token_storage')->getToken()->getUser();
741 $tag->setLabel('super');
744 $entry = new Entry($user);
745 $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');
746 $entry->setContent('Youhou');
747 $entry->setTitle('Youhou');
748 $entry->addTag($tag);
749 $em->persist($entry);
751 $entry2 = new Entry($user);
752 $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');
753 $entry2->setContent('Youhou');
754 $entry2->setTitle('Youhou');
755 $entry2->addTag($tag);
756 $em->persist($entry2);
758 $annotation = new Annotation($user);
759 $annotation->setText('annotated');
760 $annotation->setQuote('annotated');
761 $annotation->setRanges([]);
762 $annotation->setEntry($entry);
763 $em->persist($annotation);
768 $crawler = $client->request('GET', '/config#set3');
770 $this->assertSame(200, $client->getResponse()->getStatusCode());
772 $crawler = $client->click($crawler->selectLink('config.reset.annotations')->link());
774 $this->assertSame(302, $client->getResponse()->getStatusCode());
775 $this->assertContains('flashes.config.notice.annotations_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]);
777 $annotationsReset = $em
778 ->getRepository('WallabagAnnotationBundle:Annotation')
779 ->findAnnotationsByPageId($entry->getId(), $user->getId());
781 $this->assertEmpty($annotationsReset, 'Annotations were reset');
784 $crawler = $client->request('GET', '/config#set3');
786 $this->assertSame(200, $client->getResponse()->getStatusCode());
788 $crawler = $client->click($crawler->selectLink('config.reset.tags')->link());
790 $this->assertSame(302, $client->getResponse()->getStatusCode());
791 $this->assertContains('flashes.config.notice.tags_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]);
794 ->getRepository('WallabagCoreBundle:Tag')
795 ->countAllTags($user->getId());
797 $this->assertSame(0, $tagReset, 'Tags were reset');
800 $crawler = $client->request('GET', '/config#set3');
802 $this->assertSame(200, $client->getResponse()->getStatusCode());
804 $crawler = $client->click($crawler->selectLink('config.reset.entries')->link());
806 $this->assertSame(302, $client->getResponse()->getStatusCode());
807 $this->assertContains('flashes.config.notice.entries_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]);
810 ->getRepository('WallabagCoreBundle:Entry')
811 ->countAllEntriesByUser($user->getId());
813 $this->assertSame(0, $entryReset, 'Entries were reset');
816 public function testResetArchivedEntries()
818 $this->logInAs('empty');
819 $client = $this->getClient();
821 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
823 $user = static::$kernel->getContainer()->get('security.token_storage')->getToken()->getUser();
826 $tag->setLabel('super');
829 $entry = new Entry($user);
830 $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');
831 $entry->setContent('Youhou');
832 $entry->setTitle('Youhou');
833 $entry->addTag($tag);
834 $em->persist($entry);
836 $annotation = new Annotation($user);
837 $annotation->setText('annotated');
838 $annotation->setQuote('annotated');
839 $annotation->setRanges([]);
840 $annotation->setEntry($entry);
841 $em->persist($annotation);
843 $tagArchived = new Tag();
844 $tagArchived->setLabel('super');
845 $em->persist($tagArchived);
847 $entryArchived = new Entry($user);
848 $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');
849 $entryArchived->setContent('Youhou');
850 $entryArchived->setTitle('Youhou');
851 $entryArchived->addTag($tagArchived);
852 $entryArchived->updateArchived(true);
853 $em->persist($entryArchived);
855 $annotationArchived = new Annotation($user);
856 $annotationArchived->setText('annotated');
857 $annotationArchived->setQuote('annotated');
858 $annotationArchived->setRanges([]);
859 $annotationArchived->setEntry($entryArchived);
860 $em->persist($annotationArchived);
864 $crawler = $client->request('GET', '/config#set3');
866 $this->assertSame(200, $client->getResponse()->getStatusCode());
868 $crawler = $client->click($crawler->selectLink('config.reset.archived')->link());
870 $this->assertSame(302, $client->getResponse()->getStatusCode());
871 $this->assertContains('flashes.config.notice.archived_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]);
874 ->getRepository('WallabagCoreBundle:Entry')
875 ->countAllEntriesByUser($user->getId());
877 $this->assertSame(1, $entryReset, 'Entries were reset');
880 ->getRepository('WallabagCoreBundle:Tag')
881 ->countAllTags($user->getId());
883 $this->assertSame(1, $tagReset, 'Tags were reset');
885 $annotationsReset = $em
886 ->getRepository('WallabagAnnotationBundle:Annotation')
887 ->findAnnotationsByPageId($annotationArchived->getId(), $user->getId());
889 $this->assertEmpty($annotationsReset, 'Annotations were reset');
892 public function testResetEntriesCascade()
894 $this->logInAs('empty');
895 $client = $this->getClient();
897 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
899 $user = static::$kernel->getContainer()->get('security.token_storage')->getToken()->getUser();
902 $tag->setLabel('super');
905 $entry = new Entry($user);
906 $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');
907 $entry->setContent('Youhou');
908 $entry->setTitle('Youhou');
909 $entry->addTag($tag);
910 $em->persist($entry);
912 $annotation = new Annotation($user);
913 $annotation->setText('annotated');
914 $annotation->setQuote('annotated');
915 $annotation->setRanges([]);
916 $annotation->setEntry($entry);
917 $em->persist($annotation);
921 $crawler = $client->request('GET', '/config#set3');
923 $this->assertSame(200, $client->getResponse()->getStatusCode());
925 $crawler = $client->click($crawler->selectLink('config.reset.entries')->link());
927 $this->assertSame(302, $client->getResponse()->getStatusCode());
928 $this->assertContains('flashes.config.notice.entries_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]);
931 ->getRepository('WallabagCoreBundle:Entry')
932 ->countAllEntriesByUser($user->getId());
934 $this->assertSame(0, $entryReset, 'Entries were reset');
937 ->getRepository('WallabagCoreBundle:Tag')
938 ->countAllTags($user->getId());
940 $this->assertSame(0, $tagReset, 'Tags were reset');
942 $annotationsReset = $em
943 ->getRepository('WallabagAnnotationBundle:Annotation')
944 ->findAnnotationsByPageId($entry->getId(), $user->getId());
946 $this->assertEmpty($annotationsReset, 'Annotations were reset');
949 public function testSwitchViewMode()
951 $this->logInAs('admin');
952 $this->useTheme('baggy');
953 $client = $this->getClient();
955 $client->request('GET', '/unread/list');
957 $this->assertNotContains('listmode', $client->getResponse()->getContent());
959 $client->request('GET', '/config/view-mode');
960 $crawler = $client->followRedirect();
962 $client->request('GET', '/unread/list');
964 $this->assertContains('listmode', $client->getResponse()->getContent());
966 $client->request('GET', '/config/view-mode');
969 public function testChangeLocaleWithoutReferer()
971 $client = $this->getClient();
973 $client->request('GET', '/locale/de');
974 $client->followRedirect();
976 $this->assertSame('de', $client->getRequest()->getLocale());
977 $this->assertSame('de', $client->getContainer()->get('session')->get('_locale'));
980 public function testChangeLocaleWithReferer()
982 $client = $this->getClient();
984 $client->request('GET', '/login');
985 $client->request('GET', '/locale/de');
986 $client->followRedirect();
988 $this->assertSame('de', $client->getRequest()->getLocale());
989 $this->assertSame('de', $client->getContainer()->get('session')->get('_locale'));
992 public function testChangeLocaleToBadLocale()
994 $client = $this->getClient();
996 $client->request('GET', '/login');
997 $client->request('GET', '/locale/yuyuyuyu');
998 $client->followRedirect();
1000 $this->assertNotSame('yuyuyuyu', $client->getRequest()->getLocale());
1001 $this->assertNotSame('yuyuyuyu', $client->getContainer()->get('session')->get('_locale'));
1004 public function testUserEnable2faEmail()
1006 $this->logInAs('admin');
1007 $client = $this->getClient();
1009 $crawler = $client->request('GET', '/config/otp/email');
1011 $this->assertSame(302, $client->getResponse()->getStatusCode());
1013 $crawler = $client->followRedirect();
1015 $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text']));
1016 $this->assertContains('flashes.config.notice.otp_enabled', $alert[0]);
1019 $em = $this->getEntityManager();
1021 ->getRepository('WallabagUserBundle:User')
1022 ->findOneByUsername('admin');
1024 $this->assertTrue($user->isEmailTwoFactor());
1026 $user->setEmailTwoFactor(false);
1027 $em->persist($user);
1031 public function testUserEnable2faGoogle()
1033 $this->logInAs('admin');
1034 $client = $this->getClient();
1036 $crawler = $client->request('GET', '/config/otp/app');
1038 $this->assertSame(200, $client->getResponse()->getStatusCode());
1041 $em = $this->getEntityManager();
1043 ->getRepository('WallabagUserBundle:User')
1044 ->findOneByUsername('admin');
1046 $this->assertTrue($user->isGoogleTwoFactor());
1047 $this->assertGreaterThan(0, $user->getBackupCodes());
1049 $user->setGoogleAuthenticatorSecret(false);
1050 $user->setBackupCodes(null);
1051 $em->persist($user);
1055 public function testUserEnable2faGoogleCancel()
1057 $this->logInAs('admin');
1058 $client = $this->getClient();
1060 $crawler = $client->request('GET', '/config/otp/app');
1062 $this->assertSame(200, $client->getResponse()->getStatusCode());
1065 $em = $this->getEntityManager();
1067 ->getRepository('WallabagUserBundle:User')
1068 ->findOneByUsername('admin');
1070 $this->assertTrue($user->isGoogleTwoFactor());
1071 $this->assertGreaterThan(0, $user->getBackupCodes());
1073 $crawler = $client->request('GET', '/config/otp/app/cancel');
1075 $this->assertSame(302, $client->getResponse()->getStatusCode());
1078 ->getRepository('WallabagUserBundle:User')
1079 ->findOneByUsername('admin');
1081 $this->assertFalse($user->isGoogleTwoFactor());
1082 $this->assertEmpty($user->getBackupCodes());