aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/CoreBundle
diff options
context:
space:
mode:
authorKevin Decherf <kevin@kdecherf.com>2020-02-04 22:19:45 +0100
committerKevin Decherf <kevin@kdecherf.com>2020-02-23 00:43:21 +0100
commit93c5b47e8891282693cc8bb1fedfb4af06d699b0 (patch)
treef86cf7875a4c6213043b761f8df0d257f7a4ffbc /tests/Wallabag/CoreBundle
parent3bf941c4a422237f678fd47a67b26e1b27f159ba (diff)
downloadwallabag-93c5b47e8891282693cc8bb1fedfb4af06d699b0.tar.gz
wallabag-93c5b47e8891282693cc8bb1fedfb4af06d699b0.tar.zst
wallabag-93c5b47e8891282693cc8bb1fedfb4af06d699b0.zip
ExportController: fix entries export from search view
Fixes #4240 Signed-off-by: Kevin Decherf <kevin@kdecherf.com>
Diffstat (limited to 'tests/Wallabag/CoreBundle')
-rw-r--r--tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php63
1 files changed, 63 insertions, 0 deletions
diff --git a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php
index d7ce7c45..36822ab3 100644
--- a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php
@@ -3,9 +3,13 @@
3namespace Tests\Wallabag\CoreBundle\Controller; 3namespace Tests\Wallabag\CoreBundle\Controller;
4 4
5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; 5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
6use Wallabag\CoreBundle\Entity\Entry;
6 7
7class ExportControllerTest extends WallabagCoreTestCase 8class ExportControllerTest extends WallabagCoreTestCase
8{ 9{
10 private $adminEntry;
11 private $bobEntry;
12
9 public function testLogin() 13 public function testLogin()
10 { 14 {
11 $client = $this->getClient(); 15 $client = $this->getClient();
@@ -243,6 +247,30 @@ class ExportControllerTest extends WallabagCoreTestCase
243 $this->assertContains('foo', $content[0]['tags']); 247 $this->assertContains('foo', $content[0]['tags']);
244 } 248 }
245 249
250 public function testJsonExportFromSearch()
251 {
252 $this->setUpForJsonExportFromSearch();
253
254 $this->logInAs('admin');
255 $client = $this->getClient();
256
257 ob_start();
258 $crawler = $client->request('GET', '/export/search.json?search_entry[term]=entry+search&currentRoute=homepage');
259 ob_end_clean();
260
261 $this->assertSame(200, $client->getResponse()->getStatusCode());
262
263 $headers = $client->getResponse()->headers;
264 $this->assertSame('application/json', $headers->get('content-type'));
265 $this->assertSame('attachment; filename="Search entry search articles.json"', $headers->get('content-disposition'));
266 $this->assertSame('UTF-8', $headers->get('content-transfer-encoding'));
267
268 $content = json_decode($client->getResponse()->getContent(), true);
269 $this->assertCount(1, $content);
270
271 $this->tearDownForJsonExportFromSearch();
272 }
273
246 public function testXmlExport() 274 public function testXmlExport()
247 { 275 {
248 $this->logInAs('admin'); 276 $this->logInAs('admin');
@@ -282,6 +310,41 @@ class ExportControllerTest extends WallabagCoreTestCase
282 $this->assertNotEmpty('updated_at', (string) $content->entry[0]->updated_at); 310 $this->assertNotEmpty('updated_at', (string) $content->entry[0]->updated_at);
283 } 311 }
284 312
313 private function setUpForJsonExportFromSearch()
314 {
315 $client = $this->getClient();
316 $em = $this->getEntityManager();
317
318 $userRepository = $client->getContainer()
319 ->get('wallabag_user.user_repository.test');
320
321 $user = $userRepository->findOneByUserName('admin');
322 $this->adminEntry = new Entry($user);
323 $this->adminEntry->setUrl('http://0.0.0.0/entry-search-admin');
324 $this->adminEntry->setTitle('test title entry search admin');
325 $this->adminEntry->setContent('this is my content /o/');
326 $em->persist($this->adminEntry);
327
328 $user = $userRepository->findOneByUserName('bob');
329 $this->bobEntry = new Entry($user);
330 $this->bobEntry->setUrl('http://0.0.0.0/entry-search-bob');
331 $this->bobEntry->setTitle('test title entry search bob');
332 $this->bobEntry->setContent('this is my content /o/');
333 $em->persist($this->bobEntry);
334
335 $em->flush();
336 }
337
338 private function tearDownForJsonExportFromSearch()
339 {
340 $em = $this->getEntityManager();
341
342 $em->remove($this->adminEntry);
343 $em->remove($this->bobEntry);
344
345 $em->flush();
346 }
347
285 private function getSanitizedFilename($title) 348 private function getSanitizedFilename($title)
286 { 349 {
287 return preg_replace('/[^A-Za-z0-9\- \']/', '', iconv('utf-8', 'us-ascii//TRANSLIT', $title)); 350 return preg_replace('/[^A-Za-z0-9\- \']/', '', iconv('utf-8', 'us-ascii//TRANSLIT', $title));