diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/Tests/Helper')
3 files changed, 0 insertions, 585 deletions
diff --git a/src/Wallabag/CoreBundle/Tests/Helper/ContentProxyTest.php b/src/Wallabag/CoreBundle/Tests/Helper/ContentProxyTest.php deleted file mode 100644 index 9d7b0f36..00000000 --- a/src/Wallabag/CoreBundle/Tests/Helper/ContentProxyTest.php +++ /dev/null | |||
@@ -1,318 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\CoreBundle\Tests\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\UserBundle\Entity\User; | ||
10 | |||
11 | class ContentProxyTest extends \PHPUnit_Framework_TestCase | ||
12 | { | ||
13 | public function testWithBadUrl() | ||
14 | { | ||
15 | $tagger = $this->getTaggerMock(); | ||
16 | $tagger->expects($this->once()) | ||
17 | ->method('tag'); | ||
18 | |||
19 | $graby = $this->getMockBuilder('Graby\Graby') | ||
20 | ->setMethods(['fetchContent']) | ||
21 | ->disableOriginalConstructor() | ||
22 | ->getMock(); | ||
23 | |||
24 | $graby->expects($this->any()) | ||
25 | ->method('fetchContent') | ||
26 | ->willReturn([ | ||
27 | 'html' => false, | ||
28 | 'title' => '', | ||
29 | 'url' => '', | ||
30 | 'content_type' => '', | ||
31 | 'language' => '', | ||
32 | ]); | ||
33 | |||
34 | $proxy = new ContentProxy($graby, $tagger, $this->getTagRepositoryMock(), $this->getLogger()); | ||
35 | $entry = $proxy->updateEntry(new Entry(new User()), 'http://user@:80'); | ||
36 | |||
37 | $this->assertEquals('http://user@:80', $entry->getUrl()); | ||
38 | $this->assertEmpty($entry->getTitle()); | ||
39 | $this->assertEquals('<p>Unable to retrieve readable content.</p>', $entry->getContent()); | ||
40 | $this->assertEmpty($entry->getPreviewPicture()); | ||
41 | $this->assertEmpty($entry->getMimetype()); | ||
42 | $this->assertEmpty($entry->getLanguage()); | ||
43 | $this->assertEquals(0.0, $entry->getReadingTime()); | ||
44 | $this->assertEquals(false, $entry->getDomainName()); | ||
45 | } | ||
46 | |||
47 | public function testWithEmptyContent() | ||
48 | { | ||
49 | $tagger = $this->getTaggerMock(); | ||
50 | $tagger->expects($this->once()) | ||
51 | ->method('tag'); | ||
52 | |||
53 | $graby = $this->getMockBuilder('Graby\Graby') | ||
54 | ->setMethods(['fetchContent']) | ||
55 | ->disableOriginalConstructor() | ||
56 | ->getMock(); | ||
57 | |||
58 | $graby->expects($this->any()) | ||
59 | ->method('fetchContent') | ||
60 | ->willReturn([ | ||
61 | 'html' => false, | ||
62 | 'title' => '', | ||
63 | 'url' => '', | ||
64 | 'content_type' => '', | ||
65 | 'language' => '', | ||
66 | ]); | ||
67 | |||
68 | $proxy = new ContentProxy($graby, $tagger, $this->getTagRepositoryMock(), $this->getLogger()); | ||
69 | $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0'); | ||
70 | |||
71 | $this->assertEquals('http://0.0.0.0', $entry->getUrl()); | ||
72 | $this->assertEmpty($entry->getTitle()); | ||
73 | $this->assertEquals('<p>Unable to retrieve readable content.</p>', $entry->getContent()); | ||
74 | $this->assertEmpty($entry->getPreviewPicture()); | ||
75 | $this->assertEmpty($entry->getMimetype()); | ||
76 | $this->assertEmpty($entry->getLanguage()); | ||
77 | $this->assertEquals(0.0, $entry->getReadingTime()); | ||
78 | $this->assertEquals('0.0.0.0', $entry->getDomainName()); | ||
79 | } | ||
80 | |||
81 | public function testWithEmptyContentButOG() | ||
82 | { | ||
83 | $tagger = $this->getTaggerMock(); | ||
84 | $tagger->expects($this->once()) | ||
85 | ->method('tag'); | ||
86 | |||
87 | $graby = $this->getMockBuilder('Graby\Graby') | ||
88 | ->setMethods(['fetchContent']) | ||
89 | ->disableOriginalConstructor() | ||
90 | ->getMock(); | ||
91 | |||
92 | $graby->expects($this->any()) | ||
93 | ->method('fetchContent') | ||
94 | ->willReturn([ | ||
95 | 'html' => false, | ||
96 | 'title' => '', | ||
97 | 'url' => '', | ||
98 | 'content_type' => '', | ||
99 | 'language' => '', | ||
100 | 'open_graph' => [ | ||
101 | 'og_title' => 'my title', | ||
102 | 'og_description' => 'desc', | ||
103 | ], | ||
104 | ]); | ||
105 | |||
106 | $proxy = new ContentProxy($graby, $tagger, $this->getTagRepositoryMock(), $this->getLogger()); | ||
107 | $entry = $proxy->updateEntry(new Entry(new User()), 'http://domain.io'); | ||
108 | |||
109 | $this->assertEquals('http://domain.io', $entry->getUrl()); | ||
110 | $this->assertEquals('my title', $entry->getTitle()); | ||
111 | $this->assertEquals('<p>Unable to retrieve readable content.</p><p><i>But we found a short description: </i></p>desc', $entry->getContent()); | ||
112 | $this->assertEmpty($entry->getPreviewPicture()); | ||
113 | $this->assertEmpty($entry->getLanguage()); | ||
114 | $this->assertEmpty($entry->getMimetype()); | ||
115 | $this->assertEquals(0.0, $entry->getReadingTime()); | ||
116 | $this->assertEquals('domain.io', $entry->getDomainName()); | ||
117 | } | ||
118 | |||
119 | public function testWithContent() | ||
120 | { | ||
121 | $tagger = $this->getTaggerMock(); | ||
122 | $tagger->expects($this->once()) | ||
123 | ->method('tag'); | ||
124 | |||
125 | $graby = $this->getMockBuilder('Graby\Graby') | ||
126 | ->setMethods(['fetchContent']) | ||
127 | ->disableOriginalConstructor() | ||
128 | ->getMock(); | ||
129 | |||
130 | $graby->expects($this->any()) | ||
131 | ->method('fetchContent') | ||
132 | ->willReturn([ | ||
133 | 'html' => str_repeat('this is my content', 325), | ||
134 | 'title' => 'this is my title', | ||
135 | 'url' => 'http://1.1.1.1', | ||
136 | 'content_type' => 'text/html', | ||
137 | 'language' => 'fr', | ||
138 | 'open_graph' => [ | ||
139 | 'og_title' => 'my OG title', | ||
140 | 'og_description' => 'OG desc', | ||
141 | 'og_image' => 'http://3.3.3.3/cover.jpg', | ||
142 | ], | ||
143 | ]); | ||
144 | |||
145 | $proxy = new ContentProxy($graby, $tagger, $this->getTagRepositoryMock(), $this->getLogger()); | ||
146 | $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0'); | ||
147 | |||
148 | $this->assertEquals('http://1.1.1.1', $entry->getUrl()); | ||
149 | $this->assertEquals('this is my title', $entry->getTitle()); | ||
150 | $this->assertContains('this is my content', $entry->getContent()); | ||
151 | $this->assertEquals('http://3.3.3.3/cover.jpg', $entry->getPreviewPicture()); | ||
152 | $this->assertEquals('text/html', $entry->getMimetype()); | ||
153 | $this->assertEquals('fr', $entry->getLanguage()); | ||
154 | $this->assertEquals(4.0, $entry->getReadingTime()); | ||
155 | $this->assertEquals('1.1.1.1', $entry->getDomainName()); | ||
156 | } | ||
157 | |||
158 | public function testWithForcedContent() | ||
159 | { | ||
160 | $tagger = $this->getTaggerMock(); | ||
161 | $tagger->expects($this->once()) | ||
162 | ->method('tag'); | ||
163 | |||
164 | $graby = $this->getMockBuilder('Graby\Graby')->getMock(); | ||
165 | |||
166 | $proxy = new ContentProxy($graby, $tagger, $this->getTagRepositoryMock(), $this->getLogger()); | ||
167 | $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0', [ | ||
168 | 'html' => str_repeat('this is my content', 325), | ||
169 | 'title' => 'this is my title', | ||
170 | 'url' => 'http://1.1.1.1', | ||
171 | 'content_type' => 'text/html', | ||
172 | 'language' => 'fr', | ||
173 | ]); | ||
174 | |||
175 | $this->assertEquals('http://1.1.1.1', $entry->getUrl()); | ||
176 | $this->assertEquals('this is my title', $entry->getTitle()); | ||
177 | $this->assertContains('this is my content', $entry->getContent()); | ||
178 | $this->assertEquals('text/html', $entry->getMimetype()); | ||
179 | $this->assertEquals('fr', $entry->getLanguage()); | ||
180 | $this->assertEquals(4.0, $entry->getReadingTime()); | ||
181 | $this->assertEquals('1.1.1.1', $entry->getDomainName()); | ||
182 | } | ||
183 | |||
184 | public function testTaggerThrowException() | ||
185 | { | ||
186 | $graby = $this->getMockBuilder('Graby\Graby') | ||
187 | ->disableOriginalConstructor() | ||
188 | ->getMock(); | ||
189 | |||
190 | $tagger = $this->getTaggerMock(); | ||
191 | $tagger->expects($this->once()) | ||
192 | ->method('tag') | ||
193 | ->will($this->throwException(new \Exception())); | ||
194 | |||
195 | $tagRepo = $this->getTagRepositoryMock(); | ||
196 | $proxy = new ContentProxy($graby, $tagger, $tagRepo, $this->getLogger()); | ||
197 | |||
198 | $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0', [ | ||
199 | 'html' => str_repeat('this is my content', 325), | ||
200 | 'title' => 'this is my title', | ||
201 | 'url' => 'http://1.1.1.1', | ||
202 | 'content_type' => 'text/html', | ||
203 | 'language' => 'fr', | ||
204 | ]); | ||
205 | |||
206 | $this->assertCount(0, $entry->getTags()); | ||
207 | } | ||
208 | |||
209 | public function testAssignTagsWithArrayAndExtraSpaces() | ||
210 | { | ||
211 | $graby = $this->getMockBuilder('Graby\Graby') | ||
212 | ->disableOriginalConstructor() | ||
213 | ->getMock(); | ||
214 | |||
215 | $tagRepo = $this->getTagRepositoryMock(); | ||
216 | $proxy = new ContentProxy($graby, $this->getTaggerMock(), $tagRepo, $this->getLogger()); | ||
217 | |||
218 | $entry = new Entry(new User()); | ||
219 | |||
220 | $proxy->assignTagsToEntry($entry, [' tag1', 'tag2 ']); | ||
221 | |||
222 | $this->assertCount(2, $entry->getTags()); | ||
223 | $this->assertEquals('tag1', $entry->getTags()[0]->getLabel()); | ||
224 | $this->assertEquals('tag2', $entry->getTags()[1]->getLabel()); | ||
225 | } | ||
226 | |||
227 | public function testAssignTagsWithString() | ||
228 | { | ||
229 | $graby = $this->getMockBuilder('Graby\Graby') | ||
230 | ->disableOriginalConstructor() | ||
231 | ->getMock(); | ||
232 | |||
233 | $tagRepo = $this->getTagRepositoryMock(); | ||
234 | $proxy = new ContentProxy($graby, $this->getTaggerMock(), $tagRepo, $this->getLogger()); | ||
235 | |||
236 | $entry = new Entry(new User()); | ||
237 | |||
238 | $proxy->assignTagsToEntry($entry, 'tag1, tag2'); | ||
239 | |||
240 | $this->assertCount(2, $entry->getTags()); | ||
241 | $this->assertEquals('tag1', $entry->getTags()[0]->getLabel()); | ||
242 | $this->assertEquals('tag2', $entry->getTags()[1]->getLabel()); | ||
243 | } | ||
244 | |||
245 | public function testAssignTagsWithEmptyArray() | ||
246 | { | ||
247 | $graby = $this->getMockBuilder('Graby\Graby') | ||
248 | ->disableOriginalConstructor() | ||
249 | ->getMock(); | ||
250 | |||
251 | $tagRepo = $this->getTagRepositoryMock(); | ||
252 | $proxy = new ContentProxy($graby, $this->getTaggerMock(), $tagRepo, $this->getLogger()); | ||
253 | |||
254 | $entry = new Entry(new User()); | ||
255 | |||
256 | $proxy->assignTagsToEntry($entry, []); | ||
257 | |||
258 | $this->assertCount(0, $entry->getTags()); | ||
259 | } | ||
260 | |||
261 | public function testAssignTagsWithEmptyString() | ||
262 | { | ||
263 | $graby = $this->getMockBuilder('Graby\Graby') | ||
264 | ->disableOriginalConstructor() | ||
265 | ->getMock(); | ||
266 | |||
267 | $tagRepo = $this->getTagRepositoryMock(); | ||
268 | $proxy = new ContentProxy($graby, $this->getTaggerMock(), $tagRepo, $this->getLogger()); | ||
269 | |||
270 | $entry = new Entry(new User()); | ||
271 | |||
272 | $proxy->assignTagsToEntry($entry, ''); | ||
273 | |||
274 | $this->assertCount(0, $entry->getTags()); | ||
275 | } | ||
276 | |||
277 | public function testAssignTagsAlreadyAssigned() | ||
278 | { | ||
279 | $graby = $this->getMockBuilder('Graby\Graby') | ||
280 | ->disableOriginalConstructor() | ||
281 | ->getMock(); | ||
282 | |||
283 | $tagRepo = $this->getTagRepositoryMock(); | ||
284 | $proxy = new ContentProxy($graby, $this->getTaggerMock(), $tagRepo, $this->getLogger()); | ||
285 | |||
286 | $tagEntity = new Tag(); | ||
287 | $tagEntity->setLabel('tag1'); | ||
288 | |||
289 | $entry = new Entry(new User()); | ||
290 | $entry->addTag($tagEntity); | ||
291 | |||
292 | $proxy->assignTagsToEntry($entry, 'tag1, tag2'); | ||
293 | |||
294 | $this->assertCount(2, $entry->getTags()); | ||
295 | $this->assertEquals('tag1', $entry->getTags()[0]->getLabel()); | ||
296 | $this->assertEquals('tag2', $entry->getTags()[1]->getLabel()); | ||
297 | } | ||
298 | |||
299 | private function getTaggerMock() | ||
300 | { | ||
301 | return $this->getMockBuilder('Wallabag\CoreBundle\Helper\RuleBasedTagger') | ||
302 | ->setMethods(['tag']) | ||
303 | ->disableOriginalConstructor() | ||
304 | ->getMock(); | ||
305 | } | ||
306 | |||
307 | private function getTagRepositoryMock() | ||
308 | { | ||
309 | return $this->getMockBuilder('Wallabag\CoreBundle\Repository\TagRepository') | ||
310 | ->disableOriginalConstructor() | ||
311 | ->getMock(); | ||
312 | } | ||
313 | |||
314 | private function getLogger() | ||
315 | { | ||
316 | return new NullLogger(); | ||
317 | } | ||
318 | } | ||
diff --git a/src/Wallabag/CoreBundle/Tests/Helper/RedirectTest.php b/src/Wallabag/CoreBundle/Tests/Helper/RedirectTest.php deleted file mode 100644 index f4aecc80..00000000 --- a/src/Wallabag/CoreBundle/Tests/Helper/RedirectTest.php +++ /dev/null | |||
@@ -1,55 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\CoreBundle\Tests\Helper; | ||
4 | |||
5 | use Wallabag\CoreBundle\Helper\Redirect; | ||
6 | |||
7 | class RedirectTest extends \PHPUnit_Framework_TestCase | ||
8 | { | ||
9 | /** @var \PHPUnit_Framework_MockObject_MockObject */ | ||
10 | private $routerMock; | ||
11 | |||
12 | /** @var Redirect */ | ||
13 | private $redirect; | ||
14 | |||
15 | public function setUp() | ||
16 | { | ||
17 | $this->routerMock = $this->getRouterMock(); | ||
18 | $this->redirect = new Redirect($this->routerMock); | ||
19 | } | ||
20 | |||
21 | public function testRedirectToNullWithFallback() | ||
22 | { | ||
23 | $redirectUrl = $this->redirect->to(null, 'fallback'); | ||
24 | |||
25 | $this->assertEquals('fallback', $redirectUrl); | ||
26 | } | ||
27 | |||
28 | public function testRedirectToNullWithoutFallback() | ||
29 | { | ||
30 | $redirectUrl = $this->redirect->to(null); | ||
31 | |||
32 | $this->assertEquals($this->routerMock->generate('homepage'), $redirectUrl); | ||
33 | } | ||
34 | |||
35 | public function testRedirectToValidUrl() | ||
36 | { | ||
37 | $redirectUrl = $this->redirect->to('/unread/list'); | ||
38 | |||
39 | $this->assertEquals('/unread/list', $redirectUrl); | ||
40 | } | ||
41 | |||
42 | private function getRouterMock() | ||
43 | { | ||
44 | $mock = $this->getMockBuilder('Symfony\Component\Routing\Router') | ||
45 | ->disableOriginalConstructor() | ||
46 | ->getMock(); | ||
47 | |||
48 | $mock->expects($this->any()) | ||
49 | ->method('generate') | ||
50 | ->with('homepage') | ||
51 | ->willReturn('homepage'); | ||
52 | |||
53 | return $mock; | ||
54 | } | ||
55 | } | ||
diff --git a/src/Wallabag/CoreBundle/Tests/Helper/RuleBasedTaggerTest.php b/src/Wallabag/CoreBundle/Tests/Helper/RuleBasedTaggerTest.php deleted file mode 100644 index e9025b45..00000000 --- a/src/Wallabag/CoreBundle/Tests/Helper/RuleBasedTaggerTest.php +++ /dev/null | |||
@@ -1,212 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\CoreBundle\Tests\Helper; | ||
4 | |||
5 | use Wallabag\CoreBundle\Entity\Config; | ||
6 | use Wallabag\CoreBundle\Entity\Entry; | ||
7 | use Wallabag\CoreBundle\Entity\Tag; | ||
8 | use Wallabag\CoreBundle\Entity\TaggingRule; | ||
9 | use Wallabag\CoreBundle\Helper\RuleBasedTagger; | ||
10 | use Wallabag\UserBundle\Entity\User; | ||
11 | |||
12 | class RuleBasedTaggerTest extends \PHPUnit_Framework_TestCase | ||
13 | { | ||
14 | private $rulerz; | ||
15 | private $tagRepository; | ||
16 | private $entryRepository; | ||
17 | private $tagger; | ||
18 | |||
19 | public function setUp() | ||
20 | { | ||
21 | $this->rulerz = $this->getRulerZMock(); | ||
22 | $this->tagRepository = $this->getTagRepositoryMock(); | ||
23 | $this->entryRepository = $this->getEntryRepositoryMock(); | ||
24 | |||
25 | $this->tagger = new RuleBasedTagger($this->rulerz, $this->tagRepository, $this->entryRepository); | ||
26 | } | ||
27 | |||
28 | public function testTagWithNoRule() | ||
29 | { | ||
30 | $entry = new Entry($this->getUser()); | ||
31 | |||
32 | $this->tagger->tag($entry); | ||
33 | |||
34 | $this->assertTrue($entry->getTags()->isEmpty()); | ||
35 | } | ||
36 | |||
37 | public function testTagWithNoMatchingRule() | ||
38 | { | ||
39 | $taggingRule = $this->getTaggingRule('rule as string', ['foo', 'bar']); | ||
40 | $user = $this->getUser([$taggingRule]); | ||
41 | $entry = new Entry($user); | ||
42 | |||
43 | $this->rulerz | ||
44 | ->expects($this->once()) | ||
45 | ->method('satisfies') | ||
46 | ->with($entry, 'rule as string') | ||
47 | ->willReturn(false); | ||
48 | |||
49 | $this->tagger->tag($entry); | ||
50 | |||
51 | $this->assertTrue($entry->getTags()->isEmpty()); | ||
52 | } | ||
53 | |||
54 | public function testTagWithAMatchingRule() | ||
55 | { | ||
56 | $taggingRule = $this->getTaggingRule('rule as string', ['foo', 'bar']); | ||
57 | $user = $this->getUser([$taggingRule]); | ||
58 | $entry = new Entry($user); | ||
59 | |||
60 | $this->rulerz | ||
61 | ->expects($this->once()) | ||
62 | ->method('satisfies') | ||
63 | ->with($entry, 'rule as string') | ||
64 | ->willReturn(true); | ||
65 | |||
66 | $this->tagger->tag($entry); | ||
67 | |||
68 | $this->assertFalse($entry->getTags()->isEmpty()); | ||
69 | |||
70 | $tags = $entry->getTags(); | ||
71 | $this->assertSame('foo', $tags[0]->getLabel()); | ||
72 | $this->assertSame('bar', $tags[1]->getLabel()); | ||
73 | } | ||
74 | |||
75 | public function testTagWithAMixOfMatchingRules() | ||
76 | { | ||
77 | $taggingRule = $this->getTaggingRule('bla bla', ['hey']); | ||
78 | $otherTaggingRule = $this->getTaggingRule('rule as string', ['foo']); | ||
79 | |||
80 | $user = $this->getUser([$taggingRule, $otherTaggingRule]); | ||
81 | $entry = new Entry($user); | ||
82 | |||
83 | $this->rulerz | ||
84 | ->method('satisfies') | ||
85 | ->will($this->onConsecutiveCalls(false, true)); | ||
86 | |||
87 | $this->tagger->tag($entry); | ||
88 | |||
89 | $this->assertFalse($entry->getTags()->isEmpty()); | ||
90 | |||
91 | $tags = $entry->getTags(); | ||
92 | $this->assertSame('foo', $tags[0]->getLabel()); | ||
93 | } | ||
94 | |||
95 | public function testWhenTheTagExists() | ||
96 | { | ||
97 | $taggingRule = $this->getTaggingRule('rule as string', ['foo']); | ||
98 | $user = $this->getUser([$taggingRule]); | ||
99 | $entry = new Entry($user); | ||
100 | $tag = new Tag(); | ||
101 | |||
102 | $this->rulerz | ||
103 | ->expects($this->once()) | ||
104 | ->method('satisfies') | ||
105 | ->with($entry, 'rule as string') | ||
106 | ->willReturn(true); | ||
107 | |||
108 | $this->tagRepository | ||
109 | ->expects($this->once()) | ||
110 | // the method `findOneByLabel` doesn't exist, EntityRepository will then call `_call` method | ||
111 | // to magically call the `findOneBy` with ['label' => 'foo'] | ||
112 | ->method('__call') | ||
113 | ->willReturn($tag); | ||
114 | |||
115 | $this->tagger->tag($entry); | ||
116 | |||
117 | $this->assertFalse($entry->getTags()->isEmpty()); | ||
118 | |||
119 | $tags = $entry->getTags(); | ||
120 | $this->assertSame($tag, $tags[0]); | ||
121 | } | ||
122 | |||
123 | public function testSameTagWithDifferentfMatchingRules() | ||
124 | { | ||
125 | $taggingRule = $this->getTaggingRule('bla bla', ['hey']); | ||
126 | $otherTaggingRule = $this->getTaggingRule('rule as string', ['hey']); | ||
127 | |||
128 | $user = $this->getUser([$taggingRule, $otherTaggingRule]); | ||
129 | $entry = new Entry($user); | ||
130 | |||
131 | $this->rulerz | ||
132 | ->method('satisfies') | ||
133 | ->willReturn(true); | ||
134 | |||
135 | $this->tagger->tag($entry); | ||
136 | |||
137 | $this->assertFalse($entry->getTags()->isEmpty()); | ||
138 | |||
139 | $tags = $entry->getTags(); | ||
140 | $this->assertCount(1, $tags); | ||
141 | } | ||
142 | |||
143 | public function testTagAllEntriesForAUser() | ||
144 | { | ||
145 | $taggingRule = $this->getTaggingRule('bla bla', ['hey']); | ||
146 | |||
147 | $user = $this->getUser([$taggingRule]); | ||
148 | |||
149 | $this->rulerz | ||
150 | ->method('satisfies') | ||
151 | ->willReturn(true); | ||
152 | |||
153 | $this->rulerz | ||
154 | ->method('filter') | ||
155 | ->willReturn([new Entry($user), new Entry($user)]); | ||
156 | |||
157 | $entries = $this->tagger->tagAllForUser($user); | ||
158 | |||
159 | $this->assertCount(2, $entries); | ||
160 | |||
161 | foreach ($entries as $entry) { | ||
162 | $tags = $entry->getTags(); | ||
163 | |||
164 | $this->assertCount(1, $tags); | ||
165 | $this->assertEquals('hey', $tags[0]->getLabel()); | ||
166 | } | ||
167 | } | ||
168 | |||
169 | private function getUser(array $taggingRules = []) | ||
170 | { | ||
171 | $user = new User(); | ||
172 | $config = new Config($user); | ||
173 | |||
174 | $user->setConfig($config); | ||
175 | |||
176 | foreach ($taggingRules as $rule) { | ||
177 | $config->addTaggingRule($rule); | ||
178 | } | ||
179 | |||
180 | return $user; | ||
181 | } | ||
182 | |||
183 | private function getTaggingRule($rule, array $tags) | ||
184 | { | ||
185 | $taggingRule = new TaggingRule(); | ||
186 | $taggingRule->setRule($rule); | ||
187 | $taggingRule->setTags($tags); | ||
188 | |||
189 | return $taggingRule; | ||
190 | } | ||
191 | |||
192 | private function getRulerZMock() | ||
193 | { | ||
194 | return $this->getMockBuilder('RulerZ\RulerZ') | ||
195 | ->disableOriginalConstructor() | ||
196 | ->getMock(); | ||
197 | } | ||
198 | |||
199 | private function getTagRepositoryMock() | ||
200 | { | ||
201 | return $this->getMockBuilder('Wallabag\CoreBundle\Repository\TagRepository') | ||
202 | ->disableOriginalConstructor() | ||
203 | ->getMock(); | ||
204 | } | ||
205 | |||
206 | private function getEntryRepositoryMock() | ||
207 | { | ||
208 | return $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') | ||
209 | ->disableOriginalConstructor() | ||
210 | ->getMock(); | ||
211 | } | ||
212 | } | ||