3 namespace Tests\Wallabag\CoreBundle\Controller
;
5 use Tests\Wallabag\CoreBundle\WallabagCoreTestCase
;
7 class RssControllerTest
extends WallabagCoreTestCase
9 public function validateDom($xml, $type, $nb = null)
11 $doc = new \
DOMDocument();
14 $xpath = new \
DOMXpath($doc);
17 $this->assertGreaterThan(0, $xpath->query('//item')->length
);
19 $this->assertEquals($nb, $xpath->query('//item')->length
);
22 $this->assertEquals(1, $xpath->query('/rss')->length
);
23 $this->assertEquals(1, $xpath->query('/rss/channel')->length
);
25 $this->assertEquals(1, $xpath->query('/rss/channel/title')->length
);
26 $this->assertEquals('wallabag — '.$type.' feed', $xpath->query('/rss/channel/title')->item(0)->nodeValue
);
28 $this->assertEquals(1, $xpath->query('/rss/channel/pubDate')->length
);
30 $this->assertEquals(1, $xpath->query('/rss/channel/generator')->length
);
31 $this->assertEquals('wallabag', $xpath->query('/rss/channel/generator')->item(0)->nodeValue
);
33 $this->assertEquals(1, $xpath->query('/rss/channel/description')->length
);
34 $this->assertEquals('wallabag '.$type.' elements', $xpath->query('/rss/channel/description')->item(0)->nodeValue
);
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'));
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'));
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
);
52 public function dataForBadUrl()
56 '/admin/YZIOAUZIAO/unread.xml',
59 '/wallace/YZIOAUZIAO/starred.xml',
62 '/wallace/YZIOAUZIAO/archives.xml',
68 * @dataProvider dataForBadUrl
70 public function testBadUrl($url)
72 $client = $this->getClient();
74 $client->request('GET', $url);
76 $this->assertEquals(404, $client->getResponse()->getStatusCode());
79 public function testUnread()
81 $client = $this->getClient();
82 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
84 ->getRepository('WallabagUserBundle:User')
85 ->findOneByUsername('admin');
87 $config = $user->getConfig();
88 $config->setRssToken('SUPERTOKEN');
89 $config->setRssLimit(2);
90 $em->persist($config);
93 $client->request('GET', '/admin/SUPERTOKEN/unread.xml');
95 $this->assertEquals(200, $client->getResponse()->getStatusCode());
97 $this->validateDom($client->getResponse()->getContent(), 'unread', 2);
100 public function testStarred()
102 $client = $this->getClient();
103 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
105 ->getRepository('WallabagUserBundle:User')
106 ->findOneByUsername('admin');
108 $config = $user->getConfig();
109 $config->setRssToken('SUPERTOKEN');
110 $config->setRssLimit(1);
111 $em->persist($config);
114 $client = $this->getClient();
115 $client->request('GET', '/admin/SUPERTOKEN/starred.xml');
117 $this->assertEquals(200, $client->getResponse()->getStatusCode(), 1);
119 $this->validateDom($client->getResponse()->getContent(), 'starred');
122 public function testArchives()
124 $client = $this->getClient();
125 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
127 ->getRepository('WallabagUserBundle:User')
128 ->findOneByUsername('admin');
130 $config = $user->getConfig();
131 $config->setRssToken('SUPERTOKEN');
132 $config->setRssLimit(null);
133 $em->persist($config);
136 $client = $this->getClient();
137 $client->request('GET', '/admin/SUPERTOKEN/archive.xml');
139 $this->assertEquals(200, $client->getResponse()->getStatusCode());
141 $this->validateDom($client->getResponse()->getContent(), 'archive');
144 public function testPagination()
146 $client = $this->getClient();
147 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
149 ->getRepository('WallabagUserBundle:User')
150 ->findOneByUsername('admin');
152 $config = $user->getConfig();
153 $config->setRssToken('SUPERTOKEN');
154 $config->setRssLimit(1);
155 $em->persist($config);
158 $client = $this->getClient();
160 $client->request('GET', '/admin/SUPERTOKEN/unread.xml');
161 $this->assertEquals(200, $client->getResponse()->getStatusCode());
162 $this->validateDom($client->getResponse()->getContent(), 'unread');
164 $client->request('GET', '/admin/SUPERTOKEN/unread.xml?page=2');
165 $this->assertEquals(200, $client->getResponse()->getStatusCode());
166 $this->validateDom($client->getResponse()->getContent(), 'unread');
168 $client->request('GET', '/admin/SUPERTOKEN/unread.xml?page=3000');
169 $this->assertEquals(302, $client->getResponse()->getStatusCode());