]>
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 | |
1554eb0a | 7 | class FeedControllerTest extends WallabagCoreTestCase |
371ac69a | 8 | { |
1554eb0a | 9 | public function validateDom($xml, $type, $nb = null, $tagValue = 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 | 25 | $this->assertEquals(1, $xpath->query('/a:feed/a:title')->length); |
9a62cb9f TC |
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); | |
8670250a | 28 | |
47e2d609 | 29 | $this->assertEquals(1, $xpath->query('/a:feed/a:updated')->length); |
8670250a | 30 | |
47e2d609 TC |
31 | $this->assertEquals(1, $xpath->query('/a:feed/a:generator')->length); |
32 | $this->assertEquals('wallabag', $xpath->query('/a:feed/a:generator')->item(0)->nodeValue); | |
9a62cb9f | 33 | $this->assertEquals('admin', $xpath->query('/a:feed/a:author/a:name')->item(0)->nodeValue); |
8670250a | 34 | |
47e2d609 | 35 | $this->assertEquals(1, $xpath->query('/a:feed/a:subtitle')->length); |
1554eb0a TC |
36 | if (null !== $tagValue && 0 === strpos($type, 'tag')) { |
37 | $this->assertEquals('wallabag — '.$type.' '.$tagValue.' feed', $xpath->query('/a:feed/a:title')->item(0)->nodeValue); | |
38 | $this->assertEquals('Atom feed for entries tagged with ' . $tagValue, $xpath->query('/a:feed/a:subtitle')->item(0)->nodeValue); | |
39 | } else { | |
40 | $this->assertEquals('wallabag — '.$type.' feed', $xpath->query('/a:feed/a:title')->item(0)->nodeValue); | |
41 | $this->assertEquals('Atom feed for ' . $type . ' entries', $xpath->query('/a:feed/a:subtitle')->item(0)->nodeValue); | |
42 | } | |
8670250a | 43 | |
47e2d609 TC |
44 | $this->assertEquals(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')); | |
8670250a | 46 | |
47e2d609 | 47 | $this->assertEquals(1, $xpath->query('/a:feed/a:link[@rel="last"]')->length); |
8670250a | 48 | |
47e2d609 TC |
49 | foreach ($xpath->query('//a:entry') as $item) { |
50 | $this->assertEquals(1, $xpath->query('a:title', $item)->length); | |
51 | $this->assertEquals(1, $xpath->query('a:link[@rel="via"]', $item)->length); | |
52 | $this->assertEquals(1, $xpath->query('a:link[@rel="alternate"]', $item)->length); | |
53 | $this->assertEquals(1, $xpath->query('a:id', $item)->length); | |
54 | $this->assertEquals(1, $xpath->query('a:published', $item)->length); | |
55 | $this->assertEquals(1, $xpath->query('a:content', $item)->length); | |
371ac69a J |
56 | } |
57 | } | |
58 | ||
59 | public function dataForBadUrl() | |
60 | { | |
4094ea47 JB |
61 | return [ |
62 | [ | |
47e2d609 | 63 | '/feed/admin/YZIOAUZIAO/unread', |
4094ea47 JB |
64 | ], |
65 | [ | |
47e2d609 | 66 | '/feed/wallace/YZIOAUZIAO/starred', |
4094ea47 JB |
67 | ], |
68 | [ | |
47e2d609 | 69 | '/feed/wallace/YZIOAUZIAO/archives', |
4094ea47 JB |
70 | ], |
71 | ]; | |
371ac69a J |
72 | } |
73 | ||
74 | /** | |
75 | * @dataProvider dataForBadUrl | |
76 | */ | |
77 | public function testBadUrl($url) | |
78 | { | |
79 | $client = $this->getClient(); | |
80 | ||
81 | $client->request('GET', $url); | |
82 | ||
f808b016 | 83 | $this->assertSame(404, $client->getResponse()->getStatusCode()); |
371ac69a J |
84 | } |
85 | ||
86 | public function testUnread() | |
87 | { | |
88 | $client = $this->getClient(); | |
89 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | |
90 | $user = $em | |
1210dae1 | 91 | ->getRepository('WallabagUserBundle:User') |
371ac69a J |
92 | ->findOneByUsername('admin'); |
93 | ||
94 | $config = $user->getConfig(); | |
1554eb0a TC |
95 | $config->setFeedToken('SUPERTOKEN'); |
96 | $config->setFeedLimit(2); | |
371ac69a J |
97 | $em->persist($config); |
98 | $em->flush(); | |
99 | ||
47e2d609 | 100 | $client->request('GET', '/feed/admin/SUPERTOKEN/unread'); |
371ac69a | 101 | |
f808b016 | 102 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
371ac69a | 103 | |
1554eb0a | 104 | $this->validateDom($client->getResponse()->getContent(), 'unread', 2); |
371ac69a J |
105 | } |
106 | ||
107 | public function testStarred() | |
108 | { | |
109 | $client = $this->getClient(); | |
110 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | |
111 | $user = $em | |
1210dae1 | 112 | ->getRepository('WallabagUserBundle:User') |
371ac69a J |
113 | ->findOneByUsername('admin'); |
114 | ||
115 | $config = $user->getConfig(); | |
1554eb0a TC |
116 | $config->setFeedToken('SUPERTOKEN'); |
117 | $config->setFeedLimit(1); | |
371ac69a J |
118 | $em->persist($config); |
119 | $em->flush(); | |
120 | ||
121 | $client = $this->getClient(); | |
47e2d609 | 122 | $client->request('GET', '/feed/admin/SUPERTOKEN/starred'); |
371ac69a | 123 | |
f808b016 | 124 | $this->assertSame(200, $client->getResponse()->getStatusCode(), 1); |
371ac69a | 125 | |
1554eb0a | 126 | $this->validateDom($client->getResponse()->getContent(), 'starred'); |
371ac69a J |
127 | } |
128 | ||
129 | public function testArchives() | |
130 | { | |
131 | $client = $this->getClient(); | |
132 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | |
133 | $user = $em | |
1210dae1 | 134 | ->getRepository('WallabagUserBundle:User') |
371ac69a J |
135 | ->findOneByUsername('admin'); |
136 | ||
137 | $config = $user->getConfig(); | |
1554eb0a TC |
138 | $config->setFeedToken('SUPERTOKEN'); |
139 | $config->setFeedLimit(null); | |
371ac69a J |
140 | $em->persist($config); |
141 | $em->flush(); | |
142 | ||
143 | $client = $this->getClient(); | |
47e2d609 | 144 | $client->request('GET', '/feed/admin/SUPERTOKEN/archive'); |
371ac69a | 145 | |
f808b016 | 146 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
371ac69a | 147 | |
1554eb0a | 148 | $this->validateDom($client->getResponse()->getContent(), 'archive'); |
8670250a JB |
149 | } |
150 | ||
151 | public function testPagination() | |
152 | { | |
153 | $client = $this->getClient(); | |
154 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | |
155 | $user = $em | |
156 | ->getRepository('WallabagUserBundle:User') | |
157 | ->findOneByUsername('admin'); | |
158 | ||
159 | $config = $user->getConfig(); | |
1554eb0a TC |
160 | $config->setFeedToken('SUPERTOKEN'); |
161 | $config->setFeedLimit(1); | |
8670250a JB |
162 | $em->persist($config); |
163 | $em->flush(); | |
164 | ||
165 | $client = $this->getClient(); | |
166 | ||
47e2d609 TC |
167 | $client->request('GET', '/feed/admin/SUPERTOKEN/unread'); |
168 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
169 | $this->validateDom($client->getResponse()->getContent(), 'unread'); | |
8670250a | 170 | |
47e2d609 TC |
171 | $client->request('GET', '/feed/admin/SUPERTOKEN/unread/2'); |
172 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
173 | $this->validateDom($client->getResponse()->getContent(), 'unread'); | |
8670250a | 174 | |
47e2d609 TC |
175 | $client->request('GET', '/feed/admin/SUPERTOKEN/unread/3000'); |
176 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
371ac69a | 177 | } |
18c38dff JB |
178 | |
179 | public function testTags() | |
180 | { | |
181 | $client = $this->getClient(); | |
182 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | |
183 | $user = $em | |
184 | ->getRepository('WallabagUserBundle:User') | |
185 | ->findOneByUsername('admin'); | |
186 | ||
187 | $config = $user->getConfig(); | |
1554eb0a TC |
188 | $config->setFeedToken('SUPERTOKEN'); |
189 | $config->setFeedLimit(null); | |
18c38dff JB |
190 | $em->persist($config); |
191 | $em->flush(); | |
192 | ||
193 | $client = $this->getClient(); | |
194 | $client->request('GET', '/admin/SUPERTOKEN/tags/foo-bar.xml'); | |
195 | ||
f808b016 | 196 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
18c38dff | 197 | |
1554eb0a | 198 | $this->validateDom($client->getResponse()->getContent(), 'tag', 2, 'foo-bar'); |
18c38dff JB |
199 | |
200 | $client->request('GET', '/admin/SUPERTOKEN/tags/foo-bar.xml?page=3000'); | |
f808b016 | 201 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
18c38dff | 202 | } |
371ac69a | 203 | } |