aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/Wallabag/ApiBundle/Controller/EntryRestController.php8
-rw-r--r--src/Wallabag/CoreBundle/Controller/TagController.php2
-rw-r--r--src/Wallabag/CoreBundle/Helper/ContentProxy.php56
-rw-r--r--src/Wallabag/CoreBundle/Helper/TagsAssigner.php76
-rw-r--r--src/Wallabag/CoreBundle/Resources/config/services.yml6
-rw-r--r--src/Wallabag/ImportBundle/Import/AbstractImport.php5
-rw-r--r--src/Wallabag/ImportBundle/Import/BrowserImport.php2
-rw-r--r--src/Wallabag/ImportBundle/Import/PinboardImport.php2
-rw-r--r--src/Wallabag/ImportBundle/Import/PocketImport.php2
-rw-r--r--src/Wallabag/ImportBundle/Import/WallabagImport.php2
-rw-r--r--src/Wallabag/ImportBundle/Resources/config/services.yml8
-rw-r--r--tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php139
-rw-r--r--tests/Wallabag/CoreBundle/Helper/TagsAssignerTest.php114
-rw-r--r--tests/Wallabag/ImportBundle/Import/ChromeImportTest.php7
-rw-r--r--tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php7
-rw-r--r--tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php7
-rw-r--r--tests/Wallabag/ImportBundle/Import/PocketImportTest.php8
-rw-r--r--tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php7
-rw-r--r--tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php8
-rw-r--r--tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php8
20 files changed, 274 insertions, 200 deletions
diff --git a/src/Wallabag/ApiBundle/Controller/EntryRestController.php b/src/Wallabag/ApiBundle/Controller/EntryRestController.php
index 4801811d..31bb67fd 100644
--- a/src/Wallabag/ApiBundle/Controller/EntryRestController.php
+++ b/src/Wallabag/ApiBundle/Controller/EntryRestController.php
@@ -318,7 +318,7 @@ class EntryRestController extends WallabagRestController
318 318
319 $tags = $request->request->get('tags', ''); 319 $tags = $request->request->get('tags', '');
320 if (!empty($tags)) { 320 if (!empty($tags)) {
321 $this->get('wallabag_core.content_proxy')->assignTagsToEntry($entry, $tags); 321 $this->get('wallabag_core.tags_assigner')->assignTagsToEntry($entry, $tags);
322 } 322 }
323 323
324 if (!is_null($isStarred)) { 324 if (!is_null($isStarred)) {
@@ -379,7 +379,7 @@ class EntryRestController extends WallabagRestController
379 379
380 $tags = $request->request->get('tags', ''); 380 $tags = $request->request->get('tags', '');
381 if (!empty($tags)) { 381 if (!empty($tags)) {
382 $this->get('wallabag_core.content_proxy')->assignTagsToEntry($entry, $tags); 382 $this->get('wallabag_core.tags_assigner')->assignTagsToEntry($entry, $tags);
383 } 383 }
384 384
385 $em = $this->getDoctrine()->getManager(); 385 $em = $this->getDoctrine()->getManager();
@@ -497,7 +497,7 @@ class EntryRestController extends WallabagRestController
497 497
498 $tags = $request->request->get('tags', ''); 498 $tags = $request->request->get('tags', '');
499 if (!empty($tags)) { 499 if (!empty($tags)) {
500 $this->get('wallabag_core.content_proxy')->assignTagsToEntry($entry, $tags); 500 $this->get('wallabag_core.tags_assigner')->assignTagsToEntry($entry, $tags);
501 } 501 }
502 502
503 $em = $this->getDoctrine()->getManager(); 503 $em = $this->getDoctrine()->getManager();
@@ -626,7 +626,7 @@ class EntryRestController extends WallabagRestController
626 $tags = $element->tags; 626 $tags = $element->tags;
627 627
628 if (false !== $entry && !(empty($tags))) { 628 if (false !== $entry && !(empty($tags))) {
629 $this->get('wallabag_core.content_proxy')->assignTagsToEntry($entry, $tags); 629 $this->get('wallabag_core.tags_assigner')->assignTagsToEntry($entry, $tags);
630 630
631 $em = $this->getDoctrine()->getManager(); 631 $em = $this->getDoctrine()->getManager();
632 $em->persist($entry); 632 $em->persist($entry);
diff --git a/src/Wallabag/CoreBundle/Controller/TagController.php b/src/Wallabag/CoreBundle/Controller/TagController.php
index 8a093289..fb6a720b 100644
--- a/src/Wallabag/CoreBundle/Controller/TagController.php
+++ b/src/Wallabag/CoreBundle/Controller/TagController.php
@@ -28,7 +28,7 @@ class TagController extends Controller
28 $form->handleRequest($request); 28 $form->handleRequest($request);
29 29
30 if ($form->isSubmitted() && $form->isValid()) { 30 if ($form->isSubmitted() && $form->isValid()) {
31 $this->get('wallabag_core.content_proxy')->assignTagsToEntry( 31 $this->get('wallabag_core.tags_assigner')->assignTagsToEntry(
32 $entry, 32 $entry,
33 $form->get('label')->getData() 33 $form->get('label')->getData()
34 ); 34 );
diff --git a/src/Wallabag/CoreBundle/Helper/ContentProxy.php b/src/Wallabag/CoreBundle/Helper/ContentProxy.php
index 9a08db3d..076135c7 100644
--- a/src/Wallabag/CoreBundle/Helper/ContentProxy.php
+++ b/src/Wallabag/CoreBundle/Helper/ContentProxy.php
@@ -4,10 +4,9 @@ namespace Wallabag\CoreBundle\Helper;
4 4
5use Graby\Graby; 5use Graby\Graby;
6use Psr\Log\LoggerInterface; 6use Psr\Log\LoggerInterface;
7use Symfony\Component\EventDispatcher\EventDispatcher;
7use Wallabag\CoreBundle\Entity\Entry; 8use Wallabag\CoreBundle\Entity\Entry;
8use Wallabag\CoreBundle\Entity\Tag;
9use Wallabag\CoreBundle\Tools\Utils; 9use Wallabag\CoreBundle\Tools\Utils;
10use Wallabag\CoreBundle\Repository\TagRepository;
11use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeExtensionGuesser; 10use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeExtensionGuesser;
12 11
13/** 12/**
@@ -19,16 +18,15 @@ class ContentProxy
19 protected $graby; 18 protected $graby;
20 protected $tagger; 19 protected $tagger;
21 protected $logger; 20 protected $logger;
22 protected $tagRepository;
23 protected $mimeGuesser; 21 protected $mimeGuesser;
24 protected $fetchingErrorMessage; 22 protected $fetchingErrorMessage;
23 protected $eventDispatcher;
25 24
26 public function __construct(Graby $graby, RuleBasedTagger $tagger, TagRepository $tagRepository, LoggerInterface $logger, $fetchingErrorMessage) 25 public function __construct(Graby $graby, RuleBasedTagger $tagger, LoggerInterface $logger, $fetchingErrorMessage)
27 { 26 {
28 $this->graby = $graby; 27 $this->graby = $graby;
29 $this->tagger = $tagger; 28 $this->tagger = $tagger;
30 $this->logger = $logger; 29 $this->logger = $logger;
31 $this->tagRepository = $tagRepository;
32 $this->mimeGuesser = new MimeTypeExtensionGuesser(); 30 $this->mimeGuesser = new MimeTypeExtensionGuesser();
33 $this->fetchingErrorMessage = $fetchingErrorMessage; 31 $this->fetchingErrorMessage = $fetchingErrorMessage;
34 } 32 }
@@ -122,54 +120,6 @@ class ContentProxy
122 } 120 }
123 121
124 /** 122 /**
125 * Assign some tags to an entry.
126 *
127 * @param Entry $entry
128 * @param array|string $tags An array of tag or a string coma separated of tag
129 * @param array $entitiesReady Entities from the EntityManager which are persisted but not yet flushed
130 * It is mostly to fix duplicate tag on import @see http://stackoverflow.com/a/7879164/569101
131 */
132 public function assignTagsToEntry(Entry $entry, $tags, array $entitiesReady = [])
133 {
134 if (!is_array($tags)) {
135 $tags = explode(',', $tags);
136 }
137
138 // keeps only Tag entity from the "not yet flushed entities"
139 $tagsNotYetFlushed = [];
140 foreach ($entitiesReady as $entity) {
141 if ($entity instanceof Tag) {
142 $tagsNotYetFlushed[$entity->getLabel()] = $entity;
143 }
144 }
145
146 foreach ($tags as $label) {
147 $label = trim($label);
148
149 // avoid empty tag
150 if (0 === strlen($label)) {
151 continue;
152 }
153
154 if (isset($tagsNotYetFlushed[$label])) {
155 $tagEntity = $tagsNotYetFlushed[$label];
156 } else {
157 $tagEntity = $this->tagRepository->findOneByLabel($label);
158
159 if (is_null($tagEntity)) {
160 $tagEntity = new Tag();
161 $tagEntity->setLabel($label);
162 }
163 }
164
165 // only add the tag on the entry if the relation doesn't exist
166 if (false === $entry->getTags()->contains($tagEntity)) {
167 $entry->addTag($tagEntity);
168 }
169 }
170 }
171
172 /**
173 * Validate that the given content as enough value to be used 123 * Validate that the given content as enough value to be used
174 * instead of fetch the content from the url. 124 * instead of fetch the content from the url.
175 * 125 *
diff --git a/src/Wallabag/CoreBundle/Helper/TagsAssigner.php b/src/Wallabag/CoreBundle/Helper/TagsAssigner.php
new file mode 100644
index 00000000..ae712d77
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Helper/TagsAssigner.php
@@ -0,0 +1,76 @@
1<?php
2
3namespace Wallabag\CoreBundle\Helper;
4
5use Wallabag\CoreBundle\Entity\Entry;
6use Wallabag\CoreBundle\Entity\Tag;
7use Wallabag\CoreBundle\Repository\TagRepository;
8
9class TagsAssigner
10{
11
12 /**
13 * @var TagRepository $tagRepository
14 */
15 protected $tagRepository;
16
17 public function __construct(TagRepository $tagRepository)
18 {
19 $this->tagRepository = $tagRepository;
20 }
21
22 /**
23 * Assign some tags to an entry.
24 *
25 * @param Entry $entry
26 * @param array|string $tags An array of tag or a string coma separated of tag
27 * @param array $entitiesReady Entities from the EntityManager which are persisted but not yet flushed
28 * It is mostly to fix duplicate tag on import @see http://stackoverflow.com/a/7879164/569101
29 *
30 * @return Tag[]
31 */
32 public function assignTagsToEntry(Entry $entry, $tags, array $entitiesReady = [])
33 {
34 $tagsEntities = [];
35
36 if (!is_array($tags)) {
37 $tags = explode(',', $tags);
38 }
39
40 // keeps only Tag entity from the "not yet flushed entities"
41 $tagsNotYetFlushed = [];
42 foreach ($entitiesReady as $entity) {
43 if ($entity instanceof Tag) {
44 $tagsNotYetFlushed[$entity->getLabel()] = $entity;
45 }
46 }
47
48 foreach ($tags as $label) {
49 $label = trim($label);
50
51 // avoid empty tag
52 if (0 === strlen($label)) {
53 continue;
54 }
55
56 if (isset($tagsNotYetFlushed[$label])) {
57 $tagEntity = $tagsNotYetFlushed[$label];
58 } else {
59 $tagEntity = $this->tagRepository->findOneByLabel($label);
60
61 if (null === $tagEntity) {
62 $tagEntity = new Tag();
63 $tagEntity->setLabel($label);
64 }
65 }
66
67 // only add the tag on the entry if the relation doesn't exist
68 if (false === $entry->getTags()->contains($tagEntity)) {
69 $entry->addTag($tagEntity);
70 $tagsEntities[] = $tagEntity;
71 }
72 }
73
74 return $tagsEntities;
75 }
76}
diff --git a/src/Wallabag/CoreBundle/Resources/config/services.yml b/src/Wallabag/CoreBundle/Resources/config/services.yml
index a9134ac3..a68b2fdc 100644
--- a/src/Wallabag/CoreBundle/Resources/config/services.yml
+++ b/src/Wallabag/CoreBundle/Resources/config/services.yml
@@ -89,10 +89,14 @@ services:
89 arguments: 89 arguments:
90 - "@wallabag_core.graby" 90 - "@wallabag_core.graby"
91 - "@wallabag_core.rule_based_tagger" 91 - "@wallabag_core.rule_based_tagger"
92 - "@wallabag_core.tag_repository"
93 - "@logger" 92 - "@logger"
94 - '%wallabag_core.fetching_error_message%' 93 - '%wallabag_core.fetching_error_message%'
95 94
95 wallabag_core.tags_assigner:
96 class: Wallabag\CoreBundle\Helper\TagsAssigner
97 arguments:
98 - "@wallabag_core.tag_repository"
99
96 wallabag_core.rule_based_tagger: 100 wallabag_core.rule_based_tagger:
97 class: Wallabag\CoreBundle\Helper\RuleBasedTagger 101 class: Wallabag\CoreBundle\Helper\RuleBasedTagger
98 arguments: 102 arguments:
diff --git a/src/Wallabag/ImportBundle/Import/AbstractImport.php b/src/Wallabag/ImportBundle/Import/AbstractImport.php
index 1d4a6e27..a61388c0 100644
--- a/src/Wallabag/ImportBundle/Import/AbstractImport.php
+++ b/src/Wallabag/ImportBundle/Import/AbstractImport.php
@@ -8,6 +8,7 @@ use Doctrine\ORM\EntityManager;
8use Wallabag\CoreBundle\Helper\ContentProxy; 8use Wallabag\CoreBundle\Helper\ContentProxy;
9use Wallabag\CoreBundle\Entity\Entry; 9use Wallabag\CoreBundle\Entity\Entry;
10use Wallabag\CoreBundle\Entity\Tag; 10use Wallabag\CoreBundle\Entity\Tag;
11use Wallabag\CoreBundle\Helper\TagsAssigner;
11use Wallabag\UserBundle\Entity\User; 12use Wallabag\UserBundle\Entity\User;
12use OldSound\RabbitMqBundle\RabbitMq\ProducerInterface; 13use OldSound\RabbitMqBundle\RabbitMq\ProducerInterface;
13use Symfony\Component\EventDispatcher\EventDispatcherInterface; 14use Symfony\Component\EventDispatcher\EventDispatcherInterface;
@@ -18,6 +19,7 @@ abstract class AbstractImport implements ImportInterface
18 protected $em; 19 protected $em;
19 protected $logger; 20 protected $logger;
20 protected $contentProxy; 21 protected $contentProxy;
22 protected $tagsAssigner;
21 protected $eventDispatcher; 23 protected $eventDispatcher;
22 protected $producer; 24 protected $producer;
23 protected $user; 25 protected $user;
@@ -26,11 +28,12 @@ abstract class AbstractImport implements ImportInterface
26 protected $importedEntries = 0; 28 protected $importedEntries = 0;
27 protected $queuedEntries = 0; 29 protected $queuedEntries = 0;
28 30
29 public function __construct(EntityManager $em, ContentProxy $contentProxy, EventDispatcherInterface $eventDispatcher) 31 public function __construct(EntityManager $em, ContentProxy $contentProxy, TagsAssigner $tagsAssigner, EventDispatcherInterface $eventDispatcher)
30 { 32 {
31 $this->em = $em; 33 $this->em = $em;
32 $this->logger = new NullLogger(); 34 $this->logger = new NullLogger();
33 $this->contentProxy = $contentProxy; 35 $this->contentProxy = $contentProxy;
36 $this->tagsAssigner = $tagsAssigner;
34 $this->eventDispatcher = $eventDispatcher; 37 $this->eventDispatcher = $eventDispatcher;
35 } 38 }
36 39
diff --git a/src/Wallabag/ImportBundle/Import/BrowserImport.php b/src/Wallabag/ImportBundle/Import/BrowserImport.php
index 8bf7d92e..c8a9b4e6 100644
--- a/src/Wallabag/ImportBundle/Import/BrowserImport.php
+++ b/src/Wallabag/ImportBundle/Import/BrowserImport.php
@@ -205,7 +205,7 @@ abstract class BrowserImport extends AbstractImport
205 $entry = $this->fetchContent($entry, $data['url'], $data); 205 $entry = $this->fetchContent($entry, $data['url'], $data);
206 206
207 if (array_key_exists('tags', $data)) { 207 if (array_key_exists('tags', $data)) {
208 $this->contentProxy->assignTagsToEntry( 208 $this->tagsAssigner->assignTagsToEntry(
209 $entry, 209 $entry,
210 $data['tags'] 210 $data['tags']
211 ); 211 );
diff --git a/src/Wallabag/ImportBundle/Import/PinboardImport.php b/src/Wallabag/ImportBundle/Import/PinboardImport.php
index d9865534..489b9257 100644
--- a/src/Wallabag/ImportBundle/Import/PinboardImport.php
+++ b/src/Wallabag/ImportBundle/Import/PinboardImport.php
@@ -112,7 +112,7 @@ class PinboardImport extends AbstractImport
112 $entry = $this->fetchContent($entry, $data['url'], $data); 112 $entry = $this->fetchContent($entry, $data['url'], $data);
113 113
114 if (!empty($data['tags'])) { 114 if (!empty($data['tags'])) {
115 $this->contentProxy->assignTagsToEntry( 115 $this->tagsAssigner->assignTagsToEntry(
116 $entry, 116 $entry,
117 $data['tags'], 117 $data['tags'],
118 $this->em->getUnitOfWork()->getScheduledEntityInsertions() 118 $this->em->getUnitOfWork()->getScheduledEntityInsertions()
diff --git a/src/Wallabag/ImportBundle/Import/PocketImport.php b/src/Wallabag/ImportBundle/Import/PocketImport.php
index 33093480..1171d452 100644
--- a/src/Wallabag/ImportBundle/Import/PocketImport.php
+++ b/src/Wallabag/ImportBundle/Import/PocketImport.php
@@ -216,7 +216,7 @@ class PocketImport extends AbstractImport
216 } 216 }
217 217
218 if (isset($importedEntry['tags']) && !empty($importedEntry['tags'])) { 218 if (isset($importedEntry['tags']) && !empty($importedEntry['tags'])) {
219 $this->contentProxy->assignTagsToEntry( 219 $this->tagsAssigner->assignTagsToEntry(
220 $entry, 220 $entry,
221 array_keys($importedEntry['tags']), 221 array_keys($importedEntry['tags']),
222 $this->em->getUnitOfWork()->getScheduledEntityInsertions() 222 $this->em->getUnitOfWork()->getScheduledEntityInsertions()
diff --git a/src/Wallabag/ImportBundle/Import/WallabagImport.php b/src/Wallabag/ImportBundle/Import/WallabagImport.php
index 702da057..0e5382cf 100644
--- a/src/Wallabag/ImportBundle/Import/WallabagImport.php
+++ b/src/Wallabag/ImportBundle/Import/WallabagImport.php
@@ -111,7 +111,7 @@ abstract class WallabagImport extends AbstractImport
111 $entry = $this->fetchContent($entry, $data['url'], $data); 111 $entry = $this->fetchContent($entry, $data['url'], $data);
112 112
113 if (array_key_exists('tags', $data)) { 113 if (array_key_exists('tags', $data)) {
114 $this->contentProxy->assignTagsToEntry( 114 $this->tagsAssigner->assignTagsToEntry(
115 $entry, 115 $entry,
116 $data['tags'], 116 $data['tags'],
117 $this->em->getUnitOfWork()->getScheduledEntityInsertions() 117 $this->em->getUnitOfWork()->getScheduledEntityInsertions()
diff --git a/src/Wallabag/ImportBundle/Resources/config/services.yml b/src/Wallabag/ImportBundle/Resources/config/services.yml
index c4fe3f92..661dc7e1 100644
--- a/src/Wallabag/ImportBundle/Resources/config/services.yml
+++ b/src/Wallabag/ImportBundle/Resources/config/services.yml
@@ -20,6 +20,7 @@ services:
20 arguments: 20 arguments:
21 - "@doctrine.orm.entity_manager" 21 - "@doctrine.orm.entity_manager"
22 - "@wallabag_core.content_proxy" 22 - "@wallabag_core.content_proxy"
23 - "@wallabag_core.tags_assigner"
23 - "@event_dispatcher" 24 - "@event_dispatcher"
24 calls: 25 calls:
25 - [ setClient, [ "@wallabag_import.pocket.client" ] ] 26 - [ setClient, [ "@wallabag_import.pocket.client" ] ]
@@ -32,6 +33,7 @@ services:
32 arguments: 33 arguments:
33 - "@doctrine.orm.entity_manager" 34 - "@doctrine.orm.entity_manager"
34 - "@wallabag_core.content_proxy" 35 - "@wallabag_core.content_proxy"
36 - "@wallabag_core.tags_assigner"
35 - "@event_dispatcher" 37 - "@event_dispatcher"
36 calls: 38 calls:
37 - [ setLogger, [ "@logger" ]] 39 - [ setLogger, [ "@logger" ]]
@@ -43,6 +45,7 @@ services:
43 arguments: 45 arguments:
44 - "@doctrine.orm.entity_manager" 46 - "@doctrine.orm.entity_manager"
45 - "@wallabag_core.content_proxy" 47 - "@wallabag_core.content_proxy"
48 - "@wallabag_core.tags_assigner"
46 - "@event_dispatcher" 49 - "@event_dispatcher"
47 calls: 50 calls:
48 - [ setLogger, [ "@logger" ]] 51 - [ setLogger, [ "@logger" ]]
@@ -54,6 +57,7 @@ services:
54 arguments: 57 arguments:
55 - "@doctrine.orm.entity_manager" 58 - "@doctrine.orm.entity_manager"
56 - "@wallabag_core.content_proxy" 59 - "@wallabag_core.content_proxy"
60 - "@wallabag_core.tags_assigner"
57 - "@event_dispatcher" 61 - "@event_dispatcher"
58 calls: 62 calls:
59 - [ setLogger, [ "@logger" ]] 63 - [ setLogger, [ "@logger" ]]
@@ -65,6 +69,7 @@ services:
65 arguments: 69 arguments:
66 - "@doctrine.orm.entity_manager" 70 - "@doctrine.orm.entity_manager"
67 - "@wallabag_core.content_proxy" 71 - "@wallabag_core.content_proxy"
72 - "@wallabag_core.tags_assigner"
68 - "@event_dispatcher" 73 - "@event_dispatcher"
69 calls: 74 calls:
70 - [ setLogger, [ "@logger" ]] 75 - [ setLogger, [ "@logger" ]]
@@ -76,6 +81,7 @@ services:
76 arguments: 81 arguments:
77 - "@doctrine.orm.entity_manager" 82 - "@doctrine.orm.entity_manager"
78 - "@wallabag_core.content_proxy" 83 - "@wallabag_core.content_proxy"
84 - "@wallabag_core.tags_assigner"
79 - "@event_dispatcher" 85 - "@event_dispatcher"
80 calls: 86 calls:
81 - [ setLogger, [ "@logger" ]] 87 - [ setLogger, [ "@logger" ]]
@@ -87,6 +93,7 @@ services:
87 arguments: 93 arguments:
88 - "@doctrine.orm.entity_manager" 94 - "@doctrine.orm.entity_manager"
89 - "@wallabag_core.content_proxy" 95 - "@wallabag_core.content_proxy"
96 - "@wallabag_core.tags_assigner"
90 - "@event_dispatcher" 97 - "@event_dispatcher"
91 calls: 98 calls:
92 - [ setLogger, [ "@logger" ]] 99 - [ setLogger, [ "@logger" ]]
@@ -97,6 +104,7 @@ services:
97 arguments: 104 arguments:
98 - "@doctrine.orm.entity_manager" 105 - "@doctrine.orm.entity_manager"
99 - "@wallabag_core.content_proxy" 106 - "@wallabag_core.content_proxy"
107 - "@wallabag_core.tags_assigner"
100 - "@event_dispatcher" 108 - "@event_dispatcher"
101 calls: 109 calls:
102 - [ setLogger, [ "@logger" ]] 110 - [ setLogger, [ "@logger" ]]
diff --git a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php
index 8abb1bbb..6494f348 100644
--- a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php
+++ b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php
@@ -7,6 +7,8 @@ use Wallabag\CoreBundle\Helper\ContentProxy;
7use Wallabag\CoreBundle\Entity\Entry; 7use Wallabag\CoreBundle\Entity\Entry;
8use Wallabag\CoreBundle\Entity\Tag; 8use Wallabag\CoreBundle\Entity\Tag;
9use Wallabag\UserBundle\Entity\User; 9use Wallabag\UserBundle\Entity\User;
10use Wallabag\CoreBundle\Repository\TagRepository;
11use Wallabag\CoreBundle\Helper\RuleBasedTagger;
10 12
11class ContentProxyTest extends \PHPUnit_Framework_TestCase 13class ContentProxyTest extends \PHPUnit_Framework_TestCase
12{ 14{
@@ -33,7 +35,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
33 'language' => '', 35 'language' => '',
34 ]); 36 ]);
35 37
36 $proxy = new ContentProxy($graby, $tagger, $this->getTagRepositoryMock(), $this->getLogger(), $this->fetchingErrorMessage); 38 $proxy = new ContentProxy($graby, $tagger, $this->getLogger(), $this->fetchingErrorMessage);
37 $entry = $proxy->updateEntry(new Entry(new User()), 'http://user@:80'); 39 $entry = $proxy->updateEntry(new Entry(new User()), 'http://user@:80');
38 40
39 $this->assertEquals('http://user@:80', $entry->getUrl()); 41 $this->assertEquals('http://user@:80', $entry->getUrl());
@@ -67,7 +69,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
67 'language' => '', 69 'language' => '',
68 ]); 70 ]);
69 71
70 $proxy = new ContentProxy($graby, $tagger, $this->getTagRepositoryMock(), $this->getLogger(), $this->fetchingErrorMessage); 72 $proxy = new ContentProxy($graby, $tagger, $this->getLogger(), $this->fetchingErrorMessage);
71 $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0'); 73 $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0');
72 74
73 $this->assertEquals('http://0.0.0.0', $entry->getUrl()); 75 $this->assertEquals('http://0.0.0.0', $entry->getUrl());
@@ -106,7 +108,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
106 ], 108 ],
107 ]); 109 ]);
108 110
109 $proxy = new ContentProxy($graby, $tagger, $this->getTagRepositoryMock(), $this->getLogger(), $this->fetchingErrorMessage); 111 $proxy = new ContentProxy($graby, $tagger, $this->getLogger(), $this->fetchingErrorMessage);
110 $entry = $proxy->updateEntry(new Entry(new User()), 'http://domain.io'); 112 $entry = $proxy->updateEntry(new Entry(new User()), 'http://domain.io');
111 113
112 $this->assertEquals('http://domain.io', $entry->getUrl()); 114 $this->assertEquals('http://domain.io', $entry->getUrl());
@@ -147,7 +149,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
147 ], 149 ],
148 ]); 150 ]);
149 151
150 $proxy = new ContentProxy($graby, $tagger, $this->getTagRepositoryMock(), $this->getLogger(), $this->fetchingErrorMessage); 152 $proxy = new ContentProxy($graby, $tagger, $this->getLogger(), $this->fetchingErrorMessage);
151 $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0'); 153 $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0');
152 154
153 $this->assertEquals('http://1.1.1.1', $entry->getUrl()); 155 $this->assertEquals('http://1.1.1.1', $entry->getUrl());
@@ -188,7 +190,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
188 ], 190 ],
189 ]); 191 ]);
190 192
191 $proxy = new ContentProxy($graby, $tagger, $this->getTagRepositoryMock(), $this->getLogger(), $this->fetchingErrorMessage); 193 $proxy = new ContentProxy($graby, $tagger, $this->getLogger(), $this->fetchingErrorMessage);
192 $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0'); 194 $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0');
193 195
194 $this->assertEquals('http://1.1.1.1', $entry->getUrl()); 196 $this->assertEquals('http://1.1.1.1', $entry->getUrl());
@@ -210,7 +212,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
210 212
211 $graby = $this->getMockBuilder('Graby\Graby')->getMock(); 213 $graby = $this->getMockBuilder('Graby\Graby')->getMock();
212 214
213 $proxy = new ContentProxy($graby, $tagger, $this->getTagRepositoryMock(), $this->getLogger(), $this->fetchingErrorMessage); 215 $proxy = new ContentProxy($graby, $tagger, $this->getLogger(), $this->fetchingErrorMessage);
214 $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0', [ 216 $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0', [
215 'html' => str_repeat('this is my content', 325), 217 'html' => str_repeat('this is my content', 325),
216 'title' => 'this is my title', 218 'title' => 'this is my title',
@@ -239,8 +241,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
239 ->method('tag') 241 ->method('tag')
240 ->will($this->throwException(new \Exception())); 242 ->will($this->throwException(new \Exception()));
241 243
242 $tagRepo = $this->getTagRepositoryMock(); 244 $proxy = new ContentProxy($graby, $tagger, $this->getLogger(), $this->fetchingErrorMessage);
243 $proxy = new ContentProxy($graby, $tagger, $tagRepo, $this->getLogger(), $this->fetchingErrorMessage);
244 245
245 $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0', [ 246 $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0', [
246 'html' => str_repeat('this is my content', 325), 247 'html' => str_repeat('this is my content', 325),
@@ -253,134 +254,14 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
253 $this->assertCount(0, $entry->getTags()); 254 $this->assertCount(0, $entry->getTags());
254 } 255 }
255 256
256 public function testAssignTagsWithArrayAndExtraSpaces()
257 {
258 $graby = $this->getMockBuilder('Graby\Graby')
259 ->disableOriginalConstructor()
260 ->getMock();
261
262 $tagRepo = $this->getTagRepositoryMock();
263 $proxy = new ContentProxy($graby, $this->getTaggerMock(), $tagRepo, $this->getLogger(), $this->fetchingErrorMessage);
264
265 $entry = new Entry(new User());
266
267 $proxy->assignTagsToEntry($entry, [' tag1', 'tag2 ']);
268
269 $this->assertCount(2, $entry->getTags());
270 $this->assertEquals('tag1', $entry->getTags()[0]->getLabel());
271 $this->assertEquals('tag2', $entry->getTags()[1]->getLabel());
272 }
273
274 public function testAssignTagsWithString()
275 {
276 $graby = $this->getMockBuilder('Graby\Graby')
277 ->disableOriginalConstructor()
278 ->getMock();
279
280 $tagRepo = $this->getTagRepositoryMock();
281 $proxy = new ContentProxy($graby, $this->getTaggerMock(), $tagRepo, $this->getLogger(), $this->fetchingErrorMessage);
282
283 $entry = new Entry(new User());
284
285 $proxy->assignTagsToEntry($entry, 'tag1, tag2');
286
287 $this->assertCount(2, $entry->getTags());
288 $this->assertEquals('tag1', $entry->getTags()[0]->getLabel());
289 $this->assertEquals('tag2', $entry->getTags()[1]->getLabel());
290 }
291
292 public function testAssignTagsWithEmptyArray()
293 {
294 $graby = $this->getMockBuilder('Graby\Graby')
295 ->disableOriginalConstructor()
296 ->getMock();
297
298 $tagRepo = $this->getTagRepositoryMock();
299 $proxy = new ContentProxy($graby, $this->getTaggerMock(), $tagRepo, $this->getLogger(), $this->fetchingErrorMessage);
300
301 $entry = new Entry(new User());
302
303 $proxy->assignTagsToEntry($entry, []);
304
305 $this->assertCount(0, $entry->getTags());
306 }
307
308 public function testAssignTagsWithEmptyString()
309 {
310 $graby = $this->getMockBuilder('Graby\Graby')
311 ->disableOriginalConstructor()
312 ->getMock();
313
314 $tagRepo = $this->getTagRepositoryMock();
315 $proxy = new ContentProxy($graby, $this->getTaggerMock(), $tagRepo, $this->getLogger(), $this->fetchingErrorMessage);
316
317 $entry = new Entry(new User());
318
319 $proxy->assignTagsToEntry($entry, '');
320
321 $this->assertCount(0, $entry->getTags());
322 }
323
324 public function testAssignTagsAlreadyAssigned()
325 {
326 $graby = $this->getMockBuilder('Graby\Graby')
327 ->disableOriginalConstructor()
328 ->getMock();
329
330 $tagRepo = $this->getTagRepositoryMock();
331 $proxy = new ContentProxy($graby, $this->getTaggerMock(), $tagRepo, $this->getLogger(), $this->fetchingErrorMessage);
332
333 $tagEntity = new Tag();
334 $tagEntity->setLabel('tag1');
335
336 $entry = new Entry(new User());
337 $entry->addTag($tagEntity);
338
339 $proxy->assignTagsToEntry($entry, 'tag1, tag2');
340
341 $this->assertCount(2, $entry->getTags());
342 $this->assertEquals('tag1', $entry->getTags()[0]->getLabel());
343 $this->assertEquals('tag2', $entry->getTags()[1]->getLabel());
344 }
345
346 public function testAssignTagsNotFlushed()
347 {
348 $graby = $this->getMockBuilder('Graby\Graby')
349 ->disableOriginalConstructor()
350 ->getMock();
351
352 $tagRepo = $this->getTagRepositoryMock();
353 $tagRepo->expects($this->never())
354 ->method('__call');
355
356 $proxy = new ContentProxy($graby, $this->getTaggerMock(), $tagRepo, $this->getLogger(), $this->fetchingErrorMessage);
357
358 $tagEntity = new Tag();
359 $tagEntity->setLabel('tag1');
360
361 $entry = new Entry(new User());
362
363 $proxy->assignTagsToEntry($entry, 'tag1', [$tagEntity]);
364
365 $this->assertCount(1, $entry->getTags());
366 $this->assertEquals('tag1', $entry->getTags()[0]->getLabel());
367 }
368
369 private function getTaggerMock() 257 private function getTaggerMock()
370 { 258 {
371 return $this->getMockBuilder('Wallabag\CoreBundle\Helper\RuleBasedTagger') 259 return $this->getMockBuilder(RuleBasedTagger::class)
372 ->setMethods(['tag']) 260 ->setMethods(['tag'])
373 ->disableOriginalConstructor() 261 ->disableOriginalConstructor()
374 ->getMock(); 262 ->getMock();
375 } 263 }
376 264
377 private function getTagRepositoryMock()
378 {
379 return $this->getMockBuilder('Wallabag\CoreBundle\Repository\TagRepository')
380 ->disableOriginalConstructor()
381 ->getMock();
382 }
383
384 private function getLogger() 265 private function getLogger()
385 { 266 {
386 return new NullLogger(); 267 return new NullLogger();
diff --git a/tests/Wallabag/CoreBundle/Helper/TagsAssignerTest.php b/tests/Wallabag/CoreBundle/Helper/TagsAssignerTest.php
new file mode 100644
index 00000000..bc59eeab
--- /dev/null
+++ b/tests/Wallabag/CoreBundle/Helper/TagsAssignerTest.php
@@ -0,0 +1,114 @@
1<?php
2
3namespace Tests\Wallabag\CoreBundle\Helper;
4
5use Psr\Log\NullLogger;
6use Wallabag\CoreBundle\Helper\ContentProxy;
7use Wallabag\CoreBundle\Entity\Entry;
8use Wallabag\CoreBundle\Entity\Tag;
9use Wallabag\CoreBundle\Helper\TagsAssigner;
10use Wallabag\UserBundle\Entity\User;
11use Wallabag\CoreBundle\Repository\TagRepository;
12use Wallabag\CoreBundle\Helper\RuleBasedTagger;
13
14class TagsAssignerTest extends \PHPUnit_Framework_TestCase
15{
16
17 public function testAssignTagsWithArrayAndExtraSpaces()
18 {
19
20 $tagRepo = $this->getTagRepositoryMock();
21 $tagsAssigner = new TagsAssigner($tagRepo);
22
23 $entry = new Entry(new User());
24
25 $tagsAssigner->assignTagsToEntry($entry, [' tag1', 'tag2 ']);
26
27 $this->assertCount(2, $entry->getTags());
28 $this->assertEquals('tag1', $entry->getTags()[0]->getLabel());
29 $this->assertEquals('tag2', $entry->getTags()[1]->getLabel());
30 }
31
32 public function testAssignTagsWithString()
33 {
34 $tagRepo = $this->getTagRepositoryMock();
35 $tagsAssigner = new TagsAssigner($tagRepo);
36
37 $entry = new Entry(new User());
38
39 $tagsAssigner->assignTagsToEntry($entry, 'tag1, tag2');
40
41 $this->assertCount(2, $entry->getTags());
42 $this->assertEquals('tag1', $entry->getTags()[0]->getLabel());
43 $this->assertEquals('tag2', $entry->getTags()[1]->getLabel());
44 }
45
46 public function testAssignTagsWithEmptyArray()
47 {
48 $tagRepo = $this->getTagRepositoryMock();
49 $tagsAssigner = new TagsAssigner($tagRepo);
50
51 $entry = new Entry(new User());
52
53 $tagsAssigner->assignTagsToEntry($entry, []);
54
55 $this->assertCount(0, $entry->getTags());
56 }
57
58 public function testAssignTagsWithEmptyString()
59 {
60 $tagRepo = $this->getTagRepositoryMock();
61 $tagsAssigner = new TagsAssigner($tagRepo);
62
63 $entry = new Entry(new User());
64
65 $tagsAssigner->assignTagsToEntry($entry, '');
66
67 $this->assertCount(0, $entry->getTags());
68 }
69
70 public function testAssignTagsAlreadyAssigned()
71 {
72 $tagRepo = $this->getTagRepositoryMock();
73 $tagsAssigner = new TagsAssigner($tagRepo);
74
75 $tagEntity = new Tag();
76 $tagEntity->setLabel('tag1');
77
78 $entry = new Entry(new User());
79 $entry->addTag($tagEntity);
80
81 $tagsAssigner->assignTagsToEntry($entry, 'tag1, tag2');
82
83 $this->assertCount(2, $entry->getTags());
84 $this->assertEquals('tag1', $entry->getTags()[0]->getLabel());
85 $this->assertEquals('tag2', $entry->getTags()[1]->getLabel());
86 }
87
88 public function testAssignTagsNotFlushed()
89 {
90
91 $tagRepo = $this->getTagRepositoryMock();
92 $tagRepo->expects($this->never())
93 ->method('__call');
94
95 $tagsAssigner = new TagsAssigner($tagRepo);
96
97 $tagEntity = new Tag();
98 $tagEntity->setLabel('tag1');
99
100 $entry = new Entry(new User());
101
102 $tagsAssigner->assignTagsToEntry($entry, 'tag1', [$tagEntity]);
103
104 $this->assertCount(1, $entry->getTags());
105 $this->assertEquals('tag1', $entry->getTags()[0]->getLabel());
106 }
107
108 private function getTagRepositoryMock()
109 {
110 return $this->getMockBuilder(TagRepository::class)
111 ->disableOriginalConstructor()
112 ->getMock();
113 }
114}
diff --git a/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php b/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php
index 6b3adda4..cec19534 100644
--- a/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php
+++ b/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php
@@ -17,6 +17,7 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase
17 protected $em; 17 protected $em;
18 protected $logHandler; 18 protected $logHandler;
19 protected $contentProxy; 19 protected $contentProxy;
20 protected $tagsAssigner;
20 21
21 private function getChromeImport($unsetUser = false, $dispatched = 0) 22 private function getChromeImport($unsetUser = false, $dispatched = 0)
22 { 23 {
@@ -30,6 +31,10 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase
30 ->disableOriginalConstructor() 31 ->disableOriginalConstructor()
31 ->getMock(); 32 ->getMock();
32 33
34 $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner')
35 ->disableOriginalConstructor()
36 ->getMock();
37
33 $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') 38 $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
34 ->disableOriginalConstructor() 39 ->disableOriginalConstructor()
35 ->getMock(); 40 ->getMock();
@@ -38,7 +43,7 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase
38 ->expects($this->exactly($dispatched)) 43 ->expects($this->exactly($dispatched))
39 ->method('dispatch'); 44 ->method('dispatch');
40 45
41 $wallabag = new ChromeImport($this->em, $this->contentProxy, $dispatcher); 46 $wallabag = new ChromeImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher);
42 47
43 $this->logHandler = new TestHandler(); 48 $this->logHandler = new TestHandler();
44 $logger = new Logger('test', [$this->logHandler]); 49 $logger = new Logger('test', [$this->logHandler]);
diff --git a/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php b/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php
index b516fbc5..c186c820 100644
--- a/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php
+++ b/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php
@@ -17,6 +17,7 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase
17 protected $em; 17 protected $em;
18 protected $logHandler; 18 protected $logHandler;
19 protected $contentProxy; 19 protected $contentProxy;
20 protected $tagsAssigner;
20 21
21 private function getFirefoxImport($unsetUser = false, $dispatched = 0) 22 private function getFirefoxImport($unsetUser = false, $dispatched = 0)
22 { 23 {
@@ -30,6 +31,10 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase
30 ->disableOriginalConstructor() 31 ->disableOriginalConstructor()
31 ->getMock(); 32 ->getMock();
32 33
34 $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner')
35 ->disableOriginalConstructor()
36 ->getMock();
37
33 $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') 38 $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
34 ->disableOriginalConstructor() 39 ->disableOriginalConstructor()
35 ->getMock(); 40 ->getMock();
@@ -38,7 +43,7 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase
38 ->expects($this->exactly($dispatched)) 43 ->expects($this->exactly($dispatched))
39 ->method('dispatch'); 44 ->method('dispatch');
40 45
41 $wallabag = new FirefoxImport($this->em, $this->contentProxy, $dispatcher); 46 $wallabag = new FirefoxImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher);
42 47
43 $this->logHandler = new TestHandler(); 48 $this->logHandler = new TestHandler();
44 $logger = new Logger('test', [$this->logHandler]); 49 $logger = new Logger('test', [$this->logHandler]);
diff --git a/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php b/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php
index e262a808..6777a02e 100644
--- a/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php
+++ b/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php
@@ -17,6 +17,7 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase
17 protected $em; 17 protected $em;
18 protected $logHandler; 18 protected $logHandler;
19 protected $contentProxy; 19 protected $contentProxy;
20 protected $tagsAssigner;
20 21
21 private function getInstapaperImport($unsetUser = false, $dispatched = 0) 22 private function getInstapaperImport($unsetUser = false, $dispatched = 0)
22 { 23 {
@@ -30,6 +31,10 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase
30 ->disableOriginalConstructor() 31 ->disableOriginalConstructor()
31 ->getMock(); 32 ->getMock();
32 33
34 $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner')
35 ->disableOriginalConstructor()
36 ->getMock();
37
33 $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') 38 $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
34 ->disableOriginalConstructor() 39 ->disableOriginalConstructor()
35 ->getMock(); 40 ->getMock();
@@ -38,7 +43,7 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase
38 ->expects($this->exactly($dispatched)) 43 ->expects($this->exactly($dispatched))
39 ->method('dispatch'); 44 ->method('dispatch');
40 45
41 $import = new InstapaperImport($this->em, $this->contentProxy, $dispatcher); 46 $import = new InstapaperImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher);
42 47
43 $this->logHandler = new TestHandler(); 48 $this->logHandler = new TestHandler();
44 $logger = new Logger('test', [$this->logHandler]); 49 $logger = new Logger('test', [$this->logHandler]);
diff --git a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php
index 141ece36..b81ebe15 100644
--- a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php
+++ b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php
@@ -23,6 +23,8 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase
23 protected $em; 23 protected $em;
24 protected $contentProxy; 24 protected $contentProxy;
25 protected $logHandler; 25 protected $logHandler;
26 protected $tagsAssigner;
27 protected $uow;
26 28
27 private function getPocketImport($consumerKey = 'ConsumerKey', $dispatched = 0) 29 private function getPocketImport($consumerKey = 'ConsumerKey', $dispatched = 0)
28 { 30 {
@@ -37,6 +39,10 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase
37 ->disableOriginalConstructor() 39 ->disableOriginalConstructor()
38 ->getMock(); 40 ->getMock();
39 41
42 $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner')
43 ->disableOriginalConstructor()
44 ->getMock();
45
40 $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') 46 $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
41 ->disableOriginalConstructor() 47 ->disableOriginalConstructor()
42 ->getMock(); 48 ->getMock();
@@ -63,7 +69,7 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase
63 ->expects($this->exactly($dispatched)) 69 ->expects($this->exactly($dispatched))
64 ->method('dispatch'); 70 ->method('dispatch');
65 71
66 $pocket = new PocketImport($this->em, $this->contentProxy, $dispatcher); 72 $pocket = new PocketImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher);
67 $pocket->setUser($this->user); 73 $pocket->setUser($this->user);
68 74
69 $this->logHandler = new TestHandler(); 75 $this->logHandler = new TestHandler();
diff --git a/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php
index d1bbe648..254f0a25 100644
--- a/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php
+++ b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php
@@ -17,6 +17,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase
17 protected $em; 17 protected $em;
18 protected $logHandler; 18 protected $logHandler;
19 protected $contentProxy; 19 protected $contentProxy;
20 protected $tagsAssigner;
20 21
21 private function getReadabilityImport($unsetUser = false, $dispatched = 0) 22 private function getReadabilityImport($unsetUser = false, $dispatched = 0)
22 { 23 {
@@ -30,6 +31,10 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase
30 ->disableOriginalConstructor() 31 ->disableOriginalConstructor()
31 ->getMock(); 32 ->getMock();
32 33
34 $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner')
35 ->disableOriginalConstructor()
36 ->getMock();
37
33 $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') 38 $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
34 ->disableOriginalConstructor() 39 ->disableOriginalConstructor()
35 ->getMock(); 40 ->getMock();
@@ -38,7 +43,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase
38 ->expects($this->exactly($dispatched)) 43 ->expects($this->exactly($dispatched))
39 ->method('dispatch'); 44 ->method('dispatch');
40 45
41 $wallabag = new ReadabilityImport($this->em, $this->contentProxy, $dispatcher); 46 $wallabag = new ReadabilityImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher);
42 47
43 $this->logHandler = new TestHandler(); 48 $this->logHandler = new TestHandler();
44 $logger = new Logger('test', [$this->logHandler]); 49 $logger = new Logger('test', [$this->logHandler]);
diff --git a/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php b/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php
index 4dbced60..9f0c5bac 100644
--- a/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php
+++ b/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php
@@ -17,6 +17,8 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
17 protected $em; 17 protected $em;
18 protected $logHandler; 18 protected $logHandler;
19 protected $contentProxy; 19 protected $contentProxy;
20 protected $tagsAssigner;
21 protected $uow;
20 22
21 private function getWallabagV1Import($unsetUser = false, $dispatched = 0) 23 private function getWallabagV1Import($unsetUser = false, $dispatched = 0)
22 { 24 {
@@ -44,6 +46,10 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
44 ->disableOriginalConstructor() 46 ->disableOriginalConstructor()
45 ->getMock(); 47 ->getMock();
46 48
49 $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner')
50 ->disableOriginalConstructor()
51 ->getMock();
52
47 $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') 53 $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
48 ->disableOriginalConstructor() 54 ->disableOriginalConstructor()
49 ->getMock(); 55 ->getMock();
@@ -52,7 +58,7 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
52 ->expects($this->exactly($dispatched)) 58 ->expects($this->exactly($dispatched))
53 ->method('dispatch'); 59 ->method('dispatch');
54 60
55 $wallabag = new WallabagV1Import($this->em, $this->contentProxy, $dispatcher); 61 $wallabag = new WallabagV1Import($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher);
56 62
57 $this->logHandler = new TestHandler(); 63 $this->logHandler = new TestHandler();
58 $logger = new Logger('test', [$this->logHandler]); 64 $logger = new Logger('test', [$this->logHandler]);
diff --git a/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php b/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php
index 0e50b8b2..efcaeb9e 100644
--- a/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php
+++ b/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php
@@ -17,6 +17,8 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase
17 protected $em; 17 protected $em;
18 protected $logHandler; 18 protected $logHandler;
19 protected $contentProxy; 19 protected $contentProxy;
20 protected $tagsAssigner;
21 protected $uow;
20 22
21 private function getWallabagV2Import($unsetUser = false, $dispatched = 0) 23 private function getWallabagV2Import($unsetUser = false, $dispatched = 0)
22 { 24 {
@@ -44,6 +46,10 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase
44 ->disableOriginalConstructor() 46 ->disableOriginalConstructor()
45 ->getMock(); 47 ->getMock();
46 48
49 $this->tagsAssigner = $this->getMockBuilder('Wallabag\CoreBundle\Helper\TagsAssigner')
50 ->disableOriginalConstructor()
51 ->getMock();
52
47 $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher') 53 $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
48 ->disableOriginalConstructor() 54 ->disableOriginalConstructor()
49 ->getMock(); 55 ->getMock();
@@ -52,7 +58,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase
52 ->expects($this->exactly($dispatched)) 58 ->expects($this->exactly($dispatched))
53 ->method('dispatch'); 59 ->method('dispatch');
54 60
55 $wallabag = new WallabagV2Import($this->em, $this->contentProxy, $dispatcher); 61 $wallabag = new WallabagV2Import($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher);
56 62
57 $this->logHandler = new TestHandler(); 63 $this->logHandler = new TestHandler();
58 $logger = new Logger('test', [$this->logHandler]); 64 $logger = new Logger('test', [$this->logHandler]);