diff options
Diffstat (limited to 'tests/Wallabag/CoreBundle/Controller/RssControllerTest.php')
-rw-r--r-- | tests/Wallabag/CoreBundle/Controller/RssControllerTest.php | 221 |
1 files changed, 0 insertions, 221 deletions
diff --git a/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php b/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php deleted file mode 100644 index 2af6e14f..00000000 --- a/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php +++ /dev/null | |||
@@ -1,221 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Tests\Wallabag\CoreBundle\Controller; | ||
4 | |||
5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | ||
6 | |||
7 | class RssControllerTest extends WallabagCoreTestCase | ||
8 | { | ||
9 | public function validateDom($xml, $type, $urlPagination, $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->assertSame($nb, $xpath->query('//item')->length); | ||
20 | } | ||
21 | |||
22 | $this->assertSame(1, $xpath->query('/rss')->length); | ||
23 | $this->assertSame(1, $xpath->query('/rss/channel')->length); | ||
24 | |||
25 | $this->assertSame(1, $xpath->query('/rss/channel/title')->length); | ||
26 | $this->assertSame('wallabag - ' . $type . ' feed', $xpath->query('/rss/channel/title')->item(0)->nodeValue); | ||
27 | |||
28 | $this->assertSame(1, $xpath->query('/rss/channel/pubDate')->length); | ||
29 | |||
30 | $this->assertSame(1, $xpath->query('/rss/channel/generator')->length); | ||
31 | $this->assertSame('wallabag', $xpath->query('/rss/channel/generator')->item(0)->nodeValue); | ||
32 | |||
33 | $this->assertSame(1, $xpath->query('/rss/channel/description')->length); | ||
34 | $this->assertSame('wallabag ' . $type . ' elements', $xpath->query('/rss/channel/description')->item(0)->nodeValue); | ||
35 | |||
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')); | ||
38 | |||
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')); | ||
41 | |||
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); | ||
49 | } | ||
50 | } | ||
51 | |||
52 | public function dataForBadUrl() | ||
53 | { | ||
54 | return [ | ||
55 | [ | ||
56 | '/admin/YZIOAUZIAO/unread.xml', | ||
57 | ], | ||
58 | [ | ||
59 | '/wallace/YZIOAUZIAO/starred.xml', | ||
60 | ], | ||
61 | [ | ||
62 | '/wallace/YZIOAUZIAO/archives.xml', | ||
63 | ], | ||
64 | [ | ||
65 | '/wallace/YZIOAUZIAO/all.xml', | ||
66 | ], | ||
67 | ]; | ||
68 | } | ||
69 | |||
70 | /** | ||
71 | * @dataProvider dataForBadUrl | ||
72 | */ | ||
73 | public function testBadUrl($url) | ||
74 | { | ||
75 | $client = $this->getClient(); | ||
76 | |||
77 | $client->request('GET', $url); | ||
78 | |||
79 | $this->assertSame(404, $client->getResponse()->getStatusCode()); | ||
80 | } | ||
81 | |||
82 | public function testUnread() | ||
83 | { | ||
84 | $client = $this->getClient(); | ||
85 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
86 | $user = $em | ||
87 | ->getRepository('WallabagUserBundle:User') | ||
88 | ->findOneByUsername('admin'); | ||
89 | |||
90 | $config = $user->getConfig(); | ||
91 | $config->setRssToken('SUPERTOKEN'); | ||
92 | $config->setRssLimit(2); | ||
93 | $em->persist($config); | ||
94 | $em->flush(); | ||
95 | |||
96 | $client->request('GET', '/admin/SUPERTOKEN/unread.xml'); | ||
97 | |||
98 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | ||
99 | |||
100 | $this->validateDom($client->getResponse()->getContent(), 'unread', 'unread', 2); | ||
101 | } | ||
102 | |||
103 | public function testStarred() | ||
104 | { | ||
105 | $client = $this->getClient(); | ||
106 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
107 | $user = $em | ||
108 | ->getRepository('WallabagUserBundle:User') | ||
109 | ->findOneByUsername('admin'); | ||
110 | |||
111 | $config = $user->getConfig(); | ||
112 | $config->setRssToken('SUPERTOKEN'); | ||
113 | $config->setRssLimit(1); | ||
114 | $em->persist($config); | ||
115 | $em->flush(); | ||
116 | |||
117 | $client = $this->getClient(); | ||
118 | $client->request('GET', '/admin/SUPERTOKEN/starred.xml'); | ||
119 | |||
120 | $this->assertSame(200, $client->getResponse()->getStatusCode(), 1); | ||
121 | |||
122 | $this->validateDom($client->getResponse()->getContent(), 'starred', 'starred'); | ||
123 | } | ||
124 | |||
125 | public function testArchives() | ||
126 | { | ||
127 | $client = $this->getClient(); | ||
128 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
129 | $user = $em | ||
130 | ->getRepository('WallabagUserBundle:User') | ||
131 | ->findOneByUsername('admin'); | ||
132 | |||
133 | $config = $user->getConfig(); | ||
134 | $config->setRssToken('SUPERTOKEN'); | ||
135 | $config->setRssLimit(null); | ||
136 | $em->persist($config); | ||
137 | $em->flush(); | ||
138 | |||
139 | $client = $this->getClient(); | ||
140 | $client->request('GET', '/admin/SUPERTOKEN/archive.xml'); | ||
141 | |||
142 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | ||
143 | |||
144 | $this->validateDom($client->getResponse()->getContent(), 'archive', 'archive'); | ||
145 | } | ||
146 | |||
147 | public function testAll() | ||
148 | { | ||
149 | $client = $this->getClient(); | ||
150 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
151 | $user = $em | ||
152 | ->getRepository('WallabagUserBundle:User') | ||
153 | ->findOneByUsername('admin'); | ||
154 | |||
155 | $config = $user->getConfig(); | ||
156 | $config->setRssToken('SUPERTOKEN'); | ||
157 | $config->setRssLimit(null); | ||
158 | $em->persist($config); | ||
159 | $em->flush(); | ||
160 | |||
161 | $client = $this->getClient(); | ||
162 | $client->request('GET', '/admin/SUPERTOKEN/all.xml'); | ||
163 | |||
164 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | ||
165 | |||
166 | $this->validateDom($client->getResponse()->getContent(), 'all', 'all'); | ||
167 | } | ||
168 | |||
169 | public function testPagination() | ||
170 | { | ||
171 | $client = $this->getClient(); | ||
172 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
173 | $user = $em | ||
174 | ->getRepository('WallabagUserBundle:User') | ||
175 | ->findOneByUsername('admin'); | ||
176 | |||
177 | $config = $user->getConfig(); | ||
178 | $config->setRssToken('SUPERTOKEN'); | ||
179 | $config->setRssLimit(1); | ||
180 | $em->persist($config); | ||
181 | $em->flush(); | ||
182 | |||
183 | $client = $this->getClient(); | ||
184 | |||
185 | $client->request('GET', '/admin/SUPERTOKEN/unread.xml'); | ||
186 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | ||
187 | $this->validateDom($client->getResponse()->getContent(), 'unread', 'unread'); | ||
188 | |||
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'); | ||
192 | |||
193 | $client->request('GET', '/admin/SUPERTOKEN/unread.xml?page=3000'); | ||
194 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | ||
195 | } | ||
196 | |||
197 | public function testTags() | ||
198 | { | ||
199 | $client = $this->getClient(); | ||
200 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
201 | $user = $em | ||
202 | ->getRepository('WallabagUserBundle:User') | ||
203 | ->findOneByUsername('admin'); | ||
204 | |||
205 | $config = $user->getConfig(); | ||
206 | $config->setRssToken('SUPERTOKEN'); | ||
207 | $config->setRssLimit(null); | ||
208 | $em->persist($config); | ||
209 | $em->flush(); | ||
210 | |||
211 | $client = $this->getClient(); | ||
212 | $client->request('GET', '/admin/SUPERTOKEN/tags/foo.xml'); | ||
213 | |||
214 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | ||
215 | |||
216 | $this->validateDom($client->getResponse()->getContent(), 'tag (foo)', 'tags/foo'); | ||
217 | |||
218 | $client->request('GET', '/admin/SUPERTOKEN/tags/foo.xml?page=3000'); | ||
219 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | ||
220 | } | ||
221 | } | ||