forked from wallabag/wallabag
Fix route parameters
Improve export tests Improve CSV export
This commit is contained in:
committed by
Nicolas Lœuillet
parent
268e9e7277
commit
cceca9ea1d
@ -21,7 +21,7 @@ class ExportControllerTest extends WallabagCoreTestCase
|
||||
$this->logInAs('admin');
|
||||
$client = $this->getClient();
|
||||
|
||||
$crawler = $client->request('GET', '/export/awesomeness.epub');
|
||||
$client->request('GET', '/export/awesomeness.epub');
|
||||
|
||||
$this->assertEquals(404, $client->getResponse()->getStatusCode());
|
||||
}
|
||||
@ -31,7 +31,34 @@ class ExportControllerTest extends WallabagCoreTestCase
|
||||
$this->logInAs('admin');
|
||||
$client = $this->getClient();
|
||||
|
||||
$crawler = $client->request('GET', '/export/unread.xslx');
|
||||
$client->request('GET', '/export/unread.xslx');
|
||||
|
||||
$this->assertEquals(404, $client->getResponse()->getStatusCode());
|
||||
}
|
||||
|
||||
public function testUnsupportedFormatExport()
|
||||
{
|
||||
$this->logInAs('admin');
|
||||
$client = $this->getClient();
|
||||
|
||||
$client->request('GET', '/export/unread.txt');
|
||||
$this->assertEquals(404, $client->getResponse()->getStatusCode());
|
||||
|
||||
$content = $client->getContainer()
|
||||
->get('doctrine.orm.entity_manager')
|
||||
->getRepository('WallabagCoreBundle:Entry')
|
||||
->findOneByUsernameAndNotArchived('admin');
|
||||
|
||||
$client->request('GET', '/export/'.$content->getId().'.txt');
|
||||
$this->assertEquals(404, $client->getResponse()->getStatusCode());
|
||||
}
|
||||
|
||||
public function testBadEntryId()
|
||||
{
|
||||
$this->logInAs('admin');
|
||||
$client = $this->getClient();
|
||||
|
||||
$client->request('GET', '/export/0.mobi');
|
||||
|
||||
$this->assertEquals(404, $client->getResponse()->getStatusCode());
|
||||
}
|
||||
@ -97,20 +124,33 @@ class ExportControllerTest extends WallabagCoreTestCase
|
||||
$this->logInAs('admin');
|
||||
$client = $this->getClient();
|
||||
|
||||
// to be sure results are the same
|
||||
$contentInDB = $client->getContainer()
|
||||
->get('doctrine.orm.entity_manager')
|
||||
->getRepository('WallabagCoreBundle:Entry')
|
||||
->createQueryBuilder('e')
|
||||
->leftJoin('e.user', 'u')
|
||||
->where('u.username = :username')->setParameter('username', 'admin')
|
||||
->andWhere('e.isArchived = true')
|
||||
->getQuery()
|
||||
->getArrayResult();
|
||||
|
||||
ob_start();
|
||||
$crawler = $client->request('GET', '/export/unread.csv');
|
||||
$crawler = $client->request('GET', '/export/archive.csv');
|
||||
ob_end_clean();
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode());
|
||||
|
||||
$headers = $client->getResponse()->headers;
|
||||
$this->assertEquals('application/csv', $headers->get('content-type'));
|
||||
$this->assertEquals('attachment; filename="Unread articles.csv"', $headers->get('content-disposition'));
|
||||
$this->assertEquals('attachment; filename="Archive articles.csv"', $headers->get('content-disposition'));
|
||||
$this->assertEquals('UTF-8', $headers->get('content-transfer-encoding'));
|
||||
|
||||
$csv = str_getcsv($client->getResponse()->getContent(), "\n");
|
||||
|
||||
$this->assertGreaterThan(1, $csv);
|
||||
// +1 for title line
|
||||
$this->assertEquals(count($contentInDB)+1, count($csv));
|
||||
$this->assertEquals('Title;URL;Content;Tags;"MIME Type";Language', $csv[0]);
|
||||
}
|
||||
|
||||
@ -119,6 +159,16 @@ class ExportControllerTest extends WallabagCoreTestCase
|
||||
$this->logInAs('admin');
|
||||
$client = $this->getClient();
|
||||
|
||||
// to be sure results are the same
|
||||
$contentInDB = $client->getContainer()
|
||||
->get('doctrine.orm.entity_manager')
|
||||
->getRepository('WallabagCoreBundle:Entry')
|
||||
->createQueryBuilder('e')
|
||||
->leftJoin('e.user', 'u')
|
||||
->where('u.username = :username')->setParameter('username', 'admin')
|
||||
->getQuery()
|
||||
->getArrayResult();
|
||||
|
||||
ob_start();
|
||||
$crawler = $client->request('GET', '/export/all.json');
|
||||
ob_end_clean();
|
||||
@ -129,6 +179,21 @@ class ExportControllerTest extends WallabagCoreTestCase
|
||||
$this->assertEquals('application/json', $headers->get('content-type'));
|
||||
$this->assertEquals('attachment; filename="All articles.json"', $headers->get('content-disposition'));
|
||||
$this->assertEquals('UTF-8', $headers->get('content-transfer-encoding'));
|
||||
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
$this->assertEquals(count($contentInDB), count($content));
|
||||
$this->assertArrayHasKey('id', $content[0]);
|
||||
$this->assertArrayHasKey('title', $content[0]);
|
||||
$this->assertArrayHasKey('url', $content[0]);
|
||||
$this->assertArrayHasKey('is_archived', $content[0]);
|
||||
$this->assertArrayHasKey('is_starred', $content[0]);
|
||||
$this->assertArrayHasKey('content', $content[0]);
|
||||
$this->assertArrayHasKey('mimetype', $content[0]);
|
||||
$this->assertArrayHasKey('language', $content[0]);
|
||||
$this->assertArrayHasKey('reading_time', $content[0]);
|
||||
$this->assertArrayHasKey('domain_name', $content[0]);
|
||||
$this->assertArrayHasKey('preview_picture', $content[0]);
|
||||
$this->assertArrayHasKey('tags', $content[0]);
|
||||
}
|
||||
|
||||
public function testXmlExport()
|
||||
@ -136,6 +201,17 @@ class ExportControllerTest extends WallabagCoreTestCase
|
||||
$this->logInAs('admin');
|
||||
$client = $this->getClient();
|
||||
|
||||
// to be sure results are the same
|
||||
$contentInDB = $client->getContainer()
|
||||
->get('doctrine.orm.entity_manager')
|
||||
->getRepository('WallabagCoreBundle:Entry')
|
||||
->createQueryBuilder('e')
|
||||
->leftJoin('e.user', 'u')
|
||||
->where('u.username = :username')->setParameter('username', 'admin')
|
||||
->andWhere('e.isArchived = false')
|
||||
->getQuery()
|
||||
->getArrayResult();
|
||||
|
||||
ob_start();
|
||||
$crawler = $client->request('GET', '/export/unread.xml');
|
||||
ob_end_clean();
|
||||
@ -146,5 +222,14 @@ class ExportControllerTest extends WallabagCoreTestCase
|
||||
$this->assertEquals('application/xml', $headers->get('content-type'));
|
||||
$this->assertEquals('attachment; filename="Unread articles.xml"', $headers->get('content-disposition'));
|
||||
$this->assertEquals('UTF-8', $headers->get('content-transfer-encoding'));
|
||||
|
||||
$content = new \SimpleXMLElement($client->getResponse()->getContent());
|
||||
$this->assertGreaterThan(0, $content->count());
|
||||
$this->assertEquals(count($contentInDB), $content->count());
|
||||
$this->assertNotEmpty('id', (string) $content->entry[0]->id);
|
||||
$this->assertNotEmpty('title', (string) $content->entry[0]->title);
|
||||
$this->assertNotEmpty('url', (string) $content->entry[0]->url);
|
||||
$this->assertNotEmpty('content', (string) $content->entry[0]->content);
|
||||
$this->assertNotEmpty('domain_name', (string) $content->entry[0]->domain_name);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user