aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/CoreBundle/Controller
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2016-10-02 16:06:42 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2016-10-07 07:43:19 +0200
commitb0458874c85060c992aa1cb78dec91ee85082b74 (patch)
treece2e75fd05c22c28a79ee5dcd5f6fb72b02673b8 /tests/Wallabag/CoreBundle/Controller
parent9d127b3b9365c73bc393bc303545f24c159cee31 (diff)
downloadwallabag-b0458874c85060c992aa1cb78dec91ee85082b74.tar.gz
wallabag-b0458874c85060c992aa1cb78dec91ee85082b74.tar.zst
wallabag-b0458874c85060c992aa1cb78dec91ee85082b74.zip
Fix relations export for Entry
Tags & Annotations weren’t really well exported. This is now fixed (+ tests)
Diffstat (limited to 'tests/Wallabag/CoreBundle/Controller')
-rw-r--r--tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php37
1 files changed, 28 insertions, 9 deletions
diff --git a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php
index 47b86117..9f35a448 100644
--- a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php
@@ -146,7 +146,9 @@ class ExportControllerTest extends WallabagCoreTestCase
146 ->get('doctrine.orm.entity_manager') 146 ->get('doctrine.orm.entity_manager')
147 ->getRepository('WallabagCoreBundle:Entry') 147 ->getRepository('WallabagCoreBundle:Entry')
148 ->createQueryBuilder('e') 148 ->createQueryBuilder('e')
149 ->select('e, t')
149 ->leftJoin('e.user', 'u') 150 ->leftJoin('e.user', 'u')
151 ->leftJoin('e.tags', 't')
150 ->where('u.username = :username')->setParameter('username', 'admin') 152 ->where('u.username = :username')->setParameter('username', 'admin')
151 ->andWhere('e.isArchived = true') 153 ->andWhere('e.isArchived = true')
152 ->getQuery() 154 ->getQuery()
@@ -169,6 +171,18 @@ class ExportControllerTest extends WallabagCoreTestCase
169 // +1 for title line 171 // +1 for title line
170 $this->assertEquals(count($contentInDB) + 1, count($csv)); 172 $this->assertEquals(count($contentInDB) + 1, count($csv));
171 $this->assertEquals('Title;URL;Content;Tags;"MIME Type";Language;"Creation date"', $csv[0]); 173 $this->assertEquals('Title;URL;Content;Tags;"MIME Type";Language;"Creation date"', $csv[0]);
174 $this->assertContains($contentInDB[0]['title'], $csv[1]);
175 $this->assertContains($contentInDB[0]['url'], $csv[1]);
176 $this->assertContains($contentInDB[0]['content'], $csv[1]);
177 $this->assertContains($contentInDB[0]['mimetype'], $csv[1]);
178 $this->assertContains($contentInDB[0]['language'], $csv[1]);
179 $this->assertContains($contentInDB[0]['createdAt']->format('d/m/Y h:i:s'), $csv[1]);
180
181 $expectedTag = [];
182 foreach ($contentInDB[0]['tags'] as $tag) {
183 $expectedTag[] = $tag['label'];
184 }
185 $this->assertContains(implode(', ', $expectedTag), $csv[1]);
172 } 186 }
173 187
174 public function testJsonExport() 188 public function testJsonExport()
@@ -176,29 +190,23 @@ class ExportControllerTest extends WallabagCoreTestCase
176 $this->logInAs('admin'); 190 $this->logInAs('admin');
177 $client = $this->getClient(); 191 $client = $this->getClient();
178 192
179 // to be sure results are the same
180 $contentInDB = $client->getContainer() 193 $contentInDB = $client->getContainer()
181 ->get('doctrine.orm.entity_manager') 194 ->get('doctrine.orm.entity_manager')
182 ->getRepository('WallabagCoreBundle:Entry') 195 ->getRepository('WallabagCoreBundle:Entry')
183 ->createQueryBuilder('e') 196 ->findOneByUsernameAndNotArchived('admin');
184 ->leftJoin('e.user', 'u')
185 ->where('u.username = :username')->setParameter('username', 'admin')
186 ->getQuery()
187 ->getArrayResult();
188 197
189 ob_start(); 198 ob_start();
190 $crawler = $client->request('GET', '/export/all.json'); 199 $crawler = $client->request('GET', '/export/'.$contentInDB->getId().'.json');
191 ob_end_clean(); 200 ob_end_clean();
192 201
193 $this->assertEquals(200, $client->getResponse()->getStatusCode()); 202 $this->assertEquals(200, $client->getResponse()->getStatusCode());
194 203
195 $headers = $client->getResponse()->headers; 204 $headers = $client->getResponse()->headers;
196 $this->assertEquals('application/json', $headers->get('content-type')); 205 $this->assertEquals('application/json', $headers->get('content-type'));
197 $this->assertEquals('attachment; filename="All articles.json"', $headers->get('content-disposition')); 206 $this->assertEquals('attachment; filename="'.$contentInDB->getTitle().'.json"', $headers->get('content-disposition'));
198 $this->assertEquals('UTF-8', $headers->get('content-transfer-encoding')); 207 $this->assertEquals('UTF-8', $headers->get('content-transfer-encoding'));
199 208
200 $content = json_decode($client->getResponse()->getContent(), true); 209 $content = json_decode($client->getResponse()->getContent(), true);
201 $this->assertEquals(count($contentInDB), count($content));
202 $this->assertArrayHasKey('id', $content[0]); 210 $this->assertArrayHasKey('id', $content[0]);
203 $this->assertArrayHasKey('title', $content[0]); 211 $this->assertArrayHasKey('title', $content[0]);
204 $this->assertArrayHasKey('url', $content[0]); 212 $this->assertArrayHasKey('url', $content[0]);
@@ -212,6 +220,17 @@ class ExportControllerTest extends WallabagCoreTestCase
212 $this->assertArrayHasKey('tags', $content[0]); 220 $this->assertArrayHasKey('tags', $content[0]);
213 $this->assertArrayHasKey('created_at', $content[0]); 221 $this->assertArrayHasKey('created_at', $content[0]);
214 $this->assertArrayHasKey('updated_at', $content[0]); 222 $this->assertArrayHasKey('updated_at', $content[0]);
223
224 $this->assertEquals($contentInDB->isArchived(), $content[0]['is_archived']);
225 $this->assertEquals($contentInDB->isStarred(), $content[0]['is_starred']);
226 $this->assertEquals($contentInDB->getTitle(), $content[0]['title']);
227 $this->assertEquals($contentInDB->getUrl(), $content[0]['url']);
228 $this->assertEquals([['text' => 'This is my annotation /o/', 'quote' => 'content']], $content[0]['annotations']);
229 $this->assertEquals($contentInDB->getMimetype(), $content[0]['mimetype']);
230 $this->assertEquals($contentInDB->getLanguage(), $content[0]['language']);
231 $this->assertEquals($contentInDB->getReadingtime(), $content[0]['reading_time']);
232 $this->assertEquals($contentInDB->getDomainname(), $content[0]['domain_name']);
233 $this->assertEquals(['foo', 'baz'], $content[0]['tags']);
215 } 234 }
216 235
217 public function testXmlExport() 236 public function testXmlExport()