3 namespace Tests\Wallabag\CoreBundle\Controller
;
5 use Tests\Wallabag\CoreBundle\WallabagCoreTestCase
;
7 class RssControllerTest
extends WallabagCoreTestCase
9 public function validateDom($xml, $type, $urlPagination, $nb = null)
11 $doc = new \
DOMDocument();
14 $xpath = new \
DOMXpath($doc);
17 $this->assertGreaterThan(0, $xpath->query('//item')->length
);
19 $this->assertSame($nb, $xpath->query('//item')->length
);
22 $this->assertSame(1, $xpath->query('/rss')->length
);
23 $this->assertSame(1, $xpath->query('/rss/channel')->length
);
25 $this->assertSame(1, $xpath->query('/rss/channel/title')->length
);
26 $this->assertSame('wallabag - ' . $type . ' feed', $xpath->query('/rss/channel/title')->item(0)->nodeValue
);
28 $this->assertSame(1, $xpath->query('/rss/channel/pubDate')->length
);
30 $this->assertSame(1, $xpath->query('/rss/channel/generator')->length
);
31 $this->assertSame('wallabag', $xpath->query('/rss/channel/generator')->item(0)->nodeValue
);
33 $this->assertSame(1, $xpath->query('/rss/channel/description')->length
);
34 $this->assertSame('wallabag ' . $type . ' elements', $xpath->query('/rss/channel/description')->item(0)->nodeValue
);
36 $this->assertSame(1, $xpath->query('/rss/channel/link[@rel="self"]')->length
);
37 $this->assertContains($urlPagination . '.xml', $xpath->query('/rss/channel/link[@rel="self"]')->item(0)->getAttribute('href'));
39 $this->assertSame(1, $xpath->query('/rss/channel/link[@rel="last"]')->length
);
40 $this->assertContains($urlPagination . '.xml?page=', $xpath->query('/rss/channel/link[@rel="last"]')->item(0)->getAttribute('href'));
42 foreach ($xpath->query('//item') as $item) {
43 $this->assertSame(1, $xpath->query('title', $item)->length
);
44 $this->assertSame(1, $xpath->query('source', $item)->length
);
45 $this->assertSame(1, $xpath->query('link', $item)->length
);
46 $this->assertSame(1, $xpath->query('guid', $item)->length
);
47 $this->assertSame(1, $xpath->query('pubDate', $item)->length
);
48 $this->assertSame(1, $xpath->query('description', $item)->length
);
52 public function dataForBadUrl()
56 '/admin/YZIOAUZIAO/unread.xml',
59 '/wallace/YZIOAUZIAO/starred.xml',
62 '/wallace/YZIOAUZIAO/archives.xml',
65 '/wallace/YZIOAUZIAO/all.xml',
71 * @dataProvider dataForBadUrl
73 public function testBadUrl($url)
75 $client = $this->getClient();
77 $client->request('GET', $url);
79 $this->assertSame(404, $client->getResponse()->getStatusCode());
82 public function testUnread()
84 $client = $this->getClient();
85 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
87 ->getRepository('WallabagUserBundle:User')
88 ->findOneByUsername('admin');
90 $config = $user->getConfig();
91 $config->setRssToken('SUPERTOKEN');
92 $config->setRssLimit(2);
93 $em->persist($config);
96 $client->request('GET', '/admin/SUPERTOKEN/unread.xml');
98 $this->assertSame(200, $client->getResponse()->getStatusCode());
100 $this->validateDom($client->getResponse()->getContent(), 'unread', 'unread', 2);
103 public function testStarred()
105 $client = $this->getClient();
106 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
108 ->getRepository('WallabagUserBundle:User')
109 ->findOneByUsername('admin');
111 $config = $user->getConfig();
112 $config->setRssToken('SUPERTOKEN');
113 $config->setRssLimit(1);
114 $em->persist($config);
117 $client = $this->getClient();
118 $client->request('GET', '/admin/SUPERTOKEN/starred.xml');
120 $this->assertSame(200, $client->getResponse()->getStatusCode(), 1);
122 $this->validateDom($client->getResponse()->getContent(), 'starred', 'starred');
125 public function testArchives()
127 $client = $this->getClient();
128 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
130 ->getRepository('WallabagUserBundle:User')
131 ->findOneByUsername('admin');
133 $config = $user->getConfig();
134 $config->setRssToken('SUPERTOKEN');
135 $config->setRssLimit(null);
136 $em->persist($config);
139 $client = $this->getClient();
140 $client->request('GET', '/admin/SUPERTOKEN/archive.xml');
142 $this->assertSame(200, $client->getResponse()->getStatusCode());
144 $this->validateDom($client->getResponse()->getContent(), 'archive', 'archive');
147 public function testAll()
149 $client = $this->getClient();
150 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
152 ->getRepository('WallabagUserBundle:User')
153 ->findOneByUsername('admin');
155 $config = $user->getConfig();
156 $config->setRssToken('SUPERTOKEN');
157 $config->setRssLimit(null);
158 $em->persist($config);
161 $client = $this->getClient();
162 $client->request('GET', '/admin/SUPERTOKEN/all.xml');
164 $this->assertSame(200, $client->getResponse()->getStatusCode());
166 $this->validateDom($client->getResponse()->getContent(), 'all', 'all');
169 public function testPagination()
171 $client = $this->getClient();
172 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
174 ->getRepository('WallabagUserBundle:User')
175 ->findOneByUsername('admin');
177 $config = $user->getConfig();
178 $config->setRssToken('SUPERTOKEN');
179 $config->setRssLimit(1);
180 $em->persist($config);
183 $client = $this->getClient();
185 $client->request('GET', '/admin/SUPERTOKEN/unread.xml');
186 $this->assertSame(200, $client->getResponse()->getStatusCode());
187 $this->validateDom($client->getResponse()->getContent(), 'unread', 'unread');
189 $client->request('GET', '/admin/SUPERTOKEN/unread.xml?page=2');
190 $this->assertSame(200, $client->getResponse()->getStatusCode());
191 $this->validateDom($client->getResponse()->getContent(), 'unread', 'unread');
193 $client->request('GET', '/admin/SUPERTOKEN/unread.xml?page=3000');
194 $this->assertSame(302, $client->getResponse()->getStatusCode());
197 public function testTags()
199 $client = $this->getClient();
200 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
202 ->getRepository('WallabagUserBundle:User')
203 ->findOneByUsername('admin');
205 $config = $user->getConfig();
206 $config->setRssToken('SUPERTOKEN');
207 $config->setRssLimit(null);
208 $em->persist($config);
211 $client = $this->getClient();
212 $client->request('GET', '/admin/SUPERTOKEN/tags/foo.xml');
214 $this->assertSame(200, $client->getResponse()->getStatusCode());
216 $this->validateDom($client->getResponse()->getContent(), 'tag (foo)', 'tags/foo');
218 $client->request('GET', '/admin/SUPERTOKEN/tags/foo.xml?page=3000');
219 $this->assertSame(302, $client->getResponse()->getStatusCode());