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/EntryControllerTest.php53
-rw-r--r--tests/Wallabag/CoreBundle/Controller/RssControllerTest.php43
-rw-r--r--tests/Wallabag/CoreBundle/Controller/SiteCredentialControllerTest.php139
3 files changed, 226 insertions, 9 deletions
diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
index 853f37f2..7cf28bfe 100644
--- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
@@ -5,6 +5,7 @@ namespace Tests\Wallabag\CoreBundle\Controller;
5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; 5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
6use Wallabag\CoreBundle\Entity\Config; 6use Wallabag\CoreBundle\Entity\Config;
7use Wallabag\CoreBundle\Entity\Entry; 7use Wallabag\CoreBundle\Entity\Entry;
8use Wallabag\CoreBundle\Entity\SiteCredential;
8 9
9class EntryControllerTest extends WallabagCoreTestCase 10class EntryControllerTest extends WallabagCoreTestCase
10{ 11{
@@ -1335,4 +1336,56 @@ class EntryControllerTest extends WallabagCoreTestCase
1335 $this->assertEquals($url, $content->getUrl()); 1336 $this->assertEquals($url, $content->getUrl());
1336 $this->assertEquals($expectedLanguage, $content->getLanguage()); 1337 $this->assertEquals($expectedLanguage, $content->getLanguage());
1337 } 1338 }
1339
1340 /**
1341 * This test will require an internet connection.
1342 */
1343 public function testRestrictedArticle()
1344 {
1345 $url = 'http://www.monde-diplomatique.fr/2017/05/BONNET/57475';
1346 $this->logInAs('admin');
1347 $client = $this->getClient();
1348 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
1349
1350 // enable restricted access
1351 $client->getContainer()->get('craue_config')->set('restricted_access', 1);
1352
1353 // create a new site_credential
1354 $user = $client->getContainer()->get('security.token_storage')->getToken()->getUser();
1355 $credential = new SiteCredential($user);
1356 $credential->setHost('monde-diplomatique.fr');
1357 $credential->setUsername($client->getContainer()->get('wallabag_core.helper.crypto_proxy')->crypt('foo'));
1358 $credential->setPassword($client->getContainer()->get('wallabag_core.helper.crypto_proxy')->crypt('bar'));
1359
1360 $em->persist($credential);
1361 $em->flush();
1362
1363 $crawler = $client->request('GET', '/new');
1364
1365 $this->assertEquals(200, $client->getResponse()->getStatusCode());
1366
1367 $form = $crawler->filter('form[name=entry]')->form();
1368
1369 $data = [
1370 'entry[url]' => $url,
1371 ];
1372
1373 $client->submit($form, $data);
1374
1375 $this->assertEquals(302, $client->getResponse()->getStatusCode());
1376
1377 $crawler = $client->followRedirect();
1378
1379 $this->assertEquals(200, $client->getResponse()->getStatusCode());
1380 $this->assertContains('flashes.entry.notice.entry_saved', $crawler->filter('body')->extract(['_text'])[0]);
1381
1382 $content = $em
1383 ->getRepository('WallabagCoreBundle:Entry')
1384 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1385
1386 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
1387 $this->assertSame('Crimes et réformes aux Philippines', $content->getTitle());
1388
1389 $client->getContainer()->get('craue_config')->set('restricted_access', 0);
1390 }
1338} 1391}
diff --git a/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php b/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php
index 5a59654d..530c8bbf 100644
--- a/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php
@@ -6,7 +6,7 @@ use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
6 6
7class RssControllerTest extends WallabagCoreTestCase 7class RssControllerTest extends WallabagCoreTestCase
8{ 8{
9 public function validateDom($xml, $type, $nb = null) 9 public function validateDom($xml, $type, $urlPagination, $nb = null)
10 { 10 {
11 $doc = new \DOMDocument(); 11 $doc = new \DOMDocument();
12 $doc->loadXML($xml); 12 $doc->loadXML($xml);
@@ -23,7 +23,7 @@ class RssControllerTest extends WallabagCoreTestCase
23 $this->assertEquals(1, $xpath->query('/rss/channel')->length); 23 $this->assertEquals(1, $xpath->query('/rss/channel')->length);
24 24
25 $this->assertEquals(1, $xpath->query('/rss/channel/title')->length); 25 $this->assertEquals(1, $xpath->query('/rss/channel/title')->length);
26 $this->assertEquals('wallabag '.$type.' feed', $xpath->query('/rss/channel/title')->item(0)->nodeValue); 26 $this->assertEquals('wallabag - '.$type.' feed', $xpath->query('/rss/channel/title')->item(0)->nodeValue);
27 27
28 $this->assertEquals(1, $xpath->query('/rss/channel/pubDate')->length); 28 $this->assertEquals(1, $xpath->query('/rss/channel/pubDate')->length);
29 29
@@ -34,10 +34,10 @@ class RssControllerTest extends WallabagCoreTestCase
34 $this->assertEquals('wallabag '.$type.' elements', $xpath->query('/rss/channel/description')->item(0)->nodeValue); 34 $this->assertEquals('wallabag '.$type.' elements', $xpath->query('/rss/channel/description')->item(0)->nodeValue);
35 35
36 $this->assertEquals(1, $xpath->query('/rss/channel/link[@rel="self"]')->length); 36 $this->assertEquals(1, $xpath->query('/rss/channel/link[@rel="self"]')->length);
37 $this->assertContains($type.'.xml', $xpath->query('/rss/channel/link[@rel="self"]')->item(0)->getAttribute('href')); 37 $this->assertContains($urlPagination.'.xml', $xpath->query('/rss/channel/link[@rel="self"]')->item(0)->getAttribute('href'));
38 38
39 $this->assertEquals(1, $xpath->query('/rss/channel/link[@rel="last"]')->length); 39 $this->assertEquals(1, $xpath->query('/rss/channel/link[@rel="last"]')->length);
40 $this->assertContains($type.'.xml?page=', $xpath->query('/rss/channel/link[@rel="last"]')->item(0)->getAttribute('href')); 40 $this->assertContains($urlPagination.'.xml?page=', $xpath->query('/rss/channel/link[@rel="last"]')->item(0)->getAttribute('href'));
41 41
42 foreach ($xpath->query('//item') as $item) { 42 foreach ($xpath->query('//item') as $item) {
43 $this->assertEquals(1, $xpath->query('title', $item)->length); 43 $this->assertEquals(1, $xpath->query('title', $item)->length);
@@ -94,7 +94,7 @@ class RssControllerTest extends WallabagCoreTestCase
94 94
95 $this->assertEquals(200, $client->getResponse()->getStatusCode()); 95 $this->assertEquals(200, $client->getResponse()->getStatusCode());
96 96
97 $this->validateDom($client->getResponse()->getContent(), 'unread', 2); 97 $this->validateDom($client->getResponse()->getContent(), 'unread', 'unread', 2);
98 } 98 }
99 99
100 public function testStarred() 100 public function testStarred()
@@ -116,7 +116,7 @@ class RssControllerTest extends WallabagCoreTestCase
116 116
117 $this->assertEquals(200, $client->getResponse()->getStatusCode(), 1); 117 $this->assertEquals(200, $client->getResponse()->getStatusCode(), 1);
118 118
119 $this->validateDom($client->getResponse()->getContent(), 'starred'); 119 $this->validateDom($client->getResponse()->getContent(), 'starred', 'starred');
120 } 120 }
121 121
122 public function testArchives() 122 public function testArchives()
@@ -138,7 +138,7 @@ class RssControllerTest extends WallabagCoreTestCase
138 138
139 $this->assertEquals(200, $client->getResponse()->getStatusCode()); 139 $this->assertEquals(200, $client->getResponse()->getStatusCode());
140 140
141 $this->validateDom($client->getResponse()->getContent(), 'archive'); 141 $this->validateDom($client->getResponse()->getContent(), 'archive', 'archive');
142 } 142 }
143 143
144 public function testPagination() 144 public function testPagination()
@@ -159,13 +159,38 @@ class RssControllerTest extends WallabagCoreTestCase
159 159
160 $client->request('GET', '/admin/SUPERTOKEN/unread.xml'); 160 $client->request('GET', '/admin/SUPERTOKEN/unread.xml');
161 $this->assertEquals(200, $client->getResponse()->getStatusCode()); 161 $this->assertEquals(200, $client->getResponse()->getStatusCode());
162 $this->validateDom($client->getResponse()->getContent(), 'unread'); 162 $this->validateDom($client->getResponse()->getContent(), 'unread', 'unread');
163 163
164 $client->request('GET', '/admin/SUPERTOKEN/unread.xml?page=2'); 164 $client->request('GET', '/admin/SUPERTOKEN/unread.xml?page=2');
165 $this->assertEquals(200, $client->getResponse()->getStatusCode()); 165 $this->assertEquals(200, $client->getResponse()->getStatusCode());
166 $this->validateDom($client->getResponse()->getContent(), 'unread'); 166 $this->validateDom($client->getResponse()->getContent(), 'unread', 'unread');
167 167
168 $client->request('GET', '/admin/SUPERTOKEN/unread.xml?page=3000'); 168 $client->request('GET', '/admin/SUPERTOKEN/unread.xml?page=3000');
169 $this->assertEquals(302, $client->getResponse()->getStatusCode()); 169 $this->assertEquals(302, $client->getResponse()->getStatusCode());
170 } 170 }
171
172 public function testTags()
173 {
174 $client = $this->getClient();
175 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
176 $user = $em
177 ->getRepository('WallabagUserBundle:User')
178 ->findOneByUsername('admin');
179
180 $config = $user->getConfig();
181 $config->setRssToken('SUPERTOKEN');
182 $config->setRssLimit(null);
183 $em->persist($config);
184 $em->flush();
185
186 $client = $this->getClient();
187 $client->request('GET', '/admin/SUPERTOKEN/tags/foo-bar.xml');
188
189 $this->assertEquals(200, $client->getResponse()->getStatusCode());
190
191 $this->validateDom($client->getResponse()->getContent(), 'tag (foo bar)', 'tags/foo-bar');
192
193 $client->request('GET', '/admin/SUPERTOKEN/tags/foo-bar.xml?page=3000');
194 $this->assertEquals(302, $client->getResponse()->getStatusCode());
195 }
171} 196}
diff --git a/tests/Wallabag/CoreBundle/Controller/SiteCredentialControllerTest.php b/tests/Wallabag/CoreBundle/Controller/SiteCredentialControllerTest.php
new file mode 100644
index 00000000..e73a9743
--- /dev/null
+++ b/tests/Wallabag/CoreBundle/Controller/SiteCredentialControllerTest.php
@@ -0,0 +1,139 @@
1<?php
2
3namespace Tests\Wallabag\CoreBundle\Controller;
4
5use Symfony\Bundle\FrameworkBundle\Client;
6use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
7use Wallabag\CoreBundle\Entity\SiteCredential;
8
9class SiteCredentialControllerTest extends WallabagCoreTestCase
10{
11 public function testListSiteCredential()
12 {
13 $this->logInAs('admin');
14 $client = $this->getClient();
15
16 $crawler = $client->request('GET', '/site-credentials/');
17
18 $this->assertEquals(200, $client->getResponse()->getStatusCode());
19
20 $body = $crawler->filter('body')->extract(['_text'])[0];
21
22 $this->assertContains('site_credential.description', $body);
23 $this->assertContains('site_credential.list.create_new_one', $body);
24 }
25
26 public function testNewSiteCredential()
27 {
28 $this->logInAs('admin');
29 $client = $this->getClient();
30
31 $crawler = $client->request('GET', '/site-credentials/new');
32
33 $this->assertEquals(200, $client->getResponse()->getStatusCode());
34
35 $body = $crawler->filter('body')->extract(['_text'])[0];
36
37 $this->assertContains('site_credential.new_site_credential', $body);
38 $this->assertContains('site_credential.form.back_to_list', $body);
39
40 $form = $crawler->filter('button[id=site_credential_save]')->form();
41
42 $data = [
43 'site_credential[host]' => 'google.io',
44 'site_credential[username]' => 'sergei',
45 'site_credential[password]' => 'microsoft',
46 ];
47
48 $client->submit($form, $data);
49
50 $this->assertEquals(302, $client->getResponse()->getStatusCode());
51
52 $crawler = $client->followRedirect();
53
54 $this->assertContains('flashes.site_credential.notice.added', $crawler->filter('body')->extract(['_text'])[0]);
55 }
56
57 public function testEditSiteCredential()
58 {
59 $this->logInAs('admin');
60 $client = $this->getClient();
61
62 $credential = $this->createSiteCredential($client);
63
64 $crawler = $client->request('GET', '/site-credentials/'.$credential->getId().'/edit');
65
66 $this->assertEquals(200, $client->getResponse()->getStatusCode());
67
68 $body = $crawler->filter('body')->extract(['_text'])[0];
69
70 $this->assertContains('site_credential.edit_site_credential', $body);
71 $this->assertContains('site_credential.form.back_to_list', $body);
72
73 $form = $crawler->filter('button[id=site_credential_save]')->form();
74
75 $data = [
76 'site_credential[host]' => 'google.io',
77 'site_credential[username]' => 'larry',
78 'site_credential[password]' => 'microsoft',
79 ];
80
81 $client->submit($form, $data);
82
83 $this->assertEquals(302, $client->getResponse()->getStatusCode());
84
85 $crawler = $client->followRedirect();
86
87 $this->assertContains('flashes.site_credential.notice.updated', $crawler->filter('body')->extract(['_text'])[0]);
88 }
89
90 public function testEditFromADifferentUserSiteCredential()
91 {
92 $this->logInAs('admin');
93 $client = $this->getClient();
94
95 $credential = $this->createSiteCredential($client);
96
97 $this->logInAs('bob');
98
99 $client->request('GET', '/site-credentials/'.$credential->getId().'/edit');
100
101 $this->assertEquals(403, $client->getResponse()->getStatusCode());
102 }
103
104 public function testDeleteSiteCredential()
105 {
106 $this->logInAs('admin');
107 $client = $this->getClient();
108
109 $credential = $this->createSiteCredential($client);
110
111 $crawler = $client->request('GET', '/site-credentials/'.$credential->getId().'/edit');
112
113 $this->assertEquals(200, $client->getResponse()->getStatusCode());
114
115 $deleteForm = $crawler->filter('body')->selectButton('site_credential.form.delete')->form();
116
117 $client->submit($deleteForm, []);
118
119 $this->assertEquals(302, $client->getResponse()->getStatusCode());
120
121 $crawler = $client->followRedirect();
122
123 $this->assertContains('flashes.site_credential.notice.deleted', $crawler->filter('body')->extract(['_text'])[0]);
124 }
125
126 private function createSiteCredential(Client $client)
127 {
128 $credential = new SiteCredential($this->getLoggedInUser());
129 $credential->setHost('google.io');
130 $credential->setUsername('sergei');
131 $credential->setPassword('microsoft');
132
133 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
134 $em->persist($credential);
135 $em->flush();
136
137 return $credential;
138 }
139}