]> git.immae.eu Git - github/wallabag/wallabag.git/blob - tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
Fix tests
[github/wallabag/wallabag.git] / tests / Wallabag / CoreBundle / Controller / ConfigControllerTest.php
1 <?php
2
3 namespace tests\Wallabag\CoreBundle\Controller;
4
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;
11
12 class ConfigControllerTest extends WallabagCoreTestCase
13 {
14 public function testLogin()
15 {
16 $client = $this->getClient();
17
18 $client->request('GET', '/new');
19
20 $this->assertSame(302, $client->getResponse()->getStatusCode());
21 $this->assertContains('login', $client->getResponse()->headers->get('location'));
22 }
23
24 public function testIndex()
25 {
26 $this->logInAs('admin');
27 $client = $this->getClient();
28
29 $crawler = $client->request('GET', '/config');
30
31 $this->assertSame(200, $client->getResponse()->getStatusCode());
32
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]'));
37 }
38
39 public function testUpdate()
40 {
41 $this->logInAs('admin');
42 $client = $this->getClient();
43
44 $crawler = $client->request('GET', '/config');
45
46 $this->assertSame(200, $client->getResponse()->getStatusCode());
47
48 $form = $crawler->filter('button[id=config_save]')->form();
49
50 $data = [
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',
56 ];
57
58 $client->submit($form, $data);
59
60 $this->assertSame(302, $client->getResponse()->getStatusCode());
61
62 $crawler = $client->followRedirect();
63
64 $this->assertContains('flashes.config.notice.config_saved', $crawler->filter('body')->extract(['_text'])[0]);
65 }
66
67 public function testChangeReadingSpeed()
68 {
69 $this->logInAs('admin');
70 $this->useTheme('baggy');
71 $client = $this->getClient();
72
73 $entry = new Entry($this->getLoggedInUser());
74 $entry->setUrl('http://0.0.0.0/test-entry1')
75 ->setReadingTime(22);
76 $this->getEntityManager()->persist($entry);
77
78 $this->getEntityManager()->flush();
79 $this->getEntityManager()->clear();
80
81 $crawler = $client->request('GET', '/unread/list');
82 $form = $crawler->filter('button[id=submit-filter]')->form();
83 $dataFilters = [
84 'entry_filter[readingTime][right_number]' => 22,
85 'entry_filter[readingTime][left_number]' => 22,
86 ];
87 $crawler = $client->submit($form, $dataFilters);
88 $this->assertCount(1, $crawler->filter('div[class=entry]'));
89
90 // Change reading speed
91 $crawler = $client->request('GET', '/config');
92 $form = $crawler->filter('button[id=config_save]')->form();
93 $data = [
94 'config[reading_speed]' => '2',
95 ];
96 $client->submit($form, $data);
97
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]'));
103
104 // Restore old configuration
105 $crawler = $client->request('GET', '/config');
106 $form = $crawler->filter('button[id=config_save]')->form();
107 $data = [
108 'config[reading_speed]' => '0.5',
109 ];
110 $client->submit($form, $data);
111 }
112
113 public function dataForUpdateFailed()
114 {
115 return [
116 [[
117 'config[theme]' => 'baggy',
118 'config[items_per_page]' => '',
119 'config[language]' => 'en',
120 ]],
121 ];
122 }
123
124 /**
125 * @dataProvider dataForUpdateFailed
126 */
127 public function testUpdateFailed($data)
128 {
129 $this->logInAs('admin');
130 $client = $this->getClient();
131
132 $crawler = $client->request('GET', '/config');
133
134 $this->assertSame(200, $client->getResponse()->getStatusCode());
135
136 $form = $crawler->filter('button[id=config_save]')->form();
137
138 $crawler = $client->submit($form, $data);
139
140 $this->assertSame(200, $client->getResponse()->getStatusCode());
141
142 $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text']));
143 $this->assertContains('This value should not be blank', $alert[0]);
144 }
145
146 public function dataForChangePasswordFailed()
147 {
148 return [
149 [
150 [
151 'change_passwd[old_password]' => 'material',
152 'change_passwd[new_password][first]' => '',
153 'change_passwd[new_password][second]' => '',
154 ],
155 'validator.password_wrong_value',
156 ],
157 [
158 [
159 'change_passwd[old_password]' => 'mypassword',
160 'change_passwd[new_password][first]' => '',
161 'change_passwd[new_password][second]' => '',
162 ],
163 'This value should not be blank',
164 ],
165 [
166 [
167 'change_passwd[old_password]' => 'mypassword',
168 'change_passwd[new_password][first]' => 'hop',
169 'change_passwd[new_password][second]' => '',
170 ],
171 'validator.password_must_match',
172 ],
173 [
174 [
175 'change_passwd[old_password]' => 'mypassword',
176 'change_passwd[new_password][first]' => 'hop',
177 'change_passwd[new_password][second]' => 'hop',
178 ],
179 'validator.password_too_short',
180 ],
181 ];
182 }
183
184 /**
185 * @dataProvider dataForChangePasswordFailed
186 */
187 public function testChangePasswordFailed($data, $expectedMessage)
188 {
189 $this->logInAs('admin');
190 $client = $this->getClient();
191
192 $crawler = $client->request('GET', '/config');
193
194 $this->assertSame(200, $client->getResponse()->getStatusCode());
195
196 $form = $crawler->filter('button[id=change_passwd_save]')->form();
197
198 $crawler = $client->submit($form, $data);
199
200 $this->assertSame(200, $client->getResponse()->getStatusCode());
201
202 $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text']));
203 $this->assertContains($expectedMessage, $alert[0]);
204 }
205
206 public function testChangePassword()
207 {
208 $this->logInAs('admin');
209 $client = $this->getClient();
210
211 $crawler = $client->request('GET', '/config');
212
213 $this->assertSame(200, $client->getResponse()->getStatusCode());
214
215 $form = $crawler->filter('button[id=change_passwd_save]')->form();
216
217 $data = [
218 'change_passwd[old_password]' => 'mypassword',
219 'change_passwd[new_password][first]' => 'mypassword',
220 'change_passwd[new_password][second]' => 'mypassword',
221 ];
222
223 $client->submit($form, $data);
224
225 $this->assertSame(302, $client->getResponse()->getStatusCode());
226
227 $crawler = $client->followRedirect();
228
229 $this->assertContains('flashes.config.notice.password_updated', $crawler->filter('body')->extract(['_text'])[0]);
230 }
231
232 public function dataForUserFailed()
233 {
234 return [
235 [
236 [
237 'update_user[name]' => '',
238 'update_user[email]' => '',
239 ],
240 'fos_user.email.blank',
241 ],
242 [
243 [
244 'update_user[name]' => '',
245 'update_user[email]' => 'test',
246 ],
247 'fos_user.email.invalid',
248 ],
249 ];
250 }
251
252 /**
253 * @dataProvider dataForUserFailed
254 */
255 public function testUserFailed($data, $expectedMessage)
256 {
257 $this->logInAs('admin');
258 $client = $this->getClient();
259
260 $crawler = $client->request('GET', '/config');
261
262 $this->assertSame(200, $client->getResponse()->getStatusCode());
263
264 $form = $crawler->filter('button[id=update_user_save]')->form();
265
266 $crawler = $client->submit($form, $data);
267
268 $this->assertSame(200, $client->getResponse()->getStatusCode());
269
270 $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text']));
271 $this->assertContains($expectedMessage, $alert[0]);
272 }
273
274 public function testUserUpdate()
275 {
276 $this->logInAs('admin');
277 $client = $this->getClient();
278
279 $crawler = $client->request('GET', '/config');
280
281 $this->assertSame(200, $client->getResponse()->getStatusCode());
282
283 $form = $crawler->filter('button[id=update_user_save]')->form();
284
285 $data = [
286 'update_user[name]' => 'new name',
287 'update_user[email]' => 'admin@wallabag.io',
288 ];
289
290 $client->submit($form, $data);
291
292 $this->assertSame(302, $client->getResponse()->getStatusCode());
293
294 $crawler = $client->followRedirect();
295
296 $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text']));
297 $this->assertContains('flashes.config.notice.user_updated', $alert[0]);
298 }
299
300 public function testRssUpdateResetToken()
301 {
302 $this->logInAs('admin');
303 $client = $this->getClient();
304
305 // reset the token
306 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
307 $user = $em
308 ->getRepository('WallabagUserBundle:User')
309 ->findOneByUsername('admin');
310
311 if (!$user) {
312 $this->markTestSkipped('No user found in db.');
313 }
314
315 $config = $user->getConfig();
316 $config->setRssToken(null);
317 $em->persist($config);
318 $em->flush();
319
320 $crawler = $client->request('GET', '/config');
321
322 $this->assertSame(200, $client->getResponse()->getStatusCode());
323
324 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
325 $this->assertContains('config.form_rss.no_token', $body[0]);
326
327 $client->request('GET', '/generate-token');
328 $this->assertSame(302, $client->getResponse()->getStatusCode());
329
330 $crawler = $client->followRedirect();
331
332 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
333 $this->assertNotContains('config.form_rss.no_token', $body[0]);
334 }
335
336 public function testGenerateTokenAjax()
337 {
338 $this->logInAs('admin');
339 $client = $this->getClient();
340
341 $client->request(
342 'GET',
343 '/generate-token',
344 [],
345 [],
346 ['HTTP_X-Requested-With' => 'XMLHttpRequest']
347 );
348
349 $this->assertSame(200, $client->getResponse()->getStatusCode());
350 $content = json_decode($client->getResponse()->getContent(), true);
351 $this->assertArrayHasKey('token', $content);
352 }
353
354 public function testRssUpdate()
355 {
356 $this->logInAs('admin');
357 $client = $this->getClient();
358
359 $crawler = $client->request('GET', '/config');
360
361 $this->assertSame(200, $client->getResponse()->getStatusCode());
362
363 $form = $crawler->filter('button[id=rss_config_save]')->form();
364
365 $data = [
366 'rss_config[rss_limit]' => 12,
367 ];
368
369 $client->submit($form, $data);
370
371 $this->assertSame(302, $client->getResponse()->getStatusCode());
372
373 $crawler = $client->followRedirect();
374
375 $this->assertContains('flashes.config.notice.rss_updated', $crawler->filter('body')->extract(['_text'])[0]);
376 }
377
378 public function dataForRssFailed()
379 {
380 return [
381 [
382 [
383 'rss_config[rss_limit]' => 0,
384 ],
385 'This value should be 1 or more.',
386 ],
387 [
388 [
389 'rss_config[rss_limit]' => 1000000000000,
390 ],
391 'validator.rss_limit_too_high',
392 ],
393 ];
394 }
395
396 /**
397 * @dataProvider dataForRssFailed
398 */
399 public function testRssFailed($data, $expectedMessage)
400 {
401 $this->logInAs('admin');
402 $client = $this->getClient();
403
404 $crawler = $client->request('GET', '/config');
405
406 $this->assertSame(200, $client->getResponse()->getStatusCode());
407
408 $form = $crawler->filter('button[id=rss_config_save]')->form();
409
410 $crawler = $client->submit($form, $data);
411
412 $this->assertSame(200, $client->getResponse()->getStatusCode());
413
414 $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text']));
415 $this->assertContains($expectedMessage, $alert[0]);
416 }
417
418 public function testTaggingRuleCreation()
419 {
420 $this->logInAs('admin');
421 $this->useTheme('baggy');
422 $client = $this->getClient();
423
424 $crawler = $client->request('GET', '/config');
425
426 $this->assertSame(200, $client->getResponse()->getStatusCode());
427
428 $form = $crawler->filter('button[id=tagging_rule_save]')->form();
429
430 $data = [
431 'tagging_rule[rule]' => 'readingTime <= 3',
432 'tagging_rule[tags]' => 'short reading',
433 ];
434
435 $client->submit($form, $data);
436
437 $this->assertSame(302, $client->getResponse()->getStatusCode());
438
439 $crawler = $client->followRedirect();
440
441 $this->assertContains('flashes.config.notice.tagging_rules_updated', $crawler->filter('body')->extract(['_text'])[0]);
442
443 $editLink = $crawler->filter('.mode_edit')->last()->link();
444
445 $crawler = $client->click($editLink);
446 $this->assertSame(302, $client->getResponse()->getStatusCode());
447 $this->assertContains('?tagging-rule=', $client->getResponse()->headers->get('location'));
448
449 $crawler = $client->followRedirect();
450
451 $form = $crawler->filter('button[id=tagging_rule_save]')->form();
452
453 $data = [
454 'tagging_rule[rule]' => 'readingTime <= 30',
455 'tagging_rule[tags]' => 'short reading',
456 ];
457
458 $client->submit($form, $data);
459
460 $this->assertSame(302, $client->getResponse()->getStatusCode());
461
462 $crawler = $client->followRedirect();
463
464 $this->assertContains('flashes.config.notice.tagging_rules_updated', $crawler->filter('body')->extract(['_text'])[0]);
465
466 $this->assertContains('readingTime <= 30', $crawler->filter('body')->extract(['_text'])[0]);
467
468 $deleteLink = $crawler->filter('.delete')->last()->link();
469
470 $crawler = $client->click($deleteLink);
471 $this->assertSame(302, $client->getResponse()->getStatusCode());
472
473 $crawler = $client->followRedirect();
474 $this->assertContains('flashes.config.notice.tagging_rules_deleted', $crawler->filter('body')->extract(['_text'])[0]);
475 }
476
477 public function dataForTaggingRuleFailed()
478 {
479 return [
480 [
481 [
482 'tagging_rule[rule]' => 'unknownVar <= 3',
483 'tagging_rule[tags]' => 'cool tag',
484 ],
485 [
486 'The variable',
487 'does not exist.',
488 ],
489 ],
490 [
491 [
492 'tagging_rule[rule]' => 'length(domainName) <= 42',
493 'tagging_rule[tags]' => 'cool tag',
494 ],
495 [
496 'The operator',
497 'does not exist.',
498 ],
499 ],
500 ];
501 }
502
503 /**
504 * @dataProvider dataForTaggingRuleFailed
505 */
506 public function testTaggingRuleCreationFail($data, $messages)
507 {
508 $this->logInAs('admin');
509 $client = $this->getClient();
510
511 $crawler = $client->request('GET', '/config');
512
513 $this->assertSame(200, $client->getResponse()->getStatusCode());
514
515 $form = $crawler->filter('button[id=tagging_rule_save]')->form();
516
517 $crawler = $client->submit($form, $data);
518
519 $this->assertSame(200, $client->getResponse()->getStatusCode());
520
521 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
522
523 foreach ($messages as $message) {
524 $this->assertContains($message, $body[0]);
525 }
526 }
527
528 public function testTaggingRuleTooLong()
529 {
530 $this->logInAs('admin');
531 $client = $this->getClient();
532
533 $crawler = $client->request('GET', '/config');
534
535 $this->assertSame(200, $client->getResponse()->getStatusCode());
536
537 $form = $crawler->filter('button[id=tagging_rule_save]')->form();
538
539 $crawler = $client->submit($form, [
540 'tagging_rule[rule]' => str_repeat('title', 60),
541 'tagging_rule[tags]' => 'cool tag',
542 ]);
543
544 $this->assertSame(200, $client->getResponse()->getStatusCode());
545
546 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
547
548 $this->assertContains('255 characters', $body[0]);
549 }
550
551 public function testDeletingTaggingRuleFromAnOtherUser()
552 {
553 $this->logInAs('bob');
554 $client = $this->getClient();
555
556 $rule = $client->getContainer()->get('doctrine.orm.entity_manager')
557 ->getRepository('WallabagCoreBundle:TaggingRule')
558 ->findAll()[0];
559
560 $crawler = $client->request('GET', '/tagging-rule/edit/' . $rule->getId());
561
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]);
565 }
566
567 public function testEditingTaggingRuleFromAnOtherUser()
568 {
569 $this->logInAs('bob');
570 $client = $this->getClient();
571
572 $rule = $client->getContainer()->get('doctrine.orm.entity_manager')
573 ->getRepository('WallabagCoreBundle:TaggingRule')
574 ->findAll()[0];
575
576 $crawler = $client->request('GET', '/tagging-rule/edit/' . $rule->getId());
577
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]);
581 }
582
583 public function testDemoMode()
584 {
585 $this->logInAs('admin');
586 $client = $this->getClient();
587
588 $config = $client->getContainer()->get('craue_config');
589 $config->set('demo_mode_enabled', 1);
590 $config->set('demo_mode_username', 'admin');
591
592 $crawler = $client->request('GET', '/config');
593
594 $this->assertSame(200, $client->getResponse()->getStatusCode());
595
596 $form = $crawler->filter('button[id=change_passwd_save]')->form();
597
598 $data = [
599 'change_passwd[old_password]' => 'mypassword',
600 'change_passwd[new_password][first]' => 'mypassword',
601 'change_passwd[new_password][second]' => 'mypassword',
602 ];
603
604 $client->submit($form, $data);
605
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]);
608
609 $config->set('demo_mode_enabled', 0);
610 $config->set('demo_mode_username', 'wallabag');
611 }
612
613 public function testDeleteUserButtonVisibility()
614 {
615 $this->logInAs('admin');
616 $client = $this->getClient();
617
618 $crawler = $client->request('GET', '/config');
619
620 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
621 $this->assertContains('config.form_user.delete.button', $body[0]);
622
623 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
624
625 $user = $em
626 ->getRepository('WallabagUserBundle:User')
627 ->findOneByUsername('empty');
628 $user->setEnabled(false);
629 $em->persist($user);
630
631 $user = $em
632 ->getRepository('WallabagUserBundle:User')
633 ->findOneByUsername('bob');
634 $user->setEnabled(false);
635 $em->persist($user);
636
637 $em->flush();
638
639 $crawler = $client->request('GET', '/config');
640
641 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
642 $this->assertNotContains('config.form_user.delete.button', $body[0]);
643
644 $client->request('GET', '/account/delete');
645 $this->assertSame(403, $client->getResponse()->getStatusCode());
646
647 $user = $em
648 ->getRepository('WallabagUserBundle:User')
649 ->findOneByUsername('empty');
650 $user->setEnabled(true);
651 $em->persist($user);
652
653 $user = $em
654 ->getRepository('WallabagUserBundle:User')
655 ->findOneByUsername('bob');
656 $user->setEnabled(true);
657 $em->persist($user);
658
659 $em->flush();
660 }
661
662 public function testDeleteAccount()
663 {
664 $client = $this->getClient();
665 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
666
667 $user = new User();
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');
674
675 $em->persist($user);
676
677 $config = new Config($user);
678
679 $config->setTheme('material');
680 $config->setItemsPerPage(30);
681 $config->setReadingSpeed(1);
682 $config->setLanguage('en');
683 $config->setPocketConsumerKey('xxxxx');
684
685 $em->persist($config);
686 $em->flush();
687
688 $this->logInAs('wallace');
689 $loggedInUserId = $this->getLoggedInUserId();
690
691 // create entry to check after user deletion
692 // that this entry is also deleted
693 $crawler = $client->request('GET', '/new');
694
695 $this->assertSame(200, $client->getResponse()->getStatusCode());
696
697 $form = $crawler->filter('form[name=entry]')->form();
698 $data = [
699 'entry[url]' => $url = 'https://github.com/wallabag/wallabag',
700 ];
701
702 $client->submit($form, $data);
703 $this->assertSame(302, $client->getResponse()->getStatusCode());
704
705 $crawler = $client->request('GET', '/config');
706
707 $deleteLink = $crawler->filter('.delete-account')->last()->link();
708
709 $client->click($deleteLink);
710 $this->assertSame(302, $client->getResponse()->getStatusCode());
711
712 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
713 $user = $em
714 ->getRepository('WallabagUserBundle:User')
715 ->createQueryBuilder('u')
716 ->where('u.username = :username')->setParameter('username', 'wallace')
717 ->getQuery()
718 ->getOneOrNullResult()
719 ;
720
721 $this->assertNull($user);
722
723 $entries = $client->getContainer()
724 ->get('doctrine.orm.entity_manager')
725 ->getRepository('WallabagCoreBundle:Entry')
726 ->findByUser($loggedInUserId);
727
728 $this->assertEmpty($entries);
729 }
730
731 public function testReset()
732 {
733 $this->logInAs('empty');
734 $client = $this->getClient();
735
736 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
737
738 $user = static::$kernel->getContainer()->get('security.token_storage')->getToken()->getUser();
739
740 $tag = new Tag();
741 $tag->setLabel('super');
742 $em->persist($tag);
743
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);
750
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);
757
758 $annotation = new Annotation($user);
759 $annotation->setText('annotated');
760 $annotation->setQuote('annotated');
761 $annotation->setRanges([]);
762 $annotation->setEntry($entry);
763 $em->persist($annotation);
764
765 $em->flush();
766
767 // reset annotations
768 $crawler = $client->request('GET', '/config#set3');
769
770 $this->assertSame(200, $client->getResponse()->getStatusCode());
771
772 $crawler = $client->click($crawler->selectLink('config.reset.annotations')->link());
773
774 $this->assertSame(302, $client->getResponse()->getStatusCode());
775 $this->assertContains('flashes.config.notice.annotations_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]);
776
777 $annotationsReset = $em
778 ->getRepository('WallabagAnnotationBundle:Annotation')
779 ->findAnnotationsByPageId($entry->getId(), $user->getId());
780
781 $this->assertEmpty($annotationsReset, 'Annotations were reset');
782
783 // reset tags
784 $crawler = $client->request('GET', '/config#set3');
785
786 $this->assertSame(200, $client->getResponse()->getStatusCode());
787
788 $crawler = $client->click($crawler->selectLink('config.reset.tags')->link());
789
790 $this->assertSame(302, $client->getResponse()->getStatusCode());
791 $this->assertContains('flashes.config.notice.tags_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]);
792
793 $tagReset = $em
794 ->getRepository('WallabagCoreBundle:Tag')
795 ->countAllTags($user->getId());
796
797 $this->assertSame(0, $tagReset, 'Tags were reset');
798
799 // reset entries
800 $crawler = $client->request('GET', '/config#set3');
801
802 $this->assertSame(200, $client->getResponse()->getStatusCode());
803
804 $crawler = $client->click($crawler->selectLink('config.reset.entries')->link());
805
806 $this->assertSame(302, $client->getResponse()->getStatusCode());
807 $this->assertContains('flashes.config.notice.entries_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]);
808
809 $entryReset = $em
810 ->getRepository('WallabagCoreBundle:Entry')
811 ->countAllEntriesByUser($user->getId());
812
813 $this->assertSame(0, $entryReset, 'Entries were reset');
814 }
815
816 public function testResetArchivedEntries()
817 {
818 $this->logInAs('empty');
819 $client = $this->getClient();
820
821 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
822
823 $user = static::$kernel->getContainer()->get('security.token_storage')->getToken()->getUser();
824
825 $tag = new Tag();
826 $tag->setLabel('super');
827 $em->persist($tag);
828
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);
835
836 $annotation = new Annotation($user);
837 $annotation->setText('annotated');
838 $annotation->setQuote('annotated');
839 $annotation->setRanges([]);
840 $annotation->setEntry($entry);
841 $em->persist($annotation);
842
843 $tagArchived = new Tag();
844 $tagArchived->setLabel('super');
845 $em->persist($tagArchived);
846
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->setArchived(true);
853 $em->persist($entryArchived);
854
855 $annotationArchived = new Annotation($user);
856 $annotationArchived->setText('annotated');
857 $annotationArchived->setQuote('annotated');
858 $annotationArchived->setRanges([]);
859 $annotationArchived->setEntry($entryArchived);
860 $em->persist($annotationArchived);
861
862 $em->flush();
863
864 $crawler = $client->request('GET', '/config#set3');
865
866 $this->assertSame(200, $client->getResponse()->getStatusCode());
867
868 $crawler = $client->click($crawler->selectLink('config.reset.archived')->link());
869
870 $this->assertSame(302, $client->getResponse()->getStatusCode());
871 $this->assertContains('flashes.config.notice.archived_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]);
872
873 $entryReset = $em
874 ->getRepository('WallabagCoreBundle:Entry')
875 ->countAllEntriesByUser($user->getId());
876
877 $this->assertSame(1, $entryReset, 'Entries were reset');
878
879 $tagReset = $em
880 ->getRepository('WallabagCoreBundle:Tag')
881 ->countAllTags($user->getId());
882
883 $this->assertSame(1, $tagReset, 'Tags were reset');
884
885 $annotationsReset = $em
886 ->getRepository('WallabagAnnotationBundle:Annotation')
887 ->findAnnotationsByPageId($annotationArchived->getId(), $user->getId());
888
889 $this->assertEmpty($annotationsReset, 'Annotations were reset');
890 }
891
892 public function testResetEntriesCascade()
893 {
894 $this->logInAs('empty');
895 $client = $this->getClient();
896
897 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
898
899 $user = static::$kernel->getContainer()->get('security.token_storage')->getToken()->getUser();
900
901 $tag = new Tag();
902 $tag->setLabel('super');
903 $em->persist($tag);
904
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);
911
912 $annotation = new Annotation($user);
913 $annotation->setText('annotated');
914 $annotation->setQuote('annotated');
915 $annotation->setRanges([]);
916 $annotation->setEntry($entry);
917 $em->persist($annotation);
918
919 $em->flush();
920
921 $crawler = $client->request('GET', '/config#set3');
922
923 $this->assertSame(200, $client->getResponse()->getStatusCode());
924
925 $crawler = $client->click($crawler->selectLink('config.reset.entries')->link());
926
927 $this->assertSame(302, $client->getResponse()->getStatusCode());
928 $this->assertContains('flashes.config.notice.entries_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]);
929
930 $entryReset = $em
931 ->getRepository('WallabagCoreBundle:Entry')
932 ->countAllEntriesByUser($user->getId());
933
934 $this->assertSame(0, $entryReset, 'Entries were reset');
935
936 $tagReset = $em
937 ->getRepository('WallabagCoreBundle:Tag')
938 ->countAllTags($user->getId());
939
940 $this->assertSame(0, $tagReset, 'Tags were reset');
941
942 $annotationsReset = $em
943 ->getRepository('WallabagAnnotationBundle:Annotation')
944 ->findAnnotationsByPageId($entry->getId(), $user->getId());
945
946 $this->assertEmpty($annotationsReset, 'Annotations were reset');
947 }
948
949 public function testSwitchViewMode()
950 {
951 $this->logInAs('admin');
952 $this->useTheme('baggy');
953 $client = $this->getClient();
954
955 $client->request('GET', '/unread/list');
956
957 $this->assertNotContains('listmode', $client->getResponse()->getContent());
958
959 $client->request('GET', '/config/view-mode');
960 $crawler = $client->followRedirect();
961
962 $client->request('GET', '/unread/list');
963
964 $this->assertContains('listmode', $client->getResponse()->getContent());
965
966 $client->request('GET', '/config/view-mode');
967 }
968 }