diff options
Diffstat (limited to 'tests/Wallabag/CoreBundle')
4 files changed, 37 insertions, 105 deletions
diff --git a/tests/Wallabag/CoreBundle/Controller/DeveloperControllerTest.php b/tests/Wallabag/CoreBundle/Controller/DeveloperControllerTest.php deleted file mode 100644 index 97ed0d58..00000000 --- a/tests/Wallabag/CoreBundle/Controller/DeveloperControllerTest.php +++ /dev/null | |||
@@ -1,78 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Tests\Wallabag\CoreBundle\Controller; | ||
4 | |||
5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | ||
6 | |||
7 | class 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 | $data = [ | ||
22 | 'client[name]' => 'My app', | ||
23 | ]; | ||
24 | |||
25 | $crawler = $client->submit($form, $data); | ||
26 | |||
27 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
28 | |||
29 | $newNbClients = $em->getRepository('WallabagApiBundle:Client')->findAll(); | ||
30 | $this->assertGreaterThan(count($nbClients), count($newNbClients)); | ||
31 | |||
32 | $this->assertGreaterThan(1, $alert = $crawler->filter('.settings ul li strong')->extract(['_text'])); | ||
33 | $this->assertContains('My app', $alert[0]); | ||
34 | } | ||
35 | |||
36 | public function testListingClient() | ||
37 | { | ||
38 | $this->logInAs('admin'); | ||
39 | $client = $this->getClient(); | ||
40 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
41 | $nbClients = $em->getRepository('WallabagApiBundle:Client')->findAll(); | ||
42 | |||
43 | $crawler = $client->request('GET', '/developer'); | ||
44 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
45 | $this->assertEquals(count($nbClients), $crawler->filter('ul[class=collapsible] li')->count()); | ||
46 | } | ||
47 | |||
48 | public function testDeveloperHowto() | ||
49 | { | ||
50 | $this->logInAs('admin'); | ||
51 | $client = $this->getClient(); | ||
52 | |||
53 | $crawler = $client->request('GET', '/developer/howto/first-app'); | ||
54 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
55 | } | ||
56 | |||
57 | public function testRemoveClient() | ||
58 | { | ||
59 | $this->logInAs('admin'); | ||
60 | $client = $this->getClient(); | ||
61 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
62 | $nbClients = $em->getRepository('WallabagApiBundle:Client')->findAll(); | ||
63 | |||
64 | $crawler = $client->request('GET', '/developer'); | ||
65 | |||
66 | $link = $crawler | ||
67 | ->filter('div[class=collapsible-body] p a') | ||
68 | ->eq(0) | ||
69 | ->link() | ||
70 | ; | ||
71 | |||
72 | $client->click($link); | ||
73 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
74 | |||
75 | $newNbClients = $em->getRepository('WallabagApiBundle:Client')->findAll(); | ||
76 | $this->assertGreaterThan(count($newNbClients), count($nbClients)); | ||
77 | } | ||
78 | } | ||
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 @@ | |||
3 | namespace Tests\Wallabag\CoreBundle\Controller; | 3 | namespace Tests\Wallabag\CoreBundle\Controller; |
4 | 4 | ||
5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | 5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; |
6 | use Wallabag\CoreBundle\Entity\Tag; | ||
6 | 7 | ||
7 | class TagControllerTest extends WallabagCoreTestCase | 8 | class 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 | } |