3 namespace Tests\Wallabag\CoreBundle\Controller
;
5 use Symfony\Component\HttpFoundation\File\UploadedFile
;
6 use Tests\Wallabag\CoreBundle\WallabagCoreTestCase
;
7 use Wallabag\AnnotationBundle\Entity\Annotation
;
8 use Wallabag\CoreBundle\Entity\Config
;
9 use Wallabag\CoreBundle\Entity\Entry
;
10 use Wallabag\CoreBundle\Entity\Tag
;
11 use Wallabag\UserBundle\Entity\User
;
13 class ConfigControllerTest
extends WallabagCoreTestCase
15 public function testLogin()
17 $client = $this->getClient();
19 $client->request('GET', '/new');
21 $this->assertSame(302, $client->getResponse()->getStatusCode());
22 $this->assertContains('login', $client->getResponse()->headers
->get('location'));
25 public function testIndex()
27 $this->logInAs('admin');
28 $client = $this->getClient();
30 $crawler = $client->request('GET', '/config');
32 $this->assertSame(200, $client->getResponse()->getStatusCode());
34 $this->assertCount(1, $crawler->filter('button[id=config_save]'));
35 $this->assertCount(1, $crawler->filter('button[id=change_passwd_save]'));
36 $this->assertCount(1, $crawler->filter('button[id=update_user_save]'));
37 $this->assertCount(1, $crawler->filter('button[id=feed_config_save]'));
40 public function testUpdate()
42 $this->logInAs('admin');
43 $client = $this->getClient();
45 $crawler = $client->request('GET', '/config');
47 $this->assertSame(200, $client->getResponse()->getStatusCode());
49 $form = $crawler->filter('button[id=config_save]')->form();
52 'config[theme]' => 'baggy',
53 'config[items_per_page]' => '30',
54 'config[reading_speed]' => '100',
55 'config[action_mark_as_read]' => '0',
56 'config[language]' => 'en',
59 $client->submit($form, $data);
61 $this->assertSame(302, $client->getResponse()->getStatusCode());
63 $crawler = $client->followRedirect();
65 $this->assertContains('flashes.config.notice.config_saved', $crawler->filter('body')->extract(['_text'])[0]);
68 public function testChangeReadingSpeed()
70 $this->logInAs('admin');
71 $this->useTheme('baggy');
72 $client = $this->getClient();
74 $entry = new Entry($this->getLoggedInUser());
75 $entry->setUrl('http://0.0.0.0/test-entry1')
77 $this->getEntityManager()->persist($entry);
79 $this->getEntityManager()->flush();
80 $this->getEntityManager()->clear();
82 $crawler = $client->request('GET', '/unread/list');
83 $form = $crawler->filter('button[id=submit-filter]')->form();
85 'entry_filter[readingTime][right_number]' => 22,
86 'entry_filter[readingTime][left_number]' => 22,
88 $crawler = $client->submit($form, $dataFilters);
89 $this->assertCount(1, $crawler->filter('div[class=entry]'));
91 // Change reading speed
92 $crawler = $client->request('GET', '/config');
93 $form = $crawler->filter('button[id=config_save]')->form();
95 'config[reading_speed]' => '400',
97 $client->submit($form, $data);
99 // Is the entry still available via filters?
100 $crawler = $client->request('GET', '/unread/list');
101 $form = $crawler->filter('button[id=submit-filter]')->form();
102 $crawler = $client->submit($form, $dataFilters);
103 $this->assertCount(0, $crawler->filter('div[class=entry]'));
105 // Restore old configuration
106 $crawler = $client->request('GET', '/config');
107 $form = $crawler->filter('button[id=config_save]')->form();
109 'config[reading_speed]' => '100',
111 $client->submit($form, $data);
114 public function dataForUpdateFailed()
118 'config[theme]' => 'baggy',
119 'config[items_per_page]' => '',
120 'config[language]' => 'en',
126 * @dataProvider dataForUpdateFailed
128 public function testUpdateFailed($data)
130 $this->logInAs('admin');
131 $client = $this->getClient();
133 $crawler = $client->request('GET', '/config');
135 $this->assertSame(200, $client->getResponse()->getStatusCode());
137 $form = $crawler->filter('button[id=config_save]')->form();
139 $crawler = $client->submit($form, $data);
141 $this->assertSame(200, $client->getResponse()->getStatusCode());
143 $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text']));
144 $this->assertContains('This value should not be blank', $alert[0]);
147 public function dataForChangePasswordFailed()
152 'change_passwd[old_password]' => 'material',
153 'change_passwd[new_password][first]' => '',
154 'change_passwd[new_password][second]' => '',
156 'validator.password_wrong_value',
160 'change_passwd[old_password]' => 'mypassword',
161 'change_passwd[new_password][first]' => '',
162 'change_passwd[new_password][second]' => '',
164 'This value should not be blank',
168 'change_passwd[old_password]' => 'mypassword',
169 'change_passwd[new_password][first]' => 'hop',
170 'change_passwd[new_password][second]' => '',
172 'validator.password_must_match',
176 'change_passwd[old_password]' => 'mypassword',
177 'change_passwd[new_password][first]' => 'hop',
178 'change_passwd[new_password][second]' => 'hop',
180 'validator.password_too_short',
186 * @dataProvider dataForChangePasswordFailed
188 public function testChangePasswordFailed($data, $expectedMessage)
190 $this->logInAs('admin');
191 $client = $this->getClient();
193 $crawler = $client->request('GET', '/config');
195 $this->assertSame(200, $client->getResponse()->getStatusCode());
197 $form = $crawler->filter('button[id=change_passwd_save]')->form();
199 $crawler = $client->submit($form, $data);
201 $this->assertSame(200, $client->getResponse()->getStatusCode());
203 $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text']));
204 $this->assertContains($expectedMessage, $alert[0]);
207 public function testChangePassword()
209 $this->logInAs('admin');
210 $client = $this->getClient();
212 $crawler = $client->request('GET', '/config');
214 $this->assertSame(200, $client->getResponse()->getStatusCode());
216 $form = $crawler->filter('button[id=change_passwd_save]')->form();
219 'change_passwd[old_password]' => 'mypassword',
220 'change_passwd[new_password][first]' => 'mypassword',
221 'change_passwd[new_password][second]' => 'mypassword',
224 $client->submit($form, $data);
226 $this->assertSame(302, $client->getResponse()->getStatusCode());
228 $crawler = $client->followRedirect();
230 $this->assertContains('flashes.config.notice.password_updated', $crawler->filter('body')->extract(['_text'])[0]);
233 public function dataForUserFailed()
238 'update_user[name]' => '',
239 'update_user[email]' => '',
241 'fos_user.email.blank',
245 'update_user[name]' => '',
246 'update_user[email]' => 'test',
248 'fos_user.email.invalid',
254 * @dataProvider dataForUserFailed
256 public function testUserFailed($data, $expectedMessage)
258 $this->logInAs('admin');
259 $client = $this->getClient();
261 $crawler = $client->request('GET', '/config');
263 $this->assertSame(200, $client->getResponse()->getStatusCode());
265 $form = $crawler->filter('button[id=update_user_save]')->form();
267 $crawler = $client->submit($form, $data);
269 $this->assertSame(200, $client->getResponse()->getStatusCode());
271 $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text']));
272 $this->assertContains($expectedMessage, $alert[0]);
275 public function testUserUpdate()
277 $this->logInAs('admin');
278 $client = $this->getClient();
280 $crawler = $client->request('GET', '/config');
282 $this->assertSame(200, $client->getResponse()->getStatusCode());
284 $form = $crawler->filter('button[id=update_user_save]')->form();
287 'update_user[name]' => 'new name',
288 'update_user[email]' => 'admin@wallabag.io',
291 $client->submit($form, $data);
293 $this->assertSame(302, $client->getResponse()->getStatusCode());
295 $crawler = $client->followRedirect();
297 $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text']));
298 $this->assertContains('flashes.config.notice.user_updated', $alert[0]);
301 public function testFeedUpdateResetToken()
303 $this->logInAs('admin');
304 $client = $this->getClient();
307 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
309 ->getRepository('WallabagUserBundle:User')
310 ->findOneByUsername('admin');
313 $this->markTestSkipped('No user found in db.');
316 $config = $user->getConfig();
317 $config->setFeedToken(null);
318 $em->persist($config);
321 $crawler = $client->request('GET', '/config');
323 $this->assertSame(200, $client->getResponse()->getStatusCode());
325 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
326 $this->assertContains('config.form_feed.no_token', $body[0]);
328 $client->request('GET', '/generate-token');
329 $this->assertSame(302, $client->getResponse()->getStatusCode());
331 $crawler = $client->followRedirect();
333 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
334 $this->assertContains('config.form_feed.token_reset', $body[0]);
337 public function testGenerateTokenAjax()
339 $this->logInAs('admin');
340 $client = $this->getClient();
347 ['HTTP_X-Requested-With' => 'XMLHttpRequest']
350 $this->assertSame(200, $client->getResponse()->getStatusCode());
351 $content = json_decode($client->getResponse()->getContent(), true);
352 $this->assertArrayHasKey('token', $content);
355 public function testRevokeTokenAjax()
357 $this->logInAs('admin');
358 $client = $this->getClient();
365 ['HTTP_X-Requested-With' => 'XMLHttpRequest']
368 $this->assertSame(200, $client->getResponse()->getStatusCode());
371 public function testFeedUpdate()
373 $this->logInAs('admin');
374 $client = $this->getClient();
376 $crawler = $client->request('GET', '/config');
378 $this->assertSame(200, $client->getResponse()->getStatusCode());
380 $form = $crawler->filter('button[id=feed_config_save]')->form();
383 'feed_config[feed_limit]' => 12,
386 $client->submit($form, $data);
388 $this->assertSame(302, $client->getResponse()->getStatusCode());
390 $crawler = $client->followRedirect();
392 $this->assertContains('flashes.config.notice.feed_updated', $crawler->filter('body')->extract(['_text'])[0]);
395 public function dataForFeedFailed()
400 'feed_config[feed_limit]' => 0,
402 'This value should be 1 or more.',
406 'feed_config[feed_limit]' => 1000000000000,
408 'validator.feed_limit_too_high',
414 * @dataProvider dataForFeedFailed
416 public function testFeedFailed($data, $expectedMessage)
418 $this->logInAs('admin');
419 $client = $this->getClient();
421 $crawler = $client->request('GET', '/config');
423 $this->assertSame(200, $client->getResponse()->getStatusCode());
425 $form = $crawler->filter('button[id=feed_config_save]')->form();
427 $crawler = $client->submit($form, $data);
429 $this->assertSame(200, $client->getResponse()->getStatusCode());
431 $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text']));
432 $this->assertContains($expectedMessage, $alert[0]);
435 public function testTaggingRuleCreation()
437 $this->logInAs('admin');
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('div[id=set5] a.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('div[id=set5] a.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/delete/' . $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 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 rule', $body[0]);
599 public function testIgnoreOriginRuleCreation()
601 $this->logInAs('admin');
602 $client = $this->getClient();
604 $crawler = $client->request('GET', '/config');
606 $this->assertSame(200, $client->getResponse()->getStatusCode());
608 $form = $crawler->filter('button[id=ignore_origin_user_rule_save]')->form();
611 'ignore_origin_user_rule[rule]' => 'host = "example.com"',
614 $client->submit($form, $data);
616 $this->assertSame(302, $client->getResponse()->getStatusCode());
618 $crawler = $client->followRedirect();
620 $this->assertContains('flashes.config.notice.ignore_origin_rules_updated', $crawler->filter('body')->extract(['_text'])[0]);
622 $editLink = $crawler->filter('div[id=set6] a.mode_edit')->last()->link();
624 $crawler = $client->click($editLink);
625 $this->assertSame(302, $client->getResponse()->getStatusCode());
626 $this->assertContains('?ignore-origin-user-rule=', $client->getResponse()->headers
->get('location'));
628 $crawler = $client->followRedirect();
630 $form = $crawler->filter('button[id=ignore_origin_user_rule_save]')->form();
633 'ignore_origin_user_rule[rule]' => 'host = "example.org"',
636 $client->submit($form, $data);
638 $this->assertSame(302, $client->getResponse()->getStatusCode());
640 $crawler = $client->followRedirect();
642 $this->assertContains('flashes.config.notice.ignore_origin_rules_updated', $crawler->filter('body')->extract(['_text'])[0]);
644 $this->assertContains('host = "example.org"', $crawler->filter('body')->extract(['_text'])[0]);
646 $deleteLink = $crawler->filter('div[id=set6] a.delete')->last()->link();
648 $crawler = $client->click($deleteLink);
649 $this->assertSame(302, $client->getResponse()->getStatusCode());
651 $crawler = $client->followRedirect();
652 $this->assertContains('flashes.config.notice.ignore_origin_rules_deleted', $crawler->filter('body')->extract(['_text'])[0]);
655 public function dataForIgnoreOriginRuleCreationFail()
660 'ignore_origin_user_rule[rule]' => 'foo = "bar"',
669 'ignore_origin_user_rule[rule]' => '_all != "none"',
680 * @dataProvider dataForIgnoreOriginRuleCreationFail
682 public function testIgnoreOriginRuleCreationFail($data, $messages)
684 $this->logInAs('admin');
685 $client = $this->getClient();
687 $crawler = $client->request('GET', '/config');
689 $this->assertSame(200, $client->getResponse()->getStatusCode());
691 $form = $crawler->filter('button[id=ignore_origin_user_rule_save]')->form();
693 $crawler = $client->submit($form, $data);
695 $this->assertSame(200, $client->getResponse()->getStatusCode());
697 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
699 foreach ($messages as $message) {
700 $this->assertContains($message, $body[0]);
704 public function testDeletingIgnoreOriginRuleFromAnOtherUser()
706 $this->logInAs('bob');
707 $client = $this->getClient();
709 $rule = $client->getContainer()->get('doctrine.orm.entity_manager')
710 ->getRepository('WallabagCoreBundle:IgnoreOriginUserRule')
713 $crawler = $client->request('GET', '/ignore-origin-user-rule/edit/' . $rule->getId());
715 $this->assertSame(403, $client->getResponse()->getStatusCode());
716 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
717 $this->assertContains('You can not access this rule', $body[0]);
720 public function testEditingIgnoreOriginRuleFromAnOtherUser()
722 $this->logInAs('bob');
723 $client = $this->getClient();
725 $rule = $client->getContainer()->get('doctrine.orm.entity_manager')
726 ->getRepository('WallabagCoreBundle:IgnoreOriginUserRule')
729 $crawler = $client->request('GET', '/ignore-origin-user-rule/edit/' . $rule->getId());
731 $this->assertSame(403, $client->getResponse()->getStatusCode());
732 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
733 $this->assertContains('You can not access this rule', $body[0]);
736 public function testDemoMode()
738 $this->logInAs('admin');
739 $client = $this->getClient();
741 $config = $client->getContainer()->get('craue_config');
742 $config->set('demo_mode_enabled', 1);
743 $config->set('demo_mode_username', 'admin');
745 $crawler = $client->request('GET', '/config');
747 $this->assertSame(200, $client->getResponse()->getStatusCode());
749 $form = $crawler->filter('button[id=change_passwd_save]')->form();
752 'change_passwd[old_password]' => 'mypassword',
753 'change_passwd[new_password][first]' => 'mypassword',
754 'change_passwd[new_password][second]' => 'mypassword',
757 $client->submit($form, $data);
759 $this->assertSame(302, $client->getResponse()->getStatusCode());
760 $this->assertContains('flashes.config.notice.password_not_updated_demo', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]);
762 $config->set('demo_mode_enabled', 0);
763 $config->set('demo_mode_username', 'wallabag');
766 public function testDeleteUserButtonVisibility()
768 $this->logInAs('admin');
769 $client = $this->getClient();
771 $crawler = $client->request('GET', '/config');
773 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
774 $this->assertContains('config.form_user.delete.button', $body[0]);
776 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
779 ->getRepository('WallabagUserBundle:User')
780 ->findOneByUsername('empty');
781 $user->setEnabled(false);
785 ->getRepository('WallabagUserBundle:User')
786 ->findOneByUsername('bob');
787 $user->setEnabled(false);
792 $crawler = $client->request('GET', '/config');
794 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
795 $this->assertNotContains('config.form_user.delete.button', $body[0]);
797 $client->request('GET', '/account/delete');
798 $this->assertSame(403, $client->getResponse()->getStatusCode());
801 ->getRepository('WallabagUserBundle:User')
802 ->findOneByUsername('empty');
803 $user->setEnabled(true);
807 ->getRepository('WallabagUserBundle:User')
808 ->findOneByUsername('bob');
809 $user->setEnabled(true);
816 * @group NetworkCalls
818 public function testDeleteAccount()
820 $client = $this->getClient();
821 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
824 $user->setName('Wallace');
825 $user->setEmail('wallace@wallabag.org');
826 $user->setUsername('wallace');
827 $user->setPlainPassword('wallace');
828 $user->setEnabled(true);
829 $user->addRole('ROLE_SUPER_ADMIN');
833 $config = new Config($user);
835 $config->setTheme('material');
836 $config->setItemsPerPage(30);
837 $config->setReadingSpeed(200);
838 $config->setLanguage('en');
839 $config->setPocketConsumerKey('xxxxx');
841 $em->persist($config);
844 $this->logInAs('wallace');
845 $loggedInUserId = $this->getLoggedInUserId();
847 // create entry to check after user deletion
848 // that this entry is also deleted
849 $crawler = $client->request('GET', '/new');
851 $this->assertSame(200, $client->getResponse()->getStatusCode());
853 $form = $crawler->filter('form[name=entry]')->form();
855 'entry[url]' => $url = 'https://github.com/wallabag/wallabag',
858 $client->submit($form, $data);
859 $this->assertSame(302, $client->getResponse()->getStatusCode());
861 $crawler = $client->request('GET', '/config');
863 $deleteLink = $crawler->filter('.delete-account')->last()->link();
865 $client->click($deleteLink);
866 $this->assertSame(302, $client->getResponse()->getStatusCode());
868 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
870 ->getRepository('WallabagUserBundle:User')
871 ->createQueryBuilder('u')
872 ->where('u.username = :username')->setParameter('username', 'wallace')
874 ->getOneOrNullResult()
877 $this->assertNull($user);
879 $entries = $client->getContainer()
880 ->get('doctrine.orm.entity_manager')
881 ->getRepository('WallabagCoreBundle:Entry')
882 ->findByUser($loggedInUserId);
884 $this->assertEmpty($entries);
887 public function testReset()
889 $this->logInAs('empty');
890 $client = $this->getClient();
892 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
894 $user = static::$kernel->getContainer()->get('security.token_storage')->getToken()->getUser();
897 $tag->setLabel('super');
900 $entry = new Entry($user);
901 $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');
902 $entry->setContent('Youhou');
903 $entry->setTitle('Youhou');
904 $entry->addTag($tag);
905 $em->persist($entry);
907 $entry2 = new Entry($user);
908 $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');
909 $entry2->setContent('Youhou');
910 $entry2->setTitle('Youhou');
911 $entry2->addTag($tag);
912 $em->persist($entry2);
914 $annotation = new Annotation($user);
915 $annotation->setText('annotated');
916 $annotation->setQuote('annotated');
917 $annotation->setRanges([]);
918 $annotation->setEntry($entry);
919 $em->persist($annotation);
924 $crawler = $client->request('GET', '/config#set3');
926 $this->assertSame(200, $client->getResponse()->getStatusCode());
928 $crawler = $client->click($crawler->selectLink('config.reset.annotations')->link());
930 $this->assertSame(302, $client->getResponse()->getStatusCode());
931 $this->assertContains('flashes.config.notice.annotations_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]);
933 $annotationsReset = $em
934 ->getRepository('WallabagAnnotationBundle:Annotation')
935 ->findAnnotationsByPageId($entry->getId(), $user->getId());
937 $this->assertEmpty($annotationsReset, 'Annotations were reset');
940 $crawler = $client->request('GET', '/config#set3');
942 $this->assertSame(200, $client->getResponse()->getStatusCode());
944 $crawler = $client->click($crawler->selectLink('config.reset.tags')->link());
946 $this->assertSame(302, $client->getResponse()->getStatusCode());
947 $this->assertContains('flashes.config.notice.tags_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]);
950 ->getRepository('WallabagCoreBundle:Tag')
951 ->countAllTags($user->getId());
953 $this->assertSame(0, $tagReset, 'Tags were reset');
956 $crawler = $client->request('GET', '/config#set3');
958 $this->assertSame(200, $client->getResponse()->getStatusCode());
960 $crawler = $client->click($crawler->selectLink('config.reset.entries')->link());
962 $this->assertSame(302, $client->getResponse()->getStatusCode());
963 $this->assertContains('flashes.config.notice.entries_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]);
966 ->getRepository('WallabagCoreBundle:Entry')
967 ->countAllEntriesByUser($user->getId());
969 $this->assertSame(0, $entryReset, 'Entries were reset');
972 public function testResetArchivedEntries()
974 $this->logInAs('empty');
975 $client = $this->getClient();
977 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
979 $user = static::$kernel->getContainer()->get('security.token_storage')->getToken()->getUser();
982 $tag->setLabel('super');
985 $entry = new Entry($user);
986 $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');
987 $entry->setContent('Youhou');
988 $entry->setTitle('Youhou');
989 $entry->addTag($tag);
990 $em->persist($entry);
992 $annotation = new Annotation($user);
993 $annotation->setText('annotated');
994 $annotation->setQuote('annotated');
995 $annotation->setRanges([]);
996 $annotation->setEntry($entry);
997 $em->persist($annotation);
999 $tagArchived = new Tag();
1000 $tagArchived->setLabel('super');
1001 $em->persist($tagArchived);
1003 $entryArchived = new Entry($user);
1004 $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');
1005 $entryArchived->setContent('Youhou');
1006 $entryArchived->setTitle('Youhou');
1007 $entryArchived->addTag($tagArchived);
1008 $entryArchived->updateArchived(true);
1009 $em->persist($entryArchived);
1011 $annotationArchived = new Annotation($user);
1012 $annotationArchived->setText('annotated');
1013 $annotationArchived->setQuote('annotated');
1014 $annotationArchived->setRanges([]);
1015 $annotationArchived->setEntry($entryArchived);
1016 $em->persist($annotationArchived);
1020 $crawler = $client->request('GET', '/config#set3');
1022 $this->assertSame(200, $client->getResponse()->getStatusCode());
1024 $crawler = $client->click($crawler->selectLink('config.reset.archived')->link());
1026 $this->assertSame(302, $client->getResponse()->getStatusCode());
1027 $this->assertContains('flashes.config.notice.archived_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]);
1030 ->getRepository('WallabagCoreBundle:Entry')
1031 ->countAllEntriesByUser($user->getId());
1033 $this->assertSame(1, $entryReset, 'Entries were reset');
1036 ->getRepository('WallabagCoreBundle:Tag')
1037 ->countAllTags($user->getId());
1039 $this->assertSame(1, $tagReset, 'Tags were reset');
1041 $annotationsReset = $em
1042 ->getRepository('WallabagAnnotationBundle:Annotation')
1043 ->findAnnotationsByPageId($annotationArchived->getId(), $user->getId());
1045 $this->assertEmpty($annotationsReset, 'Annotations were reset');
1048 public function testResetEntriesCascade()
1050 $this->logInAs('empty');
1051 $client = $this->getClient();
1053 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
1055 $user = static::$kernel->getContainer()->get('security.token_storage')->getToken()->getUser();
1058 $tag->setLabel('super');
1061 $entry = new Entry($user);
1062 $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');
1063 $entry->setContent('Youhou');
1064 $entry->setTitle('Youhou');
1065 $entry->addTag($tag);
1066 $em->persist($entry);
1068 $annotation = new Annotation($user);
1069 $annotation->setText('annotated');
1070 $annotation->setQuote('annotated');
1071 $annotation->setRanges([]);
1072 $annotation->setEntry($entry);
1073 $em->persist($annotation);
1077 $crawler = $client->request('GET', '/config#set3');
1079 $this->assertSame(200, $client->getResponse()->getStatusCode());
1081 $crawler = $client->click($crawler->selectLink('config.reset.entries')->link());
1083 $this->assertSame(302, $client->getResponse()->getStatusCode());
1084 $this->assertContains('flashes.config.notice.entries_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]);
1087 ->getRepository('WallabagCoreBundle:Entry')
1088 ->countAllEntriesByUser($user->getId());
1090 $this->assertSame(0, $entryReset, 'Entries were reset');
1093 ->getRepository('WallabagCoreBundle:Tag')
1094 ->countAllTags($user->getId());
1096 $this->assertSame(0, $tagReset, 'Tags were reset');
1098 $annotationsReset = $em
1099 ->getRepository('WallabagAnnotationBundle:Annotation')
1100 ->findAnnotationsByPageId($entry->getId(), $user->getId());
1102 $this->assertEmpty($annotationsReset, 'Annotations were reset');
1105 public function testSwitchViewMode()
1107 $this->logInAs('admin');
1108 $this->useTheme('baggy');
1109 $client = $this->getClient();
1111 $client->request('GET', '/unread/list');
1113 $this->assertNotContains('listmode', $client->getResponse()->getContent());
1115 $client->request('GET', '/config/view-mode');
1116 $crawler = $client->followRedirect();
1118 $client->request('GET', '/unread/list');
1120 $this->assertContains('listmode', $client->getResponse()->getContent());
1122 $client->request('GET', '/config/view-mode');
1125 public function testChangeLocaleWithoutReferer()
1127 $client = $this->getClient();
1129 $client->request('GET', '/locale/de');
1130 $client->followRedirect();
1132 $this->assertSame('de', $client->getRequest()->getLocale());
1133 $this->assertSame('de', $client->getContainer()->get('session')->get('_locale'));
1136 public function testChangeLocaleWithReferer()
1138 $client = $this->getClient();
1140 $client->request('GET', '/login');
1141 $client->request('GET', '/locale/de');
1142 $client->followRedirect();
1144 $this->assertSame('de', $client->getRequest()->getLocale());
1145 $this->assertSame('de', $client->getContainer()->get('session')->get('_locale'));
1148 public function testChangeLocaleToBadLocale()
1150 $client = $this->getClient();
1152 $client->request('GET', '/login');
1153 $client->request('GET', '/locale/yuyuyuyu');
1154 $client->followRedirect();
1156 $this->assertNotSame('yuyuyuyu', $client->getRequest()->getLocale());
1157 $this->assertNotSame('yuyuyuyu', $client->getContainer()->get('session')->get('_locale'));
1160 public function testUserEnable2faEmail()
1162 $this->logInAs('admin');
1163 $client = $this->getClient();
1165 $crawler = $client->request('GET', '/config/otp/email');
1167 $this->assertSame(302, $client->getResponse()->getStatusCode());
1169 $crawler = $client->followRedirect();
1171 $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text']));
1172 $this->assertContains('flashes.config.notice.otp_enabled', $alert[0]);
1175 $em = $this->getEntityManager();
1177 ->getRepository('WallabagUserBundle:User')
1178 ->findOneByUsername('admin');
1180 $this->assertTrue($user->isEmailTwoFactor());
1182 $user->setEmailTwoFactor(false);
1183 $em->persist($user);
1187 public function testUserDisable2faEmail()
1189 $this->logInAs('admin');
1190 $client = $this->getClient();
1192 $crawler = $client->request('GET', '/config/otp/email/disable');
1194 $this->assertSame(302, $client->getResponse()->getStatusCode());
1196 $crawler = $client->followRedirect();
1198 $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text']));
1199 $this->assertContains('flashes.config.notice.otp_disabled', $alert[0]);
1202 $em = $this->getEntityManager();
1204 ->getRepository('WallabagUserBundle:User')
1205 ->findOneByUsername('admin');
1207 $this->assertFalse($user->isEmailTwoFactor());
1210 public function testUserEnable2faGoogle()
1212 $this->logInAs('admin');
1213 $client = $this->getClient();
1215 $crawler = $client->request('GET', '/config/otp/app');
1217 $this->assertSame(200, $client->getResponse()->getStatusCode());
1220 $em = $this->getEntityManager();
1222 ->getRepository('WallabagUserBundle:User')
1223 ->findOneByUsername('admin');
1225 $this->assertTrue($user->isGoogleTwoFactor());
1226 $this->assertGreaterThan(0, $user->getBackupCodes());
1228 $user->setGoogleAuthenticatorSecret(false);
1229 $user->setBackupCodes(null);
1230 $em->persist($user);
1234 public function testUserEnable2faGoogleCancel()
1236 $this->logInAs('admin');
1237 $client = $this->getClient();
1239 $crawler = $client->request('GET', '/config/otp/app');
1241 $this->assertSame(200, $client->getResponse()->getStatusCode());
1244 $em = $this->getEntityManager();
1246 ->getRepository('WallabagUserBundle:User')
1247 ->findOneByUsername('admin');
1249 $this->assertTrue($user->isGoogleTwoFactor());
1250 $this->assertGreaterThan(0, $user->getBackupCodes());
1252 $crawler = $client->request('GET', '/config/otp/app/cancel');
1254 $this->assertSame(302, $client->getResponse()->getStatusCode());
1257 ->getRepository('WallabagUserBundle:User')
1258 ->findOneByUsername('admin');
1260 $this->assertFalse($user->isGoogleTwoFactor());
1261 $this->assertEmpty($user->getBackupCodes());
1264 public function testUserDisable2faGoogle()
1266 $this->logInAs('admin');
1267 $client = $this->getClient();
1269 $crawler = $client->request('GET', '/config/otp/app/disable');
1271 $this->assertSame(302, $client->getResponse()->getStatusCode());
1273 $crawler = $client->followRedirect();
1275 $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text']));
1276 $this->assertContains('flashes.config.notice.otp_disabled', $alert[0]);
1279 $em = $this->getEntityManager();
1281 ->getRepository('WallabagUserBundle:User')
1282 ->findOneByUsername('admin');
1284 $this->assertEmpty($user->getGoogleAuthenticatorSecret());
1285 $this->assertEmpty($user->getBackupCodes());
1288 public function testExportTaggingRule()
1290 $this->logInAs('admin');
1291 $client = $this->getClient();
1294 $crawler = $client->request('GET', '/tagging-rule/export');
1297 $this->assertSame(200, $client->getResponse()->getStatusCode());
1299 $headers = $client->getResponse()->headers
;
1300 $this->assertSame('application/json', $headers->get('content-type'));
1301 $this->assertSame('attachment; filename="tagging_rules_admin.json"', $headers->get('content-disposition'));
1302 $this->assertSame('UTF-8', $headers->get('content-transfer-encoding'));
1304 $content = json_decode($client->getResponse()->getContent(), true);
1306 $this->assertCount(4, $content);
1307 $this->assertSame('content matches "spurs"', $content[0]['rule']);
1308 $this->assertSame('sport', $content[0]['tags'][0]);
1311 public function testImportTagginfRuleBadFile()
1313 $this->logInAs('admin');
1314 $client = $this->getClient();
1316 $crawler = $client->request('GET', '/config');
1317 $form = $crawler->filter('form[name=upload_tagging_rule_file] > button[type=submit]')->form();
1320 'upload_tagging_rule_file[file]' => '',
1323 $client->submit($form, $data);
1325 $this->assertSame(302, $client->getResponse()->getStatusCode());
1328 public function testImportTagginfRuleFile()
1330 $this->logInAs('admin');
1331 $client = $this->getClient();
1333 $crawler = $client->request('GET', '/config');
1334 $form = $crawler->filter('form[name=upload_tagging_rule_file] > button[type=submit]')->form();
1336 $file = new UploadedFile(__DIR__
. '/../fixtures/tagging_rules_admin.json', 'tagging_rules_admin.json');
1339 'upload_tagging_rule_file[file]' => $file,
1342 $client->submit($form, $data);
1343 $this->assertSame(302, $client->getResponse()->getStatusCode());
1345 $user = $client->getContainer()->get('fos_user.user_manager.test')->findUserBy(['username' => 'admin']);
1346 $taggingRules = $user->getConfig()->getTaggingRules()->toArray();
1347 $this->assertCount(5, $taggingRules);
1348 $this->assertSame('title matches "football"', $taggingRules[4]->getRule());