]> git.immae.eu Git - github/wallabag/wallabag.git/blob - tests/Wallabag/CoreBundle/Controller/RssControllerTest.php
Add a real configuration for CS-Fixer
[github/wallabag/wallabag.git] / tests / Wallabag / CoreBundle / Controller / RssControllerTest.php
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 }
66
67 /**
68 * @dataProvider dataForBadUrl
69 */
70 public function testBadUrl($url)
71 {
72 $client = $this->getClient();
73
74 $client->request('GET', $url);
75
76 $this->assertSame(404, $client->getResponse()->getStatusCode());
77 }
78
79 public function testUnread()
80 {
81 $client = $this->getClient();
82 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
83 $user = $em
84 ->getRepository('WallabagUserBundle:User')
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
95 $this->assertSame(200, $client->getResponse()->getStatusCode());
96
97 $this->validateDom($client->getResponse()->getContent(), 'unread', 'unread', 2);
98 }
99
100 public function testStarred()
101 {
102 $client = $this->getClient();
103 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
104 $user = $em
105 ->getRepository('WallabagUserBundle:User')
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
117 $this->assertSame(200, $client->getResponse()->getStatusCode(), 1);
118
119 $this->validateDom($client->getResponse()->getContent(), 'starred', 'starred');
120 }
121
122 public function testArchives()
123 {
124 $client = $this->getClient();
125 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
126 $user = $em
127 ->getRepository('WallabagUserBundle:User')
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
139 $this->assertSame(200, $client->getResponse()->getStatusCode());
140
141 $this->validateDom($client->getResponse()->getContent(), 'archive', 'archive');
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
160 $client->request('GET', '/admin/SUPERTOKEN/unread.xml');
161 $this->assertSame(200, $client->getResponse()->getStatusCode());
162 $this->validateDom($client->getResponse()->getContent(), 'unread', 'unread');
163
164 $client->request('GET', '/admin/SUPERTOKEN/unread.xml?page=2');
165 $this->assertSame(200, $client->getResponse()->getStatusCode());
166 $this->validateDom($client->getResponse()->getContent(), 'unread', 'unread');
167
168 $client->request('GET', '/admin/SUPERTOKEN/unread.xml?page=3000');
169 $this->assertSame(302, $client->getResponse()->getStatusCode());
170 }
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();
187 $client->request('GET', '/admin/SUPERTOKEN/tags/foo-bar.xml');
188
189 $this->assertSame(200, $client->getResponse()->getStatusCode());
190
191 $this->validateDom($client->getResponse()->getContent(), 'tag (foo bar)', 'tags/foo-bar');
192
193 $client->request('GET', '/admin/SUPERTOKEN/tags/foo-bar.xml?page=3000');
194 $this->assertSame(302, $client->getResponse()->getStatusCode());
195 }
196 }