]> git.immae.eu Git - github/wallabag/wallabag.git/blame - tests/Wallabag/CoreBundle/Controller/RssControllerTest.php
Changed RSS to Atom feed and improve paging
[github/wallabag/wallabag.git] / tests / Wallabag / CoreBundle / Controller / RssControllerTest.php
CommitLineData
371ac69a
J
1<?php
2
23634d5d 3namespace Tests\Wallabag\CoreBundle\Controller;
371ac69a 4
23634d5d 5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
371ac69a 6
9744e971 7class RssControllerTest extends WallabagCoreTestCase
371ac69a 8{
18c38dff 9 public function validateDom($xml, $type, $urlPagination, $nb = null)
371ac69a
J
10 {
11 $doc = new \DOMDocument();
12 $doc->loadXML($xml);
13
14 $xpath = new \DOMXpath($doc);
47e2d609 15 $xpath->registerNamespace('a', 'http://www.w3.org/2005/Atom');
371ac69a
J
16
17 if (null === $nb) {
47e2d609 18 $this->assertGreaterThan(0, $xpath->query('//a:entry')->length);
371ac69a 19 } else {
47e2d609 20 $this->assertEquals($nb, $xpath->query('//a:entry')->length);
371ac69a
J
21 }
22
47e2d609 23 $this->assertEquals(1, $xpath->query('/a:feed')->length);
371ac69a 24
47e2d609
TC
25 $this->assertEquals(1, $xpath->query('/a:feed/a:title')->length);
26 $this->assertEquals('wallabag — '.$type.' feed', $xpath->query('/a:feed/a:title')->item(0)->nodeValue);
8670250a 27
47e2d609 28 $this->assertEquals(1, $xpath->query('/a:feed/a:updated')->length);
8670250a 29
47e2d609
TC
30 $this->assertEquals(1, $xpath->query('/a:feed/a:generator')->length);
31 $this->assertEquals('wallabag', $xpath->query('/a:feed/a:generator')->item(0)->nodeValue);
8670250a 32
47e2d609
TC
33 $this->assertEquals(1, $xpath->query('/a:feed/a:subtitle')->length);
34 $this->assertEquals('RSS feed for '.$type.' entries', $xpath->query('/a:feed/a:subtitle')->item(0)->nodeValue);
8670250a 35
47e2d609
TC
36 $this->assertEquals(1, $xpath->query('/a:feed/a:link[@rel="self"]')->length);
37 $this->assertContains($type, $xpath->query('/a:feed/a:link[@rel="self"]')->item(0)->getAttribute('href'));
8670250a 38
47e2d609 39 $this->assertEquals(1, $xpath->query('/a:feed/a:link[@rel="last"]')->length);
8670250a 40
47e2d609
TC
41 foreach ($xpath->query('//a:entry') as $item) {
42 $this->assertEquals(1, $xpath->query('a:title', $item)->length);
43 $this->assertEquals(1, $xpath->query('a:link[@rel="via"]', $item)->length);
44 $this->assertEquals(1, $xpath->query('a:link[@rel="alternate"]', $item)->length);
45 $this->assertEquals(1, $xpath->query('a:id', $item)->length);
46 $this->assertEquals(1, $xpath->query('a:published', $item)->length);
47 $this->assertEquals(1, $xpath->query('a:content', $item)->length);
371ac69a
J
48 }
49 }
50
51 public function dataForBadUrl()
52 {
4094ea47
JB
53 return [
54 [
47e2d609 55 '/feed/admin/YZIOAUZIAO/unread',
4094ea47
JB
56 ],
57 [
47e2d609 58 '/feed/wallace/YZIOAUZIAO/starred',
4094ea47
JB
59 ],
60 [
47e2d609 61 '/feed/wallace/YZIOAUZIAO/archives',
4094ea47
JB
62 ],
63 ];
371ac69a
J
64 }
65
66 /**
67 * @dataProvider dataForBadUrl
68 */
69 public function testBadUrl($url)
70 {
71 $client = $this->getClient();
72
73 $client->request('GET', $url);
74
f808b016 75 $this->assertSame(404, $client->getResponse()->getStatusCode());
371ac69a
J
76 }
77
78 public function testUnread()
79 {
80 $client = $this->getClient();
81 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
82 $user = $em
1210dae1 83 ->getRepository('WallabagUserBundle:User')
371ac69a
J
84 ->findOneByUsername('admin');
85
86 $config = $user->getConfig();
87 $config->setRssToken('SUPERTOKEN');
88 $config->setRssLimit(2);
89 $em->persist($config);
90 $em->flush();
91
47e2d609 92 $client->request('GET', '/feed/admin/SUPERTOKEN/unread');
371ac69a 93
f808b016 94 $this->assertSame(200, $client->getResponse()->getStatusCode());
371ac69a 95
18c38dff 96 $this->validateDom($client->getResponse()->getContent(), 'unread', 'unread', 2);
371ac69a
J
97 }
98
99 public function testStarred()
100 {
101 $client = $this->getClient();
102 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
103 $user = $em
1210dae1 104 ->getRepository('WallabagUserBundle:User')
371ac69a
J
105 ->findOneByUsername('admin');
106
107 $config = $user->getConfig();
108 $config->setRssToken('SUPERTOKEN');
109 $config->setRssLimit(1);
110 $em->persist($config);
111 $em->flush();
112
113 $client = $this->getClient();
47e2d609 114 $client->request('GET', '/feed/admin/SUPERTOKEN/starred');
371ac69a 115
f808b016 116 $this->assertSame(200, $client->getResponse()->getStatusCode(), 1);
371ac69a 117
18c38dff 118 $this->validateDom($client->getResponse()->getContent(), 'starred', 'starred');
371ac69a
J
119 }
120
121 public function testArchives()
122 {
123 $client = $this->getClient();
124 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
125 $user = $em
1210dae1 126 ->getRepository('WallabagUserBundle:User')
371ac69a
J
127 ->findOneByUsername('admin');
128
129 $config = $user->getConfig();
130 $config->setRssToken('SUPERTOKEN');
131 $config->setRssLimit(null);
132 $em->persist($config);
133 $em->flush();
134
135 $client = $this->getClient();
47e2d609 136 $client->request('GET', '/feed/admin/SUPERTOKEN/archive');
371ac69a 137
f808b016 138 $this->assertSame(200, $client->getResponse()->getStatusCode());
371ac69a 139
18c38dff 140 $this->validateDom($client->getResponse()->getContent(), 'archive', 'archive');
8670250a
JB
141 }
142
143 public function testPagination()
144 {
145 $client = $this->getClient();
146 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
147 $user = $em
148 ->getRepository('WallabagUserBundle:User')
149 ->findOneByUsername('admin');
150
151 $config = $user->getConfig();
152 $config->setRssToken('SUPERTOKEN');
153 $config->setRssLimit(1);
154 $em->persist($config);
155 $em->flush();
156
157 $client = $this->getClient();
158
47e2d609
TC
159 $client->request('GET', '/feed/admin/SUPERTOKEN/unread');
160 $this->assertEquals(200, $client->getResponse()->getStatusCode());
161 $this->validateDom($client->getResponse()->getContent(), 'unread');
8670250a 162
47e2d609
TC
163 $client->request('GET', '/feed/admin/SUPERTOKEN/unread/2');
164 $this->assertEquals(200, $client->getResponse()->getStatusCode());
165 $this->validateDom($client->getResponse()->getContent(), 'unread');
8670250a 166
47e2d609
TC
167 $client->request('GET', '/feed/admin/SUPERTOKEN/unread/3000');
168 $this->assertEquals(302, $client->getResponse()->getStatusCode());
371ac69a 169 }
18c38dff
JB
170
171 public function testTags()
172 {
173 $client = $this->getClient();
174 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
175 $user = $em
176 ->getRepository('WallabagUserBundle:User')
177 ->findOneByUsername('admin');
178
179 $config = $user->getConfig();
180 $config->setRssToken('SUPERTOKEN');
181 $config->setRssLimit(null);
182 $em->persist($config);
183 $em->flush();
184
185 $client = $this->getClient();
186 $client->request('GET', '/admin/SUPERTOKEN/tags/foo-bar.xml');
187
f808b016 188 $this->assertSame(200, $client->getResponse()->getStatusCode());
18c38dff
JB
189
190 $this->validateDom($client->getResponse()->getContent(), 'tag (foo bar)', 'tags/foo-bar');
191
192 $client->request('GET', '/admin/SUPERTOKEN/tags/foo-bar.xml?page=3000');
f808b016 193 $this->assertSame(302, $client->getResponse()->getStatusCode());
18c38dff 194 }
371ac69a 195}