aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2016-09-25 11:26:15 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2016-09-25 12:03:49 +0200
commit401135852c6b25c8d5ab97beaefb02d1bd023ec9 (patch)
tree5922f4bd40af0ceb61db2c55755bc006f18410fb /tests/Wallabag
parentfaa86e06ba3032fdb98f3c0f79c72e8581d3c96f (diff)
downloadwallabag-401135852c6b25c8d5ab97beaefb02d1bd023ec9.tar.gz
wallabag-401135852c6b25c8d5ab97beaefb02d1bd023ec9.tar.zst
wallabag-401135852c6b25c8d5ab97beaefb02d1bd023ec9.zip
Use scheduled entity insertions to avoid tag duplicate
Using `getScheduledEntityInsertions()` we can retrieve not yet flushed but already persisted entities and then avoid tags duplication on import.
Diffstat (limited to 'tests/Wallabag')
-rw-r--r--tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php23
-rw-r--r--tests/Wallabag/ImportBundle/Import/PocketImportTest.php14
-rw-r--r--tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php14
-rw-r--r--tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php14
4 files changed, 65 insertions, 0 deletions
diff --git a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php
index 7abb0737..5d772602 100644
--- a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php
+++ b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php
@@ -296,6 +296,29 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
296 $this->assertEquals('tag2', $entry->getTags()[1]->getLabel()); 296 $this->assertEquals('tag2', $entry->getTags()[1]->getLabel());
297 } 297 }
298 298
299 public function testAssignTagsNotFlushed()
300 {
301 $graby = $this->getMockBuilder('Graby\Graby')
302 ->disableOriginalConstructor()
303 ->getMock();
304
305 $tagRepo = $this->getTagRepositoryMock();
306 $tagRepo->expects($this->never())
307 ->method('__call');
308
309 $proxy = new ContentProxy($graby, $this->getTaggerMock(), $tagRepo, $this->getLogger());
310
311 $tagEntity = new Tag();
312 $tagEntity->setLabel('tag1');
313
314 $entry = new Entry(new User());
315
316 $proxy->assignTagsToEntry($entry, 'tag1', [$tagEntity]);
317
318 $this->assertCount(1, $entry->getTags());
319 $this->assertEquals('tag1', $entry->getTags()[0]->getLabel());
320 }
321
299 private function getTaggerMock() 322 private function getTaggerMock()
300 { 323 {
301 return $this->getMockBuilder('Wallabag\CoreBundle\Helper\RuleBasedTagger') 324 return $this->getMockBuilder('Wallabag\CoreBundle\Helper\RuleBasedTagger')
diff --git a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php
index 952521a2..9ec7935c 100644
--- a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php
+++ b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php
@@ -41,6 +41,20 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase
41 ->disableOriginalConstructor() 41 ->disableOriginalConstructor()
42 ->getMock(); 42 ->getMock();
43 43
44 $this->uow = $this->getMockBuilder('Doctrine\ORM\UnitOfWork')
45 ->disableOriginalConstructor()
46 ->getMock();
47
48 $this->em
49 ->expects($this->any())
50 ->method('getUnitOfWork')
51 ->willReturn($this->uow);
52
53 $this->uow
54 ->expects($this->any())
55 ->method('getScheduledEntityInsertions')
56 ->willReturn([]);
57
44 $pocket = new PocketImport( 58 $pocket = new PocketImport(
45 $this->em, 59 $this->em,
46 $this->contentProxy 60 $this->contentProxy
diff --git a/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php b/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php
index 5ab4ad00..82dc4c7e 100644
--- a/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php
+++ b/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php
@@ -26,6 +26,20 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
26 ->disableOriginalConstructor() 26 ->disableOriginalConstructor()
27 ->getMock(); 27 ->getMock();
28 28
29 $this->uow = $this->getMockBuilder('Doctrine\ORM\UnitOfWork')
30 ->disableOriginalConstructor()
31 ->getMock();
32
33 $this->em
34 ->expects($this->any())
35 ->method('getUnitOfWork')
36 ->willReturn($this->uow);
37
38 $this->uow
39 ->expects($this->any())
40 ->method('getScheduledEntityInsertions')
41 ->willReturn([]);
42
29 $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') 43 $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy')
30 ->disableOriginalConstructor() 44 ->disableOriginalConstructor()
31 ->getMock(); 45 ->getMock();
diff --git a/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php b/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php
index 12bd6bdd..bea89efb 100644
--- a/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php
+++ b/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php
@@ -26,6 +26,20 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase
26 ->disableOriginalConstructor() 26 ->disableOriginalConstructor()
27 ->getMock(); 27 ->getMock();
28 28
29 $this->uow = $this->getMockBuilder('Doctrine\ORM\UnitOfWork')
30 ->disableOriginalConstructor()
31 ->getMock();
32
33 $this->em
34 ->expects($this->any())
35 ->method('getUnitOfWork')
36 ->willReturn($this->uow);
37
38 $this->uow
39 ->expects($this->any())
40 ->method('getScheduledEntityInsertions')
41 ->willReturn([]);
42
29 $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') 43 $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy')
30 ->disableOriginalConstructor() 44 ->disableOriginalConstructor()
31 ->getMock(); 45 ->getMock();