aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/CoreBundle/Controller
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Wallabag/CoreBundle/Controller')
-rw-r--r--tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php173
-rw-r--r--tests/Wallabag/CoreBundle/Controller/DeveloperControllerTest.php71
-rw-r--r--tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php130
-rw-r--r--tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php43
-rw-r--r--tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php15
-rw-r--r--tests/Wallabag/CoreBundle/Controller/TagControllerTest.php70
6 files changed, 269 insertions, 233 deletions
diff --git a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
index 7193f9b0..1954c654 100644
--- a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
@@ -28,7 +28,6 @@ class ConfigControllerTest extends WallabagCoreTestCase
28 $this->assertCount(1, $crawler->filter('button[id=config_save]')); 28 $this->assertCount(1, $crawler->filter('button[id=config_save]'));
29 $this->assertCount(1, $crawler->filter('button[id=change_passwd_save]')); 29 $this->assertCount(1, $crawler->filter('button[id=change_passwd_save]'));
30 $this->assertCount(1, $crawler->filter('button[id=update_user_save]')); 30 $this->assertCount(1, $crawler->filter('button[id=update_user_save]'));
31 $this->assertCount(1, $crawler->filter('button[id=new_user_save]'));
32 $this->assertCount(1, $crawler->filter('button[id=rss_config_save]')); 31 $this->assertCount(1, $crawler->filter('button[id=rss_config_save]'));
33 } 32 }
34 33
@@ -56,8 +55,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
56 55
57 $crawler = $client->followRedirect(); 56 $crawler = $client->followRedirect();
58 57
59 $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(['_text'])); 58 $this->assertContains('flashes.config.notice.config_saved', $crawler->filter('body')->extract(['_text'])[0]);
60 $this->assertContains('flashes.config.notice.config_saved', $alert[0]);
61 } 59 }
62 60
63 public function testChangeReadingSpeed() 61 public function testChangeReadingSpeed()
@@ -213,8 +211,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
213 211
214 $crawler = $client->followRedirect(); 212 $crawler = $client->followRedirect();
215 213
216 $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(['_text'])); 214 $this->assertContains('flashes.config.notice.password_updated', $crawler->filter('body')->extract(['_text'])[0]);
217 $this->assertContains('flashes.config.notice.password_updated', $alert[0]);
218 } 215 }
219 216
220 public function dataForUserFailed() 217 public function dataForUserFailed()
@@ -285,120 +282,6 @@ class ConfigControllerTest extends WallabagCoreTestCase
285 $this->assertContains('flashes.config.notice.user_updated', $alert[0]); 282 $this->assertContains('flashes.config.notice.user_updated', $alert[0]);
286 } 283 }
287 284
288 public function dataForNewUserFailed()
289 {
290 return [
291 [
292 [
293 'new_user[username]' => '',
294 'new_user[plainPassword][first]' => '',
295 'new_user[plainPassword][second]' => '',
296 'new_user[email]' => '',
297 ],
298 'fos_user.username.blank',
299 ],
300 [
301 [
302 'new_user[username]' => 'a',
303 'new_user[plainPassword][first]' => 'mypassword',
304 'new_user[plainPassword][second]' => 'mypassword',
305 'new_user[email]' => '',
306 ],
307 'fos_user.username.short',
308 ],
309 [
310 [
311 'new_user[username]' => 'wallace',
312 'new_user[plainPassword][first]' => 'mypassword',
313 'new_user[plainPassword][second]' => 'mypassword',
314 'new_user[email]' => 'test',
315 ],
316 'fos_user.email.invalid',
317 ],
318 [
319 [
320 'new_user[username]' => 'admin',
321 'new_user[plainPassword][first]' => 'wallacewallace',
322 'new_user[plainPassword][second]' => 'wallacewallace',
323 'new_user[email]' => 'wallace@wallace.me',
324 ],
325 'fos_user.username.already_used',
326 ],
327 [
328 [
329 'new_user[username]' => 'wallace',
330 'new_user[plainPassword][first]' => 'mypassword1',
331 'new_user[plainPassword][second]' => 'mypassword2',
332 'new_user[email]' => 'wallace@wallace.me',
333 ],
334 'validator.password_must_match',
335 ],
336 ];
337 }
338
339 /**
340 * @dataProvider dataForNewUserFailed
341 */
342 public function testNewUserFailed($data, $expectedMessage)
343 {
344 $this->logInAs('admin');
345 $client = $this->getClient();
346
347 $crawler = $client->request('GET', '/config');
348
349 $this->assertEquals(200, $client->getResponse()->getStatusCode());
350
351 $form = $crawler->filter('button[id=new_user_save]')->form();
352
353 $crawler = $client->submit($form, $data);
354
355 $this->assertEquals(200, $client->getResponse()->getStatusCode());
356
357 $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text']));
358 $this->assertContains($expectedMessage, $alert[0]);
359 }
360
361 public function testNewUserCreated()
362 {
363 $this->logInAs('admin');
364 $client = $this->getClient();
365
366 $crawler = $client->request('GET', '/config');
367
368 $this->assertEquals(200, $client->getResponse()->getStatusCode());
369
370 $form = $crawler->filter('button[id=new_user_save]')->form();
371
372 $data = [
373 'new_user[username]' => 'wallace',
374 'new_user[plainPassword][first]' => 'wallace1',
375 'new_user[plainPassword][second]' => 'wallace1',
376 'new_user[email]' => 'wallace@wallace.me',
377 ];
378
379 $client->submit($form, $data);
380
381 $this->assertEquals(302, $client->getResponse()->getStatusCode());
382
383 $crawler = $client->followRedirect();
384
385 $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(['_text']));
386 $this->assertContains('flashes.config.notice.user_added', $alert[0]);
387
388 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
389 $user = $em
390 ->getRepository('WallabagUserBundle:User')
391 ->findOneByUsername('wallace');
392
393 $this->assertTrue(false !== $user);
394 $this->assertTrue($user->isEnabled());
395 $this->assertEquals('material', $user->getConfig()->getTheme());
396 $this->assertEquals(12, $user->getConfig()->getItemsPerPage());
397 $this->assertEquals(50, $user->getConfig()->getRssLimit());
398 $this->assertEquals('en', $user->getConfig()->getLanguage());
399 $this->assertEquals(1, $user->getConfig()->getReadingSpeed());
400 }
401
402 public function testRssUpdateResetToken() 285 public function testRssUpdateResetToken()
403 { 286 {
404 $this->logInAs('admin'); 287 $this->logInAs('admin');
@@ -474,8 +357,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
474 357
475 $crawler = $client->followRedirect(); 358 $crawler = $client->followRedirect();
476 359
477 $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(['_text'])); 360 $this->assertContains('flashes.config.notice.rss_updated', $crawler->filter('body')->extract(['_text'])[0]);
478 $this->assertContains('flashes.config.notice.rss_updated', $alert[0]);
479 } 361 }
480 362
481 public function dataForRssFailed() 363 public function dataForRssFailed()
@@ -540,8 +422,32 @@ class ConfigControllerTest extends WallabagCoreTestCase
540 422
541 $crawler = $client->followRedirect(); 423 $crawler = $client->followRedirect();
542 424
543 $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(['_text'])); 425 $this->assertContains('flashes.config.notice.tagging_rules_updated', $crawler->filter('body')->extract(['_text'])[0]);
544 $this->assertContains('flashes.config.notice.tagging_rules_updated', $alert[0]); 426
427 $editLink = $crawler->filter('.mode_edit')->last()->link();
428
429 $crawler = $client->click($editLink);
430 $this->assertEquals(302, $client->getResponse()->getStatusCode());
431 $this->assertContains('?tagging-rule=', $client->getResponse()->headers->get('location'));
432
433 $crawler = $client->followRedirect();
434
435 $form = $crawler->filter('button[id=tagging_rule_save]')->form();
436
437 $data = [
438 'tagging_rule[rule]' => 'readingTime <= 30',
439 'tagging_rule[tags]' => 'short reading',
440 ];
441
442 $client->submit($form, $data);
443
444 $this->assertEquals(302, $client->getResponse()->getStatusCode());
445
446 $crawler = $client->followRedirect();
447
448 $this->assertContains('flashes.config.notice.tagging_rules_updated', $crawler->filter('body')->extract(['_text'])[0]);
449
450 $this->assertContains('readingTime <= 30', $crawler->filter('body')->extract(['_text'])[0]);
545 451
546 $deleteLink = $crawler->filter('.delete')->last()->link(); 452 $deleteLink = $crawler->filter('.delete')->last()->link();
547 453
@@ -549,8 +455,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
549 $this->assertEquals(302, $client->getResponse()->getStatusCode()); 455 $this->assertEquals(302, $client->getResponse()->getStatusCode());
550 456
551 $crawler = $client->followRedirect(); 457 $crawler = $client->followRedirect();
552 $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(['_text'])); 458 $this->assertContains('flashes.config.notice.tagging_rules_deleted', $crawler->filter('body')->extract(['_text'])[0]);
553 $this->assertContains('flashes.config.notice.tagging_rules_deleted', $alert[0]);
554 } 459 }
555 460
556 public function dataForTaggingRuleFailed() 461 public function dataForTaggingRuleFailed()
@@ -613,7 +518,23 @@ class ConfigControllerTest extends WallabagCoreTestCase
613 ->getRepository('WallabagCoreBundle:TaggingRule') 518 ->getRepository('WallabagCoreBundle:TaggingRule')
614 ->findAll()[0]; 519 ->findAll()[0];
615 520
616 $crawler = $client->request('GET', '/tagging-rule/delete/'.$rule->getId()); 521 $crawler = $client->request('GET', '/tagging-rule/edit/'.$rule->getId());
522
523 $this->assertEquals(403, $client->getResponse()->getStatusCode());
524 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
525 $this->assertContains('You can not access this tagging rule', $body[0]);
526 }
527
528 public function testEditingTaggingRuleFromAnOtherUser()
529 {
530 $this->logInAs('bob');
531 $client = $this->getClient();
532
533 $rule = $client->getContainer()->get('doctrine.orm.entity_manager')
534 ->getRepository('WallabagCoreBundle:TaggingRule')
535 ->findAll()[0];
536
537 $crawler = $client->request('GET', '/tagging-rule/edit/'.$rule->getId());
617 538
618 $this->assertEquals(403, $client->getResponse()->getStatusCode()); 539 $this->assertEquals(403, $client->getResponse()->getStatusCode());
619 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); 540 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
diff --git a/tests/Wallabag/CoreBundle/Controller/DeveloperControllerTest.php b/tests/Wallabag/CoreBundle/Controller/DeveloperControllerTest.php
deleted file mode 100644
index 79452ace..00000000
--- a/tests/Wallabag/CoreBundle/Controller/DeveloperControllerTest.php
+++ /dev/null
@@ -1,71 +0,0 @@
1<?php
2
3namespace Tests\Wallabag\CoreBundle\Controller;
4
5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
6
7class DeveloperControllerTest extends WallabagCoreTestCase
8{
9 public function testCreateClient()
10 {
11 $this->logInAs('admin');
12 $client = $this->getClient();
13 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
14 $nbClients = $em->getRepository('WallabagApiBundle:Client')->findAll();
15
16 $crawler = $client->request('GET', '/developer/client/create');
17 $this->assertEquals(200, $client->getResponse()->getStatusCode());
18
19 $form = $crawler->filter('button[type=submit]')->form();
20
21 $client->submit($form);
22
23 $this->assertEquals(200, $client->getResponse()->getStatusCode());
24
25 $newNbClients = $em->getRepository('WallabagApiBundle:Client')->findAll();
26 $this->assertGreaterThan(count($nbClients), count($newNbClients));
27 }
28
29 public function testListingClient()
30 {
31 $this->logInAs('admin');
32 $client = $this->getClient();
33 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
34 $nbClients = $em->getRepository('WallabagApiBundle:Client')->findAll();
35
36 $crawler = $client->request('GET', '/developer');
37 $this->assertEquals(200, $client->getResponse()->getStatusCode());
38 $this->assertEquals(count($nbClients), $crawler->filter('ul[class=collapsible] li')->count());
39 }
40
41 public function testDeveloperHowto()
42 {
43 $this->logInAs('admin');
44 $client = $this->getClient();
45
46 $crawler = $client->request('GET', '/developer/howto/first-app');
47 $this->assertEquals(200, $client->getResponse()->getStatusCode());
48 }
49
50 public function testRemoveClient()
51 {
52 $this->logInAs('admin');
53 $client = $this->getClient();
54 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
55 $nbClients = $em->getRepository('WallabagApiBundle:Client')->findAll();
56
57 $crawler = $client->request('GET', '/developer');
58
59 $link = $crawler
60 ->filter('div[class=collapsible-body] p a')
61 ->eq(0)
62 ->link()
63 ;
64
65 $client->click($link);
66 $this->assertEquals(302, $client->getResponse()->getStatusCode());
67
68 $newNbClients = $em->getRepository('WallabagApiBundle:Client')->findAll();
69 $this->assertGreaterThan(count($newNbClients), count($nbClients));
70 }
71}
diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
index 5c739c78..9b03a519 100644
--- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
@@ -29,7 +29,7 @@ class EntryControllerTest extends WallabagCoreTestCase
29 29
30 $this->assertEquals(200, $client->getResponse()->getStatusCode()); 30 $this->assertEquals(200, $client->getResponse()->getStatusCode());
31 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); 31 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
32 $this->assertContains('quickstart.intro.paragraph_1', $body[0]); 32 $this->assertContains('quickstart.intro.title', $body[0]);
33 33
34 // Test if quickstart is disabled when user has 1 entry 34 // Test if quickstart is disabled when user has 1 entry
35 $crawler = $client->request('GET', '/new'); 35 $crawler = $client->request('GET', '/new');
@@ -160,6 +160,50 @@ class EntryControllerTest extends WallabagCoreTestCase
160 $this->assertContains('/view/', $client->getResponse()->getTargetUrl()); 160 $this->assertContains('/view/', $client->getResponse()->getTargetUrl());
161 } 161 }
162 162
163 public function testPostNewOkUrlExistWithAccent()
164 {
165 $this->logInAs('admin');
166 $client = $this->getClient();
167
168 $url = 'http://www.aritylabs.com/post/106091708292/des-contr%C3%B4leurs-optionnels-gr%C3%A2ce-%C3%A0-constmissing';
169
170 $crawler = $client->request('GET', '/new');
171
172 $this->assertEquals(200, $client->getResponse()->getStatusCode());
173
174 $form = $crawler->filter('form[name=entry]')->form();
175
176 $data = [
177 'entry[url]' => $url,
178 ];
179
180 $client->submit($form, $data);
181
182 $crawler = $client->request('GET', '/new');
183
184 $this->assertEquals(200, $client->getResponse()->getStatusCode());
185
186 $form = $crawler->filter('form[name=entry]')->form();
187
188 $data = [
189 'entry[url]' => $url,
190 ];
191
192 $client->submit($form, $data);
193
194 $this->assertEquals(302, $client->getResponse()->getStatusCode());
195 $this->assertContains('/view/', $client->getResponse()->getTargetUrl());
196
197 $em = $client->getContainer()
198 ->get('doctrine.orm.entity_manager');
199 $entry = $em
200 ->getRepository('WallabagCoreBundle:Entry')
201 ->findOneByUrl(urldecode($url));
202
203 $em->remove($entry);
204 $em->flush();
205 }
206
163 /** 207 /**
164 * This test will require an internet connection. 208 * This test will require an internet connection.
165 */ 209 */
@@ -236,6 +280,16 @@ class EntryControllerTest extends WallabagCoreTestCase
236 $this->assertEquals(200, $client->getResponse()->getStatusCode()); 280 $this->assertEquals(200, $client->getResponse()->getStatusCode());
237 } 281 }
238 282
283 public function testUntagged()
284 {
285 $this->logInAs('admin');
286 $client = $this->getClient();
287
288 $client->request('GET', '/untagged/list');
289
290 $this->assertEquals(200, $client->getResponse()->getStatusCode());
291 }
292
239 public function testStarred() 293 public function testStarred()
240 { 294 {
241 $this->logInAs('admin'); 295 $this->logInAs('admin');
@@ -287,22 +341,23 @@ class EntryControllerTest extends WallabagCoreTestCase
287 $this->logInAs('admin'); 341 $this->logInAs('admin');
288 $client = $this->getClient(); 342 $client = $this->getClient();
289 343
290 $content = $client->getContainer() 344 $em = $client->getContainer()
291 ->get('doctrine.orm.entity_manager') 345 ->get('doctrine.orm.entity_manager');
346
347 $content = $em
292 ->getRepository('WallabagCoreBundle:Entry') 348 ->getRepository('WallabagCoreBundle:Entry')
293 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); 349 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
294 350
295 // empty content 351 // empty content
296 $content->setContent(''); 352 $content->setContent('');
297 $client->getContainer()->get('doctrine.orm.entity_manager')->persist($content); 353 $em->persist($content);
298 $client->getContainer()->get('doctrine.orm.entity_manager')->flush(); 354 $em->flush();
299 355
300 $client->request('GET', '/reload/'.$content->getId()); 356 $client->request('GET', '/reload/'.$content->getId());
301 357
302 $this->assertEquals(302, $client->getResponse()->getStatusCode()); 358 $this->assertEquals(302, $client->getResponse()->getStatusCode());
303 359
304 $content = $client->getContainer() 360 $content = $em
305 ->get('doctrine.orm.entity_manager')
306 ->getRepository('WallabagCoreBundle:Entry') 361 ->getRepository('WallabagCoreBundle:Entry')
307 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); 362 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
308 363
@@ -432,9 +487,11 @@ class EntryControllerTest extends WallabagCoreTestCase
432 $this->logInAs('admin'); 487 $this->logInAs('admin');
433 $client = $this->getClient(); 488 $client = $this->getClient();
434 489
490 $em = $client->getContainer()
491 ->get('doctrine.orm.entity_manager');
492
435 // add a new content to be removed later 493 // add a new content to be removed later
436 $user = $client->getContainer() 494 $user = $em
437 ->get('doctrine.orm.entity_manager')
438 ->getRepository('WallabagUserBundle:User') 495 ->getRepository('WallabagUserBundle:User')
439 ->findOneByUserName('admin'); 496 ->findOneByUserName('admin');
440 497
@@ -448,12 +505,8 @@ class EntryControllerTest extends WallabagCoreTestCase
448 $content->setArchived(true); 505 $content->setArchived(true);
449 $content->setLanguage('fr'); 506 $content->setLanguage('fr');
450 507
451 $client->getContainer() 508 $em->persist($content);
452 ->get('doctrine.orm.entity_manager') 509 $em->flush();
453 ->persist($content);
454 $client->getContainer()
455 ->get('doctrine.orm.entity_manager')
456 ->flush();
457 510
458 $client->request('GET', '/view/'.$content->getId()); 511 $client->request('GET', '/view/'.$content->getId());
459 $this->assertEquals(200, $client->getResponse()->getStatusCode()); 512 $this->assertEquals(200, $client->getResponse()->getStatusCode());
@@ -698,4 +751,51 @@ class EntryControllerTest extends WallabagCoreTestCase
698 $crawler = $client->submit($form, $data); 751 $crawler = $client->submit($form, $data);
699 $this->assertCount(2, $crawler->filter('div[class=entry]')); 752 $this->assertCount(2, $crawler->filter('div[class=entry]'));
700 } 753 }
754
755 public function testShareEntryPublicly()
756 {
757 $this->logInAs('admin');
758 $client = $this->getClient();
759
760 $content = $client->getContainer()
761 ->get('doctrine.orm.entity_manager')
762 ->getRepository('WallabagCoreBundle:Entry')
763 ->findOneByUser($this->getLoggedInUserId());
764
765 // no uuid
766 $client->request('GET', '/share/'.$content->getUuid());
767 $this->assertEquals(404, $client->getResponse()->getStatusCode());
768
769 // generating the uuid
770 $client->request('GET', '/share/'.$content->getId());
771 $this->assertEquals(302, $client->getResponse()->getStatusCode());
772
773 // follow link with uuid
774 $crawler = $client->followRedirect();
775 $this->assertEquals(200, $client->getResponse()->getStatusCode());
776 $this->assertContains('max-age=25200', $client->getResponse()->headers->get('cache-control'));
777 $this->assertContains('public', $client->getResponse()->headers->get('cache-control'));
778 $this->assertContains('s-maxage=25200', $client->getResponse()->headers->get('cache-control'));
779 $this->assertNotContains('no-cache', $client->getResponse()->headers->get('cache-control'));
780 $this->assertContains('og:title', $client->getResponse()->getContent());
781 $this->assertContains('og:type', $client->getResponse()->getContent());
782 $this->assertContains('og:url', $client->getResponse()->getContent());
783 $this->assertContains('og:image', $client->getResponse()->getContent());
784
785 // sharing is now disabled
786 $client->getContainer()->get('craue_config')->set('share_public', 0);
787 $client->request('GET', '/share/'.$content->getUuid());
788 $this->assertEquals(404, $client->getResponse()->getStatusCode());
789
790 $client->request('GET', '/view/'.$content->getId());
791 $this->assertContains('no-cache', $client->getResponse()->headers->get('cache-control'));
792
793 // removing the share
794 $client->request('GET', '/share/delete/'.$content->getId());
795 $this->assertEquals(302, $client->getResponse()->getStatusCode());
796
797 // share is now disable
798 $client->request('GET', '/share/'.$content->getUuid());
799 $this->assertEquals(404, $client->getResponse()->getStatusCode());
800 }
701} 801}
diff --git a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php
index b22156c3..9ecd8bc4 100644
--- a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php
@@ -146,7 +146,9 @@ class ExportControllerTest extends WallabagCoreTestCase
146 ->get('doctrine.orm.entity_manager') 146 ->get('doctrine.orm.entity_manager')
147 ->getRepository('WallabagCoreBundle:Entry') 147 ->getRepository('WallabagCoreBundle:Entry')
148 ->createQueryBuilder('e') 148 ->createQueryBuilder('e')
149 ->select('e, t')
149 ->leftJoin('e.user', 'u') 150 ->leftJoin('e.user', 'u')
151 ->leftJoin('e.tags', 't')
150 ->where('u.username = :username')->setParameter('username', 'admin') 152 ->where('u.username = :username')->setParameter('username', 'admin')
151 ->andWhere('e.isArchived = true') 153 ->andWhere('e.isArchived = true')
152 ->getQuery() 154 ->getQuery()
@@ -168,7 +170,19 @@ class ExportControllerTest extends WallabagCoreTestCase
168 $this->assertGreaterThan(1, $csv); 170 $this->assertGreaterThan(1, $csv);
169 // +1 for title line 171 // +1 for title line
170 $this->assertEquals(count($contentInDB) + 1, count($csv)); 172 $this->assertEquals(count($contentInDB) + 1, count($csv));
171 $this->assertEquals('Title;URL;Content;Tags;"MIME Type";Language', $csv[0]); 173 $this->assertEquals('Title;URL;Content;Tags;"MIME Type";Language;"Creation date"', $csv[0]);
174 $this->assertContains($contentInDB[0]['title'], $csv[1]);
175 $this->assertContains($contentInDB[0]['url'], $csv[1]);
176 $this->assertContains($contentInDB[0]['content'], $csv[1]);
177 $this->assertContains($contentInDB[0]['mimetype'], $csv[1]);
178 $this->assertContains($contentInDB[0]['language'], $csv[1]);
179 $this->assertContains($contentInDB[0]['createdAt']->format('d/m/Y h:i:s'), $csv[1]);
180
181 $expectedTag = [];
182 foreach ($contentInDB[0]['tags'] as $tag) {
183 $expectedTag[] = $tag['label'];
184 }
185 $this->assertContains(implode(', ', $expectedTag), $csv[1]);
172 } 186 }
173 187
174 public function testJsonExport() 188 public function testJsonExport()
@@ -176,29 +190,23 @@ class ExportControllerTest extends WallabagCoreTestCase
176 $this->logInAs('admin'); 190 $this->logInAs('admin');
177 $client = $this->getClient(); 191 $client = $this->getClient();
178 192
179 // to be sure results are the same
180 $contentInDB = $client->getContainer() 193 $contentInDB = $client->getContainer()
181 ->get('doctrine.orm.entity_manager') 194 ->get('doctrine.orm.entity_manager')
182 ->getRepository('WallabagCoreBundle:Entry') 195 ->getRepository('WallabagCoreBundle:Entry')
183 ->createQueryBuilder('e') 196 ->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId());
184 ->leftJoin('e.user', 'u')
185 ->where('u.username = :username')->setParameter('username', 'admin')
186 ->getQuery()
187 ->getArrayResult();
188 197
189 ob_start(); 198 ob_start();
190 $crawler = $client->request('GET', '/export/all.json'); 199 $crawler = $client->request('GET', '/export/'.$contentInDB->getId().'.json');
191 ob_end_clean(); 200 ob_end_clean();
192 201
193 $this->assertEquals(200, $client->getResponse()->getStatusCode()); 202 $this->assertEquals(200, $client->getResponse()->getStatusCode());
194 203
195 $headers = $client->getResponse()->headers; 204 $headers = $client->getResponse()->headers;
196 $this->assertEquals('application/json', $headers->get('content-type')); 205 $this->assertEquals('application/json', $headers->get('content-type'));
197 $this->assertEquals('attachment; filename="All articles.json"', $headers->get('content-disposition')); 206 $this->assertEquals('attachment; filename="'.$contentInDB->getTitle().'.json"', $headers->get('content-disposition'));
198 $this->assertEquals('UTF-8', $headers->get('content-transfer-encoding')); 207 $this->assertEquals('UTF-8', $headers->get('content-transfer-encoding'));
199 208
200 $content = json_decode($client->getResponse()->getContent(), true); 209 $content = json_decode($client->getResponse()->getContent(), true);
201 $this->assertEquals(count($contentInDB), count($content));
202 $this->assertArrayHasKey('id', $content[0]); 210 $this->assertArrayHasKey('id', $content[0]);
203 $this->assertArrayHasKey('title', $content[0]); 211 $this->assertArrayHasKey('title', $content[0]);
204 $this->assertArrayHasKey('url', $content[0]); 212 $this->assertArrayHasKey('url', $content[0]);
@@ -210,6 +218,19 @@ class ExportControllerTest extends WallabagCoreTestCase
210 $this->assertArrayHasKey('reading_time', $content[0]); 218 $this->assertArrayHasKey('reading_time', $content[0]);
211 $this->assertArrayHasKey('domain_name', $content[0]); 219 $this->assertArrayHasKey('domain_name', $content[0]);
212 $this->assertArrayHasKey('tags', $content[0]); 220 $this->assertArrayHasKey('tags', $content[0]);
221 $this->assertArrayHasKey('created_at', $content[0]);
222 $this->assertArrayHasKey('updated_at', $content[0]);
223
224 $this->assertEquals($contentInDB->isArchived(), $content[0]['is_archived']);
225 $this->assertEquals($contentInDB->isStarred(), $content[0]['is_starred']);
226 $this->assertEquals($contentInDB->getTitle(), $content[0]['title']);
227 $this->assertEquals($contentInDB->getUrl(), $content[0]['url']);
228 $this->assertEquals([['text' => 'This is my annotation /o/', 'quote' => 'content']], $content[0]['annotations']);
229 $this->assertEquals($contentInDB->getMimetype(), $content[0]['mimetype']);
230 $this->assertEquals($contentInDB->getLanguage(), $content[0]['language']);
231 $this->assertEquals($contentInDB->getReadingtime(), $content[0]['reading_time']);
232 $this->assertEquals($contentInDB->getDomainname(), $content[0]['domain_name']);
233 $this->assertEquals(['foo', 'baz'], $content[0]['tags']);
213 } 234 }
214 235
215 public function testXmlExport() 236 public function testXmlExport()
@@ -247,5 +268,7 @@ class ExportControllerTest extends WallabagCoreTestCase
247 $this->assertNotEmpty('url', (string) $content->entry[0]->url); 268 $this->assertNotEmpty('url', (string) $content->entry[0]->url);
248 $this->assertNotEmpty('content', (string) $content->entry[0]->content); 269 $this->assertNotEmpty('content', (string) $content->entry[0]->content);
249 $this->assertNotEmpty('domain_name', (string) $content->entry[0]->domain_name); 270 $this->assertNotEmpty('domain_name', (string) $content->entry[0]->domain_name);
271 $this->assertNotEmpty('created_at', (string) $content->entry[0]->created_at);
272 $this->assertNotEmpty('updated_at', (string) $content->entry[0]->updated_at);
250 } 273 }
251} 274}
diff --git a/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php b/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php
index 03355f5a..08f4676e 100644
--- a/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php
@@ -69,4 +69,19 @@ class SecurityControllerTest extends WallabagCoreTestCase
69 $this->assertTrue($user->isTrustedComputer('ABCDEF')); 69 $this->assertTrue($user->isTrustedComputer('ABCDEF'));
70 $this->assertFalse($user->isTrustedComputer('FEDCBA')); 70 $this->assertFalse($user->isTrustedComputer('FEDCBA'));
71 } 71 }
72
73 public function testEnabledRegistration()
74 {
75 $client = $this->getClient();
76
77 if (!$client->getContainer()->getParameter('fosuser_registration')) {
78 $this->markTestSkipped('fosuser_registration is not enabled.');
79
80 return;
81 }
82
83 $client->followRedirects();
84 $crawler = $client->request('GET', '/register');
85 $this->assertContains('registration.submit', $crawler->filter('body')->extract(['_text'])[0]);
86 }
72} 87}
diff --git a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php
index 58450e5f..769ce66e 100644
--- a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php
@@ -3,6 +3,7 @@
3namespace Tests\Wallabag\CoreBundle\Controller; 3namespace Tests\Wallabag\CoreBundle\Controller;
4 4
5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; 5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
6use Wallabag\CoreBundle\Entity\Tag;
6 7
7class TagControllerTest extends WallabagCoreTestCase 8class TagControllerTest extends WallabagCoreTestCase
8{ 9{
@@ -26,7 +27,7 @@ class TagControllerTest extends WallabagCoreTestCase
26 $entry = $client->getContainer() 27 $entry = $client->getContainer()
27 ->get('doctrine.orm.entity_manager') 28 ->get('doctrine.orm.entity_manager')
28 ->getRepository('WallabagCoreBundle:Entry') 29 ->getRepository('WallabagCoreBundle:Entry')
29 ->findOneByUsernameAndNotArchived('admin'); 30 ->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId());
30 31
31 $crawler = $client->request('GET', '/view/'.$entry->getId()); 32 $crawler = $client->request('GET', '/view/'.$entry->getId());
32 33
@@ -43,11 +44,11 @@ class TagControllerTest extends WallabagCoreTestCase
43 $entry = $client->getContainer() 44 $entry = $client->getContainer()
44 ->get('doctrine.orm.entity_manager') 45 ->get('doctrine.orm.entity_manager')
45 ->getRepository('WallabagCoreBundle:Entry') 46 ->getRepository('WallabagCoreBundle:Entry')
46 ->findOneByUsernameAndNotArchived('admin'); 47 ->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId());
47 48
48 $this->assertEquals(1, count($entry->getTags())); 49 $this->assertEquals(3, count($entry->getTags()));
49 50
50 # tag already exists and already assigned 51 // tag already exists and already assigned
51 $client->submit($form, $data); 52 $client->submit($form, $data);
52 $this->assertEquals(302, $client->getResponse()->getStatusCode()); 53 $this->assertEquals(302, $client->getResponse()->getStatusCode());
53 54
@@ -56,9 +57,9 @@ class TagControllerTest extends WallabagCoreTestCase
56 ->getRepository('WallabagCoreBundle:Entry') 57 ->getRepository('WallabagCoreBundle:Entry')
57 ->find($entry->getId()); 58 ->find($entry->getId());
58 59
59 $this->assertEquals(1, count($newEntry->getTags())); 60 $this->assertEquals(3, count($newEntry->getTags()));
60 61
61 # tag already exists but still not assigned to this entry 62 // tag already exists but still not assigned to this entry
62 $data = [ 63 $data = [
63 'tag[label]' => 'foo', 64 'tag[label]' => 'foo',
64 ]; 65 ];
@@ -71,7 +72,7 @@ class TagControllerTest extends WallabagCoreTestCase
71 ->getRepository('WallabagCoreBundle:Entry') 72 ->getRepository('WallabagCoreBundle:Entry')
72 ->find($entry->getId()); 73 ->find($entry->getId());
73 74
74 $this->assertEquals(2, count($newEntry->getTags())); 75 $this->assertEquals(3, count($newEntry->getTags()));
75 } 76 }
76 77
77 public function testAddMultipleTagToEntry() 78 public function testAddMultipleTagToEntry()
@@ -82,7 +83,7 @@ class TagControllerTest extends WallabagCoreTestCase
82 $entry = $client->getContainer() 83 $entry = $client->getContainer()
83 ->get('doctrine.orm.entity_manager') 84 ->get('doctrine.orm.entity_manager')
84 ->getRepository('WallabagCoreBundle:Entry') 85 ->getRepository('WallabagCoreBundle:Entry')
85 ->findOneByUsernameAndNotArchived('admin'); 86 ->findByUrlAndUserId('http://0.0.0.0/entry2', $this->getLoggedInUserId());
86 87
87 $crawler = $client->request('GET', '/view/'.$entry->getId()); 88 $crawler = $client->request('GET', '/view/'.$entry->getId());
88 89
@@ -101,9 +102,13 @@ class TagControllerTest extends WallabagCoreTestCase
101 ->find($entry->getId()); 102 ->find($entry->getId());
102 103
103 $tags = $newEntry->getTags()->toArray(); 104 $tags = $newEntry->getTags()->toArray();
105 foreach ($tags as $key => $tag) {
106 $tags[$key] = $tag->getLabel();
107 }
108
104 $this->assertGreaterThanOrEqual(2, count($tags)); 109 $this->assertGreaterThanOrEqual(2, count($tags));
105 $this->assertNotEquals(false, array_search('foo2', $tags), 'Tag foo2 is assigned to the entry'); 110 $this->assertNotFalse(array_search('foo2', $tags), 'Tag foo2 is assigned to the entry');
106 $this->assertNotEquals(false, array_search('bar2', $tags), 'Tag bar2 is assigned to the entry'); 111 $this->assertNotFalse(array_search('bar2', $tags), 'Tag bar2 is assigned to the entry');
107 } 112 }
108 113
109 public function testRemoveTagFromEntry() 114 public function testRemoveTagFromEntry()
@@ -114,7 +119,7 @@ class TagControllerTest extends WallabagCoreTestCase
114 $entry = $client->getContainer() 119 $entry = $client->getContainer()
115 ->get('doctrine.orm.entity_manager') 120 ->get('doctrine.orm.entity_manager')
116 ->getRepository('WallabagCoreBundle:Entry') 121 ->getRepository('WallabagCoreBundle:Entry')
117 ->findOneByUsernameAndNotArchived('admin'); 122 ->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId());
118 123
119 $tag = $client->getContainer() 124 $tag = $client->getContainer()
120 ->get('doctrine.orm.entity_manager') 125 ->get('doctrine.orm.entity_manager')
@@ -130,5 +135,48 @@ class TagControllerTest extends WallabagCoreTestCase
130 $client->request('GET', '/remove-tag/'.$entry->getId().'/'.$tag->getId()); 135 $client->request('GET', '/remove-tag/'.$entry->getId().'/'.$tag->getId());
131 136
132 $this->assertEquals(404, $client->getResponse()->getStatusCode()); 137 $this->assertEquals(404, $client->getResponse()->getStatusCode());
138
139 $tag = $client->getContainer()
140 ->get('doctrine.orm.entity_manager')
141 ->getRepository('WallabagCoreBundle:Tag')
142 ->findOneByLabel($this->tagName);
143
144 $this->assertNull($tag, $this->tagName.' was removed because it begun an orphan tag');
145 }
146
147 public function testShowEntriesForTagAction()
148 {
149 $this->logInAs('admin');
150 $client = $this->getClient();
151 $em = $client->getContainer()
152 ->get('doctrine.orm.entity_manager');
153
154 $tag = new Tag();
155 $tag->setLabel($this->tagName);
156
157 $entry = $client->getContainer()
158 ->get('doctrine.orm.entity_manager')
159 ->getRepository('WallabagCoreBundle:Entry')
160 ->findByUrlAndUserId('http://0.0.0.0/entry4', $this->getLoggedInUserId());
161
162 $tag->addEntry($entry);
163
164 $em->persist($entry);
165 $em->persist($tag);
166 $em->flush();
167
168 $tag = $client->getContainer()
169 ->get('doctrine.orm.entity_manager')
170 ->getRepository('WallabagCoreBundle:Tag')
171 ->findOneByEntryAndTagLabel($entry, $this->tagName);
172
173 $crawler = $client->request('GET', '/tag/list/'.$tag->getSlug());
174
175 $this->assertEquals(200, $client->getResponse()->getStatusCode());
176 $this->assertCount(1, $crawler->filter('[id*="entry-"]'));
177
178 $entry->removeTag($tag);
179 $em->remove($tag);
180 $em->flush();
133 } 181 }
134} 182}