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