aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--app/config/security.yml1
-rw-r--r--src/Wallabag/CoreBundle/Controller/ConfigController.php2
-rw-r--r--src/Wallabag/CoreBundle/Controller/RssController.php6
-rw-r--r--src/Wallabag/CoreBundle/DataFixtures/ORM/LoadEntryData.php20
-rw-r--r--src/Wallabag/CoreBundle/Entity/Config.php10
-rw-r--r--src/Wallabag/CoreBundle/Form/Type/ConfigType.php2
-rw-r--r--src/Wallabag/CoreBundle/Form/Type/RssType.php2
-rw-r--r--src/Wallabag/CoreBundle/Resources/views/Config/index.html.twig14
-rw-r--r--src/Wallabag/CoreBundle/Resources/views/Entry/entries.xml.twig6
-rwxr-xr-xsrc/Wallabag/CoreBundle/Resources/views/themes/baggy/public/css/main.css24
-rw-r--r--src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php126
-rw-r--r--src/Wallabag/CoreBundle/Tests/Controller/RssControllerTest.php126
-rw-r--r--src/Wallabag/CoreBundle/Tests/ParamConverter/UsernameRssTokenConverterTest.php220
13 files changed, 533 insertions, 26 deletions
diff --git a/app/config/security.yml b/app/config/security.yml
index 90903f31..37236d40 100644
--- a/app/config/security.yml
+++ b/app/config/security.yml
@@ -60,4 +60,5 @@ security:
60 - { path: ^/api/doc, roles: IS_AUTHENTICATED_ANONYMOUSLY } 60 - { path: ^/api/doc, roles: IS_AUTHENTICATED_ANONYMOUSLY }
61 - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY } 61 - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
62 - { path: ^/forgot-password, roles: IS_AUTHENTICATED_ANONYMOUSLY } 62 - { path: ^/forgot-password, roles: IS_AUTHENTICATED_ANONYMOUSLY }
63 - { path: /(unread|starred|archive).xml$, roles: IS_AUTHENTICATED_ANONYMOUSLY }
63 - { path: ^/, roles: ROLE_USER } 64 - { path: ^/, roles: ROLE_USER }
diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php
index 1622f348..dbae3ea7 100644
--- a/src/Wallabag/CoreBundle/Controller/ConfigController.php
+++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php
@@ -107,7 +107,7 @@ class ConfigController extends Controller
107 $config = new Config($newUser); 107 $config = new Config($newUser);
108 $config->setTheme($this->container->getParameter('theme')); 108 $config->setTheme($this->container->getParameter('theme'));
109 $config->setItemsPerPage($this->container->getParameter('items_on_page')); 109 $config->setItemsPerPage($this->container->getParameter('items_on_page'));
110 $config->setRssLimit($this->getContainer()->getParameter('rss_limit')); 110 $config->setRssLimit($this->container->getParameter('rss_limit'));
111 $config->setLanguage($this->container->getParameter('language')); 111 $config->setLanguage($this->container->getParameter('language'));
112 112
113 $em->persist($config); 113 $em->persist($config);
diff --git a/src/Wallabag/CoreBundle/Controller/RssController.php b/src/Wallabag/CoreBundle/Controller/RssController.php
index f2f8dd65..14f1dcb2 100644
--- a/src/Wallabag/CoreBundle/Controller/RssController.php
+++ b/src/Wallabag/CoreBundle/Controller/RssController.php
@@ -25,7 +25,7 @@ class RssController extends Controller
25 ->findUnreadByUser( 25 ->findUnreadByUser(
26 $user->getId(), 26 $user->getId(),
27 0, 27 0,
28 $user->getConfig()->getRssLimit() ?: $this->getContainer()->getParameter('rss_limit') 28 $user->getConfig()->getRssLimit() ?: $this->container->getParameter('rss_limit')
29 ); 29 );
30 30
31 return $this->render('WallabagCoreBundle:Entry:entries.xml.twig', array( 31 return $this->render('WallabagCoreBundle:Entry:entries.xml.twig', array(
@@ -49,7 +49,7 @@ class RssController extends Controller
49 ->findArchiveByUser( 49 ->findArchiveByUser(
50 $user->getId(), 50 $user->getId(),
51 0, 51 0,
52 $user->getConfig()->getRssLimit() ?: $this->getContainer()->getParameter('rss_limit') 52 $user->getConfig()->getRssLimit() ?: $this->container->getParameter('rss_limit')
53 ); 53 );
54 54
55 return $this->render('WallabagCoreBundle:Entry:entries.xml.twig', array( 55 return $this->render('WallabagCoreBundle:Entry:entries.xml.twig', array(
@@ -73,7 +73,7 @@ class RssController extends Controller
73 ->findStarredByUser( 73 ->findStarredByUser(
74 $user->getId(), 74 $user->getId(),
75 0, 75 0,
76 $user->getConfig()->getRssLimit() ?: $this->getContainer()->getParameter('rss_limit') 76 $user->getConfig()->getRssLimit() ?: $this->container->getParameter('rss_limit')
77 ); 77 );
78 78
79 return $this->render('WallabagCoreBundle:Entry:entries.xml.twig', array( 79 return $this->render('WallabagCoreBundle:Entry:entries.xml.twig', array(
diff --git a/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadEntryData.php b/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadEntryData.php
index ce12ec5d..54d0d6b6 100644
--- a/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadEntryData.php
+++ b/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadEntryData.php
@@ -67,6 +67,26 @@ class LoadEntryData extends AbstractFixture implements OrderedFixtureInterface
67 67
68 $this->addReference('entry4', $entry4); 68 $this->addReference('entry4', $entry4);
69 69
70 $entry5 = new Entry($this->getReference('admin-user'));
71 $entry5->setUrl('http://0.0.0.0');
72 $entry5->setTitle('test title entry5');
73 $entry5->setContent('This is my content /o/');
74 $entry5->setStarred(true);
75
76 $manager->persist($entry5);
77
78 $this->addReference('entry5', $entry5);
79
80 $entry6 = new Entry($this->getReference('admin-user'));
81 $entry6->setUrl('http://0.0.0.0');
82 $entry6->setTitle('test title entry6');
83 $entry6->setContent('This is my content /o/');
84 $entry6->setArchived(true);
85
86 $manager->persist($entry6);
87
88 $this->addReference('entry6', $entry6);
89
70 $manager->flush(); 90 $manager->flush();
71 } 91 }
72 92
diff --git a/src/Wallabag/CoreBundle/Entity/Config.php b/src/Wallabag/CoreBundle/Entity/Config.php
index 56eff30c..9f079656 100644
--- a/src/Wallabag/CoreBundle/Entity/Config.php
+++ b/src/Wallabag/CoreBundle/Entity/Config.php
@@ -35,6 +35,11 @@ class Config
35 * @var integer 35 * @var integer
36 * 36 *
37 * @Assert\NotBlank() 37 * @Assert\NotBlank()
38 * @Assert\Range(
39 * min = 1,
40 * max = 100000,
41 * maxMessage = "This will certainly kill the app"
42 * )
38 * @ORM\Column(name="items_per_page", type="integer", nullable=false) 43 * @ORM\Column(name="items_per_page", type="integer", nullable=false)
39 */ 44 */
40 private $itemsPerPage; 45 private $itemsPerPage;
@@ -58,6 +63,11 @@ class Config
58 * @var integer 63 * @var integer
59 * 64 *
60 * @ORM\Column(name="rss_limit", type="integer", nullable=true) 65 * @ORM\Column(name="rss_limit", type="integer", nullable=true)
66 * @Assert\Range(
67 * min = 1,
68 * max = 100000,
69 * maxMessage = "This will certainly kill the app"
70 * )
61 */ 71 */
62 private $rssLimit; 72 private $rssLimit;
63 73
diff --git a/src/Wallabag/CoreBundle/Form/Type/ConfigType.php b/src/Wallabag/CoreBundle/Form/Type/ConfigType.php
index 0c8706e2..0fcf020a 100644
--- a/src/Wallabag/CoreBundle/Form/Type/ConfigType.php
+++ b/src/Wallabag/CoreBundle/Form/Type/ConfigType.php
@@ -24,7 +24,7 @@ class ConfigType extends AbstractType
24 { 24 {
25 $builder 25 $builder
26 ->add('theme', 'choice', array('choices' => $this->themes)) 26 ->add('theme', 'choice', array('choices' => $this->themes))
27 ->add('items_per_page', 'text') 27 ->add('items_per_page')
28 ->add('language') 28 ->add('language')
29 ->add('save', 'submit') 29 ->add('save', 'submit')
30 ; 30 ;
diff --git a/src/Wallabag/CoreBundle/Form/Type/RssType.php b/src/Wallabag/CoreBundle/Form/Type/RssType.php
index 5edb38ba..a1ab990f 100644
--- a/src/Wallabag/CoreBundle/Form/Type/RssType.php
+++ b/src/Wallabag/CoreBundle/Form/Type/RssType.php
@@ -10,7 +10,7 @@ class RssType extends AbstractType
10 public function buildForm(FormBuilderInterface $builder, array $options) 10 public function buildForm(FormBuilderInterface $builder, array $options)
11 { 11 {
12 $builder 12 $builder
13 ->add('rss_limit', 'text') 13 ->add('rss_limit')
14 ->add('save', 'submit') 14 ->add('save', 'submit')
15 ; 15 ;
16 } 16 }
diff --git a/src/Wallabag/CoreBundle/Resources/views/Config/index.html.twig b/src/Wallabag/CoreBundle/Resources/views/Config/index.html.twig
index b134b6ca..f2a98dfb 100644
--- a/src/Wallabag/CoreBundle/Resources/views/Config/index.html.twig
+++ b/src/Wallabag/CoreBundle/Resources/views/Config/index.html.twig
@@ -56,11 +56,15 @@
56 <fieldset class="w500p inline"> 56 <fieldset class="w500p inline">
57 <div class="row"> 57 <div class="row">
58 <label>Rss links:</label> 58 <label>Rss links:</label>
59 <ul> 59 {% if rss.token %}
60 <li><a href="{{ path('unread_rss', {'username': rss.username, 'token': rss.token}) }}">unread</a></li> 60 <ul>
61 <li><a href="{{ path('starred_rss', {'username': rss.username, 'token': rss.token}) }}">fav</a></li> 61 <li><a href="{{ path('unread_rss', {'username': rss.username, 'token': rss.token}) }}">unread</a></li>
62 <li><a href="{{ path('archive_rss', {'username': rss.username, 'token': rss.token}) }}">archives</a></li> 62 <li><a href="{{ path('starred_rss', {'username': rss.username, 'token': rss.token}) }}">fav</a></li>
63 </ul> 63 <li><a href="{{ path('archive_rss', {'username': rss.username, 'token': rss.token}) }}">archives</a></li>
64 </ul>
65 {% else %}
66 <strong>You need to generate a token first.</strong>
67 {% endif %}
64 </div> 68 </div>
65 </fieldset> 69 </fieldset>
66 70
diff --git a/src/Wallabag/CoreBundle/Resources/views/Entry/entries.xml.twig b/src/Wallabag/CoreBundle/Resources/views/Entry/entries.xml.twig
index 6eebc80d..f1039f5d 100644
--- a/src/Wallabag/CoreBundle/Resources/views/Entry/entries.xml.twig
+++ b/src/Wallabag/CoreBundle/Resources/views/Entry/entries.xml.twig
@@ -17,11 +17,11 @@
17 <pubDate>{{ entry.createdAt|date('D, d M Y H:i:s') }}</pubDate> 17 <pubDate>{{ entry.createdAt|date('D, d M Y H:i:s') }}</pubDate>
18 <description> 18 <description>
19 <![CDATA[ 19 <![CDATA[
20 {%- if entry.content| readingTime > 0 %} 20 {%- if entry.content| readingTime > 0 -%}
21 {% trans %}estimated reading time :{% endtrans %} {{ entry.content| readingTime }} min 21 {% trans %}estimated reading time :{% endtrans %} {{ entry.content| readingTime }} min
22 {% else -%} 22 {%- else -%}
23 {% trans %}estimated reading time :{% endtrans %} &lt; 1 min 23 {% trans %}estimated reading time :{% endtrans %} &lt; 1 min
24 {% endif -%} 24 {%- endif %}
25 25
26 {{ entry.content -}} 26 {{ entry.content -}}
27 ]]> 27 ]]>
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/public/css/main.css b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/public/css/main.css
index 1df82910..ff1a36a1 100755
--- a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/public/css/main.css
+++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/public/css/main.css
@@ -7,7 +7,7 @@
7 4 = Messages 7 4 = Messages
8 5 = Article 8 5 = Article
9 6 = Media queries 9 6 = Media queries
10 10
11 ========================================================================== */ 11 ========================================================================== */
12 12
13html { 13html {
@@ -42,17 +42,17 @@ body {
42 position: absolute; 42 position: absolute;
43 top: 2em; 43 top: 2em;
44 left: 50%; 44 left: 50%;
45 margin-left: -55px; 45 margin-left: -55px;
46} 46}
47 47
48/* ========================================================================== 48/* ==========================================================================
49 1 = Style Guide 49 1 = Style Guide
50 ========================================================================== */ 50 ========================================================================== */
51 51
52::selection { 52::selection {
53 color: #FFF; 53 color: #FFF;
54 background-color: #000; 54 background-color: #000;
55} 55}
56 56
57.desktopHide { 57.desktopHide {
58 display: none; 58 display: none;
@@ -62,7 +62,7 @@ body {
62 position: fixed; 62 position: fixed;
63 z-index: 20; 63 z-index: 20;
64 top: 0.4em; 64 top: 0.4em;
65 left: 0.6em; 65 left: 0.6em;
66} 66}
67 67
68h2, h3, h4 { 68h2, h3, h4 {
@@ -89,7 +89,7 @@ form fieldset {
89 margin: 0; 89 margin: 0;
90} 90}
91 91
92form input[type="text"], select, form input[type="password"], form input[type="url"], form input[type="email"] { 92form input[type="text"], form input[type="number"], select, form input[type="password"], form input[type="url"], form input[type="email"] {
93 border: 1px solid #999; 93 border: 1px solid #999;
94 padding: 0.5em 1em; 94 padding: 0.5em 1em;
95 min-width: 12em; 95 min-width: 12em;
@@ -149,7 +149,7 @@ form button, input[type="submit"] {
149 149
150#bookmarklet { 150#bookmarklet {
151 cursor: move; 151 cursor: move;
152} 152}
153 153
154h2:after { 154h2:after {
155 content: ""; 155 content: "";
@@ -296,7 +296,7 @@ h2:after {
296/* ========================================================================== 296/* ==========================================================================
297 2 = Layout 297 2 = Layout
298 ========================================================================== */ 298 ========================================================================== */
299 299
300#content { 300#content {
301 margin-top: 5em; 301 margin-top: 5em;
302 min-height: 30em; 302 min-height: 30em;
@@ -653,7 +653,7 @@ a.add-to-wallabag-link-after:after {
653/* ========================================================================== 653/* ==========================================================================
654 3 = Pictos 654 3 = Pictos
655 ========================================================================== */ 655 ========================================================================== */
656 656
657@font-face { 657@font-face {
658 font-family: 'icomoon'; 658 font-family: 'icomoon';
659 src:url('../fonts/icomoon.eot?-s0mcsx'); 659 src:url('../fonts/icomoon.eot?-s0mcsx');
@@ -866,7 +866,7 @@ blockquote {
866 color: #FFF; 866 color: #FFF;
867 text-decoration: none; 867 text-decoration: none;
868} 868}
869 869
870 #article_toolbar a:hover, #article_toolbar a:focus { 870 #article_toolbar a:hover, #article_toolbar a:focus {
871 background-color: #999; 871 background-color: #999;
872 } 872 }
@@ -1052,7 +1052,7 @@ pre code {
1052 #article_toolbar a { 1052 #article_toolbar a {
1053 padding: 0.3em 0.4em 0.2em; 1053 padding: 0.3em 0.4em 0.2em;
1054 } 1054 }
1055 1055
1056 #display-mode { 1056 #display-mode {
1057 display: none; 1057 display: none;
1058 } 1058 }
diff --git a/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php
index d7d341aa..11c86423 100644
--- a/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php
+++ b/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php
@@ -28,6 +28,8 @@ class ConfigControllerTest extends WallabagTestCase
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=user_save]')); 30 $this->assertCount(1, $crawler->filter('button[id=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 } 33 }
32 34
33 public function testUpdate() 35 public function testUpdate()
@@ -347,4 +349,128 @@ class ConfigControllerTest extends WallabagTestCase
347 $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(array('_text'))); 349 $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(array('_text')));
348 $this->assertContains('User "wallace" added', $alert[0]); 350 $this->assertContains('User "wallace" added', $alert[0]);
349 } 351 }
352
353 public function testRssUpdateResetToken()
354 {
355 $this->logInAs('admin');
356 $client = $this->getClient();
357
358 // reset the token
359 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
360 $user = $em
361 ->getRepository('WallabagCoreBundle:User')
362 ->findOneByUsername('admin');
363
364 if (!$user) {
365 $this->markTestSkipped('No user found in db.');
366 }
367
368 $config = $user->getConfig();
369 $config->setRssToken(null);
370 $em->persist($config);
371 $em->flush();
372
373 $crawler = $client->request('GET', '/config');
374
375 $this->assertEquals(200, $client->getResponse()->getStatusCode());
376
377 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(array('_text')));
378 $this->assertContains('You need to generate a token first.', $body[0]);
379
380 $client->request('GET', '/generate-token');
381 $this->assertEquals(302, $client->getResponse()->getStatusCode());
382
383 $crawler = $client->followRedirect();
384
385 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(array('_text')));
386 $this->assertNotContains('You need to generate a token first.', $body[0]);
387 }
388
389 public function testGenerateTokenAjax()
390 {
391 $this->logInAs('admin');
392 $client = $this->getClient();
393
394 $client->request(
395 'GET',
396 '/generate-token',
397 array(),
398 array(),
399 array('HTTP_X-Requested-With' => 'XMLHttpRequest')
400 );
401
402 $this->assertEquals(200, $client->getResponse()->getStatusCode());
403 $content = json_decode($client->getResponse()->getContent(), true);;
404 $this->assertArrayHasKey('token', $content);
405 }
406
407 public function testRssUpdate()
408 {
409 $this->logInAs('admin');
410 $client = $this->getClient();
411
412 $crawler = $client->request('GET', '/config');
413
414 if (500 == $client->getResponse()->getStatusCode()) {
415 var_export($client->getResponse()->getContent());
416 die();
417 }
418
419 $this->assertEquals(200, $client->getResponse()->getStatusCode());
420
421 $form = $crawler->filter('button[id=rss_config_save]')->form();
422
423 $data = array(
424 'rss_config[rss_limit]' => 12,
425 );
426
427 $client->submit($form, $data);
428
429 $this->assertEquals(302, $client->getResponse()->getStatusCode());
430
431 $crawler = $client->followRedirect();
432
433 $this->assertGreaterThan(1, $alert = $crawler->filter('div.messages.success')->extract(array('_text')));
434 $this->assertContains('RSS information updated', $alert[0]);
435 }
436
437 public function dataForRssFailed()
438 {
439 return array(
440 array(
441 array(
442 'rss_config[rss_limit]' => 0,
443 ),
444 'This value should be 1 or more.',
445 ),
446 array(
447 array(
448 'rss_config[rss_limit]' => 1000000000000,
449 ),
450 'This will certainly kill the app',
451 ),
452 );
453 }
454
455 /**
456 * @dataProvider dataForRssFailed
457 */
458 public function testRssFailed($data, $expectedMessage)
459 {
460 $this->logInAs('admin');
461 $client = $this->getClient();
462
463 $crawler = $client->request('GET', '/config');
464
465 $this->assertEquals(200, $client->getResponse()->getStatusCode());
466
467 $form = $crawler->filter('button[id=rss_config_save]')->form();
468
469 $crawler = $client->submit($form, $data);
470
471 $this->assertEquals(200, $client->getResponse()->getStatusCode());
472
473 $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(array('_text')));
474 $this->assertContains($expectedMessage, $alert[0]);
475 }
350} 476}
diff --git a/src/Wallabag/CoreBundle/Tests/Controller/RssControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/RssControllerTest.php
new file mode 100644
index 00000000..8f627b4b
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Tests/Controller/RssControllerTest.php
@@ -0,0 +1,126 @@
1<?php
2
3namespace Wallabag\CoreBundle\Tests\Controller;
4
5use Wallabag\CoreBundle\Tests\WallabagTestCase;
6
7class RssControllerTest extends WallabagTestCase
8{
9 public function validateDom($xml, $nb = null)
10 {
11 $doc = new \DOMDocument();
12 $doc->loadXML($xml);
13
14 $xpath = new \DOMXpath($doc);
15
16 if (null === $nb) {
17 $this->assertGreaterThan(0, $xpath->query('//item')->length);
18 } else {
19 $this->assertEquals($nb, $xpath->query('//item')->length);
20 }
21
22 $this->assertEquals(1, $xpath->query('/rss')->length);
23 $this->assertEquals(1, $xpath->query('/rss/channel')->length);
24
25 foreach ($xpath->query('//item') as $item) {
26 $this->assertEquals(1, $xpath->query('title', $item)->length);
27 $this->assertEquals(1, $xpath->query('source', $item)->length);
28 $this->assertEquals(1, $xpath->query('link', $item)->length);
29 $this->assertEquals(1, $xpath->query('guid', $item)->length);
30 $this->assertEquals(1, $xpath->query('pubDate', $item)->length);
31 $this->assertEquals(1, $xpath->query('description', $item)->length);
32 }
33 }
34
35 public function dataForBadUrl()
36 {
37 return array(
38 array(
39 '/admin/YZIOAUZIAO/unread.xml'
40 ),
41 array(
42 '/wallace/YZIOAUZIAO/starred.xml'
43 ),
44 array(
45 '/wallace/YZIOAUZIAO/archives.xml'
46 ),
47 );
48 }
49
50 /**
51 * @dataProvider dataForBadUrl
52 */
53 public function testBadUrl($url)
54 {
55 $client = $this->getClient();
56
57 $client->request('GET', $url);
58
59 $this->assertEquals(404, $client->getResponse()->getStatusCode());
60 }
61
62 public function testUnread()
63 {
64 $client = $this->getClient();
65 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
66 $user = $em
67 ->getRepository('WallabagCoreBundle:User')
68 ->findOneByUsername('admin');
69
70 $config = $user->getConfig();
71 $config->setRssToken('SUPERTOKEN');
72 $config->setRssLimit(2);
73 $em->persist($config);
74 $em->flush();
75
76 $client->request('GET', '/admin/SUPERTOKEN/unread.xml');
77
78 $this->assertEquals(200, $client->getResponse()->getStatusCode());
79
80 $this->validateDom($client->getResponse()->getContent(), 2);
81 }
82
83 public function testStarred()
84 {
85 $client = $this->getClient();
86 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
87 $user = $em
88 ->getRepository('WallabagCoreBundle:User')
89 ->findOneByUsername('admin');
90
91 $config = $user->getConfig();
92 $config->setRssToken('SUPERTOKEN');
93 $config->setRssLimit(1);
94 $em->persist($config);
95 $em->flush();
96
97 $client = $this->getClient();
98 $client->request('GET', '/admin/SUPERTOKEN/starred.xml');
99
100 $this->assertEquals(200, $client->getResponse()->getStatusCode(), 1);
101
102 $this->validateDom($client->getResponse()->getContent());
103 }
104
105 public function testArchives()
106 {
107 $client = $this->getClient();
108 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
109 $user = $em
110 ->getRepository('WallabagCoreBundle:User')
111 ->findOneByUsername('admin');
112
113 $config = $user->getConfig();
114 $config->setRssToken('SUPERTOKEN');
115 $config->setRssLimit(null);
116 $em->persist($config);
117 $em->flush();
118
119 $client = $this->getClient();
120 $client->request('GET', '/admin/SUPERTOKEN/archive.xml');
121
122 $this->assertEquals(200, $client->getResponse()->getStatusCode());
123
124 $this->validateDom($client->getResponse()->getContent());
125 }
126}
diff --git a/src/Wallabag/CoreBundle/Tests/ParamConverter/UsernameRssTokenConverterTest.php b/src/Wallabag/CoreBundle/Tests/ParamConverter/UsernameRssTokenConverterTest.php
new file mode 100644
index 00000000..ebb550b5
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Tests/ParamConverter/UsernameRssTokenConverterTest.php
@@ -0,0 +1,220 @@
1<?php
2
3namespace Wallabag\CoreBundle\Tests\Command;
4
5use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
6use Wallabag\CoreBundle\ParamConverter\UsernameRssTokenConverter;
7use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
8use Symfony\Component\HttpFoundation\Request;
9use Wallabag\CoreBundle\Entity\User;
10
11class UsernameRssTokenConverterTest extends KernelTestCase
12{
13 public function testSupportsWithNoRegistry()
14 {
15 $params = new ParamConverter(array());
16 $converter = new UsernameRssTokenConverter();
17
18 $this->assertFalse($converter->supports($params));
19 }
20
21 public function testSupportsWithNoRegistryManagers()
22 {
23 $registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')
24 ->disableOriginalConstructor()
25 ->getMock();
26
27 $registry->expects($this->once())
28 ->method('getManagers')
29 ->will($this->returnValue(array()));
30
31 $params = new ParamConverter(array());
32 $converter = new UsernameRssTokenConverter($registry);
33
34 $this->assertFalse($converter->supports($params));
35 }
36
37 public function testSupportsWithNoConfigurationClass()
38 {
39 $registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')
40 ->disableOriginalConstructor()
41 ->getMock();
42
43 $registry->expects($this->once())
44 ->method('getManagers')
45 ->will($this->returnValue(array('default' => null)));
46
47 $params = new ParamConverter(array());
48 $converter = new UsernameRssTokenConverter($registry);
49
50 $this->assertFalse($converter->supports($params));
51 }
52
53 public function testSupportsWithNotTheGoodClass()
54 {
55 $meta = $this->getMockBuilder('Doctrine\Common\Persistence\Mapping\ClassMetadata')
56 ->disableOriginalConstructor()
57 ->getMock();
58
59 $meta->expects($this->once())
60 ->method('getName')
61 ->will($this->returnValue('nothingrelated'));
62
63 $em = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager')
64 ->disableOriginalConstructor()
65 ->getMock();
66
67 $em->expects($this->once())
68 ->method('getClassMetadata')
69 ->with('superclass')
70 ->will($this->returnValue($meta));
71
72 $registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')
73 ->disableOriginalConstructor()
74 ->getMock();
75
76 $registry->expects($this->once())
77 ->method('getManagers')
78 ->will($this->returnValue(array('default' => null)));
79
80 $registry->expects($this->once())
81 ->method('getManagerForClass')
82 ->with('superclass')
83 ->will($this->returnValue($em));
84
85 $params = new ParamConverter(array('class' => 'superclass'));
86 $converter = new UsernameRssTokenConverter($registry);
87
88 $this->assertFalse($converter->supports($params));
89 }
90
91 public function testSupportsWithGoodClass()
92 {
93 $meta = $this->getMockBuilder('Doctrine\Common\Persistence\Mapping\ClassMetadata')
94 ->disableOriginalConstructor()
95 ->getMock();
96
97 $meta->expects($this->once())
98 ->method('getName')
99 ->will($this->returnValue('Wallabag\CoreBundle\Entity\User'));
100
101 $em = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager')
102 ->disableOriginalConstructor()
103 ->getMock();
104
105 $em->expects($this->once())
106 ->method('getClassMetadata')
107 ->with('WallabagCoreBundle:User')
108 ->will($this->returnValue($meta));
109
110 $registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')
111 ->disableOriginalConstructor()
112 ->getMock();
113
114 $registry->expects($this->once())
115 ->method('getManagers')
116 ->will($this->returnValue(array('default' => null)));
117
118 $registry->expects($this->once())
119 ->method('getManagerForClass')
120 ->with('WallabagCoreBundle:User')
121 ->will($this->returnValue($em));
122
123 $params = new ParamConverter(array('class' => 'WallabagCoreBundle:User'));
124 $converter = new UsernameRssTokenConverter($registry);
125
126 $this->assertTrue($converter->supports($params));
127 }
128
129 /**
130 * @expectedException InvalidArgumentException
131 * @expectedExceptionMessage Route attribute is missing
132 */
133 public function testApplyEmptyRequest()
134 {
135 $params = new ParamConverter(array());
136 $converter = new UsernameRssTokenConverter();
137
138 $converter->apply(new Request(), $params);
139 }
140
141 /**
142 * @expectedException Symfony\Component\HttpKernel\Exception\NotFoundHttpException
143 * @expectedExceptionMessage User not found
144 */
145 public function testApplyUserNotFound()
146 {
147 $repo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\UserRepository')
148 ->disableOriginalConstructor()
149 ->getMock();
150
151 $repo->expects($this->once())
152 ->method('findOneByUsernameAndRsstoken')
153 ->with('test', 'test')
154 ->will($this->returnValue(null));
155
156 $em = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager')
157 ->disableOriginalConstructor()
158 ->getMock();
159
160 $em->expects($this->once())
161 ->method('getRepository')
162 ->with('WallabagCoreBundle:User')
163 ->will($this->returnValue($repo));
164
165 $registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')
166 ->disableOriginalConstructor()
167 ->getMock();
168
169 $registry->expects($this->once())
170 ->method('getManagerForClass')
171 ->with('WallabagCoreBundle:User')
172 ->will($this->returnValue($em));
173
174 $params = new ParamConverter(array('class' => 'WallabagCoreBundle:User'));
175 $converter = new UsernameRssTokenConverter($registry);
176 $request = new Request(array(), array(), array('username' => 'test', 'token' => 'test'));
177
178 $converter->apply($request, $params);
179 }
180
181 public function testApplyUserFound()
182 {
183 $user = new User();
184
185 $repo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\UserRepository')
186 ->disableOriginalConstructor()
187 ->getMock();
188
189 $repo->expects($this->once())
190 ->method('findOneByUsernameAndRsstoken')
191 ->with('test', 'test')
192 ->will($this->returnValue($user));
193
194 $em = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager')
195 ->disableOriginalConstructor()
196 ->getMock();
197
198 $em->expects($this->once())
199 ->method('getRepository')
200 ->with('WallabagCoreBundle:User')
201 ->will($this->returnValue($repo));
202
203 $registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')
204 ->disableOriginalConstructor()
205 ->getMock();
206
207 $registry->expects($this->once())
208 ->method('getManagerForClass')
209 ->with('WallabagCoreBundle:User')
210 ->will($this->returnValue($em));
211
212 $params = new ParamConverter(array('class' => 'WallabagCoreBundle:User', 'name' => 'user'));
213 $converter = new UsernameRssTokenConverter($registry);
214 $request = new Request(array(), array(), array('username' => 'test', 'token' => 'test'));
215
216 $converter->apply($request, $params);
217
218 $this->assertEquals($user, $request->attributes->get('user'));
219 }
220}