3 namespace Wallabag\CoreBundle\Tests\Controller
;
5 use Wallabag\CoreBundle\Tests\WallabagCoreTestCase
;
7 class RssControllerTest
extends WallabagCoreTestCase
9 public function validateDom($xml, $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 foreach ($xpath->query('//item') as $item) {
26 $this->assertEquals(1, $xpath->query('title', $item)->length
);
27 $this->assertEquals(1, $xpath->query('source', $item)->length
);
28 $this->assertEquals(1, $xpath->query('link', $item)->length
);
29 $this->assertEquals(1, $xpath->query('guid', $item)->length
);
30 $this->assertEquals(1, $xpath->query('pubDate', $item)->length
);
31 $this->assertEquals(1, $xpath->query('description', $item)->length
);
35 public function dataForBadUrl()
39 '/admin/YZIOAUZIAO/unread.xml',
42 '/wallace/YZIOAUZIAO/starred.xml',
45 '/wallace/YZIOAUZIAO/archives.xml',
51 * @dataProvider dataForBadUrl
53 public function testBadUrl($url)
55 $client = $this->getClient();
57 $client->request('GET', $url);
59 $this->assertEquals(404, $client->getResponse()->getStatusCode());
62 public function testUnread()
64 $client = $this->getClient();
65 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
67 ->getRepository('WallabagUserBundle:User')
68 ->findOneByUsername('admin');
70 $config = $user->getConfig();
71 $config->setRssToken('SUPERTOKEN');
72 $config->setRssLimit(2);
73 $em->persist($config);
76 $client->request('GET', '/admin/SUPERTOKEN/unread.xml');
78 $this->assertEquals(200, $client->getResponse()->getStatusCode());
80 $this->validateDom($client->getResponse()->getContent(), 2);
83 public function testStarred()
85 $client = $this->getClient();
86 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
88 ->getRepository('WallabagUserBundle:User')
89 ->findOneByUsername('admin');
91 $config = $user->getConfig();
92 $config->setRssToken('SUPERTOKEN');
93 $config->setRssLimit(1);
94 $em->persist($config);
97 $client = $this->getClient();
98 $client->request('GET', '/admin/SUPERTOKEN/starred.xml');
100 $this->assertEquals(200, $client->getResponse()->getStatusCode(), 1);
102 $this->validateDom($client->getResponse()->getContent());
105 public function testArchives()
107 $client = $this->getClient();
108 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
110 ->getRepository('WallabagUserBundle:User')
111 ->findOneByUsername('admin');
113 $config = $user->getConfig();
114 $config->setRssToken('SUPERTOKEN');
115 $config->setRssLimit(null);
116 $em->persist($config);
119 $client = $this->getClient();
120 $client->request('GET', '/admin/SUPERTOKEN/archive.xml');
122 $this->assertEquals(200, $client->getResponse()->getStatusCode());
124 $this->validateDom($client->getResponse()->getContent());