aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Tests
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2016-02-19 14:22:20 +0100
committerJeremy Benoist <jeremy.benoist@gmail.com>2016-02-19 14:22:20 +0100
commitc2656f96d4776c86b13d8a4c93a78ee7c4d3824c (patch)
treee7aaddb8e35197420db96bb067fe410e40c0025c /src/Wallabag/CoreBundle/Tests
parentfa64d861105bd0713acd7ac5d116353273524b4f (diff)
downloadwallabag-c2656f96d4776c86b13d8a4c93a78ee7c4d3824c.tar.gz
wallabag-c2656f96d4776c86b13d8a4c93a78ee7c4d3824c.tar.zst
wallabag-c2656f96d4776c86b13d8a4c93a78ee7c4d3824c.zip
Move assignTagsToEntry in ContentProxy helper
Diffstat (limited to 'src/Wallabag/CoreBundle/Tests')
-rw-r--r--src/Wallabag/CoreBundle/Tests/Helper/ContentProxyTest.php106
1 files changed, 102 insertions, 4 deletions
diff --git a/src/Wallabag/CoreBundle/Tests/Helper/ContentProxyTest.php b/src/Wallabag/CoreBundle/Tests/Helper/ContentProxyTest.php
index d29984e9..f58b5828 100644
--- a/src/Wallabag/CoreBundle/Tests/Helper/ContentProxyTest.php
+++ b/src/Wallabag/CoreBundle/Tests/Helper/ContentProxyTest.php
@@ -3,8 +3,9 @@
3namespace Wallabag\CoreBundle\Tests\Helper; 3namespace Wallabag\CoreBundle\Tests\Helper;
4 4
5use Psr\Log\NullLogger; 5use Psr\Log\NullLogger;
6use Wallabag\CoreBundle\Entity\Entry;
7use Wallabag\CoreBundle\Helper\ContentProxy; 6use Wallabag\CoreBundle\Helper\ContentProxy;
7use Wallabag\CoreBundle\Entity\Entry;
8use Wallabag\CoreBundle\Entity\Tag;
8use Wallabag\UserBundle\Entity\User; 9use Wallabag\UserBundle\Entity\User;
9 10
10class ContentProxyTest extends \PHPUnit_Framework_TestCase 11class ContentProxyTest extends \PHPUnit_Framework_TestCase
@@ -30,7 +31,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
30 'language' => '', 31 'language' => '',
31 )); 32 ));
32 33
33 $proxy = new ContentProxy($graby, $tagger, $this->getLogger()); 34 $proxy = new ContentProxy($graby, $tagger, $this->getTagRepositoryMock(), $this->getLogger());
34 $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0'); 35 $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0');
35 36
36 $this->assertEquals('http://0.0.0.0', $entry->getUrl()); 37 $this->assertEquals('http://0.0.0.0', $entry->getUrl());
@@ -68,7 +69,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
68 ), 69 ),
69 )); 70 ));
70 71
71 $proxy = new ContentProxy($graby, $tagger, $this->getLogger()); 72 $proxy = new ContentProxy($graby, $tagger, $this->getTagRepositoryMock(), $this->getLogger());
72 $entry = $proxy->updateEntry(new Entry(new User()), 'http://domain.io'); 73 $entry = $proxy->updateEntry(new Entry(new User()), 'http://domain.io');
73 74
74 $this->assertEquals('http://domain.io', $entry->getUrl()); 75 $this->assertEquals('http://domain.io', $entry->getUrl());
@@ -107,7 +108,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
107 ), 108 ),
108 )); 109 ));
109 110
110 $proxy = new ContentProxy($graby, $tagger, $this->getLogger()); 111 $proxy = new ContentProxy($graby, $tagger, $this->getTagRepositoryMock(), $this->getLogger());
111 $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0'); 112 $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0');
112 113
113 $this->assertEquals('http://1.1.1.1', $entry->getUrl()); 114 $this->assertEquals('http://1.1.1.1', $entry->getUrl());
@@ -120,6 +121,96 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
120 $this->assertEquals('1.1.1.1', $entry->getDomainName()); 121 $this->assertEquals('1.1.1.1', $entry->getDomainName());
121 } 122 }
122 123
124 public function testAssignTagsWithArrayAndExtraSpaces()
125 {
126 $graby = $this->getMockBuilder('Graby\Graby')
127 ->disableOriginalConstructor()
128 ->getMock();
129
130 $tagRepo = $this->getTagRepositoryMock();
131 $proxy = new ContentProxy($graby, $this->getTaggerMock(), $tagRepo, $this->getLogger());
132
133 $entry = new Entry(new User());
134
135 $proxy->assignTagsToEntry($entry, array(' tag1', 'tag2 '));
136
137 $this->assertCount(2, $entry->getTags());
138 $this->assertEquals('tag1', $entry->getTags()[0]->getLabel());
139 $this->assertEquals('tag2', $entry->getTags()[1]->getLabel());
140 }
141
142 public function testAssignTagsWithString()
143 {
144 $graby = $this->getMockBuilder('Graby\Graby')
145 ->disableOriginalConstructor()
146 ->getMock();
147
148 $tagRepo = $this->getTagRepositoryMock();
149 $proxy = new ContentProxy($graby, $this->getTaggerMock(), $tagRepo, $this->getLogger());
150
151 $entry = new Entry(new User());
152
153 $proxy->assignTagsToEntry($entry, 'tag1, tag2');
154
155 $this->assertCount(2, $entry->getTags());
156 $this->assertEquals('tag1', $entry->getTags()[0]->getLabel());
157 $this->assertEquals('tag2', $entry->getTags()[1]->getLabel());
158 }
159
160 public function testAssignTagsWithEmptyArray()
161 {
162 $graby = $this->getMockBuilder('Graby\Graby')
163 ->disableOriginalConstructor()
164 ->getMock();
165
166 $tagRepo = $this->getTagRepositoryMock();
167 $proxy = new ContentProxy($graby, $this->getTaggerMock(), $tagRepo, $this->getLogger());
168
169 $entry = new Entry(new User());
170
171 $proxy->assignTagsToEntry($entry, array());
172
173 $this->assertCount(0, $entry->getTags());
174 }
175
176 public function testAssignTagsWithEmptyString()
177 {
178 $graby = $this->getMockBuilder('Graby\Graby')
179 ->disableOriginalConstructor()
180 ->getMock();
181
182 $tagRepo = $this->getTagRepositoryMock();
183 $proxy = new ContentProxy($graby, $this->getTaggerMock(), $tagRepo, $this->getLogger());
184
185 $entry = new Entry(new User());
186
187 $proxy->assignTagsToEntry($entry, '');
188
189 $this->assertCount(0, $entry->getTags());
190 }
191
192 public function testAssignTagsAlreadyAssigned()
193 {
194 $graby = $this->getMockBuilder('Graby\Graby')
195 ->disableOriginalConstructor()
196 ->getMock();
197
198 $tagRepo = $this->getTagRepositoryMock();
199 $proxy = new ContentProxy($graby, $this->getTaggerMock(), $tagRepo, $this->getLogger());
200
201 $tagEntity = new Tag();
202 $tagEntity->setLabel('tag1');
203
204 $entry = new Entry(new User());
205 $entry->addTag($tagEntity);
206
207 $proxy->assignTagsToEntry($entry, 'tag1, tag2');
208
209 $this->assertCount(2, $entry->getTags());
210 $this->assertEquals('tag1', $entry->getTags()[0]->getLabel());
211 $this->assertEquals('tag2', $entry->getTags()[1]->getLabel());
212 }
213
123 private function getTaggerMock() 214 private function getTaggerMock()
124 { 215 {
125 return $this->getMockBuilder('Wallabag\CoreBundle\Helper\RuleBasedTagger') 216 return $this->getMockBuilder('Wallabag\CoreBundle\Helper\RuleBasedTagger')
@@ -128,6 +219,13 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
128 ->getMock(); 219 ->getMock();
129 } 220 }
130 221
222 private function getTagRepositoryMock()
223 {
224 return $this->getMockBuilder('Wallabag\CoreBundle\Repository\TagRepository')
225 ->disableOriginalConstructor()
226 ->getMock();
227 }
228
131 private function getLogger() 229 private function getLogger()
132 { 230 {
133 return new NullLogger(); 231 return new NullLogger();