aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorJeremy Benoist <j0k3r@users.noreply.github.com>2016-10-07 13:55:55 +0200
committerGitHub <noreply@github.com>2016-10-07 13:55:55 +0200
commitbf71a734f64a911549e188a5c69ac8e08eec896e (patch)
tree0e40afc2a85658705fdf4a1a6b8e7c6c3d7dfbc3 /tests
parent9d127b3b9365c73bc393bc303545f24c159cee31 (diff)
parent74e1f7433a5fc0a9bbf3942a22917e0dd1cc6923 (diff)
downloadwallabag-bf71a734f64a911549e188a5c69ac8e08eec896e.tar.gz
wallabag-bf71a734f64a911549e188a5c69ac8e08eec896e.tar.zst
wallabag-bf71a734f64a911549e188a5c69ac8e08eec896e.zip
Merge pull request #2332 from wallabag/tags-export
Fix relations export for Entry
Diffstat (limited to 'tests')
-rw-r--r--tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php37
-rw-r--r--tests/Wallabag/CoreBundle/Controller/TagControllerTest.php26
2 files changed, 43 insertions, 20 deletions
diff --git a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php
index 47b86117..9ecd8bc4 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 ->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId());
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()
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
26 $entry = $client->getContainer() 26 $entry = $client->getContainer()
27 ->get('doctrine.orm.entity_manager') 27 ->get('doctrine.orm.entity_manager')
28 ->getRepository('WallabagCoreBundle:Entry') 28 ->getRepository('WallabagCoreBundle:Entry')
29 ->findOneByUsernameAndNotArchived('admin'); 29 ->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId());
30 30
31 $crawler = $client->request('GET', '/view/'.$entry->getId()); 31 $crawler = $client->request('GET', '/view/'.$entry->getId());
32 32
@@ -43,9 +43,9 @@ class TagControllerTest extends WallabagCoreTestCase
43 $entry = $client->getContainer() 43 $entry = $client->getContainer()
44 ->get('doctrine.orm.entity_manager') 44 ->get('doctrine.orm.entity_manager')
45 ->getRepository('WallabagCoreBundle:Entry') 45 ->getRepository('WallabagCoreBundle:Entry')
46 ->findOneByUsernameAndNotArchived('admin'); 46 ->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId());
47 47
48 $this->assertEquals(1, count($entry->getTags())); 48 $this->assertEquals(3, count($entry->getTags()));
49 49
50 // tag already exists and already assigned 50 // tag already exists and already assigned
51 $client->submit($form, $data); 51 $client->submit($form, $data);
@@ -56,7 +56,7 @@ class TagControllerTest extends WallabagCoreTestCase
56 ->getRepository('WallabagCoreBundle:Entry') 56 ->getRepository('WallabagCoreBundle:Entry')
57 ->find($entry->getId()); 57 ->find($entry->getId());
58 58
59 $this->assertEquals(1, count($newEntry->getTags())); 59 $this->assertEquals(3, count($newEntry->getTags()));
60 60
61 // tag already exists but still not assigned to this entry 61 // tag already exists but still not assigned to this entry
62 $data = [ 62 $data = [
@@ -71,7 +71,7 @@ class TagControllerTest extends WallabagCoreTestCase
71 ->getRepository('WallabagCoreBundle:Entry') 71 ->getRepository('WallabagCoreBundle:Entry')
72 ->find($entry->getId()); 72 ->find($entry->getId());
73 73
74 $this->assertEquals(2, count($newEntry->getTags())); 74 $this->assertEquals(3, count($newEntry->getTags()));
75 } 75 }
76 76
77 public function testAddMultipleTagToEntry() 77 public function testAddMultipleTagToEntry()
@@ -82,7 +82,7 @@ class TagControllerTest extends WallabagCoreTestCase
82 $entry = $client->getContainer() 82 $entry = $client->getContainer()
83 ->get('doctrine.orm.entity_manager') 83 ->get('doctrine.orm.entity_manager')
84 ->getRepository('WallabagCoreBundle:Entry') 84 ->getRepository('WallabagCoreBundle:Entry')
85 ->findOneByUsernameAndNotArchived('admin'); 85 ->findByUrlAndUserId('http://0.0.0.0/entry2', $this->getLoggedInUserId());
86 86
87 $crawler = $client->request('GET', '/view/'.$entry->getId()); 87 $crawler = $client->request('GET', '/view/'.$entry->getId());
88 88
@@ -101,9 +101,13 @@ class TagControllerTest extends WallabagCoreTestCase
101 ->find($entry->getId()); 101 ->find($entry->getId());
102 102
103 $tags = $newEntry->getTags()->toArray(); 103 $tags = $newEntry->getTags()->toArray();
104 foreach ($tags as $key => $tag) {
105 $tags[$key] = $tag->getLabel();
106 }
107
104 $this->assertGreaterThanOrEqual(2, count($tags)); 108 $this->assertGreaterThanOrEqual(2, count($tags));
105 $this->assertNotEquals(false, array_search('foo2', $tags), 'Tag foo2 is assigned to the entry'); 109 $this->assertNotFalse(array_search('foo2', $tags), 'Tag foo2 is assigned to the entry');
106 $this->assertNotEquals(false, array_search('bar2', $tags), 'Tag bar2 is assigned to the entry'); 110 $this->assertNotFalse(array_search('bar2', $tags), 'Tag bar2 is assigned to the entry');
107 } 111 }
108 112
109 public function testRemoveTagFromEntry() 113 public function testRemoveTagFromEntry()
@@ -114,7 +118,7 @@ class TagControllerTest extends WallabagCoreTestCase
114 $entry = $client->getContainer() 118 $entry = $client->getContainer()
115 ->get('doctrine.orm.entity_manager') 119 ->get('doctrine.orm.entity_manager')
116 ->getRepository('WallabagCoreBundle:Entry') 120 ->getRepository('WallabagCoreBundle:Entry')
117 ->findOneByUsernameAndNotArchived('admin'); 121 ->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId());
118 122
119 $tag = $client->getContainer() 123 $tag = $client->getContainer()
120 ->get('doctrine.orm.entity_manager') 124 ->get('doctrine.orm.entity_manager')
@@ -140,7 +144,7 @@ class TagControllerTest extends WallabagCoreTestCase
140 $entry = $client->getContainer() 144 $entry = $client->getContainer()
141 ->get('doctrine.orm.entity_manager') 145 ->get('doctrine.orm.entity_manager')
142 ->getRepository('WallabagCoreBundle:Entry') 146 ->getRepository('WallabagCoreBundle:Entry')
143 ->findOneByUsernameAndNotArchived('admin'); 147 ->findByUrlAndUserId('http://0.0.0.0/entry4', $this->getLoggedInUserId());
144 148
145 $tag = $client->getContainer() 149 $tag = $client->getContainer()
146 ->get('doctrine.orm.entity_manager') 150 ->get('doctrine.orm.entity_manager')
@@ -160,6 +164,6 @@ class TagControllerTest extends WallabagCoreTestCase
160 $crawler = $client->request('GET', '/tag/list/'.$tag->getSlug()); 164 $crawler = $client->request('GET', '/tag/list/'.$tag->getSlug());
161 165
162 $this->assertEquals(200, $client->getResponse()->getStatusCode()); 166 $this->assertEquals(200, $client->getResponse()->getStatusCode());
163 $this->assertCount(0, $crawler->filter('div[class=entry]')); 167 $this->assertCount(1, $crawler->filter('div[class=entry]'));
164 } 168 }
165} 169}