aboutsummaryrefslogtreecommitdiffhomepage
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
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)
-rw-r--r--src/Wallabag/AnnotationBundle/Entity/Annotation.php7
-rw-r--r--src/Wallabag/CoreBundle/DataFixtures/ORM/LoadEntryData.php4
-rw-r--r--src/Wallabag/CoreBundle/Entity/Entry.php17
-rw-r--r--src/Wallabag/CoreBundle/Helper/EntriesExport.php12
-rw-r--r--tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php37
5 files changed, 58 insertions, 19 deletions
diff --git a/src/Wallabag/AnnotationBundle/Entity/Annotation.php b/src/Wallabag/AnnotationBundle/Entity/Annotation.php
index 90ee7c2d..c48d8731 100644
--- a/src/Wallabag/AnnotationBundle/Entity/Annotation.php
+++ b/src/Wallabag/AnnotationBundle/Entity/Annotation.php
@@ -7,6 +7,7 @@ use JMS\Serializer\Annotation\ExclusionPolicy;
7use JMS\Serializer\Annotation\Exclude; 7use JMS\Serializer\Annotation\Exclude;
8use JMS\Serializer\Annotation\VirtualProperty; 8use JMS\Serializer\Annotation\VirtualProperty;
9use JMS\Serializer\Annotation\SerializedName; 9use JMS\Serializer\Annotation\SerializedName;
10use JMS\Serializer\Annotation\Groups;
10use Wallabag\UserBundle\Entity\User; 11use Wallabag\UserBundle\Entity\User;
11use Wallabag\CoreBundle\Entity\Entry; 12use Wallabag\CoreBundle\Entity\Entry;
12 13
@@ -33,6 +34,8 @@ class Annotation
33 * @var string 34 * @var string
34 * 35 *
35 * @ORM\Column(name="text", type="text") 36 * @ORM\Column(name="text", type="text")
37 *
38 * @Groups({"entries_for_user", "export_all"})
36 */ 39 */
37 private $text; 40 private $text;
38 41
@@ -54,6 +57,8 @@ class Annotation
54 * @var string 57 * @var string
55 * 58 *
56 * @ORM\Column(name="quote", type="string") 59 * @ORM\Column(name="quote", type="string")
60 *
61 * @Groups({"entries_for_user", "export_all"})
57 */ 62 */
58 private $quote; 63 private $quote;
59 64
@@ -61,6 +66,8 @@ class Annotation
61 * @var array 66 * @var array
62 * 67 *
63 * @ORM\Column(name="ranges", type="array") 68 * @ORM\Column(name="ranges", type="array")
69 *
70 * @Groups({"entries_for_user", "export_all"})
64 */ 71 */
65 private $ranges; 72 private $ranges;
66 73
diff --git a/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadEntryData.php b/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadEntryData.php
index 6c6a331a..fedad009 100644
--- a/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadEntryData.php
+++ b/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadEntryData.php
@@ -23,6 +23,9 @@ class LoadEntryData extends AbstractFixture implements OrderedFixtureInterface
23 $entry1->setContent('This is my content /o/'); 23 $entry1->setContent('This is my content /o/');
24 $entry1->setLanguage('en'); 24 $entry1->setLanguage('en');
25 25
26 $entry1->addTag($this->getReference('foo-tag'));
27 $entry1->addTag($this->getReference('baz-tag'));
28
26 $manager->persist($entry1); 29 $manager->persist($entry1);
27 30
28 $this->addReference('entry1', $entry1); 31 $this->addReference('entry1', $entry1);
@@ -96,6 +99,7 @@ class LoadEntryData extends AbstractFixture implements OrderedFixtureInterface
96 $entry6->setContent('This is my content /o/'); 99 $entry6->setContent('This is my content /o/');
97 $entry6->setArchived(true); 100 $entry6->setArchived(true);
98 $entry6->setLanguage('de'); 101 $entry6->setLanguage('de');
102 $entry6->addTag($this->getReference('bar-tag'));
99 103
100 $manager->persist($entry6); 104 $manager->persist($entry6);
101 105
diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php
index a4b0d7a8..f2da3f4d 100644
--- a/src/Wallabag/CoreBundle/Entity/Entry.php
+++ b/src/Wallabag/CoreBundle/Entity/Entry.php
@@ -196,8 +196,6 @@ class Entry
196 * @ORM\JoinColumn(name="tag_id", referencedColumnName="id") 196 * @ORM\JoinColumn(name="tag_id", referencedColumnName="id")
197 * } 197 * }
198 * ) 198 * )
199 *
200 * @Groups({"entries_for_user", "export_all"})
201 */ 199 */
202 private $tags; 200 private $tags;
203 201
@@ -542,6 +540,21 @@ class Entry
542 } 540 }
543 541
544 /** 542 /**
543 * @VirtualProperty
544 * @SerializedName("tags")
545 * @Groups({"entries_for_user", "export_all"})
546 */
547 public function getSerializedTags()
548 {
549 $data = [];
550 foreach ($this->tags as $tag) {
551 $data[] = $tag->getLabel();
552 }
553
554 return $data;
555 }
556
557 /**
545 * @param Tag $tag 558 * @param Tag $tag
546 */ 559 */
547 public function addTag(Tag $tag) 560 public function addTag(Tag $tag)
diff --git a/src/Wallabag/CoreBundle/Helper/EntriesExport.php b/src/Wallabag/CoreBundle/Helper/EntriesExport.php
index 0c627dcd..d1f1e233 100644
--- a/src/Wallabag/CoreBundle/Helper/EntriesExport.php
+++ b/src/Wallabag/CoreBundle/Helper/EntriesExport.php
@@ -53,10 +53,6 @@ class EntriesExport
53 53
54 $this->entries = $entries; 54 $this->entries = $entries;
55 55
56 foreach ($entries as $entry) {
57 $this->tags[] = $entry->getTags();
58 }
59
60 return $this; 56 return $this;
61 } 57 }
62 58
@@ -159,8 +155,8 @@ class EntriesExport
159 155
160 // set tags as subjects 156 // set tags as subjects
161 foreach ($this->entries as $entry) { 157 foreach ($this->entries as $entry) {
162 foreach ($this->tags as $tag) { 158 foreach ($entry->getTags() as $tag) {
163 $book->setSubject($tag['value']); 159 $book->setSubject($tag->getLabel());
164 } 160 }
165 161
166 // the reader in Kobo Devices doesn't likes special caracters 162 // the reader in Kobo Devices doesn't likes special caracters
@@ -265,8 +261,8 @@ class EntriesExport
265 * Adding actual entries 261 * Adding actual entries
266 */ 262 */
267 foreach ($this->entries as $entry) { 263 foreach ($this->entries as $entry) {
268 foreach ($this->tags as $tag) { 264 foreach ($entry->getTags() as $tag) {
269 $pdf->SetKeywords($tag['value']); 265 $pdf->SetKeywords($tag->getLabel());
270 } 266 }
271 267
272 $pdf->AddPage(); 268 $pdf->AddPage();
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()