diff options
author | Thomas Citharel <tcit@tcit.fr> | 2017-05-27 22:08:14 +0200 |
---|---|---|
committer | Thomas Citharel <tcit@tcit.fr> | 2017-05-27 22:08:14 +0200 |
commit | 6bc6fb1f60e7b81a21f844dca025671a2f4a4564 (patch) | |
tree | fde672650c6a2ef2ccb611a6a29989a7c944ea00 /tests/Wallabag/CoreBundle/Helper/TagsAssignerTest.php | |
parent | 35941d57ee4d06ec3557d4b126d5f6fd263bcf3a (diff) | |
download | wallabag-6bc6fb1f60e7b81a21f844dca025671a2f4a4564.tar.gz wallabag-6bc6fb1f60e7b81a21f844dca025671a2f4a4564.tar.zst wallabag-6bc6fb1f60e7b81a21f844dca025671a2f4a4564.zip |
Move Tags assigner to a separate file
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
Diffstat (limited to 'tests/Wallabag/CoreBundle/Helper/TagsAssignerTest.php')
-rw-r--r-- | tests/Wallabag/CoreBundle/Helper/TagsAssignerTest.php | 114 |
1 files changed, 114 insertions, 0 deletions
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 | |||
3 | namespace Tests\Wallabag\CoreBundle\Helper; | ||
4 | |||
5 | use Psr\Log\NullLogger; | ||
6 | use Wallabag\CoreBundle\Helper\ContentProxy; | ||
7 | use Wallabag\CoreBundle\Entity\Entry; | ||
8 | use Wallabag\CoreBundle\Entity\Tag; | ||
9 | use Wallabag\CoreBundle\Helper\TagsAssigner; | ||
10 | use Wallabag\UserBundle\Entity\User; | ||
11 | use Wallabag\CoreBundle\Repository\TagRepository; | ||
12 | use Wallabag\CoreBundle\Helper\RuleBasedTagger; | ||
13 | |||
14 | class 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 | } | ||