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