]> git.immae.eu Git - github/wallabag/wallabag.git/blame - tests/Wallabag/CoreBundle/Controller/RssControllerTest.php
Ensure download_images_enabled is disabled
[github/wallabag/wallabag.git] / tests / Wallabag / CoreBundle / Controller / RssControllerTest.php
CommitLineData
371ac69a
J
1<?php
2
23634d5d 3namespace Tests\Wallabag\CoreBundle\Controller;
371ac69a 4
23634d5d 5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
371ac69a 6
9744e971 7class RssControllerTest extends WallabagCoreTestCase
371ac69a 8{
8670250a 9 public function validateDom($xml, $type, $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 {
19 $this->assertEquals($nb, $xpath->query('//item')->length);
20 }
21
22 $this->assertEquals(1, $xpath->query('/rss')->length);
23 $this->assertEquals(1, $xpath->query('/rss/channel')->length);
24
8670250a
JB
25 $this->assertEquals(1, $xpath->query('/rss/channel/title')->length);
26 $this->assertEquals('wallabag — '.$type.' feed', $xpath->query('/rss/channel/title')->item(0)->nodeValue);
27
28 $this->assertEquals(1, $xpath->query('/rss/channel/pubDate')->length);
29
30 $this->assertEquals(1, $xpath->query('/rss/channel/generator')->length);
31 $this->assertEquals('wallabag', $xpath->query('/rss/channel/generator')->item(0)->nodeValue);
32
33 $this->assertEquals(1, $xpath->query('/rss/channel/description')->length);
34 $this->assertEquals('wallabag '.$type.' elements', $xpath->query('/rss/channel/description')->item(0)->nodeValue);
35
36 $this->assertEquals(1, $xpath->query('/rss/channel/link[@rel="self"]')->length);
37 $this->assertContains($type.'.xml', $xpath->query('/rss/channel/link[@rel="self"]')->item(0)->getAttribute('href'));
38
39 $this->assertEquals(1, $xpath->query('/rss/channel/link[@rel="last"]')->length);
40 $this->assertContains($type.'.xml?page=', $xpath->query('/rss/channel/link[@rel="last"]')->item(0)->getAttribute('href'));
41
371ac69a
J
42 foreach ($xpath->query('//item') as $item) {
43 $this->assertEquals(1, $xpath->query('title', $item)->length);
44 $this->assertEquals(1, $xpath->query('source', $item)->length);
45 $this->assertEquals(1, $xpath->query('link', $item)->length);
46 $this->assertEquals(1, $xpath->query('guid', $item)->length);
47 $this->assertEquals(1, $xpath->query('pubDate', $item)->length);
48 $this->assertEquals(1, $xpath->query('description', $item)->length);
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
76 $this->assertEquals(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
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
95 $this->assertEquals(200, $client->getResponse()->getStatusCode());
96
8670250a 97 $this->validateDom($client->getResponse()->getContent(), '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
117 $this->assertEquals(200, $client->getResponse()->getStatusCode(), 1);
118
8670250a 119 $this->validateDom($client->getResponse()->getContent(), '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
139 $this->assertEquals(200, $client->getResponse()->getStatusCode());
140
8670250a
JB
141 $this->validateDom($client->getResponse()->getContent(), '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
edd2472f 160 $client->request('GET', '/admin/SUPERTOKEN/unread.xml');
8670250a 161 $this->assertEquals(200, $client->getResponse()->getStatusCode());
edd2472f 162 $this->validateDom($client->getResponse()->getContent(), 'unread');
8670250a 163
edd2472f 164 $client->request('GET', '/admin/SUPERTOKEN/unread.xml?page=2');
8670250a 165 $this->assertEquals(200, $client->getResponse()->getStatusCode());
edd2472f 166 $this->validateDom($client->getResponse()->getContent(), 'unread');
8670250a 167
edd2472f 168 $client->request('GET', '/admin/SUPERTOKEN/unread.xml?page=3000');
8670250a 169 $this->assertEquals(302, $client->getResponse()->getStatusCode());
371ac69a
J
170 }
171}