aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php150
-rw-r--r--tests/Wallabag/AnnotationBundle/WallabagAnnotationTestCase.php6
-rw-r--r--tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php19
-rw-r--r--tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php104
-rw-r--r--tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php265
-rw-r--r--tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php60
-rw-r--r--tests/Wallabag/CoreBundle/Event/Listener/LocaleListenerTest.php (renamed from tests/Wallabag/CoreBundle/EventListener/LocaleListenerTest.php)4
-rw-r--r--tests/Wallabag/CoreBundle/Event/Listener/UserLocaleListenerTest.php (renamed from tests/Wallabag/CoreBundle/EventListener/UserLocaleListenerTest.php)4
-rw-r--r--tests/Wallabag/CoreBundle/Event/Subscriber/TablePrefixSubscriberTest.php (renamed from tests/Wallabag/CoreBundle/Subscriber/TablePrefixSubscriberTest.php)4
-rw-r--r--tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php143
-rw-r--r--tests/Wallabag/CoreBundle/fixtures/unnamed.pngbin0 -> 3688 bytes
-rw-r--r--tests/Wallabag/ImportBundle/Consumer/AMQPEntryConsumerTest.php33
-rw-r--r--tests/Wallabag/ImportBundle/Consumer/RedisEntryConsumerTest.php33
-rw-r--r--tests/Wallabag/ImportBundle/Import/ChromeImportTest.php16
-rw-r--r--tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php16
-rw-r--r--tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php16
-rw-r--r--tests/Wallabag/ImportBundle/Import/PocketImportTest.php21
-rw-r--r--tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php16
-rw-r--r--tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php16
-rw-r--r--tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php18
20 files changed, 811 insertions, 133 deletions
diff --git a/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php b/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php
index 70849f74..81f9e9ec 100644
--- a/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php
+++ b/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php
@@ -3,35 +3,80 @@
3namespace Tests\AnnotationBundle\Controller; 3namespace Tests\AnnotationBundle\Controller;
4 4
5use Tests\Wallabag\AnnotationBundle\WallabagAnnotationTestCase; 5use Tests\Wallabag\AnnotationBundle\WallabagAnnotationTestCase;
6use Wallabag\AnnotationBundle\Entity\Annotation;
7use Wallabag\CoreBundle\Entity\Entry;
6 8
7class AnnotationControllerTest extends WallabagAnnotationTestCase 9class AnnotationControllerTest extends WallabagAnnotationTestCase
8{ 10{
9 public function testGetAnnotations() 11 /**
12 * This data provider allow to tests annotation from the :
13 * - API POV (when user use the api to manage annotations)
14 * - and User POV (when user use the web interface - using javascript - to manage annotations).
15 */
16 public function dataForEachAnnotations()
10 { 17 {
11 $annotation = $this->client->getContainer() 18 return [
12 ->get('doctrine.orm.entity_manager') 19 ['/api/annotations'],
13 ->getRepository('WallabagAnnotationBundle:Annotation') 20 ['annotations'],
14 ->findOneByUsername('admin'); 21 ];
22 }
23
24 /**
25 * Test fetching annotations for an entry.
26 *
27 * @dataProvider dataForEachAnnotations
28 */
29 public function testGetAnnotations($prefixUrl)
30 {
31 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
32
33 $user = $em
34 ->getRepository('WallabagUserBundle:User')
35 ->findOneByUserName('admin');
36 $entry = $em
37 ->getRepository('WallabagCoreBundle:Entry')
38 ->findOneByUsernameAndNotArchived('admin');
15 39
16 if (!$annotation) { 40 $annotation = new Annotation($user);
17 $this->markTestSkipped('No content found in db.'); 41 $annotation->setEntry($entry);
42 $annotation->setText('This is my annotation /o/');
43 $annotation->setQuote('content');
44
45 $em->persist($annotation);
46 $em->flush();
47
48 if ('annotations' === $prefixUrl) {
49 $this->logInAs('admin');
18 } 50 }
19 51
20 $this->logInAs('admin'); 52 $this->client->request('GET', $prefixUrl.'/'.$entry->getId().'.json');
21 $crawler = $this->client->request('GET', 'annotations/'.$annotation->getEntry()->getId().'.json');
22 $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); 53 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
23 54
24 $content = json_decode($this->client->getResponse()->getContent(), true); 55 $content = json_decode($this->client->getResponse()->getContent(), true);
25 $this->assertEquals(1, $content['total']); 56 $this->assertGreaterThanOrEqual(1, $content['total']);
26 $this->assertEquals($annotation->getText(), $content['rows'][0]['text']); 57 $this->assertEquals($annotation->getText(), $content['rows'][0]['text']);
58
59 // we need to re-fetch the annotation becase after the flush, it has been "detached" from the entity manager
60 $annotation = $em->getRepository('WallabagAnnotationBundle:Annotation')->findAnnotationById($annotation->getId());
61 $em->remove($annotation);
62 $em->flush();
27 } 63 }
28 64
29 public function testSetAnnotation() 65 /**
66 * Test creating an annotation for an entry.
67 *
68 * @dataProvider dataForEachAnnotations
69 */
70 public function testSetAnnotation($prefixUrl)
30 { 71 {
31 $this->logInAs('admin'); 72 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
32 73
33 $entry = $this->client->getContainer() 74 if ('annotations' === $prefixUrl) {
34 ->get('doctrine.orm.entity_manager') 75 $this->logInAs('admin');
76 }
77
78 /** @var Entry $entry */
79 $entry = $em
35 ->getRepository('WallabagCoreBundle:Entry') 80 ->getRepository('WallabagCoreBundle:Entry')
36 ->findOneByUsernameAndNotArchived('admin'); 81 ->findOneByUsernameAndNotArchived('admin');
37 82
@@ -41,7 +86,7 @@ class AnnotationControllerTest extends WallabagAnnotationTestCase
41 'quote' => 'my quote', 86 'quote' => 'my quote',
42 'ranges' => ['start' => '', 'startOffset' => 24, 'end' => '', 'endOffset' => 31], 87 'ranges' => ['start' => '', 'startOffset' => 24, 'end' => '', 'endOffset' => 31],
43 ]); 88 ]);
44 $crawler = $this->client->request('POST', 'annotations/'.$entry->getId().'.json', [], [], $headers, $content); 89 $this->client->request('POST', $prefixUrl.'/'.$entry->getId().'.json', [], [], $headers, $content);
45 90
46 $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); 91 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
47 92
@@ -52,6 +97,7 @@ class AnnotationControllerTest extends WallabagAnnotationTestCase
52 $this->assertEquals('my annotation', $content['text']); 97 $this->assertEquals('my annotation', $content['text']);
53 $this->assertEquals('my quote', $content['quote']); 98 $this->assertEquals('my quote', $content['quote']);
54 99
100 /** @var Annotation $annotation */
55 $annotation = $this->client->getContainer() 101 $annotation = $this->client->getContainer()
56 ->get('doctrine.orm.entity_manager') 102 ->get('doctrine.orm.entity_manager')
57 ->getRepository('WallabagAnnotationBundle:Annotation') 103 ->getRepository('WallabagAnnotationBundle:Annotation')
@@ -60,20 +106,35 @@ class AnnotationControllerTest extends WallabagAnnotationTestCase
60 $this->assertEquals('my annotation', $annotation->getText()); 106 $this->assertEquals('my annotation', $annotation->getText());
61 } 107 }
62 108
63 public function testEditAnnotation() 109 /**
110 * Test editing an existing annotation.
111 *
112 * @dataProvider dataForEachAnnotations
113 */
114 public function testEditAnnotation($prefixUrl)
64 { 115 {
65 $annotation = $this->client->getContainer() 116 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
66 ->get('doctrine.orm.entity_manager')
67 ->getRepository('WallabagAnnotationBundle:Annotation')
68 ->findOneByUsername('admin');
69 117
70 $this->logInAs('admin'); 118 $user = $em
119 ->getRepository('WallabagUserBundle:User')
120 ->findOneByUserName('admin');
121 $entry = $em
122 ->getRepository('WallabagCoreBundle:Entry')
123 ->findOneByUsernameAndNotArchived('admin');
124
125 $annotation = new Annotation($user);
126 $annotation->setEntry($entry);
127 $annotation->setText('This is my annotation /o/');
128 $annotation->setQuote('my quote');
129
130 $em->persist($annotation);
131 $em->flush();
71 132
72 $headers = ['CONTENT_TYPE' => 'application/json']; 133 $headers = ['CONTENT_TYPE' => 'application/json'];
73 $content = json_encode([ 134 $content = json_encode([
74 'text' => 'a modified annotation', 135 'text' => 'a modified annotation',
75 ]); 136 ]);
76 $crawler = $this->client->request('PUT', 'annotations/'.$annotation->getId().'.json', [], [], $headers, $content); 137 $this->client->request('PUT', $prefixUrl.'/'.$annotation->getId().'.json', [], [], $headers, $content);
77 $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); 138 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
78 139
79 $content = json_decode($this->client->getResponse()->getContent(), true); 140 $content = json_decode($this->client->getResponse()->getContent(), true);
@@ -83,35 +144,56 @@ class AnnotationControllerTest extends WallabagAnnotationTestCase
83 $this->assertEquals('a modified annotation', $content['text']); 144 $this->assertEquals('a modified annotation', $content['text']);
84 $this->assertEquals('my quote', $content['quote']); 145 $this->assertEquals('my quote', $content['quote']);
85 146
86 $annotationUpdated = $this->client->getContainer() 147 /** @var Annotation $annotationUpdated */
87 ->get('doctrine.orm.entity_manager') 148 $annotationUpdated = $em
88 ->getRepository('WallabagAnnotationBundle:Annotation') 149 ->getRepository('WallabagAnnotationBundle:Annotation')
89 ->findOneById($annotation->getId()); 150 ->findOneById($annotation->getId());
90 $this->assertEquals('a modified annotation', $annotationUpdated->getText()); 151 $this->assertEquals('a modified annotation', $annotationUpdated->getText());
152
153 $em->remove($annotationUpdated);
154 $em->flush();
91 } 155 }
92 156
93 public function testDeleteAnnotation() 157 /**
158 * Test deleting an annotation.
159 *
160 * @dataProvider dataForEachAnnotations
161 */
162 public function testDeleteAnnotation($prefixUrl)
94 { 163 {
95 $annotation = $this->client->getContainer() 164 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
96 ->get('doctrine.orm.entity_manager')
97 ->getRepository('WallabagAnnotationBundle:Annotation')
98 ->findOneByUsername('admin');
99 165
100 $this->logInAs('admin'); 166 $user = $em
167 ->getRepository('WallabagUserBundle:User')
168 ->findOneByUserName('admin');
169 $entry = $em
170 ->getRepository('WallabagCoreBundle:Entry')
171 ->findOneByUsernameAndNotArchived('admin');
172
173 $annotation = new Annotation($user);
174 $annotation->setEntry($entry);
175 $annotation->setText('This is my annotation /o/');
176 $annotation->setQuote('my quote');
177
178 $em->persist($annotation);
179 $em->flush();
180
181 if ('annotations' === $prefixUrl) {
182 $this->logInAs('admin');
183 }
101 184
102 $headers = ['CONTENT_TYPE' => 'application/json']; 185 $headers = ['CONTENT_TYPE' => 'application/json'];
103 $content = json_encode([ 186 $content = json_encode([
104 'text' => 'a modified annotation', 187 'text' => 'a modified annotation',
105 ]); 188 ]);
106 $crawler = $this->client->request('DELETE', 'annotations/'.$annotation->getId().'.json', [], [], $headers, $content); 189 $this->client->request('DELETE', $prefixUrl.'/'.$annotation->getId().'.json', [], [], $headers, $content);
107 $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); 190 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
108 191
109 $content = json_decode($this->client->getResponse()->getContent(), true); 192 $content = json_decode($this->client->getResponse()->getContent(), true);
110 193
111 $this->assertEquals('a modified annotation', $content['text']); 194 $this->assertEquals('This is my annotation /o/', $content['text']);
112 195
113 $annotationDeleted = $this->client->getContainer() 196 $annotationDeleted = $em
114 ->get('doctrine.orm.entity_manager')
115 ->getRepository('WallabagAnnotationBundle:Annotation') 197 ->getRepository('WallabagAnnotationBundle:Annotation')
116 ->findOneById($annotation->getId()); 198 ->findOneById($annotation->getId());
117 199
diff --git a/tests/Wallabag/AnnotationBundle/WallabagAnnotationTestCase.php b/tests/Wallabag/AnnotationBundle/WallabagAnnotationTestCase.php
index 82790a5c..ef3f1324 100644
--- a/tests/Wallabag/AnnotationBundle/WallabagAnnotationTestCase.php
+++ b/tests/Wallabag/AnnotationBundle/WallabagAnnotationTestCase.php
@@ -8,7 +8,7 @@ use Symfony\Component\BrowserKit\Cookie;
8abstract class WallabagAnnotationTestCase extends WebTestCase 8abstract class WallabagAnnotationTestCase extends WebTestCase
9{ 9{
10 /** 10 /**
11 * @var Client 11 * @var \Symfony\Bundle\FrameworkBundle\Client
12 */ 12 */
13 protected $client = null; 13 protected $client = null;
14 14
@@ -35,7 +35,7 @@ abstract class WallabagAnnotationTestCase extends WebTestCase
35 } 35 }
36 36
37 /** 37 /**
38 * @return Client 38 * @return \Symfony\Bundle\FrameworkBundle\Client
39 */ 39 */
40 protected function createAuthorizedClient() 40 protected function createAuthorizedClient()
41 { 41 {
@@ -49,7 +49,7 @@ abstract class WallabagAnnotationTestCase extends WebTestCase
49 $firewallName = $container->getParameter('fos_user.firewall_name'); 49 $firewallName = $container->getParameter('fos_user.firewall_name');
50 50
51 $this->user = $userManager->findUserBy(['username' => 'admin']); 51 $this->user = $userManager->findUserBy(['username' => 'admin']);
52 $loginManager->loginUser($firewallName, $this->user); 52 $loginManager->logInUser($firewallName, $this->user);
53 53
54 // save the login token into the session and put it in a cookie 54 // save the login token into the session and put it in a cookie
55 $container->get('session')->set('_security_'.$firewallName, serialize($container->get('security.token_storage')->getToken())); 55 $container->get('session')->set('_security_'.$firewallName, serialize($container->get('security.token_storage')->getToken()));
diff --git a/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php b/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php
index 95befa9c..6659443b 100644
--- a/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php
+++ b/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php
@@ -82,11 +82,24 @@ class DeveloperControllerTest extends WallabagCoreTestCase
82 82
83 public function testRemoveClient() 83 public function testRemoveClient()
84 { 84 {
85 $this->logInAs('admin');
86 $client = $this->getClient(); 85 $client = $this->getClient();
87 $em = $client->getContainer()->get('doctrine.orm.entity_manager'); 86 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
88 $nbClients = $em->getRepository('WallabagApiBundle:Client')->findAll();
89 87
88 // Try to remove an admin's client with a wrong user
89 $this->logInAs('bob');
90 $client->request('GET', '/developer');
91 $this->assertContains('no_client', $client->getResponse()->getContent());
92
93 // get an ID of a admin's client
94 $this->logInAs('admin');
95 $nbClients = $em->getRepository('WallabagApiBundle:Client')->findByUser($this->getLoggedInUserId());
96
97 $this->logInAs('bob');
98 $client->request('GET', '/developer/client/delete/'.$nbClients[0]->getId());
99 $this->assertEquals(403, $client->getResponse()->getStatusCode());
100
101 // Try to remove the admin's client with the good user
102 $this->logInAs('admin');
90 $crawler = $client->request('GET', '/developer'); 103 $crawler = $client->request('GET', '/developer');
91 104
92 $link = $crawler 105 $link = $crawler
@@ -98,7 +111,7 @@ class DeveloperControllerTest extends WallabagCoreTestCase
98 $client->click($link); 111 $client->click($link);
99 $this->assertEquals(302, $client->getResponse()->getStatusCode()); 112 $this->assertEquals(302, $client->getResponse()->getStatusCode());
100 113
101 $newNbClients = $em->getRepository('WallabagApiBundle:Client')->findAll(); 114 $newNbClients = $em->getRepository('WallabagApiBundle:Client')->findByUser($this->getLoggedInUserId());
102 $this->assertGreaterThan(count($newNbClients), count($nbClients)); 115 $this->assertGreaterThan(count($newNbClients), count($nbClients));
103 } 116 }
104} 117}
diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
index 825f8f7a..566e9493 100644
--- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
+++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
@@ -30,12 +30,55 @@ class EntryRestControllerTest extends WallabagApiTestCase
30 $this->assertEquals($entry->getUserEmail(), $content['user_email']); 30 $this->assertEquals($entry->getUserEmail(), $content['user_email']);
31 $this->assertEquals($entry->getUserId(), $content['user_id']); 31 $this->assertEquals($entry->getUserId(), $content['user_id']);
32 32
33 $this->assertTrue( 33 $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type'));
34 $this->client->getResponse()->headers->contains( 34 }
35 'Content-Type', 35
36 'application/json' 36 public function testExportEntry()
37 ) 37 {
38 ); 38 $entry = $this->client->getContainer()
39 ->get('doctrine.orm.entity_manager')
40 ->getRepository('WallabagCoreBundle:Entry')
41 ->findOneBy(['user' => 1, 'isArchived' => false]);
42
43 if (!$entry) {
44 $this->markTestSkipped('No content found in db.');
45 }
46
47 $this->client->request('GET', '/api/entries/'.$entry->getId().'/export.epub');
48 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
49
50 // epub format got the content type in the content
51 $this->assertContains('application/epub', $this->client->getResponse()->getContent());
52 $this->assertEquals('application/epub+zip', $this->client->getResponse()->headers->get('Content-Type'));
53
54 // re-auth client for mobi
55 $client = $this->createAuthorizedClient();
56 $client->request('GET', '/api/entries/'.$entry->getId().'/export.mobi');
57 $this->assertEquals(200, $client->getResponse()->getStatusCode());
58
59 $this->assertEquals('application/x-mobipocket-ebook', $client->getResponse()->headers->get('Content-Type'));
60
61 // re-auth client for pdf
62 $client = $this->createAuthorizedClient();
63 $client->request('GET', '/api/entries/'.$entry->getId().'/export.pdf');
64 $this->assertEquals(200, $client->getResponse()->getStatusCode());
65
66 $this->assertContains('PDF-', $client->getResponse()->getContent());
67 $this->assertEquals('application/pdf', $client->getResponse()->headers->get('Content-Type'));
68
69 // re-auth client for pdf
70 $client = $this->createAuthorizedClient();
71 $client->request('GET', '/api/entries/'.$entry->getId().'/export.txt');
72 $this->assertEquals(200, $client->getResponse()->getStatusCode());
73
74 $this->assertContains('text/plain', $client->getResponse()->headers->get('Content-Type'));
75
76 // re-auth client for pdf
77 $client = $this->createAuthorizedClient();
78 $client->request('GET', '/api/entries/'.$entry->getId().'/export.csv');
79 $this->assertEquals(200, $client->getResponse()->getStatusCode());
80
81 $this->assertContains('application/csv', $client->getResponse()->headers->get('Content-Type'));
39 } 82 }
40 83
41 public function testGetOneEntryWrongUser() 84 public function testGetOneEntryWrongUser()
@@ -68,12 +111,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
68 $this->assertEquals(1, $content['page']); 111 $this->assertEquals(1, $content['page']);
69 $this->assertGreaterThanOrEqual(1, $content['pages']); 112 $this->assertGreaterThanOrEqual(1, $content['pages']);
70 113
71 $this->assertTrue( 114 $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type'));
72 $this->client->getResponse()->headers->contains(
73 'Content-Type',
74 'application/json'
75 )
76 );
77 } 115 }
78 116
79 public function testGetEntriesWithFullOptions() 117 public function testGetEntriesWithFullOptions()
@@ -115,12 +153,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
115 $this->assertContains('since=1443274283', $content['_links'][$link]['href']); 153 $this->assertContains('since=1443274283', $content['_links'][$link]['href']);
116 } 154 }
117 155
118 $this->assertTrue( 156 $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type'));
119 $this->client->getResponse()->headers->contains(
120 'Content-Type',
121 'application/json'
122 )
123 );
124 } 157 }
125 158
126 public function testGetStarredEntries() 159 public function testGetStarredEntries()
@@ -148,12 +181,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
148 $this->assertContains('sort=updated', $content['_links'][$link]['href']); 181 $this->assertContains('sort=updated', $content['_links'][$link]['href']);
149 } 182 }
150 183
151 $this->assertTrue( 184 $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type'));
152 $this->client->getResponse()->headers->contains(
153 'Content-Type',
154 'application/json'
155 )
156 );
157 } 185 }
158 186
159 public function testGetArchiveEntries() 187 public function testGetArchiveEntries()
@@ -180,12 +208,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
180 $this->assertContains('archive=1', $content['_links'][$link]['href']); 208 $this->assertContains('archive=1', $content['_links'][$link]['href']);
181 } 209 }
182 210
183 $this->assertTrue( 211 $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type'));
184 $this->client->getResponse()->headers->contains(
185 'Content-Type',
186 'application/json'
187 )
188 );
189 } 212 }
190 213
191 public function testGetTaggedEntries() 214 public function testGetTaggedEntries()
@@ -212,12 +235,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
212 $this->assertContains('tags='.urlencode('foo,bar'), $content['_links'][$link]['href']); 235 $this->assertContains('tags='.urlencode('foo,bar'), $content['_links'][$link]['href']);
213 } 236 }
214 237
215 $this->assertTrue( 238 $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type'));
216 $this->client->getResponse()->headers->contains(
217 'Content-Type',
218 'application/json'
219 )
220 );
221 } 239 }
222 240
223 public function testGetDatedEntries() 241 public function testGetDatedEntries()
@@ -244,12 +262,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
244 $this->assertContains('since=1443274283', $content['_links'][$link]['href']); 262 $this->assertContains('since=1443274283', $content['_links'][$link]['href']);
245 } 263 }
246 264
247 $this->assertTrue( 265 $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type'));
248 $this->client->getResponse()->headers->contains(
249 'Content-Type',
250 'application/json'
251 )
252 );
253 } 266 }
254 267
255 public function testGetDatedSupEntries() 268 public function testGetDatedSupEntries()
@@ -277,12 +290,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
277 $this->assertContains('since='.($future->getTimestamp() + 1000), $content['_links'][$link]['href']); 290 $this->assertContains('since='.($future->getTimestamp() + 1000), $content['_links'][$link]['href']);
278 } 291 }
279 292
280 $this->assertTrue( 293 $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type'));
281 $this->client->getResponse()->headers->contains(
282 'Content-Type',
283 'application/json'
284 )
285 );
286 } 294 }
287 295
288 public function testDeleteEntry() 296 public function testDeleteEntry()
diff --git a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
index 1954c654..8d0644d1 100644
--- a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
@@ -3,6 +3,11 @@
3namespace Tests\Wallabag\CoreBundle\Controller; 3namespace Tests\Wallabag\CoreBundle\Controller;
4 4
5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; 5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
6use Wallabag\CoreBundle\Entity\Config;
7use Wallabag\UserBundle\Entity\User;
8use Wallabag\CoreBundle\Entity\Entry;
9use Wallabag\CoreBundle\Entity\Tag;
10use Wallabag\AnnotationBundle\Entity\Annotation;
6 11
7class ConfigControllerTest extends WallabagCoreTestCase 12class ConfigControllerTest extends WallabagCoreTestCase
8{ 13{
@@ -570,4 +575,264 @@ class ConfigControllerTest extends WallabagCoreTestCase
570 $config->set('demo_mode_enabled', 0); 575 $config->set('demo_mode_enabled', 0);
571 $config->set('demo_mode_username', 'wallabag'); 576 $config->set('demo_mode_username', 'wallabag');
572 } 577 }
578
579 public function testDeleteUserButtonVisibility()
580 {
581 $this->logInAs('admin');
582 $client = $this->getClient();
583
584 $crawler = $client->request('GET', '/config');
585
586 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
587 $this->assertContains('config.form_user.delete.button', $body[0]);
588
589 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
590
591 $user = $em
592 ->getRepository('WallabagUserBundle:User')
593 ->findOneByUsername('empty');
594 $user->setExpired(1);
595 $em->persist($user);
596
597 $user = $em
598 ->getRepository('WallabagUserBundle:User')
599 ->findOneByUsername('bob');
600 $user->setExpired(1);
601 $em->persist($user);
602
603 $em->flush();
604
605 $crawler = $client->request('GET', '/config');
606
607 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
608 $this->assertNotContains('config.form_user.delete.button', $body[0]);
609
610 $client->request('GET', '/account/delete');
611 $this->assertEquals(403, $client->getResponse()->getStatusCode());
612
613 $user = $em
614 ->getRepository('WallabagUserBundle:User')
615 ->findOneByUsername('empty');
616 $user->setExpired(0);
617 $em->persist($user);
618
619 $user = $em
620 ->getRepository('WallabagUserBundle:User')
621 ->findOneByUsername('bob');
622 $user->setExpired(0);
623 $em->persist($user);
624
625 $em->flush();
626 }
627
628 public function testDeleteAccount()
629 {
630 $client = $this->getClient();
631 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
632
633 $user = new User();
634 $user->setName('Wallace');
635 $user->setEmail('wallace@wallabag.org');
636 $user->setUsername('wallace');
637 $user->setPlainPassword('wallace');
638 $user->setEnabled(true);
639 $user->addRole('ROLE_SUPER_ADMIN');
640
641 $em->persist($user);
642
643 $config = new Config($user);
644
645 $config->setTheme('material');
646 $config->setItemsPerPage(30);
647 $config->setReadingSpeed(1);
648 $config->setLanguage('en');
649 $config->setPocketConsumerKey('xxxxx');
650
651 $em->persist($config);
652 $em->flush();
653
654 $this->logInAs('wallace');
655 $loggedInUserId = $this->getLoggedInUserId();
656
657 // create entry to check after user deletion
658 // that this entry is also deleted
659 $crawler = $client->request('GET', '/new');
660
661 $this->assertEquals(200, $client->getResponse()->getStatusCode());
662
663 $form = $crawler->filter('form[name=entry]')->form();
664 $data = [
665 'entry[url]' => $url = 'https://github.com/wallabag/wallabag',
666 ];
667
668 $client->submit($form, $data);
669 $this->assertEquals(302, $client->getResponse()->getStatusCode());
670
671 $crawler = $client->request('GET', '/config');
672
673 $deleteLink = $crawler->filter('.delete-account')->last()->link();
674
675 $client->click($deleteLink);
676 $this->assertEquals(302, $client->getResponse()->getStatusCode());
677
678 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
679 $user = $em
680 ->getRepository('WallabagUserBundle:User')
681 ->createQueryBuilder('u')
682 ->where('u.username = :username')->setParameter('username', 'wallace')
683 ->getQuery()
684 ->getOneOrNullResult()
685 ;
686
687 $this->assertNull($user);
688
689 $entries = $client->getContainer()
690 ->get('doctrine.orm.entity_manager')
691 ->getRepository('WallabagCoreBundle:Entry')
692 ->findByUser($loggedInUserId);
693
694 $this->assertEmpty($entries);
695 }
696
697 public function testReset()
698 {
699 $this->logInAs('empty');
700 $client = $this->getClient();
701
702 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
703
704 $user = static::$kernel->getContainer()->get('security.token_storage')->getToken()->getUser();
705
706 $tag = new Tag();
707 $tag->setLabel('super');
708 $em->persist($tag);
709
710 $entry = new Entry($user);
711 $entry->setUrl('http://www.lemonde.fr/europe/article/2016/10/01/pour-le-psoe-chaque-election-s-est-transformee-en-une-agonie_5006476_3214.html');
712 $entry->setContent('Youhou');
713 $entry->setTitle('Youhou');
714 $entry->addTag($tag);
715 $em->persist($entry);
716
717 $entry2 = new Entry($user);
718 $entry2->setUrl('http://www.lemonde.de/europe/article/2016/10/01/pour-le-psoe-chaque-election-s-est-transformee-en-une-agonie_5006476_3214.html');
719 $entry2->setContent('Youhou');
720 $entry2->setTitle('Youhou');
721 $entry2->addTag($tag);
722 $em->persist($entry2);
723
724 $annotation = new Annotation($user);
725 $annotation->setText('annotated');
726 $annotation->setQuote('annotated');
727 $annotation->setRanges([]);
728 $annotation->setEntry($entry);
729 $em->persist($annotation);
730
731 $em->flush();
732
733 // reset annotations
734 $crawler = $client->request('GET', '/config#set3');
735
736 $this->assertEquals(200, $client->getResponse()->getStatusCode());
737
738 $crawler = $client->click($crawler->selectLink('config.reset.annotations')->link());
739
740 $this->assertEquals(302, $client->getResponse()->getStatusCode());
741 $this->assertContains('flashes.config.notice.annotations_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]);
742
743 $annotationsReset = $em
744 ->getRepository('WallabagAnnotationBundle:Annotation')
745 ->findAnnotationsByPageId($entry->getId(), $user->getId());
746
747 $this->assertEmpty($annotationsReset, 'Annotations were reset');
748
749 // reset tags
750 $crawler = $client->request('GET', '/config#set3');
751
752 $this->assertEquals(200, $client->getResponse()->getStatusCode());
753
754 $crawler = $client->click($crawler->selectLink('config.reset.tags')->link());
755
756 $this->assertEquals(302, $client->getResponse()->getStatusCode());
757 $this->assertContains('flashes.config.notice.tags_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]);
758
759 $tagReset = $em
760 ->getRepository('WallabagCoreBundle:Tag')
761 ->countAllTags($user->getId());
762
763 $this->assertEquals(0, $tagReset, 'Tags were reset');
764
765 // reset entries
766 $crawler = $client->request('GET', '/config#set3');
767
768 $this->assertEquals(200, $client->getResponse()->getStatusCode());
769
770 $crawler = $client->click($crawler->selectLink('config.reset.entries')->link());
771
772 $this->assertEquals(302, $client->getResponse()->getStatusCode());
773 $this->assertContains('flashes.config.notice.entries_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]);
774
775 $entryReset = $em
776 ->getRepository('WallabagCoreBundle:Entry')
777 ->countAllEntriesByUsername($user->getId());
778
779 $this->assertEquals(0, $entryReset, 'Entries were reset');
780 }
781
782 public function testResetEntriesCascade()
783 {
784 $this->logInAs('empty');
785 $client = $this->getClient();
786
787 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
788
789 $user = static::$kernel->getContainer()->get('security.token_storage')->getToken()->getUser();
790
791 $tag = new Tag();
792 $tag->setLabel('super');
793 $em->persist($tag);
794
795 $entry = new Entry($user);
796 $entry->setUrl('http://www.lemonde.fr/europe/article/2016/10/01/pour-le-psoe-chaque-election-s-est-transformee-en-une-agonie_5006476_3214.html');
797 $entry->setContent('Youhou');
798 $entry->setTitle('Youhou');
799 $entry->addTag($tag);
800 $em->persist($entry);
801
802 $annotation = new Annotation($user);
803 $annotation->setText('annotated');
804 $annotation->setQuote('annotated');
805 $annotation->setRanges([]);
806 $annotation->setEntry($entry);
807 $em->persist($annotation);
808
809 $em->flush();
810
811 $crawler = $client->request('GET', '/config#set3');
812
813 $this->assertEquals(200, $client->getResponse()->getStatusCode());
814
815 $crawler = $client->click($crawler->selectLink('config.reset.entries')->link());
816
817 $this->assertEquals(302, $client->getResponse()->getStatusCode());
818 $this->assertContains('flashes.config.notice.entries_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]);
819
820 $entryReset = $em
821 ->getRepository('WallabagCoreBundle:Entry')
822 ->countAllEntriesByUsername($user->getId());
823
824 $this->assertEquals(0, $entryReset, 'Entries were reset');
825
826 $tagReset = $em
827 ->getRepository('WallabagCoreBundle:Tag')
828 ->countAllTags($user->getId());
829
830 $this->assertEquals(0, $tagReset, 'Tags were reset');
831
832 $annotationsReset = $em
833 ->getRepository('WallabagAnnotationBundle:Annotation')
834 ->findAnnotationsByPageId($entry->getId(), $user->getId());
835
836 $this->assertEmpty($annotationsReset, 'Annotations were reset');
837 }
573} 838}
diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
index 05113650..4ab06dbf 100644
--- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
@@ -836,4 +836,64 @@ class EntryControllerTest extends WallabagCoreTestCase
836 $client->request('GET', '/share/'.$content->getUuid()); 836 $client->request('GET', '/share/'.$content->getUuid());
837 $this->assertEquals(404, $client->getResponse()->getStatusCode()); 837 $this->assertEquals(404, $client->getResponse()->getStatusCode());
838 } 838 }
839
840 public function testNewEntryWithDownloadImagesEnabled()
841 {
842 $this->logInAs('admin');
843 $client = $this->getClient();
844
845 $url = 'http://www.20minutes.fr/montpellier/1952003-20161030-video-car-tombe-panne-rugbymen-perpignan-improvisent-melee-route';
846 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
847
848 $crawler = $client->request('GET', '/new');
849
850 $this->assertEquals(200, $client->getResponse()->getStatusCode());
851
852 $form = $crawler->filter('form[name=entry]')->form();
853
854 $data = [
855 'entry[url]' => $url,
856 ];
857
858 $client->submit($form, $data);
859
860 $this->assertEquals(302, $client->getResponse()->getStatusCode());
861
862 $em = $client->getContainer()
863 ->get('doctrine.orm.entity_manager');
864
865 $entry = $em
866 ->getRepository('WallabagCoreBundle:Entry')
867 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
868
869 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $entry);
870 $this->assertEquals($url, $entry->getUrl());
871 $this->assertContains('Perpignan', $entry->getTitle());
872 $this->assertContains('/d9bc0fcd.jpeg', $entry->getContent());
873
874 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
875 }
876
877 /**
878 * @depends testNewEntryWithDownloadImagesEnabled
879 */
880 public function testRemoveEntryWithDownloadImagesEnabled()
881 {
882 $this->logInAs('admin');
883 $client = $this->getClient();
884
885 $url = 'http://www.20minutes.fr/montpellier/1952003-20161030-video-car-tombe-panne-rugbymen-perpignan-improvisent-melee-route';
886 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
887
888 $content = $client->getContainer()
889 ->get('doctrine.orm.entity_manager')
890 ->getRepository('WallabagCoreBundle:Entry')
891 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
892
893 $client->request('GET', '/delete/'.$content->getId());
894
895 $this->assertEquals(302, $client->getResponse()->getStatusCode());
896
897 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
898 }
839} 899}
diff --git a/tests/Wallabag/CoreBundle/EventListener/LocaleListenerTest.php b/tests/Wallabag/CoreBundle/Event/Listener/LocaleListenerTest.php
index 078bb69a..84a54d3a 100644
--- a/tests/Wallabag/CoreBundle/EventListener/LocaleListenerTest.php
+++ b/tests/Wallabag/CoreBundle/Event/Listener/LocaleListenerTest.php
@@ -1,6 +1,6 @@
1<?php 1<?php
2 2
3namespace Tests\Wallabag\CoreBundle\EventListener; 3namespace Tests\Wallabag\CoreBundle\Event\Listener;
4 4
5use Symfony\Component\EventDispatcher\EventDispatcher; 5use Symfony\Component\EventDispatcher\EventDispatcher;
6use Symfony\Component\HttpFoundation\Request; 6use Symfony\Component\HttpFoundation\Request;
@@ -9,7 +9,7 @@ use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
9use Symfony\Component\HttpKernel\Event\GetResponseEvent; 9use Symfony\Component\HttpKernel\Event\GetResponseEvent;
10use Symfony\Component\HttpKernel\HttpKernelInterface; 10use Symfony\Component\HttpKernel\HttpKernelInterface;
11use Symfony\Component\HttpKernel\KernelEvents; 11use Symfony\Component\HttpKernel\KernelEvents;
12use Wallabag\CoreBundle\EventListener\LocaleListener; 12use Wallabag\CoreBundle\Event\Listener\LocaleListener;
13 13
14class LocaleListenerTest extends \PHPUnit_Framework_TestCase 14class LocaleListenerTest extends \PHPUnit_Framework_TestCase
15{ 15{
diff --git a/tests/Wallabag/CoreBundle/EventListener/UserLocaleListenerTest.php b/tests/Wallabag/CoreBundle/Event/Listener/UserLocaleListenerTest.php
index e9ac7c1d..45aecc63 100644
--- a/tests/Wallabag/CoreBundle/EventListener/UserLocaleListenerTest.php
+++ b/tests/Wallabag/CoreBundle/Event/Listener/UserLocaleListenerTest.php
@@ -1,6 +1,6 @@
1<?php 1<?php
2 2
3namespace Tests\Wallabag\CoreBundle\EventListener; 3namespace Tests\Wallabag\CoreBundle\Event\Listener;
4 4
5use Symfony\Component\HttpFoundation\Request; 5use Symfony\Component\HttpFoundation\Request;
6use Symfony\Component\HttpFoundation\Session\Session; 6use Symfony\Component\HttpFoundation\Session\Session;
@@ -8,7 +8,7 @@ use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
8use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; 8use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
9use Symfony\Component\Security\Http\Event\InteractiveLoginEvent; 9use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
10use Wallabag\CoreBundle\Entity\Config; 10use Wallabag\CoreBundle\Entity\Config;
11use Wallabag\CoreBundle\EventListener\UserLocaleListener; 11use Wallabag\CoreBundle\Event\Listener\UserLocaleListener;
12use Wallabag\UserBundle\Entity\User; 12use Wallabag\UserBundle\Entity\User;
13 13
14class UserLocaleListenerTest extends \PHPUnit_Framework_TestCase 14class UserLocaleListenerTest extends \PHPUnit_Framework_TestCase
diff --git a/tests/Wallabag/CoreBundle/Subscriber/TablePrefixSubscriberTest.php b/tests/Wallabag/CoreBundle/Event/Subscriber/TablePrefixSubscriberTest.php
index 4ae76703..b8cd0fad 100644
--- a/tests/Wallabag/CoreBundle/Subscriber/TablePrefixSubscriberTest.php
+++ b/tests/Wallabag/CoreBundle/Event/Subscriber/TablePrefixSubscriberTest.php
@@ -1,11 +1,11 @@
1<?php 1<?php
2 2
3namespace Tests\Wallabag\CoreBundle\Subscriber; 3namespace Tests\Wallabag\CoreBundle\Event\Subscriber;
4 4
5use Doctrine\Common\EventManager; 5use Doctrine\Common\EventManager;
6use Doctrine\ORM\Event\LoadClassMetadataEventArgs; 6use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
7use Doctrine\ORM\Mapping\ClassMetadata; 7use Doctrine\ORM\Mapping\ClassMetadata;
8use Wallabag\CoreBundle\Subscriber\TablePrefixSubscriber; 8use Wallabag\CoreBundle\Event\Subscriber\TablePrefixSubscriber;
9 9
10class TablePrefixSubscriberTest extends \PHPUnit_Framework_TestCase 10class TablePrefixSubscriberTest extends \PHPUnit_Framework_TestCase
11{ 11{
diff --git a/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php b/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php
new file mode 100644
index 00000000..920c21d9
--- /dev/null
+++ b/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php
@@ -0,0 +1,143 @@
1<?php
2
3namespace Tests\Wallabag\CoreBundle\Helper;
4
5use Wallabag\CoreBundle\Helper\DownloadImages;
6use Psr\Log\NullLogger;
7use Monolog\Logger;
8use Monolog\Handler\TestHandler;
9use GuzzleHttp\Client;
10use GuzzleHttp\Subscriber\Mock;
11use GuzzleHttp\Message\Response;
12use GuzzleHttp\Stream\Stream;
13
14class DownloadImagesTest extends \PHPUnit_Framework_TestCase
15{
16 public function testProcessHtml()
17 {
18 $client = new Client();
19
20 $mock = new Mock([
21 new Response(200, ['content-type' => 'image/png'], Stream::factory(file_get_contents(__DIR__.'/../fixtures/unnamed.png'))),
22 ]);
23
24 $client->getEmitter()->attach($mock);
25
26 $logHandler = new TestHandler();
27 $logger = new Logger('test', array($logHandler));
28
29 $download = new DownloadImages($client, sys_get_temp_dir().'/wallabag_test', 'http://wallabag.io/', $logger);
30
31 $res = $download->processHtml(123, '<div><img src="http://i.imgur.com/T9qgcHc.jpg" /></div>', 'http://imgur.com/gallery/WxtWY');
32
33 $this->assertContains('http://wallabag.io/assets/images/9/b/9b0ead26/c638b4c2.png', $res);
34 }
35
36 public function testProcessHtmlWithBadImage()
37 {
38 $client = new Client();
39
40 $mock = new Mock([
41 new Response(200, ['content-type' => 'application/json'], Stream::factory('')),
42 ]);
43
44 $client->getEmitter()->attach($mock);
45
46 $logHandler = new TestHandler();
47 $logger = new Logger('test', array($logHandler));
48
49 $download = new DownloadImages($client, sys_get_temp_dir().'/wallabag_test', 'http://wallabag.io/', $logger);
50 $res = $download->processHtml(123, '<div><img src="http://i.imgur.com/T9qgcHc.jpg" /></div>', 'http://imgur.com/gallery/WxtWY');
51
52 $this->assertContains('http://i.imgur.com/T9qgcHc.jpg', $res, 'Image were not replace because of content-type');
53 }
54
55 public function singleImage()
56 {
57 return [
58 ['image/pjpeg', 'jpeg'],
59 ['image/jpeg', 'jpeg'],
60 ['image/png', 'png'],
61 ['image/gif', 'gif'],
62 ];
63 }
64
65 /**
66 * @dataProvider singleImage
67 */
68 public function testProcessSingleImage($header, $extension)
69 {
70 $client = new Client();
71
72 $mock = new Mock([
73 new Response(200, ['content-type' => $header], Stream::factory(file_get_contents(__DIR__.'/../fixtures/unnamed.png'))),
74 ]);
75
76 $client->getEmitter()->attach($mock);
77
78 $logHandler = new TestHandler();
79 $logger = new Logger('test', array($logHandler));
80
81 $download = new DownloadImages($client, sys_get_temp_dir().'/wallabag_test', 'http://wallabag.io/', $logger);
82 $res = $download->processSingleImage(123, 'T9qgcHc.jpg', 'http://imgur.com/gallery/WxtWY');
83
84 $this->assertContains('/assets/images/9/b/9b0ead26/ebe60399.'.$extension, $res);
85 }
86
87 public function testProcessSingleImageWithBadUrl()
88 {
89 $client = new Client();
90
91 $mock = new Mock([
92 new Response(404, []),
93 ]);
94
95 $client->getEmitter()->attach($mock);
96
97 $logHandler = new TestHandler();
98 $logger = new Logger('test', array($logHandler));
99
100 $download = new DownloadImages($client, sys_get_temp_dir().'/wallabag_test', 'http://wallabag.io/', $logger);
101 $res = $download->processSingleImage(123, 'T9qgcHc.jpg', 'http://imgur.com/gallery/WxtWY');
102
103 $this->assertFalse($res, 'Image can not be found, so it will not be replaced');
104 }
105
106 public function testProcessSingleImageWithBadImage()
107 {
108 $client = new Client();
109
110 $mock = new Mock([
111 new Response(200, ['content-type' => 'image/png'], Stream::factory('')),
112 ]);
113
114 $client->getEmitter()->attach($mock);
115
116 $logHandler = new TestHandler();
117 $logger = new Logger('test', array($logHandler));
118
119 $download = new DownloadImages($client, sys_get_temp_dir().'/wallabag_test', 'http://wallabag.io/', $logger);
120 $res = $download->processSingleImage(123, 'http://i.imgur.com/T9qgcHc.jpg', 'http://imgur.com/gallery/WxtWY');
121
122 $this->assertFalse($res, 'Image can not be loaded, so it will not be replaced');
123 }
124
125 public function testProcessSingleImageFailAbsolute()
126 {
127 $client = new Client();
128
129 $mock = new Mock([
130 new Response(200, ['content-type' => 'image/png'], Stream::factory(file_get_contents(__DIR__.'/../fixtures/unnamed.png'))),
131 ]);
132
133 $client->getEmitter()->attach($mock);
134
135 $logHandler = new TestHandler();
136 $logger = new Logger('test', array($logHandler));
137
138 $download = new DownloadImages($client, sys_get_temp_dir().'/wallabag_test', 'http://wallabag.io/', $logger);
139 $res = $download->processSingleImage(123, '/i.imgur.com/T9qgcHc.jpg', 'imgur.com/gallery/WxtWY');
140
141 $this->assertFalse($res, 'Absolute image can not be determined, so it will not be replaced');
142 }
143}
diff --git a/tests/Wallabag/CoreBundle/fixtures/unnamed.png b/tests/Wallabag/CoreBundle/fixtures/unnamed.png
new file mode 100644
index 00000000..e6dd9caa
--- /dev/null
+++ b/tests/Wallabag/CoreBundle/fixtures/unnamed.png
Binary files differ
diff --git a/tests/Wallabag/ImportBundle/Consumer/AMQPEntryConsumerTest.php b/tests/Wallabag/ImportBundle/Consumer/AMQPEntryConsumerTest.php
index a3263771..856954a6 100644
--- a/tests/Wallabag/ImportBundle/Consumer/AMQPEntryConsumerTest.php
+++ b/tests/Wallabag/ImportBundle/Consumer/AMQPEntryConsumerTest.php
@@ -112,10 +112,19 @@ JSON;
112 ->with(json_decode($body, true)) 112 ->with(json_decode($body, true))
113 ->willReturn($entry); 113 ->willReturn($entry);
114 114
115 $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
116 ->disableOriginalConstructor()
117 ->getMock();
118
119 $dispatcher
120 ->expects($this->once())
121 ->method('dispatch');
122
115 $consumer = new AMQPEntryConsumer( 123 $consumer = new AMQPEntryConsumer(
116 $em, 124 $em,
117 $userRepository, 125 $userRepository,
118 $import 126 $import,
127 $dispatcher
119 ); 128 );
120 129
121 $message = new AMQPMessage($body); 130 $message = new AMQPMessage($body);
@@ -157,10 +166,19 @@ JSON;
157 ->disableOriginalConstructor() 166 ->disableOriginalConstructor()
158 ->getMock(); 167 ->getMock();
159 168
169 $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
170 ->disableOriginalConstructor()
171 ->getMock();
172
173 $dispatcher
174 ->expects($this->never())
175 ->method('dispatch');
176
160 $consumer = new AMQPEntryConsumer( 177 $consumer = new AMQPEntryConsumer(
161 $em, 178 $em,
162 $userRepository, 179 $userRepository,
163 $import 180 $import,
181 $dispatcher
164 ); 182 );
165 183
166 $message = new AMQPMessage($body); 184 $message = new AMQPMessage($body);
@@ -212,10 +230,19 @@ JSON;
212 ->with(json_decode($body, true)) 230 ->with(json_decode($body, true))
213 ->willReturn(null); 231 ->willReturn(null);
214 232
233 $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
234 ->disableOriginalConstructor()
235 ->getMock();
236
237 $dispatcher
238 ->expects($this->never())
239 ->method('dispatch');
240
215 $consumer = new AMQPEntryConsumer( 241 $consumer = new AMQPEntryConsumer(
216 $em, 242 $em,
217 $userRepository, 243 $userRepository,
218 $import 244 $import,
245 $dispatcher
219 ); 246 );
220 247
221 $message = new AMQPMessage($body); 248 $message = new AMQPMessage($body);
diff --git a/tests/Wallabag/ImportBundle/Consumer/RedisEntryConsumerTest.php b/tests/Wallabag/ImportBundle/Consumer/RedisEntryConsumerTest.php
index 01a92ad2..3b92f759 100644
--- a/tests/Wallabag/ImportBundle/Consumer/RedisEntryConsumerTest.php
+++ b/tests/Wallabag/ImportBundle/Consumer/RedisEntryConsumerTest.php
@@ -111,10 +111,19 @@ JSON;
111 ->with(json_decode($body, true)) 111 ->with(json_decode($body, true))
112 ->willReturn($entry); 112 ->willReturn($entry);
113 113
114 $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
115 ->disableOriginalConstructor()
116 ->getMock();
117
118 $dispatcher
119 ->expects($this->once())
120 ->method('dispatch');
121
114 $consumer = new RedisEntryConsumer( 122 $consumer = new RedisEntryConsumer(
115 $em, 123 $em,
116 $userRepository, 124 $userRepository,
117 $import 125 $import,
126 $dispatcher
118 ); 127 );
119 128
120 $res = $consumer->manage($body); 129 $res = $consumer->manage($body);
@@ -156,10 +165,19 @@ JSON;
156 ->disableOriginalConstructor() 165 ->disableOriginalConstructor()
157 ->getMock(); 166 ->getMock();
158 167
168 $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
169 ->disableOriginalConstructor()
170 ->getMock();
171
172 $dispatcher
173 ->expects($this->never())
174 ->method('dispatch');
175
159 $consumer = new RedisEntryConsumer( 176 $consumer = new RedisEntryConsumer(
160 $em, 177 $em,
161 $userRepository, 178 $userRepository,
162 $import 179 $import,
180 $dispatcher
163 ); 181 );
164 182
165 $res = $consumer->manage($body); 183 $res = $consumer->manage($body);
@@ -211,10 +229,19 @@ JSON;
211 ->with(json_decode($body, true)) 229 ->with(json_decode($body, true))
212 ->willReturn(null); 230 ->willReturn(null);
213 231
232 $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
233 ->disableOriginalConstructor()
234 ->getMock();
235
236 $dispatcher
237 ->expects($this->never())
238 ->method('dispatch');
239
214 $consumer = new RedisEntryConsumer( 240 $consumer = new RedisEntryConsumer(
215 $em, 241 $em,
216 $userRepository, 242 $userRepository,
217 $import 243 $import,
244 $dispatcher
218 ); 245 );
219 246
220 $res = $consumer->manage($body); 247 $res = $consumer->manage($body);
diff --git a/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php b/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php
index 1e52615c..6b3adda4 100644
--- a/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php
+++ b/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php
@@ -18,7 +18,7 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase
18 protected $logHandler; 18 protected $logHandler;
19 protected $contentProxy; 19 protected $contentProxy;
20 20
21 private function getChromeImport($unsetUser = false) 21 private function getChromeImport($unsetUser = false, $dispatched = 0)
22 { 22 {
23 $this->user = new User(); 23 $this->user = new User();
24 24
@@ -30,7 +30,15 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase
30 ->disableOriginalConstructor() 30 ->disableOriginalConstructor()
31 ->getMock(); 31 ->getMock();
32 32
33 $wallabag = new ChromeImport($this->em, $this->contentProxy); 33 $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
34 ->disableOriginalConstructor()
35 ->getMock();
36
37 $dispatcher
38 ->expects($this->exactly($dispatched))
39 ->method('dispatch');
40
41 $wallabag = new ChromeImport($this->em, $this->contentProxy, $dispatcher);
34 42
35 $this->logHandler = new TestHandler(); 43 $this->logHandler = new TestHandler();
36 $logger = new Logger('test', [$this->logHandler]); 44 $logger = new Logger('test', [$this->logHandler]);
@@ -54,7 +62,7 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase
54 62
55 public function testImport() 63 public function testImport()
56 { 64 {
57 $chromeImport = $this->getChromeImport(); 65 $chromeImport = $this->getChromeImport(false, 1);
58 $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks'); 66 $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks');
59 67
60 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 68 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
@@ -87,7 +95,7 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase
87 95
88 public function testImportAndMarkAllAsRead() 96 public function testImportAndMarkAllAsRead()
89 { 97 {
90 $chromeImport = $this->getChromeImport(); 98 $chromeImport = $this->getChromeImport(false, 1);
91 $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks'); 99 $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks');
92 100
93 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 101 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
diff --git a/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php b/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php
index 007dda6a..b516fbc5 100644
--- a/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php
+++ b/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php
@@ -18,7 +18,7 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase
18 protected $logHandler; 18 protected $logHandler;
19 protected $contentProxy; 19 protected $contentProxy;
20 20
21 private function getFirefoxImport($unsetUser = false) 21 private function getFirefoxImport($unsetUser = false, $dispatched = 0)
22 { 22 {
23 $this->user = new User(); 23 $this->user = new User();
24 24
@@ -30,7 +30,15 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase
30 ->disableOriginalConstructor() 30 ->disableOriginalConstructor()
31 ->getMock(); 31 ->getMock();
32 32
33 $wallabag = new FirefoxImport($this->em, $this->contentProxy); 33 $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
34 ->disableOriginalConstructor()
35 ->getMock();
36
37 $dispatcher
38 ->expects($this->exactly($dispatched))
39 ->method('dispatch');
40
41 $wallabag = new FirefoxImport($this->em, $this->contentProxy, $dispatcher);
34 42
35 $this->logHandler = new TestHandler(); 43 $this->logHandler = new TestHandler();
36 $logger = new Logger('test', [$this->logHandler]); 44 $logger = new Logger('test', [$this->logHandler]);
@@ -54,7 +62,7 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase
54 62
55 public function testImport() 63 public function testImport()
56 { 64 {
57 $firefoxImport = $this->getFirefoxImport(); 65 $firefoxImport = $this->getFirefoxImport(false, 2);
58 $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json'); 66 $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json');
59 67
60 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 68 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
@@ -87,7 +95,7 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase
87 95
88 public function testImportAndMarkAllAsRead() 96 public function testImportAndMarkAllAsRead()
89 { 97 {
90 $firefoxImport = $this->getFirefoxImport(); 98 $firefoxImport = $this->getFirefoxImport(false, 1);
91 $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json'); 99 $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json');
92 100
93 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 101 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
diff --git a/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php b/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php
index 75900bd7..e262a808 100644
--- a/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php
+++ b/tests/Wallabag/ImportBundle/Import/InstapaperImportTest.php
@@ -18,7 +18,7 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase
18 protected $logHandler; 18 protected $logHandler;
19 protected $contentProxy; 19 protected $contentProxy;
20 20
21 private function getInstapaperImport($unsetUser = false) 21 private function getInstapaperImport($unsetUser = false, $dispatched = 0)
22 { 22 {
23 $this->user = new User(); 23 $this->user = new User();
24 24
@@ -30,7 +30,15 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase
30 ->disableOriginalConstructor() 30 ->disableOriginalConstructor()
31 ->getMock(); 31 ->getMock();
32 32
33 $import = new InstapaperImport($this->em, $this->contentProxy); 33 $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
34 ->disableOriginalConstructor()
35 ->getMock();
36
37 $dispatcher
38 ->expects($this->exactly($dispatched))
39 ->method('dispatch');
40
41 $import = new InstapaperImport($this->em, $this->contentProxy, $dispatcher);
34 42
35 $this->logHandler = new TestHandler(); 43 $this->logHandler = new TestHandler();
36 $logger = new Logger('test', [$this->logHandler]); 44 $logger = new Logger('test', [$this->logHandler]);
@@ -54,7 +62,7 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase
54 62
55 public function testImport() 63 public function testImport()
56 { 64 {
57 $instapaperImport = $this->getInstapaperImport(); 65 $instapaperImport = $this->getInstapaperImport(false, 3);
58 $instapaperImport->setFilepath(__DIR__.'/../fixtures/instapaper-export.csv'); 66 $instapaperImport->setFilepath(__DIR__.'/../fixtures/instapaper-export.csv');
59 67
60 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 68 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
@@ -87,7 +95,7 @@ class InstapaperImportTest extends \PHPUnit_Framework_TestCase
87 95
88 public function testImportAndMarkAllAsRead() 96 public function testImportAndMarkAllAsRead()
89 { 97 {
90 $instapaperImport = $this->getInstapaperImport(); 98 $instapaperImport = $this->getInstapaperImport(false, 1);
91 $instapaperImport->setFilepath(__DIR__.'/../fixtures/instapaper-export.csv'); 99 $instapaperImport->setFilepath(__DIR__.'/../fixtures/instapaper-export.csv');
92 100
93 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 101 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
diff --git a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php
index 9ec7935c..141ece36 100644
--- a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php
+++ b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php
@@ -24,7 +24,7 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase
24 protected $contentProxy; 24 protected $contentProxy;
25 protected $logHandler; 25 protected $logHandler;
26 26
27 private function getPocketImport($consumerKey = 'ConsumerKey') 27 private function getPocketImport($consumerKey = 'ConsumerKey', $dispatched = 0)
28 { 28 {
29 $this->user = new User(); 29 $this->user = new User();
30 30
@@ -55,10 +55,15 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase
55 ->method('getScheduledEntityInsertions') 55 ->method('getScheduledEntityInsertions')
56 ->willReturn([]); 56 ->willReturn([]);
57 57
58 $pocket = new PocketImport( 58 $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
59 $this->em, 59 ->disableOriginalConstructor()
60 $this->contentProxy 60 ->getMock();
61 ); 61
62 $dispatcher
63 ->expects($this->exactly($dispatched))
64 ->method('dispatch');
65
66 $pocket = new PocketImport($this->em, $this->contentProxy, $dispatcher);
62 $pocket->setUser($this->user); 67 $pocket->setUser($this->user);
63 68
64 $this->logHandler = new TestHandler(); 69 $this->logHandler = new TestHandler();
@@ -252,7 +257,7 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase
252 257
253 $client->getEmitter()->attach($mock); 258 $client->getEmitter()->attach($mock);
254 259
255 $pocketImport = $this->getPocketImport(); 260 $pocketImport = $this->getPocketImport('ConsumerKey', 1);
256 261
257 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 262 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
258 ->disableOriginalConstructor() 263 ->disableOriginalConstructor()
@@ -339,7 +344,7 @@ class PocketImportTest extends \PHPUnit_Framework_TestCase
339 344
340 $client->getEmitter()->attach($mock); 345 $client->getEmitter()->attach($mock);
341 346
342 $pocketImport = $this->getPocketImport(); 347 $pocketImport = $this->getPocketImport('ConsumerKey', 2);
343 348
344 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 349 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
345 ->disableOriginalConstructor() 350 ->disableOriginalConstructor()
@@ -591,7 +596,7 @@ JSON;
591 596
592 $client->getEmitter()->attach($mock); 597 $client->getEmitter()->attach($mock);
593 598
594 $pocketImport = $this->getPocketImport(); 599 $pocketImport = $this->getPocketImport('ConsumerKey', 1);
595 600
596 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 601 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
597 ->disableOriginalConstructor() 602 ->disableOriginalConstructor()
diff --git a/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php
index d98cd486..d1bbe648 100644
--- a/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php
+++ b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php
@@ -18,7 +18,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase
18 protected $logHandler; 18 protected $logHandler;
19 protected $contentProxy; 19 protected $contentProxy;
20 20
21 private function getReadabilityImport($unsetUser = false) 21 private function getReadabilityImport($unsetUser = false, $dispatched = 0)
22 { 22 {
23 $this->user = new User(); 23 $this->user = new User();
24 24
@@ -30,7 +30,15 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase
30 ->disableOriginalConstructor() 30 ->disableOriginalConstructor()
31 ->getMock(); 31 ->getMock();
32 32
33 $wallabag = new ReadabilityImport($this->em, $this->contentProxy); 33 $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
34 ->disableOriginalConstructor()
35 ->getMock();
36
37 $dispatcher
38 ->expects($this->exactly($dispatched))
39 ->method('dispatch');
40
41 $wallabag = new ReadabilityImport($this->em, $this->contentProxy, $dispatcher);
34 42
35 $this->logHandler = new TestHandler(); 43 $this->logHandler = new TestHandler();
36 $logger = new Logger('test', [$this->logHandler]); 44 $logger = new Logger('test', [$this->logHandler]);
@@ -54,7 +62,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase
54 62
55 public function testImport() 63 public function testImport()
56 { 64 {
57 $readabilityImport = $this->getReadabilityImport(); 65 $readabilityImport = $this->getReadabilityImport(false, 24);
58 $readabilityImport->setFilepath(__DIR__.'/../fixtures/readability.json'); 66 $readabilityImport->setFilepath(__DIR__.'/../fixtures/readability.json');
59 67
60 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 68 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
@@ -87,7 +95,7 @@ class ReadabilityImportTest extends \PHPUnit_Framework_TestCase
87 95
88 public function testImportAndMarkAllAsRead() 96 public function testImportAndMarkAllAsRead()
89 { 97 {
90 $readabilityImport = $this->getReadabilityImport(); 98 $readabilityImport = $this->getReadabilityImport(false, 1);
91 $readabilityImport->setFilepath(__DIR__.'/../fixtures/readability-read.json'); 99 $readabilityImport->setFilepath(__DIR__.'/../fixtures/readability-read.json');
92 100
93 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 101 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
diff --git a/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php b/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php
index 82dc4c7e..4dbced60 100644
--- a/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php
+++ b/tests/Wallabag/ImportBundle/Import/WallabagV1ImportTest.php
@@ -18,7 +18,7 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
18 protected $logHandler; 18 protected $logHandler;
19 protected $contentProxy; 19 protected $contentProxy;
20 20
21 private function getWallabagV1Import($unsetUser = false) 21 private function getWallabagV1Import($unsetUser = false, $dispatched = 0)
22 { 22 {
23 $this->user = new User(); 23 $this->user = new User();
24 24
@@ -44,7 +44,15 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
44 ->disableOriginalConstructor() 44 ->disableOriginalConstructor()
45 ->getMock(); 45 ->getMock();
46 46
47 $wallabag = new WallabagV1Import($this->em, $this->contentProxy); 47 $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
48 ->disableOriginalConstructor()
49 ->getMock();
50
51 $dispatcher
52 ->expects($this->exactly($dispatched))
53 ->method('dispatch');
54
55 $wallabag = new WallabagV1Import($this->em, $this->contentProxy, $dispatcher);
48 56
49 $this->logHandler = new TestHandler(); 57 $this->logHandler = new TestHandler();
50 $logger = new Logger('test', [$this->logHandler]); 58 $logger = new Logger('test', [$this->logHandler]);
@@ -68,7 +76,7 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
68 76
69 public function testImport() 77 public function testImport()
70 { 78 {
71 $wallabagV1Import = $this->getWallabagV1Import(); 79 $wallabagV1Import = $this->getWallabagV1Import(false, 3);
72 $wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v1.json'); 80 $wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v1.json');
73 81
74 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 82 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
@@ -101,7 +109,7 @@ class WallabagV1ImportTest extends \PHPUnit_Framework_TestCase
101 109
102 public function testImportAndMarkAllAsRead() 110 public function testImportAndMarkAllAsRead()
103 { 111 {
104 $wallabagV1Import = $this->getWallabagV1Import(); 112 $wallabagV1Import = $this->getWallabagV1Import(false, 3);
105 $wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v1-read.json'); 113 $wallabagV1Import->setFilepath(__DIR__.'/../fixtures/wallabag-v1-read.json');
106 114
107 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 115 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
diff --git a/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php b/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php
index bea89efb..0e50b8b2 100644
--- a/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php
+++ b/tests/Wallabag/ImportBundle/Import/WallabagV2ImportTest.php
@@ -18,7 +18,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase
18 protected $logHandler; 18 protected $logHandler;
19 protected $contentProxy; 19 protected $contentProxy;
20 20
21 private function getWallabagV2Import($unsetUser = false) 21 private function getWallabagV2Import($unsetUser = false, $dispatched = 0)
22 { 22 {
23 $this->user = new User(); 23 $this->user = new User();
24 24
@@ -44,7 +44,15 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase
44 ->disableOriginalConstructor() 44 ->disableOriginalConstructor()
45 ->getMock(); 45 ->getMock();
46 46
47 $wallabag = new WallabagV2Import($this->em, $this->contentProxy); 47 $dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
48 ->disableOriginalConstructor()
49 ->getMock();
50
51 $dispatcher
52 ->expects($this->exactly($dispatched))
53 ->method('dispatch');
54
55 $wallabag = new WallabagV2Import($this->em, $this->contentProxy, $dispatcher);
48 56
49 $this->logHandler = new TestHandler(); 57 $this->logHandler = new TestHandler();
50 $logger = new Logger('test', [$this->logHandler]); 58 $logger = new Logger('test', [$this->logHandler]);
@@ -68,7 +76,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase
68 76
69 public function testImport() 77 public function testImport()
70 { 78 {
71 $wallabagV2Import = $this->getWallabagV2Import(); 79 $wallabagV2Import = $this->getWallabagV2Import(false, 2);
72 $wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2.json'); 80 $wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2.json');
73 81
74 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 82 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
@@ -97,7 +105,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase
97 105
98 public function testImportAndMarkAllAsRead() 106 public function testImportAndMarkAllAsRead()
99 { 107 {
100 $wallabagV2Import = $this->getWallabagV2Import(); 108 $wallabagV2Import = $this->getWallabagV2Import(false, 2);
101 $wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2-read.json'); 109 $wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2-read.json');
102 110
103 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 111 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
@@ -246,7 +254,7 @@ class WallabagV2ImportTest extends \PHPUnit_Framework_TestCase
246 254
247 public function testImportWithExceptionFromGraby() 255 public function testImportWithExceptionFromGraby()
248 { 256 {
249 $wallabagV2Import = $this->getWallabagV2Import(); 257 $wallabagV2Import = $this->getWallabagV2Import(false, 2);
250 $wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2.json'); 258 $wallabagV2Import->setFilepath(__DIR__.'/../fixtures/wallabag-v2.json');
251 259
252 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') 260 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')