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.php270
-rw-r--r--tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php182
-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/ContentProxyTest.php4
-rw-r--r--tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php142
-rw-r--r--tests/Wallabag/CoreBundle/Helper/RedirectTest.php59
-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/Controller/ChromeControllerTest.php4
-rw-r--r--tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php12
-rw-r--r--tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php2
-rw-r--r--tests/Wallabag/ImportBundle/Controller/InstapaperControllerTest.php6
-rw-r--r--tests/Wallabag/ImportBundle/Controller/PinboardControllerTest.php197
-rw-r--r--tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php10
-rw-r--r--tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php6
-rw-r--r--tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php12
-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
-rw-r--r--tests/Wallabag/ImportBundle/fixtures/pinboard_export5
31 files changed, 1215 insertions, 172 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 d4fbe2d4..9bbc5960 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{
@@ -46,6 +51,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
46 'config[theme]' => 'baggy', 51 'config[theme]' => 'baggy',
47 'config[items_per_page]' => '30', 52 'config[items_per_page]' => '30',
48 'config[reading_speed]' => '0.5', 53 'config[reading_speed]' => '0.5',
54 'config[action_mark_as_read]' => '0',
49 'config[language]' => 'en', 55 'config[language]' => 'en',
50 ]; 56 ];
51 57
@@ -407,7 +413,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
407 413
408 $crawler = $client->request('GET', '/config'); 414 $crawler = $client->request('GET', '/config');
409 415
410 $this->assertTrue($client->getResponse()->isSuccessful()); 416 $this->assertEquals(200, $client->getResponse()->getStatusCode());
411 417
412 $form = $crawler->filter('button[id=tagging_rule_save]')->form(); 418 $form = $crawler->filter('button[id=tagging_rule_save]')->form();
413 419
@@ -494,7 +500,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
494 500
495 $crawler = $client->request('GET', '/config'); 501 $crawler = $client->request('GET', '/config');
496 502
497 $this->assertTrue($client->getResponse()->isSuccessful()); 503 $this->assertEquals(200, $client->getResponse()->getStatusCode());
498 504
499 $form = $crawler->filter('button[id=tagging_rule_save]')->form(); 505 $form = $crawler->filter('button[id=tagging_rule_save]')->form();
500 506
@@ -570,4 +576,264 @@ class ConfigControllerTest extends WallabagCoreTestCase
570 $config->set('demo_mode_enabled', 0); 576 $config->set('demo_mode_enabled', 0);
571 $config->set('demo_mode_username', 'wallabag'); 577 $config->set('demo_mode_username', 'wallabag');
572 } 578 }
579
580 public function testDeleteUserButtonVisibility()
581 {
582 $this->logInAs('admin');
583 $client = $this->getClient();
584
585 $crawler = $client->request('GET', '/config');
586
587 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
588 $this->assertContains('config.form_user.delete.button', $body[0]);
589
590 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
591
592 $user = $em
593 ->getRepository('WallabagUserBundle:User')
594 ->findOneByUsername('empty');
595 $user->setExpired(1);
596 $em->persist($user);
597
598 $user = $em
599 ->getRepository('WallabagUserBundle:User')
600 ->findOneByUsername('bob');
601 $user->setExpired(1);
602 $em->persist($user);
603
604 $em->flush();
605
606 $crawler = $client->request('GET', '/config');
607
608 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
609 $this->assertNotContains('config.form_user.delete.button', $body[0]);
610
611 $client->request('GET', '/account/delete');
612 $this->assertEquals(403, $client->getResponse()->getStatusCode());
613
614 $user = $em
615 ->getRepository('WallabagUserBundle:User')
616 ->findOneByUsername('empty');
617 $user->setExpired(0);
618 $em->persist($user);
619
620 $user = $em
621 ->getRepository('WallabagUserBundle:User')
622 ->findOneByUsername('bob');
623 $user->setExpired(0);
624 $em->persist($user);
625
626 $em->flush();
627 }
628
629 public function testDeleteAccount()
630 {
631 $client = $this->getClient();
632 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
633
634 $user = new User();
635 $user->setName('Wallace');
636 $user->setEmail('wallace@wallabag.org');
637 $user->setUsername('wallace');
638 $user->setPlainPassword('wallace');
639 $user->setEnabled(true);
640 $user->addRole('ROLE_SUPER_ADMIN');
641
642 $em->persist($user);
643
644 $config = new Config($user);
645
646 $config->setTheme('material');
647 $config->setItemsPerPage(30);
648 $config->setReadingSpeed(1);
649 $config->setLanguage('en');
650 $config->setPocketConsumerKey('xxxxx');
651
652 $em->persist($config);
653 $em->flush();
654
655 $this->logInAs('wallace');
656 $loggedInUserId = $this->getLoggedInUserId();
657
658 // create entry to check after user deletion
659 // that this entry is also deleted
660 $crawler = $client->request('GET', '/new');
661
662 $this->assertEquals(200, $client->getResponse()->getStatusCode());
663
664 $form = $crawler->filter('form[name=entry]')->form();
665 $data = [
666 'entry[url]' => $url = 'https://github.com/wallabag/wallabag',
667 ];
668
669 $client->submit($form, $data);
670 $this->assertEquals(302, $client->getResponse()->getStatusCode());
671
672 $crawler = $client->request('GET', '/config');
673
674 $deleteLink = $crawler->filter('.delete-account')->last()->link();
675
676 $client->click($deleteLink);
677 $this->assertEquals(302, $client->getResponse()->getStatusCode());
678
679 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
680 $user = $em
681 ->getRepository('WallabagUserBundle:User')
682 ->createQueryBuilder('u')
683 ->where('u.username = :username')->setParameter('username', 'wallace')
684 ->getQuery()
685 ->getOneOrNullResult()
686 ;
687
688 $this->assertNull($user);
689
690 $entries = $client->getContainer()
691 ->get('doctrine.orm.entity_manager')
692 ->getRepository('WallabagCoreBundle:Entry')
693 ->findByUser($loggedInUserId);
694
695 $this->assertEmpty($entries);
696 }
697
698 public function testReset()
699 {
700 $this->logInAs('empty');
701 $client = $this->getClient();
702
703 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
704
705 $user = static::$kernel->getContainer()->get('security.token_storage')->getToken()->getUser();
706
707 $tag = new Tag();
708 $tag->setLabel('super');
709 $em->persist($tag);
710
711 $entry = new Entry($user);
712 $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');
713 $entry->setContent('Youhou');
714 $entry->setTitle('Youhou');
715 $entry->addTag($tag);
716 $em->persist($entry);
717
718 $entry2 = new Entry($user);
719 $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');
720 $entry2->setContent('Youhou');
721 $entry2->setTitle('Youhou');
722 $entry2->addTag($tag);
723 $em->persist($entry2);
724
725 $annotation = new Annotation($user);
726 $annotation->setText('annotated');
727 $annotation->setQuote('annotated');
728 $annotation->setRanges([]);
729 $annotation->setEntry($entry);
730 $em->persist($annotation);
731
732 $em->flush();
733
734 // reset annotations
735 $crawler = $client->request('GET', '/config#set3');
736
737 $this->assertEquals(200, $client->getResponse()->getStatusCode());
738
739 $crawler = $client->click($crawler->selectLink('config.reset.annotations')->link());
740
741 $this->assertEquals(302, $client->getResponse()->getStatusCode());
742 $this->assertContains('flashes.config.notice.annotations_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]);
743
744 $annotationsReset = $em
745 ->getRepository('WallabagAnnotationBundle:Annotation')
746 ->findAnnotationsByPageId($entry->getId(), $user->getId());
747
748 $this->assertEmpty($annotationsReset, 'Annotations were reset');
749
750 // reset tags
751 $crawler = $client->request('GET', '/config#set3');
752
753 $this->assertEquals(200, $client->getResponse()->getStatusCode());
754
755 $crawler = $client->click($crawler->selectLink('config.reset.tags')->link());
756
757 $this->assertEquals(302, $client->getResponse()->getStatusCode());
758 $this->assertContains('flashes.config.notice.tags_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]);
759
760 $tagReset = $em
761 ->getRepository('WallabagCoreBundle:Tag')
762 ->countAllTags($user->getId());
763
764 $this->assertEquals(0, $tagReset, 'Tags were reset');
765
766 // reset entries
767 $crawler = $client->request('GET', '/config#set3');
768
769 $this->assertEquals(200, $client->getResponse()->getStatusCode());
770
771 $crawler = $client->click($crawler->selectLink('config.reset.entries')->link());
772
773 $this->assertEquals(302, $client->getResponse()->getStatusCode());
774 $this->assertContains('flashes.config.notice.entries_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]);
775
776 $entryReset = $em
777 ->getRepository('WallabagCoreBundle:Entry')
778 ->countAllEntriesByUsername($user->getId());
779
780 $this->assertEquals(0, $entryReset, 'Entries were reset');
781 }
782
783 public function testResetEntriesCascade()
784 {
785 $this->logInAs('empty');
786 $client = $this->getClient();
787
788 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
789
790 $user = static::$kernel->getContainer()->get('security.token_storage')->getToken()->getUser();
791
792 $tag = new Tag();
793 $tag->setLabel('super');
794 $em->persist($tag);
795
796 $entry = new Entry($user);
797 $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');
798 $entry->setContent('Youhou');
799 $entry->setTitle('Youhou');
800 $entry->addTag($tag);
801 $em->persist($entry);
802
803 $annotation = new Annotation($user);
804 $annotation->setText('annotated');
805 $annotation->setQuote('annotated');
806 $annotation->setRanges([]);
807 $annotation->setEntry($entry);
808 $em->persist($annotation);
809
810 $em->flush();
811
812 $crawler = $client->request('GET', '/config#set3');
813
814 $this->assertEquals(200, $client->getResponse()->getStatusCode());
815
816 $crawler = $client->click($crawler->selectLink('config.reset.entries')->link());
817
818 $this->assertEquals(302, $client->getResponse()->getStatusCode());
819 $this->assertContains('flashes.config.notice.entries_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]);
820
821 $entryReset = $em
822 ->getRepository('WallabagCoreBundle:Entry')
823 ->countAllEntriesByUsername($user->getId());
824
825 $this->assertEquals(0, $entryReset, 'Entries were reset');
826
827 $tagReset = $em
828 ->getRepository('WallabagCoreBundle:Tag')
829 ->countAllTags($user->getId());
830
831 $this->assertEquals(0, $tagReset, 'Tags were reset');
832
833 $annotationsReset = $em
834 ->getRepository('WallabagAnnotationBundle:Annotation')
835 ->findAnnotationsByPageId($entry->getId(), $user->getId());
836
837 $this->assertEmpty($annotationsReset, 'Annotations were reset');
838 }
573} 839}
diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
index 05113650..09cf01b8 100644
--- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
@@ -3,6 +3,7 @@
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;
6use Wallabag\CoreBundle\Entity\Entry; 7use Wallabag\CoreBundle\Entity\Entry;
7 8
8class EntryControllerTest extends WallabagCoreTestCase 9class EntryControllerTest extends WallabagCoreTestCase
@@ -836,4 +837,185 @@ class EntryControllerTest extends WallabagCoreTestCase
836 $client->request('GET', '/share/'.$content->getUuid()); 837 $client->request('GET', '/share/'.$content->getUuid());
837 $this->assertEquals(404, $client->getResponse()->getStatusCode()); 838 $this->assertEquals(404, $client->getResponse()->getStatusCode());
838 } 839 }
840
841 public function testNewEntryWithDownloadImagesEnabled()
842 {
843 $this->logInAs('admin');
844 $client = $this->getClient();
845
846 $url = 'http://www.20minutes.fr/montpellier/1952003-20161030-video-car-tombe-panne-rugbymen-perpignan-improvisent-melee-route';
847 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
848
849 $crawler = $client->request('GET', '/new');
850
851 $this->assertEquals(200, $client->getResponse()->getStatusCode());
852
853 $form = $crawler->filter('form[name=entry]')->form();
854
855 $data = [
856 'entry[url]' => $url,
857 ];
858
859 $client->submit($form, $data);
860
861 $this->assertEquals(302, $client->getResponse()->getStatusCode());
862
863 $em = $client->getContainer()
864 ->get('doctrine.orm.entity_manager');
865
866 $entry = $em
867 ->getRepository('WallabagCoreBundle:Entry')
868 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
869
870 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $entry);
871 $this->assertEquals($url, $entry->getUrl());
872 $this->assertContains('Perpignan', $entry->getTitle());
873 $this->assertContains('/d9bc0fcd.jpeg', $entry->getContent());
874
875 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
876 }
877
878 /**
879 * @depends testNewEntryWithDownloadImagesEnabled
880 */
881 public function testRemoveEntryWithDownloadImagesEnabled()
882 {
883 $this->logInAs('admin');
884 $client = $this->getClient();
885
886 $url = 'http://www.20minutes.fr/montpellier/1952003-20161030-video-car-tombe-panne-rugbymen-perpignan-improvisent-melee-route';
887 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
888
889 $content = $client->getContainer()
890 ->get('doctrine.orm.entity_manager')
891 ->getRepository('WallabagCoreBundle:Entry')
892 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
893
894 $client->request('GET', '/delete/'.$content->getId());
895
896 $this->assertEquals(302, $client->getResponse()->getStatusCode());
897
898 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
899 }
900
901 public function testRedirectToHomepage()
902 {
903 $this->logInAs('empty');
904 $client = $this->getClient();
905
906 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
907 $user = $em
908 ->getRepository('WallabagUserBundle:User')
909 ->find($this->getLoggedInUserId());
910
911 if (!$user) {
912 $this->markTestSkipped('No user found in db.');
913 }
914
915 // Redirect to homepage
916 $config = $user->getConfig();
917 $config->setActionMarkAsRead(Config::REDIRECT_TO_HOMEPAGE);
918 $em->persist($config);
919 $em->flush();
920
921 $content = $client->getContainer()
922 ->get('doctrine.orm.entity_manager')
923 ->getRepository('WallabagCoreBundle:Entry')
924 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
925
926 $client->request('GET', '/view/'.$content->getId());
927 $client->request('GET', '/archive/'.$content->getId());
928
929 $this->assertEquals(302, $client->getResponse()->getStatusCode());
930 $this->assertEquals('/', $client->getResponse()->headers->get('location'));
931 }
932
933 public function testRedirectToCurrentPage()
934 {
935 $this->logInAs('empty');
936 $client = $this->getClient();
937
938 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
939 $user = $em
940 ->getRepository('WallabagUserBundle:User')
941 ->find($this->getLoggedInUserId());
942
943 if (!$user) {
944 $this->markTestSkipped('No user found in db.');
945 }
946
947 // Redirect to current page
948 $config = $user->getConfig();
949 $config->setActionMarkAsRead(Config::REDIRECT_TO_CURRENT_PAGE);
950 $em->persist($config);
951 $em->flush();
952
953 $content = $client->getContainer()
954 ->get('doctrine.orm.entity_manager')
955 ->getRepository('WallabagCoreBundle:Entry')
956 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
957
958 $client->request('GET', '/view/'.$content->getId());
959 $client->request('GET', '/archive/'.$content->getId());
960
961 $this->assertEquals(302, $client->getResponse()->getStatusCode());
962 $this->assertContains('/view/'.$content->getId(), $client->getResponse()->headers->get('location'));
963 }
964
965 public function testFilterOnHttpStatus()
966 {
967 $this->logInAs('admin');
968 $client = $this->getClient();
969
970 $crawler = $client->request('GET', '/new');
971 $form = $crawler->filter('form[name=entry]')->form();
972
973 $data = [
974 'entry[url]' => 'http://www.lemonde.fr/incorrect-url/',
975 ];
976
977 $client->submit($form, $data);
978
979 $crawler = $client->request('GET', '/all/list');
980 $form = $crawler->filter('button[id=submit-filter]')->form();
981
982 $data = [
983 'entry_filter[httpStatus]' => 404,
984 ];
985
986 $crawler = $client->submit($form, $data);
987
988 $this->assertCount(1, $crawler->filter('div[class=entry]'));
989
990 $crawler = $client->request('GET', '/new');
991 $form = $crawler->filter('form[name=entry]')->form();
992
993 $data = [
994 'entry[url]' => 'http://www.nextinpact.com/news/101235-wallabag-alternative-libre-a-pocket-creuse-petit-a-petit-son-nid.htm',
995 ];
996
997 $client->submit($form, $data);
998
999 $crawler = $client->request('GET', '/all/list');
1000 $form = $crawler->filter('button[id=submit-filter]')->form();
1001
1002 $data = [
1003 'entry_filter[httpStatus]' => 200,
1004 ];
1005
1006 $crawler = $client->submit($form, $data);
1007
1008 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1009
1010 $crawler = $client->request('GET', '/all/list');
1011 $form = $crawler->filter('button[id=submit-filter]')->form();
1012
1013 $data = [
1014 'entry_filter[httpStatus]' => 1024,
1015 ];
1016
1017 $crawler = $client->submit($form, $data);
1018
1019 $this->assertCount(7, $crawler->filter('div[class=entry]'));
1020 }
839} 1021}
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/ContentProxyTest.php b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php
index 5d772602..33b3ff2a 100644
--- a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php
+++ b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php
@@ -97,6 +97,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
97 'url' => '', 97 'url' => '',
98 'content_type' => '', 98 'content_type' => '',
99 'language' => '', 99 'language' => '',
100 'status' => '',
100 'open_graph' => [ 101 'open_graph' => [
101 'og_title' => 'my title', 102 'og_title' => 'my title',
102 'og_description' => 'desc', 103 'og_description' => 'desc',
@@ -111,6 +112,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
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->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->getPreviewPicture());
113 $this->assertEmpty($entry->getLanguage()); 114 $this->assertEmpty($entry->getLanguage());
115 $this->assertEmpty($entry->getHttpStatus());
114 $this->assertEmpty($entry->getMimetype()); 116 $this->assertEmpty($entry->getMimetype());
115 $this->assertEquals(0.0, $entry->getReadingTime()); 117 $this->assertEquals(0.0, $entry->getReadingTime());
116 $this->assertEquals('domain.io', $entry->getDomainName()); 118 $this->assertEquals('domain.io', $entry->getDomainName());
@@ -135,6 +137,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
135 'url' => 'http://1.1.1.1', 137 'url' => 'http://1.1.1.1',
136 'content_type' => 'text/html', 138 'content_type' => 'text/html',
137 'language' => 'fr', 139 'language' => 'fr',
140 'status' => '200',
138 'open_graph' => [ 141 'open_graph' => [
139 'og_title' => 'my OG title', 142 'og_title' => 'my OG title',
140 'og_description' => 'OG desc', 143 'og_description' => 'OG desc',
@@ -151,6 +154,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
151 $this->assertEquals('http://3.3.3.3/cover.jpg', $entry->getPreviewPicture()); 154 $this->assertEquals('http://3.3.3.3/cover.jpg', $entry->getPreviewPicture());
152 $this->assertEquals('text/html', $entry->getMimetype()); 155 $this->assertEquals('text/html', $entry->getMimetype());
153 $this->assertEquals('fr', $entry->getLanguage()); 156 $this->assertEquals('fr', $entry->getLanguage());
157 $this->assertEquals('200', $entry->getHttpStatus());
154 $this->assertEquals(4.0, $entry->getReadingTime()); 158 $this->assertEquals(4.0, $entry->getReadingTime());
155 $this->assertEquals('1.1.1.1', $entry->getDomainName()); 159 $this->assertEquals('1.1.1.1', $entry->getDomainName());
156 } 160 }
diff --git a/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php b/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php
new file mode 100644
index 00000000..85f12d87
--- /dev/null
+++ b/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php
@@ -0,0 +1,142 @@
1<?php
2
3namespace Tests\Wallabag\CoreBundle\Helper;
4
5use Wallabag\CoreBundle\Helper\DownloadImages;
6use Monolog\Logger;
7use Monolog\Handler\TestHandler;
8use GuzzleHttp\Client;
9use GuzzleHttp\Subscriber\Mock;
10use GuzzleHttp\Message\Response;
11use GuzzleHttp\Stream\Stream;
12
13class DownloadImagesTest extends \PHPUnit_Framework_TestCase
14{
15 public function testProcessHtml()
16 {
17 $client = new Client();
18
19 $mock = new Mock([
20 new Response(200, ['content-type' => 'image/png'], Stream::factory(file_get_contents(__DIR__.'/../fixtures/unnamed.png'))),
21 ]);
22
23 $client->getEmitter()->attach($mock);
24
25 $logHandler = new TestHandler();
26 $logger = new Logger('test', array($logHandler));
27
28 $download = new DownloadImages($client, sys_get_temp_dir().'/wallabag_test', 'http://wallabag.io/', $logger);
29
30 $res = $download->processHtml(123, '<div><img src="http://i.imgur.com/T9qgcHc.jpg" /></div>', 'http://imgur.com/gallery/WxtWY');
31
32 $this->assertContains('http://wallabag.io/assets/images/9/b/9b0ead26/c638b4c2.png', $res);
33 }
34
35 public function testProcessHtmlWithBadImage()
36 {
37 $client = new Client();
38
39 $mock = new Mock([
40 new Response(200, ['content-type' => 'application/json'], Stream::factory('')),
41 ]);
42
43 $client->getEmitter()->attach($mock);
44
45 $logHandler = new TestHandler();
46 $logger = new Logger('test', array($logHandler));
47
48 $download = new DownloadImages($client, sys_get_temp_dir().'/wallabag_test', 'http://wallabag.io/', $logger);
49 $res = $download->processHtml(123, '<div><img src="http://i.imgur.com/T9qgcHc.jpg" /></div>', 'http://imgur.com/gallery/WxtWY');
50
51 $this->assertContains('http://i.imgur.com/T9qgcHc.jpg', $res, 'Image were not replace because of content-type');
52 }
53
54 public function singleImage()
55 {
56 return [
57 ['image/pjpeg', 'jpeg'],
58 ['image/jpeg', 'jpeg'],
59 ['image/png', 'png'],
60 ['image/gif', 'gif'],
61 ];
62 }
63
64 /**
65 * @dataProvider singleImage
66 */
67 public function testProcessSingleImage($header, $extension)
68 {
69 $client = new Client();
70
71 $mock = new Mock([
72 new Response(200, ['content-type' => $header], Stream::factory(file_get_contents(__DIR__.'/../fixtures/unnamed.png'))),
73 ]);
74
75 $client->getEmitter()->attach($mock);
76
77 $logHandler = new TestHandler();
78 $logger = new Logger('test', array($logHandler));
79
80 $download = new DownloadImages($client, sys_get_temp_dir().'/wallabag_test', 'http://wallabag.io/', $logger);
81 $res = $download->processSingleImage(123, 'T9qgcHc.jpg', 'http://imgur.com/gallery/WxtWY');
82
83 $this->assertContains('/assets/images/9/b/9b0ead26/ebe60399.'.$extension, $res);
84 }
85
86 public function testProcessSingleImageWithBadUrl()
87 {
88 $client = new Client();
89
90 $mock = new Mock([
91 new Response(404, []),
92 ]);
93
94 $client->getEmitter()->attach($mock);
95
96 $logHandler = new TestHandler();
97 $logger = new Logger('test', array($logHandler));
98
99 $download = new DownloadImages($client, sys_get_temp_dir().'/wallabag_test', 'http://wallabag.io/', $logger);
100 $res = $download->processSingleImage(123, 'T9qgcHc.jpg', 'http://imgur.com/gallery/WxtWY');
101
102 $this->assertFalse($res, 'Image can not be found, so it will not be replaced');
103 }
104
105 public function testProcessSingleImageWithBadImage()
106 {
107 $client = new Client();
108
109 $mock = new Mock([
110 new Response(200, ['content-type' => 'image/png'], Stream::factory('')),
111 ]);
112
113 $client->getEmitter()->attach($mock);
114
115 $logHandler = new TestHandler();
116 $logger = new Logger('test', array($logHandler));
117
118 $download = new DownloadImages($client, sys_get_temp_dir().'/wallabag_test', 'http://wallabag.io/', $logger);
119 $res = $download->processSingleImage(123, 'http://i.imgur.com/T9qgcHc.jpg', 'http://imgur.com/gallery/WxtWY');
120
121 $this->assertFalse($res, 'Image can not be loaded, so it will not be replaced');
122 }
123
124 public function testProcessSingleImageFailAbsolute()
125 {
126 $client = new Client();
127
128 $mock = new Mock([
129 new Response(200, ['content-type' => 'image/png'], Stream::factory(file_get_contents(__DIR__.'/../fixtures/unnamed.png'))),
130 ]);
131
132 $client->getEmitter()->attach($mock);
133
134 $logHandler = new TestHandler();
135 $logger = new Logger('test', array($logHandler));
136
137 $download = new DownloadImages($client, sys_get_temp_dir().'/wallabag_test', 'http://wallabag.io/', $logger);
138 $res = $download->processSingleImage(123, '/i.imgur.com/T9qgcHc.jpg', 'imgur.com/gallery/WxtWY');
139
140 $this->assertFalse($res, 'Absolute image can not be determined, so it will not be replaced');
141 }
142}
diff --git a/tests/Wallabag/CoreBundle/Helper/RedirectTest.php b/tests/Wallabag/CoreBundle/Helper/RedirectTest.php
index f339f75e..0539f20a 100644
--- a/tests/Wallabag/CoreBundle/Helper/RedirectTest.php
+++ b/tests/Wallabag/CoreBundle/Helper/RedirectTest.php
@@ -2,7 +2,11 @@
2 2
3namespace Tests\Wallabag\CoreBundle\Helper; 3namespace Tests\Wallabag\CoreBundle\Helper;
4 4
5use Wallabag\CoreBundle\Entity\Config;
6use Wallabag\UserBundle\Entity\User;
5use Wallabag\CoreBundle\Helper\Redirect; 7use Wallabag\CoreBundle\Helper\Redirect;
8use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
9use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
6 10
7class RedirectTest extends \PHPUnit_Framework_TestCase 11class RedirectTest extends \PHPUnit_Framework_TestCase
8{ 12{
@@ -14,8 +18,38 @@ class RedirectTest extends \PHPUnit_Framework_TestCase
14 18
15 public function setUp() 19 public function setUp()
16 { 20 {
17 $this->routerMock = $this->getRouterMock(); 21 $this->routerMock = $this->getMockBuilder('Symfony\Component\Routing\Router')
18 $this->redirect = new Redirect($this->routerMock); 22 ->disableOriginalConstructor()
23 ->getMock();
24
25 $this->routerMock->expects($this->any())
26 ->method('generate')
27 ->with('homepage')
28 ->willReturn('homepage');
29
30 $user = new User();
31 $user->setName('youpi');
32 $user->setEmail('youpi@youpi.org');
33 $user->setUsername('youpi');
34 $user->setPlainPassword('youpi');
35 $user->setEnabled(true);
36 $user->addRole('ROLE_SUPER_ADMIN');
37
38 $config = new Config($user);
39 $config->setTheme('material');
40 $config->setItemsPerPage(30);
41 $config->setReadingSpeed(1);
42 $config->setLanguage('en');
43 $config->setPocketConsumerKey('xxxxx');
44 $config->setActionMarkAsRead(Config::REDIRECT_TO_CURRENT_PAGE);
45
46 $user->setConfig($config);
47
48 $this->token = new UsernamePasswordToken($user, 'password', 'key');
49 $tokenStorage = new TokenStorage();
50 $tokenStorage->setToken($this->token);
51
52 $this->redirect = new Redirect($this->routerMock, $tokenStorage);
19 } 53 }
20 54
21 public function testRedirectToNullWithFallback() 55 public function testRedirectToNullWithFallback()
@@ -39,17 +73,20 @@ class RedirectTest extends \PHPUnit_Framework_TestCase
39 $this->assertEquals('/unread/list', $redirectUrl); 73 $this->assertEquals('/unread/list', $redirectUrl);
40 } 74 }
41 75
42 private function getRouterMock() 76 public function testWithNotLoggedUser()
43 { 77 {
44 $mock = $this->getMockBuilder('Symfony\Component\Routing\Router') 78 $redirect = new Redirect($this->routerMock, new TokenStorage());
45 ->disableOriginalConstructor() 79 $redirectUrl = $redirect->to('/unread/list');
46 ->getMock();
47 80
48 $mock->expects($this->any()) 81 $this->assertEquals('/unread/list', $redirectUrl);
49 ->method('generate') 82 }
50 ->with('homepage')
51 ->willReturn('homepage');
52 83
53 return $mock; 84 public function testUserForRedirectToHomepage()
85 {
86 $this->token->getUser()->getConfig()->setActionMarkAsRead(Config::REDIRECT_TO_HOMEPAGE);
87
88 $redirectUrl = $this->redirect->to('/unread/list');
89
90 $this->assertEquals($this->routerMock->generate('homepage'), $redirectUrl);
54 } 91 }
55} 92}
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/Controller/ChromeControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php
index c0417bbe..c1f82ea9 100644
--- a/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php
+++ b/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php
@@ -118,8 +118,8 @@ class ChromeControllerTest extends WallabagCoreTestCase
118 $this->getLoggedInUserId() 118 $this->getLoggedInUserId()
119 ); 119 );
120 120
121 $this->assertNotEmpty($content->getPreviewPicture()); 121 $this->assertNotEmpty($content->getPreviewPicture(), 'Preview picture for http://www.usinenouvelle.com is ok');
122 $this->assertNotEmpty($content->getLanguage()); 122 $this->assertNotEmpty($content->getLanguage(), 'Language for http://www.usinenouvelle.com is ok');
123 $this->assertEquals(0, count($content->getTags())); 123 $this->assertEquals(0, count($content->getTags()));
124 124
125 $createdAt = $content->getCreatedAt(); 125 $createdAt = $content->getCreatedAt();
diff --git a/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php b/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php
index 6154ae8d..7557ea32 100644
--- a/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php
+++ b/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php
@@ -118,9 +118,9 @@ class FirefoxControllerTest extends WallabagCoreTestCase
118 $this->getLoggedInUserId() 118 $this->getLoggedInUserId()
119 ); 119 );
120 120
121 $this->assertNotEmpty($content->getMimetype()); 121 $this->assertNotEmpty($content->getMimetype(), 'Mimetype for http://lexpansion.lexpress.fr is ok');
122 $this->assertNotEmpty($content->getPreviewPicture()); 122 $this->assertNotEmpty($content->getPreviewPicture(), 'Preview picture for http://lexpansion.lexpress.fr is ok');
123 $this->assertNotEmpty($content->getLanguage()); 123 $this->assertNotEmpty($content->getLanguage(), 'Language for http://lexpansion.lexpress.fr is ok');
124 $this->assertEquals(2, count($content->getTags())); 124 $this->assertEquals(2, count($content->getTags()));
125 125
126 $content = $client->getContainer() 126 $content = $client->getContainer()
@@ -131,9 +131,9 @@ class FirefoxControllerTest extends WallabagCoreTestCase
131 $this->getLoggedInUserId() 131 $this->getLoggedInUserId()
132 ); 132 );
133 133
134 $this->assertNotEmpty($content->getMimetype()); 134 $this->assertNotEmpty($content->getMimetype(), 'Mimetype for http://stackoverflow.com is ok');
135 $this->assertNotEmpty($content->getPreviewPicture()); 135 $this->assertNotEmpty($content->getPreviewPicture(), 'Preview picture for http://stackoverflow.com is ok');
136 $this->assertEmpty($content->getLanguage()); 136 $this->assertEmpty($content->getLanguage(), 'Language for http://stackoverflow.com is ok');
137 137
138 $createdAt = $content->getCreatedAt(); 138 $createdAt = $content->getCreatedAt();
139 $this->assertEquals('2013', $createdAt->format('Y')); 139 $this->assertEquals('2013', $createdAt->format('Y'));
diff --git a/tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php
index 0bc40bdd..5e57dcef 100644
--- a/tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php
+++ b/tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php
@@ -24,6 +24,6 @@ class ImportControllerTest extends WallabagCoreTestCase
24 $crawler = $client->request('GET', '/import/'); 24 $crawler = $client->request('GET', '/import/');
25 25
26 $this->assertEquals(200, $client->getResponse()->getStatusCode()); 26 $this->assertEquals(200, $client->getResponse()->getStatusCode());
27 $this->assertEquals(7, $crawler->filter('blockquote')->count()); 27 $this->assertEquals(8, $crawler->filter('blockquote')->count());
28 } 28 }
29} 29}
diff --git a/tests/Wallabag/ImportBundle/Controller/InstapaperControllerTest.php b/tests/Wallabag/ImportBundle/Controller/InstapaperControllerTest.php
index 9df08e75..3f6f2b9f 100644
--- a/tests/Wallabag/ImportBundle/Controller/InstapaperControllerTest.php
+++ b/tests/Wallabag/ImportBundle/Controller/InstapaperControllerTest.php
@@ -118,9 +118,9 @@ class InstapaperControllerTest extends WallabagCoreTestCase
118 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); 118 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
119 $this->assertContains('flashes.import.notice.summary', $body[0]); 119 $this->assertContains('flashes.import.notice.summary', $body[0]);
120 120
121 $this->assertNotEmpty($content->getMimetype()); 121 $this->assertNotEmpty($content->getMimetype(), 'Mimetype for http://www.liberation.fr is ok');
122 $this->assertNotEmpty($content->getPreviewPicture()); 122 $this->assertNotEmpty($content->getPreviewPicture(), 'Preview picture for http://www.liberation.fr is ok');
123 $this->assertNotEmpty($content->getLanguage()); 123 $this->assertNotEmpty($content->getLanguage(), 'Language for http://www.liberation.fr is ok');
124 $this->assertEquals(0, count($content->getTags())); 124 $this->assertEquals(0, count($content->getTags()));
125 $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt()); 125 $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt());
126 } 126 }
diff --git a/tests/Wallabag/ImportBundle/Controller/PinboardControllerTest.php b/tests/Wallabag/ImportBundle/Controller/PinboardControllerTest.php
new file mode 100644
index 00000000..75a7e332
--- /dev/null
+++ b/tests/Wallabag/ImportBundle/Controller/PinboardControllerTest.php
@@ -0,0 +1,197 @@
1<?php
2
3namespace Tests\Wallabag\ImportBundle\Controller;
4
5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
6use Symfony\Component\HttpFoundation\File\UploadedFile;
7
8class PinboardControllerTest extends WallabagCoreTestCase
9{
10 public function testImportPinboard()
11 {
12 $this->logInAs('admin');
13 $client = $this->getClient();
14
15 $crawler = $client->request('GET', '/import/pinboard');
16
17 $this->assertEquals(200, $client->getResponse()->getStatusCode());
18 $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count());
19 $this->assertEquals(1, $crawler->filter('input[type=file]')->count());
20 }
21
22 public function testImportPinboardWithRabbitEnabled()
23 {
24 $this->logInAs('admin');
25 $client = $this->getClient();
26
27 $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 1);
28
29 $crawler = $client->request('GET', '/import/pinboard');
30
31 $this->assertEquals(200, $client->getResponse()->getStatusCode());
32 $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count());
33 $this->assertEquals(1, $crawler->filter('input[type=file]')->count());
34
35 $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 0);
36 }
37
38 public function testImportPinboardBadFile()
39 {
40 $this->logInAs('admin');
41 $client = $this->getClient();
42
43 $crawler = $client->request('GET', '/import/pinboard');
44 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
45
46 $data = [
47 'upload_import_file[file]' => '',
48 ];
49
50 $client->submit($form, $data);
51
52 $this->assertEquals(200, $client->getResponse()->getStatusCode());
53 }
54
55 public function testImportPinboardWithRedisEnabled()
56 {
57 $this->checkRedis();
58 $this->logInAs('admin');
59 $client = $this->getClient();
60 $client->getContainer()->get('craue_config')->set('import_with_redis', 1);
61
62 $crawler = $client->request('GET', '/import/pinboard');
63
64 $this->assertEquals(200, $client->getResponse()->getStatusCode());
65 $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count());
66 $this->assertEquals(1, $crawler->filter('input[type=file]')->count());
67
68 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
69
70 $file = new UploadedFile(__DIR__.'/../fixtures/pinboard_export', 'pinboard.json');
71
72 $data = [
73 'upload_import_file[file]' => $file,
74 ];
75
76 $client->submit($form, $data);
77
78 $this->assertEquals(302, $client->getResponse()->getStatusCode());
79
80 $crawler = $client->followRedirect();
81
82 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
83 $this->assertContains('flashes.import.notice.summary', $body[0]);
84
85 $this->assertNotEmpty($client->getContainer()->get('wallabag_core.redis.client')->lpop('wallabag.import.pinboard'));
86
87 $client->getContainer()->get('craue_config')->set('import_with_redis', 0);
88 }
89
90 public function testImportPinboardWithFile()
91 {
92 $this->logInAs('admin');
93 $client = $this->getClient();
94
95 $crawler = $client->request('GET', '/import/pinboard');
96 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
97
98 $file = new UploadedFile(__DIR__.'/../fixtures/pinboard_export', 'pinboard.json');
99
100 $data = [
101 'upload_import_file[file]' => $file,
102 ];
103
104 $client->submit($form, $data);
105
106 $this->assertEquals(302, $client->getResponse()->getStatusCode());
107
108 $crawler = $client->followRedirect();
109
110 $content = $client->getContainer()
111 ->get('doctrine.orm.entity_manager')
112 ->getRepository('WallabagCoreBundle:Entry')
113 ->findByUrlAndUserId(
114 'https://ma.ttias.be/varnish-explained/',
115 $this->getLoggedInUserId()
116 );
117
118 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
119 $this->assertContains('flashes.import.notice.summary', $body[0]);
120
121 $this->assertNotEmpty($content->getMimetype(), 'Mimetype for https://ma.ttias.be is ok');
122 $this->assertNotEmpty($content->getPreviewPicture(), 'Preview picture for https://ma.ttias.be is ok');
123 $this->assertNotEmpty($content->getLanguage(), 'Language for https://ma.ttias.be is ok');
124 $this->assertEquals(2, count($content->getTags()));
125 $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt());
126 $this->assertEquals('2016-10-26', $content->getCreatedAt()->format('Y-m-d'));
127 }
128
129 public function testImportPinboardWithFileAndMarkAllAsRead()
130 {
131 $this->logInAs('admin');
132 $client = $this->getClient();
133
134 $crawler = $client->request('GET', '/import/pinboard');
135 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
136
137 $file = new UploadedFile(__DIR__.'/../fixtures/pinboard_export', 'pinboard-read.json');
138
139 $data = [
140 'upload_import_file[file]' => $file,
141 'upload_import_file[mark_as_read]' => 1,
142 ];
143
144 $client->submit($form, $data);
145
146 $this->assertEquals(302, $client->getResponse()->getStatusCode());
147
148 $crawler = $client->followRedirect();
149
150 $content1 = $client->getContainer()
151 ->get('doctrine.orm.entity_manager')
152 ->getRepository('WallabagCoreBundle:Entry')
153 ->findByUrlAndUserId(
154 'https://ilia.ws/files/nginx_torontophpug.pdf',
155 $this->getLoggedInUserId()
156 );
157
158 $this->assertTrue($content1->isArchived());
159
160 $content2 = $client->getContainer()
161 ->get('doctrine.orm.entity_manager')
162 ->getRepository('WallabagCoreBundle:Entry')
163 ->findByUrlAndUserId(
164 'https://developers.google.com/web/updates/2016/07/infinite-scroller',
165 $this->getLoggedInUserId()
166 );
167
168 $this->assertTrue($content2->isArchived());
169
170 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
171 $this->assertContains('flashes.import.notice.summary', $body[0]);
172 }
173
174 public function testImportPinboardWithEmptyFile()
175 {
176 $this->logInAs('admin');
177 $client = $this->getClient();
178
179 $crawler = $client->request('GET', '/import/pinboard');
180 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
181
182 $file = new UploadedFile(__DIR__.'/../fixtures/test.txt', 'test.txt');
183
184 $data = [
185 'upload_import_file[file]' => $file,
186 ];
187
188 $client->submit($form, $data);
189
190 $this->assertEquals(302, $client->getResponse()->getStatusCode());
191
192 $crawler = $client->followRedirect();
193
194 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
195 $this->assertContains('flashes.import.notice.failed', $body[0]);
196 }
197}
diff --git a/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php
index 916dd297..acb61ca1 100644
--- a/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php
+++ b/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php
@@ -111,19 +111,19 @@ class ReadabilityControllerTest extends WallabagCoreTestCase
111 ->get('doctrine.orm.entity_manager') 111 ->get('doctrine.orm.entity_manager')
112 ->getRepository('WallabagCoreBundle:Entry') 112 ->getRepository('WallabagCoreBundle:Entry')
113 ->findByUrlAndUserId( 113 ->findByUrlAndUserId(
114 'https://venngage.com/blog/hashtags-are-worthless/', 114 'http://www.zataz.com/90-des-dossiers-medicaux-des-coreens-du-sud-vendus-a-des-entreprises-privees/',
115 $this->getLoggedInUserId() 115 $this->getLoggedInUserId()
116 ); 116 );
117 117
118 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); 118 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
119 $this->assertContains('flashes.import.notice.summary', $body[0]); 119 $this->assertContains('flashes.import.notice.summary', $body[0]);
120 120
121 $this->assertNotEmpty($content->getMimetype()); 121 $this->assertNotEmpty($content->getMimetype(), 'Mimetype for http://www.zataz.com is ok');
122 $this->assertNotEmpty($content->getPreviewPicture()); 122 $this->assertNotEmpty($content->getPreviewPicture(), 'Preview picture for http://www.zataz.com is ok');
123 $this->assertNotEmpty($content->getLanguage()); 123 $this->assertNotEmpty($content->getLanguage(), 'Language for http://www.zataz.com is ok');
124 $this->assertEquals(0, count($content->getTags())); 124 $this->assertEquals(0, count($content->getTags()));
125 $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt()); 125 $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt());
126 $this->assertEquals('2016-08-25', $content->getCreatedAt()->format('Y-m-d')); 126 $this->assertEquals('2016-09-08', $content->getCreatedAt()->format('Y-m-d'));
127 } 127 }
128 128
129 public function testImportReadabilityWithFileAndMarkAllAsRead() 129 public function testImportReadabilityWithFileAndMarkAllAsRead()
diff --git a/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php b/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php
index 3497c4b8..2c370ed9 100644
--- a/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php
+++ b/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php
@@ -126,9 +126,9 @@ class WallabagV1ControllerTest extends WallabagCoreTestCase
126 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); 126 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
127 $this->assertContains('flashes.import.notice.summary', $body[0]); 127 $this->assertContains('flashes.import.notice.summary', $body[0]);
128 128
129 $this->assertEmpty($content->getMimetype()); 129 $this->assertEmpty($content->getMimetype(), 'Mimetype for http://www.framablog.org is ok');
130 $this->assertEmpty($content->getPreviewPicture()); 130 $this->assertEmpty($content->getPreviewPicture(), 'Preview picture for http://www.framablog.org is ok');
131 $this->assertEmpty($content->getLanguage()); 131 $this->assertEmpty($content->getLanguage(), 'Language for http://www.framablog.org is ok');
132 $this->assertEquals(1, count($content->getTags())); 132 $this->assertEquals(1, count($content->getTags()));
133 $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt()); 133 $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt());
134 } 134 }
diff --git a/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php b/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php
index 27d2d52b..26e2f40b 100644
--- a/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php
+++ b/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php
@@ -119,9 +119,9 @@ class WallabagV2ControllerTest extends WallabagCoreTestCase
119 $this->getLoggedInUserId() 119 $this->getLoggedInUserId()
120 ); 120 );
121 121
122 $this->assertNotEmpty($content->getMimetype()); 122 $this->assertNotEmpty($content->getMimetype(), 'Mimetype for http://www.liberation.fr is ok');
123 $this->assertNotEmpty($content->getPreviewPicture()); 123 $this->assertNotEmpty($content->getPreviewPicture(), 'Preview picture for http://www.liberation.fr is ok');
124 $this->assertNotEmpty($content->getLanguage()); 124 $this->assertNotEmpty($content->getLanguage(), 'Language for http://www.liberation.fr is ok');
125 $this->assertEquals(0, count($content->getTags())); 125 $this->assertEquals(0, count($content->getTags()));
126 126
127 $content = $client->getContainer() 127 $content = $client->getContainer()
@@ -132,9 +132,9 @@ class WallabagV2ControllerTest extends WallabagCoreTestCase
132 $this->getLoggedInUserId() 132 $this->getLoggedInUserId()
133 ); 133 );
134 134
135 $this->assertNotEmpty($content->getMimetype()); 135 $this->assertNotEmpty($content->getMimetype(), 'Mimetype for https://www.mediapart.fr is ok');
136 $this->assertNotEmpty($content->getPreviewPicture()); 136 $this->assertNotEmpty($content->getPreviewPicture(), 'Preview picture for https://www.mediapart.fr is ok');
137 $this->assertNotEmpty($content->getLanguage()); 137 $this->assertNotEmpty($content->getLanguage(), 'Language for https://www.mediapart.fr is ok');
138 $this->assertEquals(2, count($content->getTags())); 138 $this->assertEquals(2, count($content->getTags()));
139 $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt()); 139 $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt());
140 $this->assertEquals('2016-09-08', $content->getCreatedAt()->format('Y-m-d')); 140 $this->assertEquals('2016-09-08', $content->getCreatedAt()->format('Y-m-d'));
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')
diff --git a/tests/Wallabag/ImportBundle/fixtures/pinboard_export b/tests/Wallabag/ImportBundle/fixtures/pinboard_export
new file mode 100644
index 00000000..2dd744d3
--- /dev/null
+++ b/tests/Wallabag/ImportBundle/fixtures/pinboard_export
@@ -0,0 +1,5 @@
1[{"href":"https:\/\/developers.google.com\/web\/updates\/2016\/07\/infinite-scroller","description":"Complexities of an Infinite Scroller","extended":"TL;DR: Re-use your DOM elements and remove the ones that are far away from the viewport. Use placeholders to account for delayed data","meta":"21ff61c6f648901168f9e6119f53df7d","hash":"e69b65724cca1c585b446d4c47865d76","time":"2016-10-31T15:57:56Z","shared":"yes","toread":"no","tags":"infinite dom performance scroll"},
2{"href":"https:\/\/ma.ttias.be\/varnish-explained\/","description":"Varnish (explained) for PHP developers","extended":"A few months ago, I gave a presentation at LaraconEU in Amsterdam titled \"Varnish for PHP developers\". The generic title of that presentation is actually Varnish Explained and this is a write-up of that presentation, the video and the slides.","meta":"d32ad9fac2ed29da4aec12c562e9afb1","hash":"21dd6bdda8ad62666a2c9e79f6e80f98","time":"2016-10-26T06:43:03Z","shared":"yes","toread":"no","tags":"varnish PHP"},
3{"href":"https:\/\/ilia.ws\/files\/nginx_torontophpug.pdf","description":"Nginx Tricks for PHP Developers","extended":"","meta":"9adbb5c4ca6760e335b920800d88c70a","hash":"0189bb08f8bd0122c6544bed4624c546","time":"2016-10-05T07:11:27Z","shared":"yes","toread":"no","tags":"nginx PHP best_practice"},
4{"href":"https:\/\/jolicode.com\/blog\/starting-a-mobile-application-with-react-native","description":"Starting a mobile application with React Native","extended":"While preparing our next React Native training, I learnt a lot on the library and discovered an amazing community with a lot of packages.","meta":"bd140bd3e53e3a0b4cb08cdaf64bcbfc","hash":"015fa10cd97f56186420555e52cfab62","time":"2016-09-23T10:58:20Z","shared":"yes","toread":"no","tags":"react-native"},
5{"href":"http:\/\/open.blogs.nytimes.com\/2016\/08\/29\/testing-varnish-using-varnishtest\/","description":"Testing Varnish Using Varnishtest","extended":"Varnish ships with the ability to test using the testing tool varnishtest. Varnishtest gives you the ability to write VCL tests you can run on the command line or as part of your build process.","meta":"ca2752a07adea4bab52cd19e8fdbf356","hash":"d3e642cc1274d10e4c12ee31f5dde736","time":"2016-08-30T09:33:24Z","shared":"yes","toread":"no","tags":"varnish test vcl"}]