aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php (renamed from tests/Wallabag/CoreBundle/Controller/DeveloperControllerTest.php)28
-rw-r--r--tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php25
-rw-r--r--tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php120
-rw-r--r--tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php27
-rw-r--r--tests/Wallabag/CoreBundle/Controller/TagControllerTest.php33
-rw-r--r--tests/Wallabag/CoreBundle/WallabagCoreTestCase.php4
-rw-r--r--tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php1
-rw-r--r--tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php1
8 files changed, 211 insertions, 28 deletions
diff --git a/tests/Wallabag/CoreBundle/Controller/DeveloperControllerTest.php b/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php
index 97ed0d58..95befa9c 100644
--- a/tests/Wallabag/CoreBundle/Controller/DeveloperControllerTest.php
+++ b/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php
@@ -1,6 +1,6 @@
1<?php 1<?php
2 2
3namespace Tests\Wallabag\CoreBundle\Controller; 3namespace Tests\Wallabag\ApiBundle\Controller;
4 4
5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; 5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
6 6
@@ -33,6 +33,32 @@ class DeveloperControllerTest extends WallabagCoreTestCase
33 $this->assertContains('My app', $alert[0]); 33 $this->assertContains('My app', $alert[0]);
34 } 34 }
35 35
36 /**
37 * @depends testCreateClient
38 */
39 public function testCreateToken()
40 {
41 $client = $this->getClient();
42 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
43 $apiClient = $em->getRepository('WallabagApiBundle:Client')->findOneByName('My app');
44
45 $client->request('POST', '/oauth/v2/token', [
46 'grant_type' => 'password',
47 'client_id' => $apiClient->getPublicId(),
48 'client_secret' => $apiClient->getSecret(),
49 'username' => 'admin',
50 'password' => 'mypassword',
51 ]);
52
53 $this->assertEquals(200, $client->getResponse()->getStatusCode());
54
55 $data = json_decode($client->getResponse()->getContent(), true);
56 $this->assertArrayHasKey('access_token', $data);
57 $this->assertArrayHasKey('expires_in', $data);
58 $this->assertArrayHasKey('token_type', $data);
59 $this->assertArrayHasKey('refresh_token', $data);
60 }
61
36 public function testListingClient() 62 public function testListingClient()
37 { 63 {
38 $this->logInAs('admin'); 64 $this->logInAs('admin');
diff --git a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php
index 79353857..6bca3c8b 100644
--- a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php
+++ b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php
@@ -569,6 +569,8 @@ class WallabagRestControllerTest extends WallabagApiTestCase
569 */ 569 */
570 public function testDeleteUserTag($tag) 570 public function testDeleteUserTag($tag)
571 { 571 {
572 $tagName = $tag['label'];
573
572 $this->client->request('DELETE', '/api/tags/'.$tag['id'].'.json'); 574 $this->client->request('DELETE', '/api/tags/'.$tag['id'].'.json');
573 575
574 $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); 576 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
@@ -585,6 +587,13 @@ class WallabagRestControllerTest extends WallabagApiTestCase
585 ->findAllByTagId($this->user->getId(), $tag['id']); 587 ->findAllByTagId($this->user->getId(), $tag['id']);
586 588
587 $this->assertCount(0, $entries); 589 $this->assertCount(0, $entries);
590
591 $tag = $this->client->getContainer()
592 ->get('doctrine.orm.entity_manager')
593 ->getRepository('WallabagCoreBundle:Tag')
594 ->findOneByLabel($tagName);
595
596 $this->assertNull($tag, $tagName.' was removed because it begun an orphan tag');
588 } 597 }
589 598
590 public function testDeleteTagByLabel() 599 public function testDeleteTagByLabel()
@@ -802,6 +811,22 @@ class WallabagRestControllerTest extends WallabagApiTestCase
802 $this->assertEquals(true, $content['exists']); 811 $this->assertEquals(true, $content['exists']);
803 } 812 }
804 813
814 public function testGetEntriesExistsWithManyUrls()
815 {
816 $url1 = 'http://0.0.0.0/entry2';
817 $url2 = 'http://0.0.0.0/entry10';
818 $this->client->request('GET', '/api/entries/exists?urls[]='.$url1.'&urls[]='.$url2);
819
820 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
821
822 $content = json_decode($this->client->getResponse()->getContent(), true);
823
824 $this->assertArrayHasKey($url1, $content);
825 $this->assertArrayHasKey($url2, $content);
826 $this->assertEquals(true, $content[$url1]);
827 $this->assertEquals(false, $content[$url2]);
828 }
829
805 public function testGetEntriesExistsWhichDoesNotExists() 830 public function testGetEntriesExistsWhichDoesNotExists()
806 { 831 {
807 $this->client->request('GET', '/api/entries/exists?url=http://google.com/entry2'); 832 $this->client->request('GET', '/api/entries/exists?url=http://google.com/entry2');
diff --git a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
index 1954c654..5faa0130 100644
--- a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
@@ -3,6 +3,8 @@
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\Config;
7use Wallabag\UserBundle\Entity\User;
6 8
7class ConfigControllerTest extends WallabagCoreTestCase 9class ConfigControllerTest extends WallabagCoreTestCase
8{ 10{
@@ -570,4 +572,122 @@ class ConfigControllerTest extends WallabagCoreTestCase
570 $config->set('demo_mode_enabled', 0); 572 $config->set('demo_mode_enabled', 0);
571 $config->set('demo_mode_username', 'wallabag'); 573 $config->set('demo_mode_username', 'wallabag');
572 } 574 }
575
576 public function testDeleteUserButtonVisibility()
577 {
578 $this->logInAs('admin');
579 $client = $this->getClient();
580
581 $crawler = $client->request('GET', '/config');
582
583 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
584 $this->assertContains('config.form_user.delete.button', $body[0]);
585
586 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
587
588 $user = $em
589 ->getRepository('WallabagUserBundle:User')
590 ->findOneByUsername('empty');
591 $user->setExpired(1);
592 $em->persist($user);
593
594 $user = $em
595 ->getRepository('WallabagUserBundle:User')
596 ->findOneByUsername('bob');
597 $user->setExpired(1);
598 $em->persist($user);
599
600 $em->flush();
601
602 $crawler = $client->request('GET', '/config');
603
604 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
605 $this->assertNotContains('config.form_user.delete.button', $body[0]);
606
607 $client->request('GET', '/account/delete');
608 $this->assertEquals(403, $client->getResponse()->getStatusCode());
609
610 $user = $em
611 ->getRepository('WallabagUserBundle:User')
612 ->findOneByUsername('empty');
613 $user->setExpired(0);
614 $em->persist($user);
615
616 $user = $em
617 ->getRepository('WallabagUserBundle:User')
618 ->findOneByUsername('bob');
619 $user->setExpired(0);
620 $em->persist($user);
621
622 $em->flush();
623 }
624
625 public function testDeleteAccount()
626 {
627 $client = $this->getClient();
628 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
629
630 $user = new User();
631 $user->setName('Wallace');
632 $user->setEmail('wallace@wallabag.org');
633 $user->setUsername('wallace');
634 $user->setPlainPassword('wallace');
635 $user->setEnabled(true);
636 $user->addRole('ROLE_SUPER_ADMIN');
637
638 $em->persist($user);
639
640 $config = new Config($user);
641
642 $config->setTheme('material');
643 $config->setItemsPerPage(30);
644 $config->setReadingSpeed(1);
645 $config->setLanguage('en');
646 $config->setPocketConsumerKey('xxxxx');
647
648 $em->persist($config);
649 $em->flush();
650
651 $this->logInAs('wallace');
652 $loggedInUserId = $this->getLoggedInUserId();
653
654 // create entry to check after user deletion
655 // that this entry is also deleted
656 $crawler = $client->request('GET', '/new');
657
658 $this->assertEquals(200, $client->getResponse()->getStatusCode());
659
660 $form = $crawler->filter('form[name=entry]')->form();
661 $data = [
662 'entry[url]' => $url = 'https://github.com/wallabag/wallabag',
663 ];
664
665 $client->submit($form, $data);
666 $this->assertEquals(302, $client->getResponse()->getStatusCode());
667
668 $crawler = $client->request('GET', '/config');
669
670 $deleteLink = $crawler->filter('.delete-account')->last()->link();
671
672 $client->click($deleteLink);
673 $this->assertEquals(302, $client->getResponse()->getStatusCode());
674
675 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
676 $user = $em
677 ->getRepository('WallabagUserBundle:User')
678 ->createQueryBuilder('u')
679 ->where('u.username = :username')->setParameter('username', 'wallace')
680 ->getQuery()
681 ->getOneOrNullResult()
682 ;
683
684 $this->assertNull($user);
685
686 $entries = $client->getContainer()
687 ->get('doctrine.orm.entity_manager')
688 ->getRepository('WallabagCoreBundle:Entry')
689 ->findByUser($loggedInUserId);
690
691 $this->assertEmpty($entries);
692 }
573} 693}
diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
index d7bf03ba..9b03a519 100644
--- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
@@ -341,22 +341,23 @@ class EntryControllerTest extends WallabagCoreTestCase
341 $this->logInAs('admin'); 341 $this->logInAs('admin');
342 $client = $this->getClient(); 342 $client = $this->getClient();
343 343
344 $content = $client->getContainer() 344 $em = $client->getContainer()
345 ->get('doctrine.orm.entity_manager') 345 ->get('doctrine.orm.entity_manager');
346
347 $content = $em
346 ->getRepository('WallabagCoreBundle:Entry') 348 ->getRepository('WallabagCoreBundle:Entry')
347 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); 349 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
348 350
349 // empty content 351 // empty content
350 $content->setContent(''); 352 $content->setContent('');
351 $client->getContainer()->get('doctrine.orm.entity_manager')->persist($content); 353 $em->persist($content);
352 $client->getContainer()->get('doctrine.orm.entity_manager')->flush(); 354 $em->flush();
353 355
354 $client->request('GET', '/reload/'.$content->getId()); 356 $client->request('GET', '/reload/'.$content->getId());
355 357
356 $this->assertEquals(302, $client->getResponse()->getStatusCode()); 358 $this->assertEquals(302, $client->getResponse()->getStatusCode());
357 359
358 $content = $client->getContainer() 360 $content = $em
359 ->get('doctrine.orm.entity_manager')
360 ->getRepository('WallabagCoreBundle:Entry') 361 ->getRepository('WallabagCoreBundle:Entry')
361 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); 362 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
362 363
@@ -486,9 +487,11 @@ class EntryControllerTest extends WallabagCoreTestCase
486 $this->logInAs('admin'); 487 $this->logInAs('admin');
487 $client = $this->getClient(); 488 $client = $this->getClient();
488 489
490 $em = $client->getContainer()
491 ->get('doctrine.orm.entity_manager');
492
489 // add a new content to be removed later 493 // add a new content to be removed later
490 $user = $client->getContainer() 494 $user = $em
491 ->get('doctrine.orm.entity_manager')
492 ->getRepository('WallabagUserBundle:User') 495 ->getRepository('WallabagUserBundle:User')
493 ->findOneByUserName('admin'); 496 ->findOneByUserName('admin');
494 497
@@ -502,12 +505,8 @@ class EntryControllerTest extends WallabagCoreTestCase
502 $content->setArchived(true); 505 $content->setArchived(true);
503 $content->setLanguage('fr'); 506 $content->setLanguage('fr');
504 507
505 $client->getContainer() 508 $em->persist($content);
506 ->get('doctrine.orm.entity_manager') 509 $em->flush();
507 ->persist($content);
508 $client->getContainer()
509 ->get('doctrine.orm.entity_manager')
510 ->flush();
511 510
512 $client->request('GET', '/view/'.$content->getId()); 511 $client->request('GET', '/view/'.$content->getId());
513 $this->assertEquals(200, $client->getResponse()->getStatusCode()); 512 $this->assertEquals(200, $client->getResponse()->getStatusCode());
diff --git a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php
index 86a6cca2..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{
@@ -134,36 +135,48 @@ class TagControllerTest extends WallabagCoreTestCase
134 $client->request('GET', '/remove-tag/'.$entry->getId().'/'.$tag->getId()); 135 $client->request('GET', '/remove-tag/'.$entry->getId().'/'.$tag->getId());
135 136
136 $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');
137 } 145 }
138 146
139 public function testShowEntriesForTagAction() 147 public function testShowEntriesForTagAction()
140 { 148 {
141 $this->logInAs('admin'); 149 $this->logInAs('admin');
142 $client = $this->getClient(); 150 $client = $this->getClient();
151 $em = $client->getContainer()
152 ->get('doctrine.orm.entity_manager');
153
154 $tag = new Tag();
155 $tag->setLabel($this->tagName);
143 156
144 $entry = $client->getContainer() 157 $entry = $client->getContainer()
145 ->get('doctrine.orm.entity_manager') 158 ->get('doctrine.orm.entity_manager')
146 ->getRepository('WallabagCoreBundle:Entry') 159 ->getRepository('WallabagCoreBundle:Entry')
147 ->findByUrlAndUserId('http://0.0.0.0/entry4', $this->getLoggedInUserId()); 160 ->findByUrlAndUserId('http://0.0.0.0/entry4', $this->getLoggedInUserId());
148 161
149 $tag = $client->getContainer() 162 $tag->addEntry($entry);
150 ->get('doctrine.orm.entity_manager')
151 ->getRepository('WallabagCoreBundle:Tag')
152 ->findOneByEntryAndTagLabel($entry, 'foo');
153
154 $crawler = $client->request('GET', '/tag/list/'.$tag->getSlug());
155 163
156 $this->assertEquals(200, $client->getResponse()->getStatusCode()); 164 $em->persist($entry);
157 $this->assertCount(2, $crawler->filter('div[class=entry]')); 165 $em->persist($tag);
166 $em->flush();
158 167
159 $tag = $client->getContainer() 168 $tag = $client->getContainer()
160 ->get('doctrine.orm.entity_manager') 169 ->get('doctrine.orm.entity_manager')
161 ->getRepository('WallabagCoreBundle:Tag') 170 ->getRepository('WallabagCoreBundle:Tag')
162 ->findOneByLabel('baz'); 171 ->findOneByEntryAndTagLabel($entry, $this->tagName);
163 172
164 $crawler = $client->request('GET', '/tag/list/'.$tag->getSlug()); 173 $crawler = $client->request('GET', '/tag/list/'.$tag->getSlug());
165 174
166 $this->assertEquals(200, $client->getResponse()->getStatusCode()); 175 $this->assertEquals(200, $client->getResponse()->getStatusCode());
167 $this->assertCount(1, $crawler->filter('div[class=entry]')); 176 $this->assertCount(1, $crawler->filter('[id*="entry-"]'));
177
178 $entry->removeTag($tag);
179 $em->remove($tag);
180 $em->flush();
168 } 181 }
169} 182}
diff --git a/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php b/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php
index 4f103921..7bf4b43c 100644
--- a/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php
+++ b/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php
@@ -90,9 +90,7 @@ abstract class WallabagCoreTestCase extends WebTestCase
90 try { 90 try {
91 $this->client->getContainer()->get('wallabag_core.redis.client')->connect(); 91 $this->client->getContainer()->get('wallabag_core.redis.client')->connect();
92 } catch (\Exception $e) { 92 } catch (\Exception $e) {
93 $this->markTestSkipped( 93 $this->markTestSkipped('Redis is not installed/activated');
94 'Redis is not installed/activated'
95 );
96 } 94 }
97 } 95 }
98} 96}
diff --git a/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php
index 23c80bec..c0417bbe 100644
--- a/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php
+++ b/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php
@@ -54,6 +54,7 @@ class ChromeControllerTest extends WallabagCoreTestCase
54 54
55 public function testImportChromeWithRedisEnabled() 55 public function testImportChromeWithRedisEnabled()
56 { 56 {
57 $this->checkRedis();
57 $this->logInAs('admin'); 58 $this->logInAs('admin');
58 $client = $this->getClient(); 59 $client = $this->getClient();
59 $client->getContainer()->get('craue_config')->set('import_with_redis', 1); 60 $client->getContainer()->get('craue_config')->set('import_with_redis', 1);
diff --git a/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php b/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php
index 98f13d72..6154ae8d 100644
--- a/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php
+++ b/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php
@@ -54,6 +54,7 @@ class FirefoxControllerTest extends WallabagCoreTestCase
54 54
55 public function testImportFirefoxWithRedisEnabled() 55 public function testImportFirefoxWithRedisEnabled()
56 { 56 {
57 $this->checkRedis();
57 $this->logInAs('admin'); 58 $this->logInAs('admin');
58 $client = $this->getClient(); 59 $client = $this->getClient();
59 $client->getContainer()->get('craue_config')->set('import_with_redis', 1); 60 $client->getContainer()->get('craue_config')->set('import_with_redis', 1);