aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Wallabag')
-rw-r--r--tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php122
-rw-r--r--tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php173
-rw-r--r--tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php46
-rw-r--r--tests/Wallabag/CoreBundle/Controller/TagControllerTest.php4
-rw-r--r--tests/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php8
-rw-r--r--tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php18
-rw-r--r--tests/Wallabag/CoreBundle/WallabagCoreTestCase.php2
-rw-r--r--tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php2
-rw-r--r--tests/Wallabag/ImportBundle/Controller/InstapaperControllerTest.php196
-rw-r--r--tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php233
-rw-r--r--tests/Wallabag/ImportBundle/fixtures/instapaper-export.csv4
-rw-r--r--tests/Wallabag/UserBundle/Controller/ManageControllerTest.php82
-rw-r--r--tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php (renamed from tests/Wallabag/CoreBundle/EventListener/RegistrationConfirmedListenerTest.php)16
-rw-r--r--tests/Wallabag/UserBundle/Mailer/AuthCodeMailerTest.php2
14 files changed, 762 insertions, 146 deletions
diff --git a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php
index 101c20eb..fd72b8f2 100644
--- a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php
+++ b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php
@@ -78,6 +78,53 @@ class WallabagRestControllerTest extends WallabagApiTestCase
78 ); 78 );
79 } 79 }
80 80
81 public function testGetEntriesWithFullOptions()
82 {
83 $this->client->request('GET', '/api/entries', [
84 'archive' => 1,
85 'starred' => 1,
86 'sort' => 'updated',
87 'order' => 'asc',
88 'page' => 1,
89 'perPage' => 2,
90 'tags' => 'foo',
91 'since' => 1443274283,
92 ]);
93
94 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
95
96 $content = json_decode($this->client->getResponse()->getContent(), true);
97
98 $this->assertGreaterThanOrEqual(1, count($content));
99 $this->assertArrayHasKey('items', $content['_embedded']);
100 $this->assertGreaterThanOrEqual(0, $content['total']);
101 $this->assertEquals(1, $content['page']);
102 $this->assertEquals(2, $content['limit']);
103 $this->assertGreaterThanOrEqual(1, $content['pages']);
104
105 $this->assertArrayHasKey('_links', $content);
106 $this->assertArrayHasKey('self', $content['_links']);
107 $this->assertArrayHasKey('first', $content['_links']);
108 $this->assertArrayHasKey('last', $content['_links']);
109
110 foreach (['self', 'first', 'last'] as $link) {
111 $this->assertArrayHasKey('href', $content['_links'][$link]);
112 $this->assertContains('archive=1', $content['_links'][$link]['href']);
113 $this->assertContains('starred=1', $content['_links'][$link]['href']);
114 $this->assertContains('sort=updated', $content['_links'][$link]['href']);
115 $this->assertContains('order=asc', $content['_links'][$link]['href']);
116 $this->assertContains('tags=foo', $content['_links'][$link]['href']);
117 $this->assertContains('since=1443274283', $content['_links'][$link]['href']);
118 }
119
120 $this->assertTrue(
121 $this->client->getResponse()->headers->contains(
122 'Content-Type',
123 'application/json'
124 )
125 );
126 }
127
81 public function testGetStarredEntries() 128 public function testGetStarredEntries()
82 { 129 {
83 $this->client->request('GET', '/api/entries', ['starred' => 1, 'sort' => 'updated']); 130 $this->client->request('GET', '/api/entries', ['starred' => 1, 'sort' => 'updated']);
@@ -92,6 +139,17 @@ class WallabagRestControllerTest extends WallabagApiTestCase
92 $this->assertEquals(1, $content['page']); 139 $this->assertEquals(1, $content['page']);
93 $this->assertGreaterThanOrEqual(1, $content['pages']); 140 $this->assertGreaterThanOrEqual(1, $content['pages']);
94 141
142 $this->assertArrayHasKey('_links', $content);
143 $this->assertArrayHasKey('self', $content['_links']);
144 $this->assertArrayHasKey('first', $content['_links']);
145 $this->assertArrayHasKey('last', $content['_links']);
146
147 foreach (['self', 'first', 'last'] as $link) {
148 $this->assertArrayHasKey('href', $content['_links'][$link]);
149 $this->assertContains('starred=1', $content['_links'][$link]['href']);
150 $this->assertContains('sort=updated', $content['_links'][$link]['href']);
151 }
152
95 $this->assertTrue( 153 $this->assertTrue(
96 $this->client->getResponse()->headers->contains( 154 $this->client->getResponse()->headers->contains(
97 'Content-Type', 155 'Content-Type',
@@ -114,6 +172,16 @@ class WallabagRestControllerTest extends WallabagApiTestCase
114 $this->assertEquals(1, $content['page']); 172 $this->assertEquals(1, $content['page']);
115 $this->assertGreaterThanOrEqual(1, $content['pages']); 173 $this->assertGreaterThanOrEqual(1, $content['pages']);
116 174
175 $this->assertArrayHasKey('_links', $content);
176 $this->assertArrayHasKey('self', $content['_links']);
177 $this->assertArrayHasKey('first', $content['_links']);
178 $this->assertArrayHasKey('last', $content['_links']);
179
180 foreach (['self', 'first', 'last'] as $link) {
181 $this->assertArrayHasKey('href', $content['_links'][$link]);
182 $this->assertContains('archive=1', $content['_links'][$link]['href']);
183 }
184
117 $this->assertTrue( 185 $this->assertTrue(
118 $this->client->getResponse()->headers->contains( 186 $this->client->getResponse()->headers->contains(
119 'Content-Type', 187 'Content-Type',
@@ -136,6 +204,16 @@ class WallabagRestControllerTest extends WallabagApiTestCase
136 $this->assertEquals(1, $content['page']); 204 $this->assertEquals(1, $content['page']);
137 $this->assertGreaterThanOrEqual(1, $content['pages']); 205 $this->assertGreaterThanOrEqual(1, $content['pages']);
138 206
207 $this->assertArrayHasKey('_links', $content);
208 $this->assertArrayHasKey('self', $content['_links']);
209 $this->assertArrayHasKey('first', $content['_links']);
210 $this->assertArrayHasKey('last', $content['_links']);
211
212 foreach (['self', 'first', 'last'] as $link) {
213 $this->assertArrayHasKey('href', $content['_links'][$link]);
214 $this->assertContains('tags='.urlencode('foo,bar'), $content['_links'][$link]['href']);
215 }
216
139 $this->assertTrue( 217 $this->assertTrue(
140 $this->client->getResponse()->headers->contains( 218 $this->client->getResponse()->headers->contains(
141 'Content-Type', 219 'Content-Type',
@@ -146,7 +224,7 @@ class WallabagRestControllerTest extends WallabagApiTestCase
146 224
147 public function testGetDatedEntries() 225 public function testGetDatedEntries()
148 { 226 {
149 $this->client->request('GET', '/api/entries', ['since' => 1]); 227 $this->client->request('GET', '/api/entries', ['since' => 1443274283]);
150 228
151 $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); 229 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
152 230
@@ -158,6 +236,16 @@ class WallabagRestControllerTest extends WallabagApiTestCase
158 $this->assertEquals(1, $content['page']); 236 $this->assertEquals(1, $content['page']);
159 $this->assertGreaterThanOrEqual(1, $content['pages']); 237 $this->assertGreaterThanOrEqual(1, $content['pages']);
160 238
239 $this->assertArrayHasKey('_links', $content);
240 $this->assertArrayHasKey('self', $content['_links']);
241 $this->assertArrayHasKey('first', $content['_links']);
242 $this->assertArrayHasKey('last', $content['_links']);
243
244 foreach (['self', 'first', 'last'] as $link) {
245 $this->assertArrayHasKey('href', $content['_links'][$link]);
246 $this->assertContains('since=1443274283', $content['_links'][$link]['href']);
247 }
248
161 $this->assertTrue( 249 $this->assertTrue(
162 $this->client->getResponse()->headers->contains( 250 $this->client->getResponse()->headers->contains(
163 'Content-Type', 251 'Content-Type',
@@ -181,6 +269,16 @@ class WallabagRestControllerTest extends WallabagApiTestCase
181 $this->assertEquals(1, $content['page']); 269 $this->assertEquals(1, $content['page']);
182 $this->assertEquals(1, $content['pages']); 270 $this->assertEquals(1, $content['pages']);
183 271
272 $this->assertArrayHasKey('_links', $content);
273 $this->assertArrayHasKey('self', $content['_links']);
274 $this->assertArrayHasKey('first', $content['_links']);
275 $this->assertArrayHasKey('last', $content['_links']);
276
277 foreach (['self', 'first', 'last'] as $link) {
278 $this->assertArrayHasKey('href', $content['_links'][$link]);
279 $this->assertContains('since='.($future->getTimestamp() + 1000), $content['_links'][$link]['href']);
280 }
281
184 $this->assertTrue( 282 $this->assertTrue(
185 $this->client->getResponse()->headers->contains( 283 $this->client->getResponse()->headers->contains(
186 'Content-Type', 284 'Content-Type',
@@ -684,4 +782,26 @@ class WallabagRestControllerTest extends WallabagApiTestCase
684 782
685 $this->assertEquals(true, $content['is_starred']); 783 $this->assertEquals(true, $content['is_starred']);
686 } 784 }
785
786 public function testGetEntriesExists()
787 {
788 $this->client->request('GET', '/api/entries/exists?url=http://0.0.0.0/entry2');
789
790 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
791
792 $content = json_decode($this->client->getResponse()->getContent(), true);
793
794 $this->assertEquals(true, $content['exists']);
795 }
796
797 public function testGetEntriesExistsWhichDoesNotExists()
798 {
799 $this->client->request('GET', '/api/entries/exists?url=http://google.com/entry2');
800
801 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
802
803 $content = json_decode($this->client->getResponse()->getContent(), true);
804
805 $this->assertEquals(false, $content['exists']);
806 }
687} 807}
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/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
index a74c17d9..c40e10a5 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 */
diff --git a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php
index 71652760..2c32393f 100644
--- a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php
@@ -47,7 +47,7 @@ class TagControllerTest extends WallabagCoreTestCase
47 47
48 $this->assertEquals(1, count($entry->getTags())); 48 $this->assertEquals(1, count($entry->getTags()));
49 49
50 # tag already exists and already assigned 50 // tag already exists and already assigned
51 $client->submit($form, $data); 51 $client->submit($form, $data);
52 $this->assertEquals(302, $client->getResponse()->getStatusCode()); 52 $this->assertEquals(302, $client->getResponse()->getStatusCode());
53 53
@@ -58,7 +58,7 @@ class TagControllerTest extends WallabagCoreTestCase
58 58
59 $this->assertEquals(1, count($newEntry->getTags())); 59 $this->assertEquals(1, count($newEntry->getTags()));
60 60
61 # tag already exists but still not assigned to this entry 61 // tag already exists but still not assigned to this entry
62 $data = [ 62 $data = [
63 'tag[label]' => 'foo', 63 'tag[label]' => 'foo',
64 ]; 64 ];
diff --git a/tests/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php b/tests/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php
index e29b58b5..2e6fccfb 100644
--- a/tests/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php
+++ b/tests/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php
@@ -125,16 +125,14 @@ class UsernameRssTokenConverterTest extends \PHPUnit_Framework_TestCase
125 $this->assertTrue($converter->supports($params)); 125 $this->assertTrue($converter->supports($params));
126 } 126 }
127 127
128 /**
129 * @expectedException InvalidArgumentException
130 * @expectedExceptionMessage Route attribute is missing
131 */
132 public function testApplyEmptyRequest() 128 public function testApplyEmptyRequest()
133 { 129 {
134 $params = new ParamConverter([]); 130 $params = new ParamConverter([]);
135 $converter = new UsernameRssTokenConverter(); 131 $converter = new UsernameRssTokenConverter();
136 132
137 $converter->apply(new Request(), $params); 133 $res = $converter->apply(new Request(), $params);
134
135 $this->assertFalse($res);
138 } 136 }
139 137
140 /** 138 /**
diff --git a/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php b/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php
index 8ec2a75a..b1c8c946 100644
--- a/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php
+++ b/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php
@@ -8,7 +8,23 @@ class WallabagExtensionTest extends \PHPUnit_Framework_TestCase
8{ 8{
9 public function testRemoveWww() 9 public function testRemoveWww()
10 { 10 {
11 $extension = new WallabagExtension(); 11 $entryRepository = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
12 ->disableOriginalConstructor()
13 ->getMock();
14
15 $tagRepository = $this->getMockBuilder('Wallabag\CoreBundle\Repository\TagRepository')
16 ->disableOriginalConstructor()
17 ->getMock();
18
19 $tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')
20 ->disableOriginalConstructor()
21 ->getMock();
22
23 $translator = $this->getMockBuilder('Symfony\Component\Translation\TranslatorInterface')
24 ->disableOriginalConstructor()
25 ->getMock();
26
27 $extension = new WallabagExtension($entryRepository, $tagRepository, $tokenStorage, 0, $translator);
12 28
13 $this->assertEquals('lemonde.fr', $extension->removeWww('www.lemonde.fr')); 29 $this->assertEquals('lemonde.fr', $extension->removeWww('www.lemonde.fr'));
14 $this->assertEquals('lemonde.fr', $extension->removeWww('lemonde.fr')); 30 $this->assertEquals('lemonde.fr', $extension->removeWww('lemonde.fr'));
diff --git a/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php b/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php
index 75b7ee0b..4f103921 100644
--- a/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php
+++ b/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php
@@ -83,7 +83,7 @@ abstract class WallabagCoreTestCase extends WebTestCase
83 83
84 /** 84 /**
85 * Check if Redis is installed. 85 * Check if Redis is installed.
86 * If not, mark test as skip 86 * If not, mark test as skip.
87 */ 87 */
88 protected function checkRedis() 88 protected function checkRedis()
89 { 89 {
diff --git a/tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php
index b6783a56..0bc40bdd 100644
--- a/tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php
+++ b/tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php
@@ -24,6 +24,6 @@ class ImportControllerTest extends WallabagCoreTestCase
24 $crawler = $client->request('GET', '/import/'); 24 $crawler = $client->request('GET', '/import/');
25 25
26 $this->assertEquals(200, $client->getResponse()->getStatusCode()); 26 $this->assertEquals(200, $client->getResponse()->getStatusCode());
27 $this->assertEquals(6, $crawler->filter('blockquote')->count()); 27 $this->assertEquals(7, $crawler->filter('blockquote')->count());
28 } 28 }
29} 29}
diff --git a/tests/Wallabag/ImportBundle/Controller/InstapaperControllerTest.php b/tests/Wallabag/ImportBundle/Controller/InstapaperControllerTest.php
new file mode 100644
index 00000000..9df08e75
--- /dev/null
+++ b/tests/Wallabag/ImportBundle/Controller/InstapaperControllerTest.php
@@ -0,0 +1,196 @@
1<?php
2
3namespace Tests\Wallabag\ImportBundle\Controller;
4
5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
6use Symfony\Component\HttpFoundation\File\UploadedFile;
7
8class InstapaperControllerTest extends WallabagCoreTestCase
9{
10 public function testImportInstapaper()
11 {
12 $this->logInAs('admin');
13 $client = $this->getClient();
14
15 $crawler = $client->request('GET', '/import/instapaper');
16
17 $this->assertEquals(200, $client->getResponse()->getStatusCode());
18 $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count());
19 $this->assertEquals(1, $crawler->filter('input[type=file]')->count());
20 }
21
22 public function testImportInstapaperWithRabbitEnabled()
23 {
24 $this->logInAs('admin');
25 $client = $this->getClient();
26
27 $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 1);
28
29 $crawler = $client->request('GET', '/import/instapaper');
30
31 $this->assertEquals(200, $client->getResponse()->getStatusCode());
32 $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count());
33 $this->assertEquals(1, $crawler->filter('input[type=file]')->count());
34
35 $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 0);
36 }
37
38 public function testImportInstapaperBadFile()
39 {
40 $this->logInAs('admin');
41 $client = $this->getClient();
42
43 $crawler = $client->request('GET', '/import/instapaper');
44 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
45
46 $data = [
47 'upload_import_file[file]' => '',
48 ];
49
50 $client->submit($form, $data);
51
52 $this->assertEquals(200, $client->getResponse()->getStatusCode());
53 }
54
55 public function testImportInstapaperWithRedisEnabled()
56 {
57 $this->checkRedis();
58 $this->logInAs('admin');
59 $client = $this->getClient();
60 $client->getContainer()->get('craue_config')->set('import_with_redis', 1);
61
62 $crawler = $client->request('GET', '/import/instapaper');
63
64 $this->assertEquals(200, $client->getResponse()->getStatusCode());
65 $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count());
66 $this->assertEquals(1, $crawler->filter('input[type=file]')->count());
67
68 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
69
70 $file = new UploadedFile(__DIR__.'/../fixtures/instapaper-export.csv', 'instapaper.csv');
71
72 $data = [
73 'upload_import_file[file]' => $file,
74 ];
75
76 $client->submit($form, $data);
77
78 $this->assertEquals(302, $client->getResponse()->getStatusCode());
79
80 $crawler = $client->followRedirect();
81
82 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
83 $this->assertContains('flashes.import.notice.summary', $body[0]);
84
85 $this->assertNotEmpty($client->getContainer()->get('wallabag_core.redis.client')->lpop('wallabag.import.instapaper'));
86
87 $client->getContainer()->get('craue_config')->set('import_with_redis', 0);
88 }
89
90 public function testImportInstapaperWithFile()
91 {
92 $this->logInAs('admin');
93 $client = $this->getClient();
94
95 $crawler = $client->request('GET', '/import/instapaper');
96 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
97
98 $file = new UploadedFile(__DIR__.'/../fixtures/instapaper-export.csv', 'instapaper.csv');
99
100 $data = [
101 'upload_import_file[file]' => $file,
102 ];
103
104 $client->submit($form, $data);
105
106 $this->assertEquals(302, $client->getResponse()->getStatusCode());
107
108 $crawler = $client->followRedirect();
109
110 $content = $client->getContainer()
111 ->get('doctrine.orm.entity_manager')
112 ->getRepository('WallabagCoreBundle:Entry')
113 ->findByUrlAndUserId(
114 'http://www.liberation.fr/societe/2012/12/06/baumettes-un-tour-en-cellule_865551',
115 $this->getLoggedInUserId()
116 );
117
118 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
119 $this->assertContains('flashes.import.notice.summary', $body[0]);
120
121 $this->assertNotEmpty($content->getMimetype());
122 $this->assertNotEmpty($content->getPreviewPicture());
123 $this->assertNotEmpty($content->getLanguage());
124 $this->assertEquals(0, count($content->getTags()));
125 $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt());
126 }
127
128 public function testImportInstapaperWithFileAndMarkAllAsRead()
129 {
130 $this->logInAs('admin');
131 $client = $this->getClient();
132
133 $crawler = $client->request('GET', '/import/instapaper');
134 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
135
136 $file = new UploadedFile(__DIR__.'/../fixtures/instapaper-export.csv', 'instapaper-read.csv');
137
138 $data = [
139 'upload_import_file[file]' => $file,
140 'upload_import_file[mark_as_read]' => 1,
141 ];
142
143 $client->submit($form, $data);
144
145 $this->assertEquals(302, $client->getResponse()->getStatusCode());
146
147 $crawler = $client->followRedirect();
148
149 $content1 = $client->getContainer()
150 ->get('doctrine.orm.entity_manager')
151 ->getRepository('WallabagCoreBundle:Entry')
152 ->findByUrlAndUserId(
153 'https://redditblog.com/2016/09/20/amp-and-reactredux/',
154 $this->getLoggedInUserId()
155 );
156
157 $this->assertTrue($content1->isArchived());
158
159 $content2 = $client->getContainer()
160 ->get('doctrine.orm.entity_manager')
161 ->getRepository('WallabagCoreBundle:Entry')
162 ->findByUrlAndUserId(
163 'https://medium.com/@the_minh/why-foursquare-swarm-is-still-my-favourite-social-network-e38228493e6c',
164 $this->getLoggedInUserId()
165 );
166
167 $this->assertTrue($content2->isArchived());
168
169 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
170 $this->assertContains('flashes.import.notice.summary', $body[0]);
171 }
172
173 public function testImportInstapaperWithEmptyFile()
174 {
175 $this->logInAs('admin');
176 $client = $this->getClient();
177
178 $crawler = $client->request('GET', '/import/instapaper');
179 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
180
181 $file = new UploadedFile(__DIR__.'/../fixtures/test.txt', 'test.txt');
182
183 $data = [
184 'upload_import_file[file]' => $file,
185 ];
186
187 $client->submit($form, $data);
188
189 $this->assertEquals(302, $client->getResponse()->getStatusCode());
190
191 $crawler = $client->followRedirect();
192
193 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
194 $this->assertContains('flashes.import.notice.failed', $body[0]);
195 }
196}
diff --git a/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php b/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php
new file mode 100644
index 00000000..75900bd7
--- /dev/null
+++ b/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php
@@ -0,0 +1,233 @@
1<?php
2
3namespace Tests\Wallabag\ImportBundle\Import;
4
5use Wallabag\ImportBundle\Import\InstapaperImport;
6use Wallabag\UserBundle\Entity\User;
7use Wallabag\CoreBundle\Entity\Entry;
8use Wallabag\ImportBundle\Redis\Producer;
9use Monolog\Logger;
10use Monolog\Handler\TestHandler;
11use Simpleue\Queue\RedisQueue;
12use M6Web\Component\RedisMock\RedisMockFactory;
13
14class InstapaperImportTest extends \PHPUnit_Framework_TestCase
15{
16 protected $user;
17 protected $em;
18 protected $logHandler;
19 protected $contentProxy;
20
21 private function getInstapaperImport($unsetUser = false)
22 {
23 $this->user = new User();
24
25 $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
26 ->disableOriginalConstructor()
27 ->getMock();
28
29 $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy')
30 ->disableOriginalConstructor()
31 ->getMock();
32
33 $import = new InstapaperImport($this->em, $this->contentProxy);
34
35 $this->logHandler = new TestHandler();
36 $logger = new Logger('test', [$this->logHandler]);
37 $import->setLogger($logger);
38
39 if (false === $unsetUser) {
40 $import->setUser($this->user);
41 }
42
43 return $import;
44 }
45
46 public function testInit()
47 {
48 $instapaperImport = $this->getInstapaperImport();
49
50 $this->assertEquals('Instapaper', $instapaperImport->getName());
51 $this->assertNotEmpty($instapaperImport->getUrl());
52 $this->assertEquals('import.instapaper.description', $instapaperImport->getDescription());
53 }
54
55 public function testImport()
56 {
57 $instapaperImport = $this->getInstapaperImport();
58 $instapaperImport->setFilepath(__DIR__.'/../fixtures/instapaper-export.csv');
59
60 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
61 ->disableOriginalConstructor()
62 ->getMock();
63
64 $entryRepo->expects($this->exactly(3))
65 ->method('findByUrlAndUserId')
66 ->willReturn(false);
67
68 $this->em
69 ->expects($this->any())
70 ->method('getRepository')
71 ->willReturn($entryRepo);
72
73 $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry')
74 ->disableOriginalConstructor()
75 ->getMock();
76
77 $this->contentProxy
78 ->expects($this->exactly(3))
79 ->method('updateEntry')
80 ->willReturn($entry);
81
82 $res = $instapaperImport->import();
83
84 $this->assertTrue($res);
85 $this->assertEquals(['skipped' => 0, 'imported' => 3, 'queued' => 0], $instapaperImport->getSummary());
86 }
87
88 public function testImportAndMarkAllAsRead()
89 {
90 $instapaperImport = $this->getInstapaperImport();
91 $instapaperImport->setFilepath(__DIR__.'/../fixtures/instapaper-export.csv');
92
93 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
94 ->disableOriginalConstructor()
95 ->getMock();
96
97 $entryRepo->expects($this->exactly(3))
98 ->method('findByUrlAndUserId')
99 ->will($this->onConsecutiveCalls(false, true, true));
100
101 $this->em
102 ->expects($this->any())
103 ->method('getRepository')
104 ->willReturn($entryRepo);
105
106 $this->contentProxy
107 ->expects($this->once())
108 ->method('updateEntry')
109 ->willReturn(new Entry($this->user));
110
111 // check that every entry persisted are archived
112 $this->em
113 ->expects($this->once())
114 ->method('persist')
115 ->with($this->callback(function ($persistedEntry) {
116 return $persistedEntry->isArchived();
117 }));
118
119 $res = $instapaperImport->setMarkAsRead(true)->import();
120
121 $this->assertTrue($res);
122
123 $this->assertEquals(['skipped' => 2, 'imported' => 1, 'queued' => 0], $instapaperImport->getSummary());
124 }
125
126 public function testImportWithRabbit()
127 {
128 $instapaperImport = $this->getInstapaperImport();
129 $instapaperImport->setFilepath(__DIR__.'/../fixtures/instapaper-export.csv');
130
131 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
132 ->disableOriginalConstructor()
133 ->getMock();
134
135 $entryRepo->expects($this->never())
136 ->method('findByUrlAndUserId');
137
138 $this->em
139 ->expects($this->never())
140 ->method('getRepository');
141
142 $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry')
143 ->disableOriginalConstructor()
144 ->getMock();
145
146 $this->contentProxy
147 ->expects($this->never())
148 ->method('updateEntry');
149
150 $producer = $this->getMockBuilder('OldSound\RabbitMqBundle\RabbitMq\Producer')
151 ->disableOriginalConstructor()
152 ->getMock();
153
154 $producer
155 ->expects($this->exactly(3))
156 ->method('publish');
157
158 $instapaperImport->setProducer($producer);
159
160 $res = $instapaperImport->setMarkAsRead(true)->import();
161
162 $this->assertTrue($res);
163 $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 3], $instapaperImport->getSummary());
164 }
165
166 public function testImportWithRedis()
167 {
168 $instapaperImport = $this->getInstapaperImport();
169 $instapaperImport->setFilepath(__DIR__.'/../fixtures/instapaper-export.csv');
170
171 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
172 ->disableOriginalConstructor()
173 ->getMock();
174
175 $entryRepo->expects($this->never())
176 ->method('findByUrlAndUserId');
177
178 $this->em
179 ->expects($this->never())
180 ->method('getRepository');
181
182 $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry')
183 ->disableOriginalConstructor()
184 ->getMock();
185
186 $this->contentProxy
187 ->expects($this->never())
188 ->method('updateEntry');
189
190 $factory = new RedisMockFactory();
191 $redisMock = $factory->getAdapter('Predis\Client', true);
192
193 $queue = new RedisQueue($redisMock, 'instapaper');
194 $producer = new Producer($queue);
195
196 $instapaperImport->setProducer($producer);
197
198 $res = $instapaperImport->setMarkAsRead(true)->import();
199
200 $this->assertTrue($res);
201 $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 3], $instapaperImport->getSummary());
202
203 $this->assertNotEmpty($redisMock->lpop('instapaper'));
204 }
205
206 public function testImportBadFile()
207 {
208 $instapaperImport = $this->getInstapaperImport();
209 $instapaperImport->setFilepath(__DIR__.'/../fixtures/wallabag-v1.jsonx');
210
211 $res = $instapaperImport->import();
212
213 $this->assertFalse($res);
214
215 $records = $this->logHandler->getRecords();
216 $this->assertContains('InstapaperImport: unable to read file', $records[0]['message']);
217 $this->assertEquals('ERROR', $records[0]['level_name']);
218 }
219
220 public function testImportUserNotDefined()
221 {
222 $instapaperImport = $this->getInstapaperImport(true);
223 $instapaperImport->setFilepath(__DIR__.'/../fixtures/instapaper-export.csv');
224
225 $res = $instapaperImport->import();
226
227 $this->assertFalse($res);
228
229 $records = $this->logHandler->getRecords();
230 $this->assertContains('InstapaperImport: user is not defined', $records[0]['message']);
231 $this->assertEquals('ERROR', $records[0]['level_name']);
232 }
233}
diff --git a/tests/Wallabag/ImportBundle/fixtures/instapaper-export.csv b/tests/Wallabag/ImportBundle/fixtures/instapaper-export.csv
new file mode 100644
index 00000000..28a4c8e6
--- /dev/null
+++ b/tests/Wallabag/ImportBundle/fixtures/instapaper-export.csv
@@ -0,0 +1,4 @@
1URL,Title,Selection,Folder
2http://www.liberation.fr/societe/2012/12/06/baumettes-un-tour-en-cellule_865551,Baumettes : un tour en cellule,,Unread
3https://redditblog.com/2016/09/20/amp-and-reactredux/,AMP and React+Redux: Why Not?,,Archive
4https://medium.com/@the_minh/why-foursquare-swarm-is-still-my-favourite-social-network-e38228493e6c,Why Foursquare / Swarm is still my favourite social network,,Starred
diff --git a/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php b/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php
new file mode 100644
index 00000000..19b824b8
--- /dev/null
+++ b/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php
@@ -0,0 +1,82 @@
1<?php
2
3namespace Wallabag\UserBundle\Tests\Controller;
4
5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
6
7class ManageControllerTest extends WallabagCoreTestCase
8{
9 public function testLogin()
10 {
11 $client = $this->getClient();
12
13 $client->request('GET', '/users/');
14
15 $this->assertEquals(302, $client->getResponse()->getStatusCode());
16 $this->assertContains('login', $client->getResponse()->headers->get('location'));
17 }
18
19 public function testCompleteScenario()
20 {
21 $this->logInAs('admin');
22 $client = $this->getClient();
23
24 // Create a new user in the database
25 $crawler = $client->request('GET', '/users/');
26 $this->assertEquals(200, $client->getResponse()->getStatusCode(), "Unexpected HTTP status code for GET /users/");
27 $crawler = $client->click($crawler->selectLink('user.list.create_new_one')->link());
28
29 // Fill in the form and submit it
30 $form = $crawler->selectButton('user.form.save')->form(array(
31 'new_user[username]' => 'test_user',
32 'new_user[email]' => 'test@test.io',
33 'new_user[plainPassword][first]' => 'test',
34 'new_user[plainPassword][second]' => 'test',
35 ));
36
37 $client->submit($form);
38 $client->followRedirect();
39 $crawler = $client->request('GET', '/users/');
40
41 // Check data in the show view
42 $this->assertGreaterThan(0, $crawler->filter('td:contains("test_user")')->count(), 'Missing element td:contains("test_user")');
43
44 // Edit the user
45 $crawler = $client->click($crawler->selectLink('user.list.edit_action')->last()->link());
46
47 $form = $crawler->selectButton('user.form.save')->form(array(
48 'user[name]' => 'Foo User',
49 'user[username]' => 'test_user',
50 'user[email]' => 'test@test.io',
51 'user[enabled]' => true,
52 'user[locked]' => false,
53 ));
54
55 $client->submit($form);
56 $crawler = $client->followRedirect();
57
58 // Check the element contains an attribute with value equals "Foo User"
59 $this->assertGreaterThan(0, $crawler->filter('[value="Foo User"]')->count(), 'Missing element [value="Foo User"]');
60
61 $crawler = $client->request('GET', '/users/');
62 $crawler = $client->click($crawler->selectLink('user.list.edit_action')->last()->link());
63
64 // Delete the user
65 $client->submit($crawler->selectButton('user.form.delete')->form());
66 $crawler = $client->followRedirect();
67
68 // Check the user has been delete on the list
69 $this->assertNotRegExp('/Foo User/', $client->getResponse()->getContent());
70 }
71
72 public function testDeleteDisabledForLoggedUser()
73 {
74 $this->logInAs('admin');
75 $client = $this->getClient();
76
77 $crawler = $client->request('GET', '/users/'.$this->getLoggedInUserId().'/edit');
78 $disabled = $crawler->selectButton('user.form.delete')->extract('disabled');
79
80 $this->assertEquals('disabled', $disabled[0]);
81 }
82}
diff --git a/tests/Wallabag/CoreBundle/EventListener/RegistrationConfirmedListenerTest.php b/tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php
index e45722fa..0cebd3e4 100644
--- a/tests/Wallabag/CoreBundle/EventListener/RegistrationConfirmedListenerTest.php
+++ b/tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php
@@ -1,6 +1,6 @@
1<?php 1<?php
2 2
3namespace Tests\Wallabag\CoreBundle\EventListener; 3namespace Tests\Wallabag\UserBundle\EventListener;
4 4
5use FOS\UserBundle\Event\FilterUserResponseEvent; 5use FOS\UserBundle\Event\FilterUserResponseEvent;
6use FOS\UserBundle\FOSUserEvents; 6use FOS\UserBundle\FOSUserEvents;
@@ -8,10 +8,10 @@ use Symfony\Component\EventDispatcher\EventDispatcher;
8use Symfony\Component\HttpFoundation\Request; 8use Symfony\Component\HttpFoundation\Request;
9use Symfony\Component\HttpFoundation\Response; 9use Symfony\Component\HttpFoundation\Response;
10use Wallabag\CoreBundle\Entity\Config; 10use Wallabag\CoreBundle\Entity\Config;
11use Wallabag\CoreBundle\EventListener\RegistrationConfirmedListener; 11use Wallabag\UserBundle\EventListener\CreateConfigListener;
12use Wallabag\UserBundle\Entity\User; 12use Wallabag\UserBundle\Entity\User;
13 13
14class RegistrationConfirmedListenerTest extends \PHPUnit_Framework_TestCase 14class CreateConfigListenerTest extends \PHPUnit_Framework_TestCase
15{ 15{
16 private $em; 16 private $em;
17 private $listener; 17 private $listener;
@@ -25,12 +25,13 @@ class RegistrationConfirmedListenerTest extends \PHPUnit_Framework_TestCase
25 ->disableOriginalConstructor() 25 ->disableOriginalConstructor()
26 ->getMock(); 26 ->getMock();
27 27
28 $this->listener = new RegistrationConfirmedListener( 28 $this->listener = new CreateConfigListener(
29 $this->em, 29 $this->em,
30 'baggy', 30 'baggy',
31 20, 31 20,
32 50, 32 50,
33 'fr' 33 'fr',
34 1
34 ); 35 );
35 36
36 $this->dispatcher = new EventDispatcher(); 37 $this->dispatcher = new EventDispatcher();
@@ -55,7 +56,7 @@ class RegistrationConfirmedListenerTest extends \PHPUnit_Framework_TestCase
55 $this->em->expects($this->never())->method('flush'); 56 $this->em->expects($this->never())->method('flush');
56 57
57 $this->dispatcher->dispatch( 58 $this->dispatcher->dispatch(
58 FOSUserEvents::REGISTRATION_CONFIRMED, 59 FOSUserEvents::REGISTRATION_COMPLETED,
59 $event 60 $event
60 ); 61 );
61 } 62 }
@@ -76,6 +77,7 @@ class RegistrationConfirmedListenerTest extends \PHPUnit_Framework_TestCase
76 $config->setItemsPerPage(20); 77 $config->setItemsPerPage(20);
77 $config->setRssLimit(50); 78 $config->setRssLimit(50);
78 $config->setLanguage('fr'); 79 $config->setLanguage('fr');
80 $config->setReadingSpeed(1);
79 81
80 $this->em->expects($this->once()) 82 $this->em->expects($this->once())
81 ->method('persist') 83 ->method('persist')
@@ -84,7 +86,7 @@ class RegistrationConfirmedListenerTest extends \PHPUnit_Framework_TestCase
84 ->method('flush'); 86 ->method('flush');
85 87
86 $this->dispatcher->dispatch( 88 $this->dispatcher->dispatch(
87 FOSUserEvents::REGISTRATION_CONFIRMED, 89 FOSUserEvents::REGISTRATION_COMPLETED,
88 $event 90 $event
89 ); 91 );
90 } 92 }
diff --git a/tests/Wallabag/UserBundle/Mailer/AuthCodeMailerTest.php b/tests/Wallabag/UserBundle/Mailer/AuthCodeMailerTest.php
index f670c925..441d6519 100644
--- a/tests/Wallabag/UserBundle/Mailer/AuthCodeMailerTest.php
+++ b/tests/Wallabag/UserBundle/Mailer/AuthCodeMailerTest.php
@@ -37,7 +37,7 @@ class AuthCodeMailerTest extends \PHPUnit_Framework_TestCase
37 ); 37 );
38 $this->mailer = new \Swift_Mailer($transport); 38 $this->mailer = new \Swift_Mailer($transport);
39 39
40 $twigTemplate = <<<TWIG 40 $twigTemplate = <<<'TWIG'
41{% block subject %}subject{% endblock %} 41{% block subject %}subject{% endblock %}
42{% block body_html %}html body {{ code }}{% endblock %} 42{% block body_html %}html body {{ code }}{% endblock %}
43{% block body_text %}text body {{ support_url }}{% endblock %} 43{% block body_text %}text body {{ support_url }}{% endblock %}