aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/CoreBundle/Tests')
-rw-r--r--src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php38
-rw-r--r--src/Wallabag/CoreBundle/Tests/Controller/SecurityControllerTest.php40
-rw-r--r--src/Wallabag/CoreBundle/Tests/WallabagTestCase.php34
3 files changed, 103 insertions, 9 deletions
diff --git a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php
index fde210c9..5d8daea3 100644
--- a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php
+++ b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php
@@ -2,13 +2,24 @@
2 2
3namespace Wallabag\CoreBundle\Tests\Controller; 3namespace Wallabag\CoreBundle\Tests\Controller;
4 4
5use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; 5use Wallabag\CoreBundle\Tests\WallabagTestCase;
6 6
7class EntryControllerTest extends WebTestCase 7class EntryControllerTest extends WallabagTestCase
8{ 8{
9 public function testLogin()
10 {
11 $client = $this->getClient();
12
13 $crawler = $client->request('GET', '/new');
14
15 $this->assertEquals(302, $client->getResponse()->getStatusCode());
16 $this->assertContains('login', $client->getResponse()->headers->get('location'));
17 }
18
9 public function testGetNew() 19 public function testGetNew()
10 { 20 {
11 $client = static::createClient(); 21 $this->logIn();
22 $client = $this->getClient();
12 23
13 $crawler = $client->request('GET', '/new'); 24 $crawler = $client->request('GET', '/new');
14 25
@@ -20,7 +31,8 @@ class EntryControllerTest extends WebTestCase
20 31
21 public function testPostNewEmpty() 32 public function testPostNewEmpty()
22 { 33 {
23 $client = static::createClient(); 34 $this->logIn();
35 $client = $this->getClient();
24 36
25 $crawler = $client->request('GET', '/new'); 37 $crawler = $client->request('GET', '/new');
26 38
@@ -37,7 +49,8 @@ class EntryControllerTest extends WebTestCase
37 49
38 public function testPostNewOk() 50 public function testPostNewOk()
39 { 51 {
40 $client = static::createClient(); 52 $this->logIn();
53 $client = $this->getClient();
41 54
42 $crawler = $client->request('GET', '/new'); 55 $crawler = $client->request('GET', '/new');
43 56
@@ -55,13 +68,14 @@ class EntryControllerTest extends WebTestCase
55 68
56 $crawler = $client->followRedirect(); 69 $crawler = $client->followRedirect();
57 70
58 $this->assertCount(1, $alert = $crawler->filter('h2 a')->extract(array('_text'))); 71 $this->assertGreaterThan(1, $alert = $crawler->filter('h2 a')->extract(array('_text')));
59 $this->assertContains('Mailjet', $alert[0]); 72 $this->assertContains('Mailjet', $alert[0]);
60 } 73 }
61 74
62 public function testArchive() 75 public function testArchive()
63 { 76 {
64 $client = static::createClient(); 77 $this->logIn();
78 $client = $this->getClient();
65 79
66 $crawler = $client->request('GET', '/archive'); 80 $crawler = $client->request('GET', '/archive');
67 81
@@ -70,7 +84,8 @@ class EntryControllerTest extends WebTestCase
70 84
71 public function testStarred() 85 public function testStarred()
72 { 86 {
73 $client = static::createClient(); 87 $this->logIn();
88 $client = $this->getClient();
74 89
75 $crawler = $client->request('GET', '/starred'); 90 $crawler = $client->request('GET', '/starred');
76 91
@@ -79,13 +94,18 @@ class EntryControllerTest extends WebTestCase
79 94
80 public function testView() 95 public function testView()
81 { 96 {
82 $client = static::createClient(); 97 $this->logIn();
98 $client = $this->getClient();
83 99
84 $content = $client->getContainer() 100 $content = $client->getContainer()
85 ->get('doctrine.orm.entity_manager') 101 ->get('doctrine.orm.entity_manager')
86 ->getRepository('WallabagCoreBundle:Entry') 102 ->getRepository('WallabagCoreBundle:Entry')
87 ->findOneByIsArchived(false); 103 ->findOneByIsArchived(false);
88 104
105 if (!$content) {
106 $this->markTestSkipped('No content found in db.');
107 }
108
89 $crawler = $client->request('GET', '/view/'.$content->getId()); 109 $crawler = $client->request('GET', '/view/'.$content->getId());
90 110
91 $this->assertEquals(200, $client->getResponse()->getStatusCode()); 111 $this->assertEquals(200, $client->getResponse()->getStatusCode());
diff --git a/src/Wallabag/CoreBundle/Tests/Controller/SecurityControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/SecurityControllerTest.php
new file mode 100644
index 00000000..54cf5073
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Tests/Controller/SecurityControllerTest.php
@@ -0,0 +1,40 @@
1<?php
2
3namespace Wallabag\CoreBundle\Tests\Controller;
4
5use Wallabag\CoreBundle\Tests\WallabagTestCase;
6
7class SecurityControllerTest extends WallabagTestCase
8{
9 public function testLogin()
10 {
11 $client = $this->getClient();
12
13 $crawler = $client->request('GET', '/new');
14
15 $this->assertEquals(302, $client->getResponse()->getStatusCode());
16 $this->assertContains('login', $client->getResponse()->headers->get('location'));
17 }
18
19 public function testLoginFail()
20 {
21 $client = $this->getClient();
22
23 $crawler = $client->request('GET', '/login');
24
25 $form = $crawler->filter('button[type=submit]')->form();
26 $data = array(
27 '_username' => 'admin',
28 '_password' => 'admin',
29 );
30
31 $client->submit($form, $data);
32
33 $this->assertEquals(302, $client->getResponse()->getStatusCode());
34 $this->assertContains('login', $client->getResponse()->headers->get('location'));
35
36 $crawler = $client->followRedirect();
37
38 $this->assertContains('Bad credentials', $client->getResponse()->getContent());
39 }
40}
diff --git a/src/Wallabag/CoreBundle/Tests/WallabagTestCase.php b/src/Wallabag/CoreBundle/Tests/WallabagTestCase.php
new file mode 100644
index 00000000..5f092318
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Tests/WallabagTestCase.php
@@ -0,0 +1,34 @@
1<?php
2
3namespace Wallabag\CoreBundle\Tests;
4
5use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
6use Symfony\Component\BrowserKit\Cookie;
7use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
8
9class WallabagTestCase extends WebTestCase
10{
11 private $client = null;
12
13 public function getClient()
14 {
15 return $this->client;
16 }
17
18 public function setUp()
19 {
20 $this->client = static::createClient();
21 }
22
23 public function logIn()
24 {
25 $crawler = $this->client->request('GET', '/login');
26 $form = $crawler->filter('button[type=submit]')->form();
27 $data = array(
28 '_username' => 'admin',
29 '_password' => 'test',
30 );
31
32 $this->client->submit($form, $data);
33 }
34}