From b0458874c85060c992aa1cb78dec91ee85082b74 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 2 Oct 2016 16:06:42 +0200 Subject: Fix relations export for Entry MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Tags & Annotations weren’t really well exported. This is now fixed (+ tests) --- .../CoreBundle/Controller/ExportControllerTest.php | 37 ++++++++++++++++------ 1 file changed, 28 insertions(+), 9 deletions(-) (limited to 'tests/Wallabag') 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 ->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') ->createQueryBuilder('e') + ->select('e, t') ->leftJoin('e.user', 'u') + ->leftJoin('e.tags', 't') ->where('u.username = :username')->setParameter('username', 'admin') ->andWhere('e.isArchived = true') ->getQuery() @@ -169,6 +171,18 @@ class ExportControllerTest extends WallabagCoreTestCase // +1 for title line $this->assertEquals(count($contentInDB) + 1, count($csv)); $this->assertEquals('Title;URL;Content;Tags;"MIME Type";Language;"Creation date"', $csv[0]); + $this->assertContains($contentInDB[0]['title'], $csv[1]); + $this->assertContains($contentInDB[0]['url'], $csv[1]); + $this->assertContains($contentInDB[0]['content'], $csv[1]); + $this->assertContains($contentInDB[0]['mimetype'], $csv[1]); + $this->assertContains($contentInDB[0]['language'], $csv[1]); + $this->assertContains($contentInDB[0]['createdAt']->format('d/m/Y h:i:s'), $csv[1]); + + $expectedTag = []; + foreach ($contentInDB[0]['tags'] as $tag) { + $expectedTag[] = $tag['label']; + } + $this->assertContains(implode(', ', $expectedTag), $csv[1]); } public function testJsonExport() @@ -176,29 +190,23 @@ 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(); + ->findOneByUsernameAndNotArchived('admin'); ob_start(); - $crawler = $client->request('GET', '/export/all.json'); + $crawler = $client->request('GET', '/export/'.$contentInDB->getId().'.json'); ob_end_clean(); $this->assertEquals(200, $client->getResponse()->getStatusCode()); $headers = $client->getResponse()->headers; $this->assertEquals('application/json', $headers->get('content-type')); - $this->assertEquals('attachment; filename="All articles.json"', $headers->get('content-disposition')); + $this->assertEquals('attachment; filename="'.$contentInDB->getTitle().'.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]); @@ -212,6 +220,17 @@ class ExportControllerTest extends WallabagCoreTestCase $this->assertArrayHasKey('tags', $content[0]); $this->assertArrayHasKey('created_at', $content[0]); $this->assertArrayHasKey('updated_at', $content[0]); + + $this->assertEquals($contentInDB->isArchived(), $content[0]['is_archived']); + $this->assertEquals($contentInDB->isStarred(), $content[0]['is_starred']); + $this->assertEquals($contentInDB->getTitle(), $content[0]['title']); + $this->assertEquals($contentInDB->getUrl(), $content[0]['url']); + $this->assertEquals([['text' => 'This is my annotation /o/', 'quote' => 'content']], $content[0]['annotations']); + $this->assertEquals($contentInDB->getMimetype(), $content[0]['mimetype']); + $this->assertEquals($contentInDB->getLanguage(), $content[0]['language']); + $this->assertEquals($contentInDB->getReadingtime(), $content[0]['reading_time']); + $this->assertEquals($contentInDB->getDomainname(), $content[0]['domain_name']); + $this->assertEquals(['foo', 'baz'], $content[0]['tags']); } public function testXmlExport() -- cgit v1.2.3 From 74e1f7433a5fc0a9bbf3942a22917e0dd1cc6923 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 2 Oct 2016 16:53:52 +0200 Subject: Fix tag test --- .../CoreBundle/Controller/ExportControllerTest.php | 2 +- .../CoreBundle/Controller/TagControllerTest.php | 26 +++++++++++++--------- 2 files changed, 16 insertions(+), 12 deletions(-) (limited to 'tests/Wallabag') diff --git a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php index 9f35a448..9ecd8bc4 100644 --- a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php @@ -193,7 +193,7 @@ class ExportControllerTest extends WallabagCoreTestCase $contentInDB = $client->getContainer() ->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') - ->findOneByUsernameAndNotArchived('admin'); + ->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId()); ob_start(); $crawler = $client->request('GET', '/export/'.$contentInDB->getId().'.json'); diff --git a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php index 2c32393f..86a6cca2 100644 --- a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php @@ -26,7 +26,7 @@ class TagControllerTest extends WallabagCoreTestCase $entry = $client->getContainer() ->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') - ->findOneByUsernameAndNotArchived('admin'); + ->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId()); $crawler = $client->request('GET', '/view/'.$entry->getId()); @@ -43,9 +43,9 @@ class TagControllerTest extends WallabagCoreTestCase $entry = $client->getContainer() ->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') - ->findOneByUsernameAndNotArchived('admin'); + ->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId()); - $this->assertEquals(1, count($entry->getTags())); + $this->assertEquals(3, count($entry->getTags())); // tag already exists and already assigned $client->submit($form, $data); @@ -56,7 +56,7 @@ class TagControllerTest extends WallabagCoreTestCase ->getRepository('WallabagCoreBundle:Entry') ->find($entry->getId()); - $this->assertEquals(1, count($newEntry->getTags())); + $this->assertEquals(3, count($newEntry->getTags())); // tag already exists but still not assigned to this entry $data = [ @@ -71,7 +71,7 @@ class TagControllerTest extends WallabagCoreTestCase ->getRepository('WallabagCoreBundle:Entry') ->find($entry->getId()); - $this->assertEquals(2, count($newEntry->getTags())); + $this->assertEquals(3, count($newEntry->getTags())); } public function testAddMultipleTagToEntry() @@ -82,7 +82,7 @@ class TagControllerTest extends WallabagCoreTestCase $entry = $client->getContainer() ->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') - ->findOneByUsernameAndNotArchived('admin'); + ->findByUrlAndUserId('http://0.0.0.0/entry2', $this->getLoggedInUserId()); $crawler = $client->request('GET', '/view/'.$entry->getId()); @@ -101,9 +101,13 @@ class TagControllerTest extends WallabagCoreTestCase ->find($entry->getId()); $tags = $newEntry->getTags()->toArray(); + foreach ($tags as $key => $tag) { + $tags[$key] = $tag->getLabel(); + } + $this->assertGreaterThanOrEqual(2, count($tags)); - $this->assertNotEquals(false, array_search('foo2', $tags), 'Tag foo2 is assigned to the entry'); - $this->assertNotEquals(false, array_search('bar2', $tags), 'Tag bar2 is assigned to the entry'); + $this->assertNotFalse(array_search('foo2', $tags), 'Tag foo2 is assigned to the entry'); + $this->assertNotFalse(array_search('bar2', $tags), 'Tag bar2 is assigned to the entry'); } public function testRemoveTagFromEntry() @@ -114,7 +118,7 @@ class TagControllerTest extends WallabagCoreTestCase $entry = $client->getContainer() ->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') - ->findOneByUsernameAndNotArchived('admin'); + ->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId()); $tag = $client->getContainer() ->get('doctrine.orm.entity_manager') @@ -140,7 +144,7 @@ class TagControllerTest extends WallabagCoreTestCase $entry = $client->getContainer() ->get('doctrine.orm.entity_manager') ->getRepository('WallabagCoreBundle:Entry') - ->findOneByUsernameAndNotArchived('admin'); + ->findByUrlAndUserId('http://0.0.0.0/entry4', $this->getLoggedInUserId()); $tag = $client->getContainer() ->get('doctrine.orm.entity_manager') @@ -160,6 +164,6 @@ class TagControllerTest extends WallabagCoreTestCase $crawler = $client->request('GET', '/tag/list/'.$tag->getSlug()); $this->assertEquals(200, $client->getResponse()->getStatusCode()); - $this->assertCount(0, $crawler->filter('div[class=entry]')); + $this->assertCount(1, $crawler->filter('div[class=entry]')); } } -- cgit v1.2.3