3 namespace Tests\Wallabag\CoreBundle\Controller
;
5 use Tests\Wallabag\CoreBundle\WallabagCoreTestCase
;
7 class FeedControllerTest
extends WallabagCoreTestCase
9 public function validateDom($xml, $type, $nb = null, $tagValue = null)
11 $doc = new \
DOMDocument();
14 $xpath = new \
DOMXPath($doc);
15 $xpath->registerNamespace('a', 'http://www.w3.org/2005/Atom');
18 $this->assertGreaterThan(0, $xpath->query('//a:entry')->length
);
20 $this->assertSame($nb, $xpath->query('//a:entry')->length
);
23 $this->assertSame(1, $xpath->query('/a:feed')->length
);
25 $this->assertSame(1, $xpath->query('/a:feed/a:title')->length
);
26 $this->assertContains('favicon.ico', $xpath->query('/a:feed/a:icon')->item(0)->nodeValue
);
27 $this->assertContains('logo-square.png', $xpath->query('/a:feed/a:logo')->item(0)->nodeValue
);
29 $this->assertSame(1, $xpath->query('/a:feed/a:updated')->length
);
31 $this->assertSame(1, $xpath->query('/a:feed/a:generator')->length
);
32 $this->assertSame('wallabag', $xpath->query('/a:feed/a:generator')->item(0)->nodeValue
);
33 $this->assertSame('admin', $xpath->query('/a:feed/a:author/a:name')->item(0)->nodeValue
);
35 $this->assertSame(1, $xpath->query('/a:feed/a:subtitle')->length
);
36 if (null !== $tagValue && 0 === strpos($type, 'tag')) {
37 $this->assertSame('wallabag — ' . $type . ' ' . $tagValue . ' feed', $xpath->query('/a:feed/a:title')->item(0)->nodeValue
);
38 $this->assertSame('Atom feed for entries tagged with ' . $tagValue, $xpath->query('/a:feed/a:subtitle')->item(0)->nodeValue
);
40 $this->assertSame('wallabag — ' . $type . ' feed', $xpath->query('/a:feed/a:title')->item(0)->nodeValue
);
41 $this->assertSame('Atom feed for ' . $type . ' entries', $xpath->query('/a:feed/a:subtitle')->item(0)->nodeValue
);
44 $this->assertSame(1, $xpath->query('/a:feed/a:link[@rel="self"]')->length
);
45 $this->assertContains($type, $xpath->query('/a:feed/a:link[@rel="self"]')->item(0)->getAttribute('href'));
47 $this->assertSame(1, $xpath->query('/a:feed/a:link[@rel="last"]')->length
);
49 foreach ($xpath->query('//a:entry') as $item) {
50 $this->assertSame(1, $xpath->query('a:title', $item)->length
);
51 $this->assertSame(1, $xpath->query('a:link[@rel="via"]', $item)->length
);
52 $this->assertSame(1, $xpath->query('a:link[@rel="alternate"]', $item)->length
);
53 $this->assertSame(1, $xpath->query('a:id', $item)->length
);
54 $this->assertSame(1, $xpath->query('a:published', $item)->length
);
55 $this->assertSame(1, $xpath->query('a:content', $item)->length
);
59 public function dataForBadUrl()
63 '/feed/admin/YZIOAUZIAO/unread',
66 '/feed/wallace/YZIOAUZIAO/starred',
69 '/feed/wallace/YZIOAUZIAO/archives',
72 '/feed/wallace/YZIOAUZIAO/all',
78 * @dataProvider dataForBadUrl
80 public function testBadUrl($url)
82 $client = $this->getClient();
84 $client->request('GET', $url);
86 $this->assertSame(404, $client->getResponse()->getStatusCode());
89 public function testUnread()
91 $client = $this->getClient();
92 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
94 ->getRepository('WallabagUserBundle:User')
95 ->findOneByUsername('admin');
97 $config = $user->getConfig();
98 $config->setFeedToken('SUPERTOKEN');
99 $config->setFeedLimit(2);
100 $em->persist($config);
103 $client->request('GET', '/feed/admin/SUPERTOKEN/unread');
105 $this->assertSame(200, $client->getResponse()->getStatusCode());
107 $this->validateDom($client->getResponse()->getContent(), 'unread', 2);
110 public function testStarred()
112 $client = $this->getClient();
113 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
115 ->getRepository('WallabagUserBundle:User')
116 ->findOneByUsername('admin');
118 $config = $user->getConfig();
119 $config->setFeedToken('SUPERTOKEN');
120 $config->setFeedLimit(1);
121 $em->persist($config);
124 $client = $this->getClient();
125 $client->request('GET', '/feed/admin/SUPERTOKEN/starred');
127 $this->assertSame(200, $client->getResponse()->getStatusCode(), 1);
129 $this->validateDom($client->getResponse()->getContent(), 'starred');
132 public function testArchives()
134 $client = $this->getClient();
135 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
137 ->getRepository('WallabagUserBundle:User')
138 ->findOneByUsername('admin');
140 $config = $user->getConfig();
141 $config->setFeedToken('SUPERTOKEN');
142 $config->setFeedLimit(null);
143 $em->persist($config);
146 $client = $this->getClient();
147 $client->request('GET', '/feed/admin/SUPERTOKEN/archive');
149 $this->assertSame(200, $client->getResponse()->getStatusCode());
151 $this->validateDom($client->getResponse()->getContent(), 'archive');
154 public function testAll()
156 $client = $this->getClient();
157 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
159 ->getRepository('WallabagUserBundle:User')
160 ->findOneByUsername('admin');
162 $config = $user->getConfig();
163 $config->setFeedToken('SUPERTOKEN');
164 $config->setFeedLimit(null);
165 $em->persist($config);
168 $client = $this->getClient();
169 $client->request('GET', '/feed/admin/SUPERTOKEN/all');
171 $this->assertSame(200, $client->getResponse()->getStatusCode());
173 $this->validateDom($client->getResponse()->getContent(), 'all');
176 public function testPagination()
178 $client = $this->getClient();
179 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
181 ->getRepository('WallabagUserBundle:User')
182 ->findOneByUsername('admin');
184 $config = $user->getConfig();
185 $config->setFeedToken('SUPERTOKEN');
186 $config->setFeedLimit(1);
187 $em->persist($config);
190 $client = $this->getClient();
192 $client->request('GET', '/feed/admin/SUPERTOKEN/unread');
193 $this->assertSame(200, $client->getResponse()->getStatusCode());
194 $this->validateDom($client->getResponse()->getContent(), 'unread');
196 $client->request('GET', '/feed/admin/SUPERTOKEN/unread/2');
197 $this->assertSame(200, $client->getResponse()->getStatusCode());
198 $this->validateDom($client->getResponse()->getContent(), 'unread');
200 $client->request('GET', '/feed/admin/SUPERTOKEN/unread/3000');
201 $this->assertSame(302, $client->getResponse()->getStatusCode());
204 public function testTags()
206 $client = $this->getClient();
207 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
209 ->getRepository('WallabagUserBundle:User')
210 ->findOneByUsername('admin');
212 $config = $user->getConfig();
213 $config->setFeedToken('SUPERTOKEN');
214 $config->setFeedLimit(null);
215 $em->persist($config);
218 $client = $this->getClient();
219 $client->request('GET', '/feed/admin/SUPERTOKEN/tags/foo');
221 $this->assertSame(200, $client->getResponse()->getStatusCode());
223 $this->validateDom($client->getResponse()->getContent(), 'tag', 2, 'foo');
225 $client->request('GET', '/feed/admin/SUPERTOKEN/tags/foo/3000');
226 $this->assertSame(302, $client->getResponse()->getStatusCode());
229 public function dataForRedirect()
233 '/admin/YZIOAUZIAO/unread.xml',
236 '/admin/YZIOAUZIAO/starred.xml',
239 '/admin/YZIOAUZIAO/archive.xml',
242 '/admin/YZIOAUZIAO/all.xml',
245 '/admin/YZIOAUZIAO/tags/foo.xml',
251 * @dataProvider dataForRedirect
253 public function testRedirectFromRssToAtom($url)
255 $client = $this->getClient();
257 $client->request('GET', $url);
259 $this->assertSame(301, $client->getResponse()->getStatusCode());