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=feed_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]' => '100',
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]' => '400',
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]' => '100',
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 testFeedUpdateResetToken()
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->setFeedToken(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_feed.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->assertContains('config.form_feed.token_reset', $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 testRevokeTokenAjax()
356 $this->logInAs('admin');
357 $client = $this->getClient();
364 ['HTTP_X-Requested-With' => 'XMLHttpRequest']
367 $this->assertSame(200, $client->getResponse()->getStatusCode());
370 public function testFeedUpdate()
372 $this->logInAs('admin');
373 $client = $this->getClient();
375 $crawler = $client->request('GET', '/config');
377 $this->assertSame(200, $client->getResponse()->getStatusCode());
379 $form = $crawler->filter('button[id=feed_config_save]')->form();
382 'feed_config[feed_limit]' => 12,
385 $client->submit($form, $data);
387 $this->assertSame(302, $client->getResponse()->getStatusCode());
389 $crawler = $client->followRedirect();
391 $this->assertContains('flashes.config.notice.feed_updated', $crawler->filter('body')->extract(['_text'])[0]);
394 public function dataForFeedFailed()
399 'feed_config[feed_limit]' => 0,
401 'This value should be 1 or more.',
405 'feed_config[feed_limit]' => 1000000000000,
407 'validator.feed_limit_too_high',
413 * @dataProvider dataForFeedFailed
415 public function testFeedFailed($data, $expectedMessage)
417 $this->logInAs('admin');
418 $client = $this->getClient();
420 $crawler = $client->request('GET', '/config');
422 $this->assertSame(200, $client->getResponse()->getStatusCode());
424 $form = $crawler->filter('button[id=feed_config_save]')->form();
426 $crawler = $client->submit($form, $data);
428 $this->assertSame(200, $client->getResponse()->getStatusCode());
430 $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text']));
431 $this->assertContains($expectedMessage, $alert[0]);
434 public function testTaggingRuleCreation()
436 $this->logInAs('admin');
437 $this->useTheme('baggy');
438 $client = $this->getClient();
440 $crawler = $client->request('GET', '/config');
442 $this->assertSame(200, $client->getResponse()->getStatusCode());
444 $form = $crawler->filter('button[id=tagging_rule_save]')->form();
447 'tagging_rule[rule]' => 'readingTime <= 3',
448 'tagging_rule[tags]' => 'short reading',
451 $client->submit($form, $data);
453 $this->assertSame(302, $client->getResponse()->getStatusCode());
455 $crawler = $client->followRedirect();
457 $this->assertContains('flashes.config.notice.tagging_rules_updated', $crawler->filter('body')->extract(['_text'])[0]);
459 $editLink = $crawler->filter('.mode_edit')->last()->link();
461 $crawler = $client->click($editLink);
462 $this->assertSame(302, $client->getResponse()->getStatusCode());
463 $this->assertContains('?tagging-rule=', $client->getResponse()->headers
->get('location'));
465 $crawler = $client->followRedirect();
467 $form = $crawler->filter('button[id=tagging_rule_save]')->form();
470 'tagging_rule[rule]' => 'readingTime <= 30',
471 'tagging_rule[tags]' => 'short reading',
474 $client->submit($form, $data);
476 $this->assertSame(302, $client->getResponse()->getStatusCode());
478 $crawler = $client->followRedirect();
480 $this->assertContains('flashes.config.notice.tagging_rules_updated', $crawler->filter('body')->extract(['_text'])[0]);
482 $this->assertContains('readingTime <= 30', $crawler->filter('body')->extract(['_text'])[0]);
484 $deleteLink = $crawler->filter('.delete')->last()->link();
486 $crawler = $client->click($deleteLink);
487 $this->assertSame(302, $client->getResponse()->getStatusCode());
489 $crawler = $client->followRedirect();
490 $this->assertContains('flashes.config.notice.tagging_rules_deleted', $crawler->filter('body')->extract(['_text'])[0]);
493 public function dataForTaggingRuleFailed()
498 'tagging_rule[rule]' => 'unknownVar <= 3',
499 'tagging_rule[tags]' => 'cool tag',
508 'tagging_rule[rule]' => 'length(domainName) <= 42',
509 'tagging_rule[tags]' => 'cool tag',
520 * @dataProvider dataForTaggingRuleFailed
522 public function testTaggingRuleCreationFail($data, $messages)
524 $this->logInAs('admin');
525 $client = $this->getClient();
527 $crawler = $client->request('GET', '/config');
529 $this->assertSame(200, $client->getResponse()->getStatusCode());
531 $form = $crawler->filter('button[id=tagging_rule_save]')->form();
533 $crawler = $client->submit($form, $data);
535 $this->assertSame(200, $client->getResponse()->getStatusCode());
537 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
539 foreach ($messages as $message) {
540 $this->assertContains($message, $body[0]);
544 public function testTaggingRuleTooLong()
546 $this->logInAs('admin');
547 $client = $this->getClient();
549 $crawler = $client->request('GET', '/config');
551 $this->assertSame(200, $client->getResponse()->getStatusCode());
553 $form = $crawler->filter('button[id=tagging_rule_save]')->form();
555 $crawler = $client->submit($form, [
556 'tagging_rule[rule]' => str_repeat('title', 60),
557 'tagging_rule[tags]' => 'cool tag',
560 $this->assertSame(200, $client->getResponse()->getStatusCode());
562 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
564 $this->assertContains('255 characters', $body[0]);
567 public function testDeletingTaggingRuleFromAnOtherUser()
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 testEditingTaggingRuleFromAnOtherUser()
585 $this->logInAs('bob');
586 $client = $this->getClient();
588 $rule = $client->getContainer()->get('doctrine.orm.entity_manager')
589 ->getRepository('WallabagCoreBundle:TaggingRule')
592 $crawler = $client->request('GET', '/tagging-rule/edit/' . $rule->getId());
594 $this->assertSame(403, $client->getResponse()->getStatusCode());
595 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
596 $this->assertContains('You can not access this tagging rule', $body[0]);
599 public function testDemoMode()
601 $this->logInAs('admin');
602 $client = $this->getClient();
604 $config = $client->getContainer()->get('craue_config');
605 $config->set('demo_mode_enabled', 1);
606 $config->set('demo_mode_username', 'admin');
608 $crawler = $client->request('GET', '/config');
610 $this->assertSame(200, $client->getResponse()->getStatusCode());
612 $form = $crawler->filter('button[id=change_passwd_save]')->form();
615 'change_passwd[old_password]' => 'mypassword',
616 'change_passwd[new_password][first]' => 'mypassword',
617 'change_passwd[new_password][second]' => 'mypassword',
620 $client->submit($form, $data);
622 $this->assertSame(302, $client->getResponse()->getStatusCode());
623 $this->assertContains('flashes.config.notice.password_not_updated_demo', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]);
625 $config->set('demo_mode_enabled', 0);
626 $config->set('demo_mode_username', 'wallabag');
629 public function testDeleteUserButtonVisibility()
631 $this->logInAs('admin');
632 $client = $this->getClient();
634 $crawler = $client->request('GET', '/config');
636 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
637 $this->assertContains('config.form_user.delete.button', $body[0]);
639 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
642 ->getRepository('WallabagUserBundle:User')
643 ->findOneByUsername('empty');
644 $user->setEnabled(false);
648 ->getRepository('WallabagUserBundle:User')
649 ->findOneByUsername('bob');
650 $user->setEnabled(false);
655 $crawler = $client->request('GET', '/config');
657 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
658 $this->assertNotContains('config.form_user.delete.button', $body[0]);
660 $client->request('GET', '/account/delete');
661 $this->assertSame(403, $client->getResponse()->getStatusCode());
664 ->getRepository('WallabagUserBundle:User')
665 ->findOneByUsername('empty');
666 $user->setEnabled(true);
670 ->getRepository('WallabagUserBundle:User')
671 ->findOneByUsername('bob');
672 $user->setEnabled(true);
678 public function testDeleteAccount()
680 $client = $this->getClient();
681 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
684 $user->setName('Wallace');
685 $user->setEmail('wallace@wallabag.org');
686 $user->setUsername('wallace');
687 $user->setPlainPassword('wallace');
688 $user->setEnabled(true);
689 $user->addRole('ROLE_SUPER_ADMIN');
693 $config = new Config($user);
695 $config->setTheme('material');
696 $config->setItemsPerPage(30);
697 $config->setReadingSpeed(1);
698 $config->setLanguage('en');
699 $config->setPocketConsumerKey('xxxxx');
701 $em->persist($config);
704 $this->logInAs('wallace');
705 $loggedInUserId = $this->getLoggedInUserId();
707 // create entry to check after user deletion
708 // that this entry is also deleted
709 $crawler = $client->request('GET', '/new');
711 $this->assertSame(200, $client->getResponse()->getStatusCode());
713 $form = $crawler->filter('form[name=entry]')->form();
715 'entry[url]' => $url = 'https://github.com/wallabag/wallabag',
718 $client->submit($form, $data);
719 $this->assertSame(302, $client->getResponse()->getStatusCode());
721 $crawler = $client->request('GET', '/config');
723 $deleteLink = $crawler->filter('.delete-account')->last()->link();
725 $client->click($deleteLink);
726 $this->assertSame(302, $client->getResponse()->getStatusCode());
728 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
730 ->getRepository('WallabagUserBundle:User')
731 ->createQueryBuilder('u')
732 ->where('u.username = :username')->setParameter('username', 'wallace')
734 ->getOneOrNullResult()
737 $this->assertNull($user);
739 $entries = $client->getContainer()
740 ->get('doctrine.orm.entity_manager')
741 ->getRepository('WallabagCoreBundle:Entry')
742 ->findByUser($loggedInUserId);
744 $this->assertEmpty($entries);
747 public function testReset()
749 $this->logInAs('empty');
750 $client = $this->getClient();
752 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
754 $user = static::$kernel->getContainer()->get('security.token_storage')->getToken()->getUser();
757 $tag->setLabel('super');
760 $entry = new Entry($user);
761 $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');
762 $entry->setContent('Youhou');
763 $entry->setTitle('Youhou');
764 $entry->addTag($tag);
765 $em->persist($entry);
767 $entry2 = new Entry($user);
768 $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');
769 $entry2->setContent('Youhou');
770 $entry2->setTitle('Youhou');
771 $entry2->addTag($tag);
772 $em->persist($entry2);
774 $annotation = new Annotation($user);
775 $annotation->setText('annotated');
776 $annotation->setQuote('annotated');
777 $annotation->setRanges([]);
778 $annotation->setEntry($entry);
779 $em->persist($annotation);
784 $crawler = $client->request('GET', '/config#set3');
786 $this->assertSame(200, $client->getResponse()->getStatusCode());
788 $crawler = $client->click($crawler->selectLink('config.reset.annotations')->link());
790 $this->assertSame(302, $client->getResponse()->getStatusCode());
791 $this->assertContains('flashes.config.notice.annotations_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]);
793 $annotationsReset = $em
794 ->getRepository('WallabagAnnotationBundle:Annotation')
795 ->findAnnotationsByPageId($entry->getId(), $user->getId());
797 $this->assertEmpty($annotationsReset, 'Annotations were reset');
800 $crawler = $client->request('GET', '/config#set3');
802 $this->assertSame(200, $client->getResponse()->getStatusCode());
804 $crawler = $client->click($crawler->selectLink('config.reset.tags')->link());
806 $this->assertSame(302, $client->getResponse()->getStatusCode());
807 $this->assertContains('flashes.config.notice.tags_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]);
810 ->getRepository('WallabagCoreBundle:Tag')
811 ->countAllTags($user->getId());
813 $this->assertSame(0, $tagReset, 'Tags were reset');
816 $crawler = $client->request('GET', '/config#set3');
818 $this->assertSame(200, $client->getResponse()->getStatusCode());
820 $crawler = $client->click($crawler->selectLink('config.reset.entries')->link());
822 $this->assertSame(302, $client->getResponse()->getStatusCode());
823 $this->assertContains('flashes.config.notice.entries_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]);
826 ->getRepository('WallabagCoreBundle:Entry')
827 ->countAllEntriesByUser($user->getId());
829 $this->assertSame(0, $entryReset, 'Entries were reset');
832 public function testResetArchivedEntries()
834 $this->logInAs('empty');
835 $client = $this->getClient();
837 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
839 $user = static::$kernel->getContainer()->get('security.token_storage')->getToken()->getUser();
842 $tag->setLabel('super');
845 $entry = new Entry($user);
846 $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');
847 $entry->setContent('Youhou');
848 $entry->setTitle('Youhou');
849 $entry->addTag($tag);
850 $em->persist($entry);
852 $annotation = new Annotation($user);
853 $annotation->setText('annotated');
854 $annotation->setQuote('annotated');
855 $annotation->setRanges([]);
856 $annotation->setEntry($entry);
857 $em->persist($annotation);
859 $tagArchived = new Tag();
860 $tagArchived->setLabel('super');
861 $em->persist($tagArchived);
863 $entryArchived = new Entry($user);
864 $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');
865 $entryArchived->setContent('Youhou');
866 $entryArchived->setTitle('Youhou');
867 $entryArchived->addTag($tagArchived);
868 $entryArchived->updateArchived(true);
869 $em->persist($entryArchived);
871 $annotationArchived = new Annotation($user);
872 $annotationArchived->setText('annotated');
873 $annotationArchived->setQuote('annotated');
874 $annotationArchived->setRanges([]);
875 $annotationArchived->setEntry($entryArchived);
876 $em->persist($annotationArchived);
880 $crawler = $client->request('GET', '/config#set3');
882 $this->assertSame(200, $client->getResponse()->getStatusCode());
884 $crawler = $client->click($crawler->selectLink('config.reset.archived')->link());
886 $this->assertSame(302, $client->getResponse()->getStatusCode());
887 $this->assertContains('flashes.config.notice.archived_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]);
890 ->getRepository('WallabagCoreBundle:Entry')
891 ->countAllEntriesByUser($user->getId());
893 $this->assertSame(1, $entryReset, 'Entries were reset');
896 ->getRepository('WallabagCoreBundle:Tag')
897 ->countAllTags($user->getId());
899 $this->assertSame(1, $tagReset, 'Tags were reset');
901 $annotationsReset = $em
902 ->getRepository('WallabagAnnotationBundle:Annotation')
903 ->findAnnotationsByPageId($annotationArchived->getId(), $user->getId());
905 $this->assertEmpty($annotationsReset, 'Annotations were reset');
908 public function testResetEntriesCascade()
910 $this->logInAs('empty');
911 $client = $this->getClient();
913 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
915 $user = static::$kernel->getContainer()->get('security.token_storage')->getToken()->getUser();
918 $tag->setLabel('super');
921 $entry = new Entry($user);
922 $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');
923 $entry->setContent('Youhou');
924 $entry->setTitle('Youhou');
925 $entry->addTag($tag);
926 $em->persist($entry);
928 $annotation = new Annotation($user);
929 $annotation->setText('annotated');
930 $annotation->setQuote('annotated');
931 $annotation->setRanges([]);
932 $annotation->setEntry($entry);
933 $em->persist($annotation);
937 $crawler = $client->request('GET', '/config#set3');
939 $this->assertSame(200, $client->getResponse()->getStatusCode());
941 $crawler = $client->click($crawler->selectLink('config.reset.entries')->link());
943 $this->assertSame(302, $client->getResponse()->getStatusCode());
944 $this->assertContains('flashes.config.notice.entries_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]);
947 ->getRepository('WallabagCoreBundle:Entry')
948 ->countAllEntriesByUser($user->getId());
950 $this->assertSame(0, $entryReset, 'Entries were reset');
953 ->getRepository('WallabagCoreBundle:Tag')
954 ->countAllTags($user->getId());
956 $this->assertSame(0, $tagReset, 'Tags were reset');
958 $annotationsReset = $em
959 ->getRepository('WallabagAnnotationBundle:Annotation')
960 ->findAnnotationsByPageId($entry->getId(), $user->getId());
962 $this->assertEmpty($annotationsReset, 'Annotations were reset');
965 public function testSwitchViewMode()
967 $this->logInAs('admin');
968 $this->useTheme('baggy');
969 $client = $this->getClient();
971 $client->request('GET', '/unread/list');
973 $this->assertNotContains('listmode', $client->getResponse()->getContent());
975 $client->request('GET', '/config/view-mode');
976 $crawler = $client->followRedirect();
978 $client->request('GET', '/unread/list');
980 $this->assertContains('listmode', $client->getResponse()->getContent());
982 $client->request('GET', '/config/view-mode');
985 public function testChangeLocaleWithoutReferer()
987 $client = $this->getClient();
989 $client->request('GET', '/locale/de');
990 $client->followRedirect();
992 $this->assertSame('de', $client->getRequest()->getLocale());
993 $this->assertSame('de', $client->getContainer()->get('session')->get('_locale'));
996 public function testChangeLocaleWithReferer()
998 $client = $this->getClient();
1000 $client->request('GET', '/login');
1001 $client->request('GET', '/locale/de');
1002 $client->followRedirect();
1004 $this->assertSame('de', $client->getRequest()->getLocale());
1005 $this->assertSame('de', $client->getContainer()->get('session')->get('_locale'));
1008 public function testChangeLocaleToBadLocale()
1010 $client = $this->getClient();
1012 $client->request('GET', '/login');
1013 $client->request('GET', '/locale/yuyuyuyu');
1014 $client->followRedirect();
1016 $this->assertNotSame('yuyuyuyu', $client->getRequest()->getLocale());
1017 $this->assertNotSame('yuyuyuyu', $client->getContainer()->get('session')->get('_locale'));
1020 public function testUserEnable2faEmail()
1022 $this->logInAs('admin');
1023 $client = $this->getClient();
1025 $crawler = $client->request('GET', '/config/otp/email');
1027 $this->assertSame(302, $client->getResponse()->getStatusCode());
1029 $crawler = $client->followRedirect();
1031 $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text']));
1032 $this->assertContains('flashes.config.notice.otp_enabled', $alert[0]);
1035 $em = $this->getEntityManager();
1037 ->getRepository('WallabagUserBundle:User')
1038 ->findOneByUsername('admin');
1040 $this->assertTrue($user->isEmailTwoFactor());
1042 $user->setEmailTwoFactor(false);
1043 $em->persist($user);
1047 public function testUserEnable2faGoogle()
1049 $this->logInAs('admin');
1050 $client = $this->getClient();
1052 $crawler = $client->request('GET', '/config/otp/app');
1054 $this->assertSame(200, $client->getResponse()->getStatusCode());
1057 $em = $this->getEntityManager();
1059 ->getRepository('WallabagUserBundle:User')
1060 ->findOneByUsername('admin');
1062 $this->assertTrue($user->isGoogleTwoFactor());
1063 $this->assertGreaterThan(0, $user->getBackupCodes());
1065 $user->setGoogleAuthenticatorSecret(false);
1066 $user->setBackupCodes(null);
1067 $em->persist($user);
1071 public function testUserEnable2faGoogleCancel()
1073 $this->logInAs('admin');
1074 $client = $this->getClient();
1076 $crawler = $client->request('GET', '/config/otp/app');
1078 $this->assertSame(200, $client->getResponse()->getStatusCode());
1081 $em = $this->getEntityManager();
1083 ->getRepository('WallabagUserBundle:User')
1084 ->findOneByUsername('admin');
1086 $this->assertTrue($user->isGoogleTwoFactor());
1087 $this->assertGreaterThan(0, $user->getBackupCodes());
1089 $crawler = $client->request('GET', '/config/otp/app/cancel');
1091 $this->assertSame(302, $client->getResponse()->getStatusCode());
1094 ->getRepository('WallabagUserBundle:User')
1095 ->findOneByUsername('admin');
1097 $this->assertFalse($user->isGoogleTwoFactor());
1098 $this->assertEmpty($user->getBackupCodes());