]>
Commit | Line | Data |
---|---|---|
371ac69a J |
1 | <?php |
2 | ||
23634d5d | 3 | namespace Tests\Wallabag\CoreBundle\Controller; |
371ac69a | 4 | |
23634d5d | 5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; |
371ac69a | 6 | |
9744e971 | 7 | class 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); | |
15 | ||
16 | if (null === $nb) { | |
17 | $this->assertGreaterThan(0, $xpath->query('//item')->length); | |
18 | } else { | |
f808b016 | 19 | $this->assertSame($nb, $xpath->query('//item')->length); |
371ac69a J |
20 | } |
21 | ||
f808b016 JB |
22 | $this->assertSame(1, $xpath->query('/rss')->length); |
23 | $this->assertSame(1, $xpath->query('/rss/channel')->length); | |
371ac69a | 24 | |
f808b016 JB |
25 | $this->assertSame(1, $xpath->query('/rss/channel/title')->length); |
26 | $this->assertSame('wallabag - ' . $type . ' feed', $xpath->query('/rss/channel/title')->item(0)->nodeValue); | |
8670250a | 27 | |
f808b016 | 28 | $this->assertSame(1, $xpath->query('/rss/channel/pubDate')->length); |
8670250a | 29 | |
f808b016 JB |
30 | $this->assertSame(1, $xpath->query('/rss/channel/generator')->length); |
31 | $this->assertSame('wallabag', $xpath->query('/rss/channel/generator')->item(0)->nodeValue); | |
8670250a | 32 | |
f808b016 JB |
33 | $this->assertSame(1, $xpath->query('/rss/channel/description')->length); |
34 | $this->assertSame('wallabag ' . $type . ' elements', $xpath->query('/rss/channel/description')->item(0)->nodeValue); | |
8670250a | 35 | |
f808b016 JB |
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')); | |
8670250a | 38 | |
f808b016 JB |
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')); | |
8670250a | 41 | |
371ac69a | 42 | foreach ($xpath->query('//item') as $item) { |
f808b016 JB |
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); | |
371ac69a J |
49 | } |
50 | } | |
51 | ||
52 | public function dataForBadUrl() | |
53 | { | |
4094ea47 JB |
54 | return [ |
55 | [ | |
9744e971 | 56 | '/admin/YZIOAUZIAO/unread.xml', |
4094ea47 JB |
57 | ], |
58 | [ | |
9744e971 | 59 | '/wallace/YZIOAUZIAO/starred.xml', |
4094ea47 JB |
60 | ], |
61 | [ | |
9744e971 | 62 | '/wallace/YZIOAUZIAO/archives.xml', |
4094ea47 JB |
63 | ], |
64 | ]; | |
371ac69a J |
65 | } |
66 | ||
67 | /** | |
68 | * @dataProvider dataForBadUrl | |
69 | */ | |
70 | public function testBadUrl($url) | |
71 | { | |
72 | $client = $this->getClient(); | |
73 | ||
74 | $client->request('GET', $url); | |
75 | ||
f808b016 | 76 | $this->assertSame(404, $client->getResponse()->getStatusCode()); |
371ac69a J |
77 | } |
78 | ||
79 | public function testUnread() | |
80 | { | |
81 | $client = $this->getClient(); | |
82 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | |
83 | $user = $em | |
1210dae1 | 84 | ->getRepository('WallabagUserBundle:User') |
371ac69a J |
85 | ->findOneByUsername('admin'); |
86 | ||
87 | $config = $user->getConfig(); | |
88 | $config->setRssToken('SUPERTOKEN'); | |
89 | $config->setRssLimit(2); | |
90 | $em->persist($config); | |
91 | $em->flush(); | |
92 | ||
93 | $client->request('GET', '/admin/SUPERTOKEN/unread.xml'); | |
94 | ||
f808b016 | 95 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
371ac69a | 96 | |
18c38dff | 97 | $this->validateDom($client->getResponse()->getContent(), 'unread', 'unread', 2); |
371ac69a J |
98 | } |
99 | ||
100 | public function testStarred() | |
101 | { | |
102 | $client = $this->getClient(); | |
103 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | |
104 | $user = $em | |
1210dae1 | 105 | ->getRepository('WallabagUserBundle:User') |
371ac69a J |
106 | ->findOneByUsername('admin'); |
107 | ||
108 | $config = $user->getConfig(); | |
109 | $config->setRssToken('SUPERTOKEN'); | |
110 | $config->setRssLimit(1); | |
111 | $em->persist($config); | |
112 | $em->flush(); | |
113 | ||
114 | $client = $this->getClient(); | |
115 | $client->request('GET', '/admin/SUPERTOKEN/starred.xml'); | |
116 | ||
f808b016 | 117 | $this->assertSame(200, $client->getResponse()->getStatusCode(), 1); |
371ac69a | 118 | |
18c38dff | 119 | $this->validateDom($client->getResponse()->getContent(), 'starred', 'starred'); |
371ac69a J |
120 | } |
121 | ||
122 | public function testArchives() | |
123 | { | |
124 | $client = $this->getClient(); | |
125 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | |
126 | $user = $em | |
1210dae1 | 127 | ->getRepository('WallabagUserBundle:User') |
371ac69a J |
128 | ->findOneByUsername('admin'); |
129 | ||
130 | $config = $user->getConfig(); | |
131 | $config->setRssToken('SUPERTOKEN'); | |
132 | $config->setRssLimit(null); | |
133 | $em->persist($config); | |
134 | $em->flush(); | |
135 | ||
136 | $client = $this->getClient(); | |
137 | $client->request('GET', '/admin/SUPERTOKEN/archive.xml'); | |
138 | ||
f808b016 | 139 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
371ac69a | 140 | |
18c38dff | 141 | $this->validateDom($client->getResponse()->getContent(), 'archive', 'archive'); |
8670250a JB |
142 | } |
143 | ||
144 | public function testPagination() | |
145 | { | |
146 | $client = $this->getClient(); | |
147 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | |
148 | $user = $em | |
149 | ->getRepository('WallabagUserBundle:User') | |
150 | ->findOneByUsername('admin'); | |
151 | ||
152 | $config = $user->getConfig(); | |
153 | $config->setRssToken('SUPERTOKEN'); | |
154 | $config->setRssLimit(1); | |
155 | $em->persist($config); | |
156 | $em->flush(); | |
157 | ||
158 | $client = $this->getClient(); | |
159 | ||
edd2472f | 160 | $client->request('GET', '/admin/SUPERTOKEN/unread.xml'); |
f808b016 | 161 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
18c38dff | 162 | $this->validateDom($client->getResponse()->getContent(), 'unread', 'unread'); |
8670250a | 163 | |
edd2472f | 164 | $client->request('GET', '/admin/SUPERTOKEN/unread.xml?page=2'); |
f808b016 | 165 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
18c38dff | 166 | $this->validateDom($client->getResponse()->getContent(), 'unread', 'unread'); |
8670250a | 167 | |
edd2472f | 168 | $client->request('GET', '/admin/SUPERTOKEN/unread.xml?page=3000'); |
f808b016 | 169 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
371ac69a | 170 | } |
18c38dff JB |
171 | |
172 | public function testTags() | |
173 | { | |
174 | $client = $this->getClient(); | |
175 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | |
176 | $user = $em | |
177 | ->getRepository('WallabagUserBundle:User') | |
178 | ->findOneByUsername('admin'); | |
179 | ||
180 | $config = $user->getConfig(); | |
181 | $config->setRssToken('SUPERTOKEN'); | |
182 | $config->setRssLimit(null); | |
183 | $em->persist($config); | |
184 | $em->flush(); | |
185 | ||
186 | $client = $this->getClient(); | |
7c04b739 | 187 | $client->request('GET', '/admin/SUPERTOKEN/tags/foo.xml'); |
18c38dff | 188 | |
f808b016 | 189 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
18c38dff | 190 | |
7c04b739 | 191 | $this->validateDom($client->getResponse()->getContent(), 'tag (foo)', 'tags/foo'); |
18c38dff | 192 | |
7c04b739 | 193 | $client->request('GET', '/admin/SUPERTOKEN/tags/foo.xml?page=3000'); |
f808b016 | 194 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
18c38dff | 195 | } |
371ac69a | 196 | } |