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.php140
-rw-r--r--tests/Wallabag/CoreBundle/Command/ExportCommandTest.php78
-rw-r--r--tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php314
-rw-r--r--tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php270
-rw-r--r--tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php4
-rw-r--r--tests/Wallabag/CoreBundle/Controller/RssControllerTest.php53
-rw-r--r--tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php2
-rw-r--r--tests/Wallabag/CoreBundle/Controller/TagControllerTest.php2
-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/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php85
-rw-r--r--tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php77
-rw-r--r--tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php142
-rw-r--r--tests/Wallabag/CoreBundle/Helper/RedirectTest.php59
-rw-r--r--tests/Wallabag/CoreBundle/Tools/UtilsTest.php28
-rw-r--r--tests/Wallabag/CoreBundle/Tools/samples/cyrillic.txt7
-rw-r--r--tests/Wallabag/CoreBundle/Tools/samples/greek.txt9
-rw-r--r--tests/Wallabag/CoreBundle/Tools/samples/latin.txt9
-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.php8
-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
-rw-r--r--tests/Wallabag/UserBundle/Controller/ManageControllerTest.php1
-rw-r--r--tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php2
43 files changed, 1706 insertions, 204 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..409a8291 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()
@@ -670,4 +678,40 @@ class EntryRestControllerTest extends WallabagApiTestCase
670 678
671 $this->assertEquals(403, $this->client->getResponse()->getStatusCode()); 679 $this->assertEquals(403, $this->client->getResponse()->getStatusCode());
672 } 680 }
681
682 public function testReloadEntryErrorWhileFetching()
683 {
684 $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager')
685 ->getRepository('WallabagCoreBundle:Entry')
686 ->findByUrlAndUserId('http://0.0.0.0/entry4', 1);
687
688 if (!$entry) {
689 $this->markTestSkipped('No content found in db.');
690 }
691
692 $this->client->request('PATCH', '/api/entries/'.$entry->getId().'/reload.json');
693 $this->assertEquals(304, $this->client->getResponse()->getStatusCode());
694 }
695
696 public function testReloadEntry()
697 {
698 $this->client->request('POST', '/api/entries.json', [
699 'url' => 'http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html',
700 'archive' => '1',
701 'tags' => 'google, apple',
702 ]);
703
704 $json = json_decode($this->client->getResponse()->getContent(), true);
705
706 $this->setUp();
707
708 $this->client->request('PATCH', '/api/entries/'.$json['id'].'/reload.json');
709 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
710
711 $content = json_decode($this->client->getResponse()->getContent(), true);
712
713 $this->assertNotEmpty($content['title']);
714
715 $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type'));
716 }
673} 717}
diff --git a/tests/Wallabag/CoreBundle/Command/ExportCommandTest.php b/tests/Wallabag/CoreBundle/Command/ExportCommandTest.php
new file mode 100644
index 00000000..6798c5d7
--- /dev/null
+++ b/tests/Wallabag/CoreBundle/Command/ExportCommandTest.php
@@ -0,0 +1,78 @@
1<?php
2
3namespace Tests\Wallabag\CoreBundle\Command;
4
5use Symfony\Bundle\FrameworkBundle\Console\Application;
6use Symfony\Component\Console\Tester\CommandTester;
7use Wallabag\CoreBundle\Command\ExportCommand;
8use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
9
10class ExportCommandTest extends WallabagCoreTestCase
11{
12 /**
13 * @expectedException Symfony\Component\Console\Exception\RuntimeException
14 * @expectedExceptionMessage Not enough arguments (missing: "username")
15 */
16 public function testExportCommandWithoutUsername()
17 {
18 $application = new Application($this->getClient()->getKernel());
19 $application->add(new ExportCommand());
20
21 $command = $application->find('wallabag:export');
22
23 $tester = new CommandTester($command);
24 $tester->execute([
25 'command' => $command->getName(),
26 ]);
27 }
28
29 public function testExportCommandWithBadUsername()
30 {
31 $application = new Application($this->getClient()->getKernel());
32 $application->add(new ExportCommand());
33
34 $command = $application->find('wallabag:export');
35
36 $tester = new CommandTester($command);
37 $tester->execute([
38 'command' => $command->getName(),
39 'username' => 'unknown',
40 ]);
41
42 $this->assertContains('User "unknown" not found', $tester->getDisplay());
43 }
44
45 public function testExportCommand()
46 {
47 $application = new Application($this->getClient()->getKernel());
48 $application->add(new ExportCommand());
49
50 $command = $application->find('wallabag:export');
51
52 $tester = new CommandTester($command);
53 $tester->execute([
54 'command' => $command->getName(),
55 'username' => 'admin',
56 ]);
57
58 $this->assertContains('Exporting 6 entrie(s) for user « admin »... Done', $tester->getDisplay());
59 $this->assertFileExists('admin-export.json');
60 }
61
62 public function testExportCommandWithSpecialPath()
63 {
64 $application = new Application($this->getClient()->getKernel());
65 $application->add(new ExportCommand());
66
67 $command = $application->find('wallabag:export');
68
69 $tester = new CommandTester($command);
70 $tester->execute([
71 'command' => $command->getName(),
72 'username' => 'admin',
73 'filepath' => 'specialexport.json'
74 ]);
75
76 $this->assertFileExists('specialexport.json');
77 }
78}
diff --git a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
index d4fbe2d4..beb0598a 100644
--- a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
@@ -1,8 +1,13 @@
1<?php 1<?php
2 2
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
@@ -509,6 +515,29 @@ class ConfigControllerTest extends WallabagCoreTestCase
509 } 515 }
510 } 516 }
511 517
518 public function testTaggingRuleTooLong()
519 {
520 $this->logInAs('admin');
521 $client = $this->getClient();
522
523 $crawler = $client->request('GET', '/config');
524
525 $this->assertEquals(200, $client->getResponse()->getStatusCode());
526
527 $form = $crawler->filter('button[id=tagging_rule_save]')->form();
528
529 $crawler = $client->submit($form, [
530 'tagging_rule[rule]' => str_repeat('title', 60),
531 'tagging_rule[tags]' => 'cool tag',
532 ]);
533
534 $this->assertEquals(200, $client->getResponse()->getStatusCode());
535
536 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
537
538 $this->assertContains('255 characters', $body[0]);
539 }
540
512 public function testDeletingTaggingRuleFromAnOtherUser() 541 public function testDeletingTaggingRuleFromAnOtherUser()
513 { 542 {
514 $this->logInAs('bob'); 543 $this->logInAs('bob');
@@ -570,4 +599,283 @@ class ConfigControllerTest extends WallabagCoreTestCase
570 $config->set('demo_mode_enabled', 0); 599 $config->set('demo_mode_enabled', 0);
571 $config->set('demo_mode_username', 'wallabag'); 600 $config->set('demo_mode_username', 'wallabag');
572 } 601 }
602
603 public function testDeleteUserButtonVisibility()
604 {
605 $this->logInAs('admin');
606 $client = $this->getClient();
607
608 $crawler = $client->request('GET', '/config');
609
610 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
611 $this->assertContains('config.form_user.delete.button', $body[0]);
612
613 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
614
615 $user = $em
616 ->getRepository('WallabagUserBundle:User')
617 ->findOneByUsername('empty');
618 $user->setEnabled(false);
619 $em->persist($user);
620
621 $user = $em
622 ->getRepository('WallabagUserBundle:User')
623 ->findOneByUsername('bob');
624 $user->setEnabled(false);
625 $em->persist($user);
626
627 $em->flush();
628
629 $crawler = $client->request('GET', '/config');
630
631 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
632 $this->assertNotContains('config.form_user.delete.button', $body[0]);
633
634 $client->request('GET', '/account/delete');
635 $this->assertEquals(403, $client->getResponse()->getStatusCode());
636
637 $user = $em
638 ->getRepository('WallabagUserBundle:User')
639 ->findOneByUsername('empty');
640 $user->setEnabled(true);
641 $em->persist($user);
642
643 $user = $em
644 ->getRepository('WallabagUserBundle:User')
645 ->findOneByUsername('bob');
646 $user->setEnabled(true);
647 $em->persist($user);
648
649 $em->flush();
650 }
651
652 public function testDeleteAccount()
653 {
654 $client = $this->getClient();
655 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
656
657 $user = new User();
658 $user->setName('Wallace');
659 $user->setEmail('wallace@wallabag.org');
660 $user->setUsername('wallace');
661 $user->setPlainPassword('wallace');
662 $user->setEnabled(true);
663 $user->addRole('ROLE_SUPER_ADMIN');
664
665 $em->persist($user);
666
667 $config = new Config($user);
668
669 $config->setTheme('material');
670 $config->setItemsPerPage(30);
671 $config->setReadingSpeed(1);
672 $config->setLanguage('en');
673 $config->setPocketConsumerKey('xxxxx');
674
675 $em->persist($config);
676 $em->flush();
677
678 $this->logInAs('wallace');
679 $loggedInUserId = $this->getLoggedInUserId();
680
681 // create entry to check after user deletion
682 // that this entry is also deleted
683 $crawler = $client->request('GET', '/new');
684
685 $this->assertEquals(200, $client->getResponse()->getStatusCode());
686
687 $form = $crawler->filter('form[name=entry]')->form();
688 $data = [
689 'entry[url]' => $url = 'https://github.com/wallabag/wallabag',
690 ];
691
692 $client->submit($form, $data);
693 $this->assertEquals(302, $client->getResponse()->getStatusCode());
694
695 $crawler = $client->request('GET', '/config');
696
697 $deleteLink = $crawler->filter('.delete-account')->last()->link();
698
699 $client->click($deleteLink);
700 $this->assertEquals(302, $client->getResponse()->getStatusCode());
701
702 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
703 $user = $em
704 ->getRepository('WallabagUserBundle:User')
705 ->createQueryBuilder('u')
706 ->where('u.username = :username')->setParameter('username', 'wallace')
707 ->getQuery()
708 ->getOneOrNullResult()
709 ;
710
711 $this->assertNull($user);
712
713 $entries = $client->getContainer()
714 ->get('doctrine.orm.entity_manager')
715 ->getRepository('WallabagCoreBundle:Entry')
716 ->findByUser($loggedInUserId);
717
718 $this->assertEmpty($entries);
719 }
720
721 public function testReset()
722 {
723 $this->logInAs('empty');
724 $client = $this->getClient();
725
726 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
727
728 $user = static::$kernel->getContainer()->get('security.token_storage')->getToken()->getUser();
729
730 $tag = new Tag();
731 $tag->setLabel('super');
732 $em->persist($tag);
733
734 $entry = new Entry($user);
735 $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');
736 $entry->setContent('Youhou');
737 $entry->setTitle('Youhou');
738 $entry->addTag($tag);
739 $em->persist($entry);
740
741 $entry2 = new Entry($user);
742 $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');
743 $entry2->setContent('Youhou');
744 $entry2->setTitle('Youhou');
745 $entry2->addTag($tag);
746 $em->persist($entry2);
747
748 $annotation = new Annotation($user);
749 $annotation->setText('annotated');
750 $annotation->setQuote('annotated');
751 $annotation->setRanges([]);
752 $annotation->setEntry($entry);
753 $em->persist($annotation);
754
755 $em->flush();
756
757 // reset annotations
758 $crawler = $client->request('GET', '/config#set3');
759
760 $this->assertEquals(200, $client->getResponse()->getStatusCode());
761
762 $crawler = $client->click($crawler->selectLink('config.reset.annotations')->link());
763
764 $this->assertEquals(302, $client->getResponse()->getStatusCode());
765 $this->assertContains('flashes.config.notice.annotations_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]);
766
767 $annotationsReset = $em
768 ->getRepository('WallabagAnnotationBundle:Annotation')
769 ->findAnnotationsByPageId($entry->getId(), $user->getId());
770
771 $this->assertEmpty($annotationsReset, 'Annotations were reset');
772
773 // reset tags
774 $crawler = $client->request('GET', '/config#set3');
775
776 $this->assertEquals(200, $client->getResponse()->getStatusCode());
777
778 $crawler = $client->click($crawler->selectLink('config.reset.tags')->link());
779
780 $this->assertEquals(302, $client->getResponse()->getStatusCode());
781 $this->assertContains('flashes.config.notice.tags_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]);
782
783 $tagReset = $em
784 ->getRepository('WallabagCoreBundle:Tag')
785 ->countAllTags($user->getId());
786
787 $this->assertEquals(0, $tagReset, 'Tags were reset');
788
789 // reset entries
790 $crawler = $client->request('GET', '/config#set3');
791
792 $this->assertEquals(200, $client->getResponse()->getStatusCode());
793
794 $crawler = $client->click($crawler->selectLink('config.reset.entries')->link());
795
796 $this->assertEquals(302, $client->getResponse()->getStatusCode());
797 $this->assertContains('flashes.config.notice.entries_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]);
798
799 $entryReset = $em
800 ->getRepository('WallabagCoreBundle:Entry')
801 ->countAllEntriesByUsername($user->getId());
802
803 $this->assertEquals(0, $entryReset, 'Entries were reset');
804 }
805
806 public function testResetEntriesCascade()
807 {
808 $this->logInAs('empty');
809 $client = $this->getClient();
810
811 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
812
813 $user = static::$kernel->getContainer()->get('security.token_storage')->getToken()->getUser();
814
815 $tag = new Tag();
816 $tag->setLabel('super');
817 $em->persist($tag);
818
819 $entry = new Entry($user);
820 $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');
821 $entry->setContent('Youhou');
822 $entry->setTitle('Youhou');
823 $entry->addTag($tag);
824 $em->persist($entry);
825
826 $annotation = new Annotation($user);
827 $annotation->setText('annotated');
828 $annotation->setQuote('annotated');
829 $annotation->setRanges([]);
830 $annotation->setEntry($entry);
831 $em->persist($annotation);
832
833 $em->flush();
834
835 $crawler = $client->request('GET', '/config#set3');
836
837 $this->assertEquals(200, $client->getResponse()->getStatusCode());
838
839 $crawler = $client->click($crawler->selectLink('config.reset.entries')->link());
840
841 $this->assertEquals(302, $client->getResponse()->getStatusCode());
842 $this->assertContains('flashes.config.notice.entries_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]);
843
844 $entryReset = $em
845 ->getRepository('WallabagCoreBundle:Entry')
846 ->countAllEntriesByUsername($user->getId());
847
848 $this->assertEquals(0, $entryReset, 'Entries were reset');
849
850 $tagReset = $em
851 ->getRepository('WallabagCoreBundle:Tag')
852 ->countAllTags($user->getId());
853
854 $this->assertEquals(0, $tagReset, 'Tags were reset');
855
856 $annotationsReset = $em
857 ->getRepository('WallabagAnnotationBundle:Annotation')
858 ->findAnnotationsByPageId($entry->getId(), $user->getId());
859
860 $this->assertEmpty($annotationsReset, 'Annotations were reset');
861 }
862
863 public function testSwitchViewMode()
864 {
865 $this->logInAs('admin');
866 $client = $this->getClient();
867
868 $client->request('GET', '/unread/list');
869
870 $this->assertNotContains('listmode', $client->getResponse()->getContent());
871
872 $client->request('GET', '/config/view-mode');
873 $crawler = $client->followRedirect();
874
875 $client->request('GET', '/unread/list');
876
877 $this->assertContains('listmode', $client->getResponse()->getContent());
878
879 $client->request('GET', '/config/view-mode');
880 }
573} 881}
diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
index 05113650..06ed2db6 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
@@ -724,6 +725,15 @@ class EntryControllerTest extends WallabagCoreTestCase
724 $crawler = $client->submit($form, $data); 725 $crawler = $client->submit($form, $data);
725 $this->assertCount(5, $crawler->filter('div[class=entry]')); 726 $this->assertCount(5, $crawler->filter('div[class=entry]'));
726 727
728 $crawler = $client->request('GET', '/unread/list');
729 $form = $crawler->filter('button[id=submit-filter]')->form();
730 $data = [
731 'entry_filter[domainName]' => 'dOmain',
732 ];
733
734 $crawler = $client->submit($form, $data);
735 $this->assertCount(5, $crawler->filter('div[class=entry]'));
736
727 $form = $crawler->filter('button[id=submit-filter]')->form(); 737 $form = $crawler->filter('button[id=submit-filter]')->form();
728 $data = [ 738 $data = [
729 'entry_filter[domainName]' => 'wallabag', 739 'entry_filter[domainName]' => 'wallabag',
@@ -800,15 +810,15 @@ class EntryControllerTest extends WallabagCoreTestCase
800 ->getRepository('WallabagCoreBundle:Entry') 810 ->getRepository('WallabagCoreBundle:Entry')
801 ->findOneByUser($this->getLoggedInUserId()); 811 ->findOneByUser($this->getLoggedInUserId());
802 812
803 // no uuid 813 // no uid
804 $client->request('GET', '/share/'.$content->getUuid()); 814 $client->request('GET', '/share/'.$content->getUid());
805 $this->assertEquals(404, $client->getResponse()->getStatusCode()); 815 $this->assertEquals(404, $client->getResponse()->getStatusCode());
806 816
807 // generating the uuid 817 // generating the uid
808 $client->request('GET', '/share/'.$content->getId()); 818 $client->request('GET', '/share/'.$content->getId());
809 $this->assertEquals(302, $client->getResponse()->getStatusCode()); 819 $this->assertEquals(302, $client->getResponse()->getStatusCode());
810 820
811 // follow link with uuid 821 // follow link with uid
812 $crawler = $client->followRedirect(); 822 $crawler = $client->followRedirect();
813 $this->assertEquals(200, $client->getResponse()->getStatusCode()); 823 $this->assertEquals(200, $client->getResponse()->getStatusCode());
814 $this->assertContains('max-age=25200', $client->getResponse()->headers->get('cache-control')); 824 $this->assertContains('max-age=25200', $client->getResponse()->headers->get('cache-control'));
@@ -822,7 +832,7 @@ class EntryControllerTest extends WallabagCoreTestCase
822 832
823 // sharing is now disabled 833 // sharing is now disabled
824 $client->getContainer()->get('craue_config')->set('share_public', 0); 834 $client->getContainer()->get('craue_config')->set('share_public', 0);
825 $client->request('GET', '/share/'.$content->getUuid()); 835 $client->request('GET', '/share/'.$content->getUid());
826 $this->assertEquals(404, $client->getResponse()->getStatusCode()); 836 $this->assertEquals(404, $client->getResponse()->getStatusCode());
827 837
828 $client->request('GET', '/view/'.$content->getId()); 838 $client->request('GET', '/view/'.$content->getId());
@@ -833,7 +843,255 @@ class EntryControllerTest extends WallabagCoreTestCase
833 $this->assertEquals(302, $client->getResponse()->getStatusCode()); 843 $this->assertEquals(302, $client->getResponse()->getStatusCode());
834 844
835 // share is now disable 845 // share is now disable
836 $client->request('GET', '/share/'.$content->getUuid()); 846 $client->request('GET', '/share/'.$content->getUid());
837 $this->assertEquals(404, $client->getResponse()->getStatusCode()); 847 $this->assertEquals(404, $client->getResponse()->getStatusCode());
838 } 848 }
849
850 public function testNewEntryWithDownloadImagesEnabled()
851 {
852 $this->logInAs('admin');
853 $client = $this->getClient();
854
855 $url = 'http://www.20minutes.fr/montpellier/1952003-20161030-video-car-tombe-panne-rugbymen-perpignan-improvisent-melee-route';
856 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
857
858 $crawler = $client->request('GET', '/new');
859
860 $this->assertEquals(200, $client->getResponse()->getStatusCode());
861
862 $form = $crawler->filter('form[name=entry]')->form();
863
864 $data = [
865 'entry[url]' => $url,
866 ];
867
868 $client->submit($form, $data);
869
870 $this->assertEquals(302, $client->getResponse()->getStatusCode());
871
872 $em = $client->getContainer()
873 ->get('doctrine.orm.entity_manager');
874
875 $entry = $em
876 ->getRepository('WallabagCoreBundle:Entry')
877 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
878
879 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $entry);
880 $this->assertEquals($url, $entry->getUrl());
881 $this->assertContains('Perpignan', $entry->getTitle());
882 $this->assertContains('/d9bc0fcd.jpeg', $entry->getContent());
883
884 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
885 }
886
887 /**
888 * @depends testNewEntryWithDownloadImagesEnabled
889 */
890 public function testRemoveEntryWithDownloadImagesEnabled()
891 {
892 $this->logInAs('admin');
893 $client = $this->getClient();
894
895 $url = 'http://www.20minutes.fr/montpellier/1952003-20161030-video-car-tombe-panne-rugbymen-perpignan-improvisent-melee-route';
896 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
897
898 $content = $client->getContainer()
899 ->get('doctrine.orm.entity_manager')
900 ->getRepository('WallabagCoreBundle:Entry')
901 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
902
903 $client->request('GET', '/delete/'.$content->getId());
904
905 $this->assertEquals(302, $client->getResponse()->getStatusCode());
906
907 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
908 }
909
910 public function testRedirectToHomepage()
911 {
912 $this->logInAs('empty');
913 $client = $this->getClient();
914
915 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
916 $user = $em
917 ->getRepository('WallabagUserBundle:User')
918 ->find($this->getLoggedInUserId());
919
920 if (!$user) {
921 $this->markTestSkipped('No user found in db.');
922 }
923
924 // Redirect to homepage
925 $config = $user->getConfig();
926 $config->setActionMarkAsRead(Config::REDIRECT_TO_HOMEPAGE);
927 $em->persist($config);
928 $em->flush();
929
930 $content = $client->getContainer()
931 ->get('doctrine.orm.entity_manager')
932 ->getRepository('WallabagCoreBundle:Entry')
933 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
934
935 $client->request('GET', '/view/'.$content->getId());
936 $client->request('GET', '/archive/'.$content->getId());
937
938 $this->assertEquals(302, $client->getResponse()->getStatusCode());
939 $this->assertEquals('/', $client->getResponse()->headers->get('location'));
940 }
941
942 public function testRedirectToCurrentPage()
943 {
944 $this->logInAs('empty');
945 $client = $this->getClient();
946
947 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
948 $user = $em
949 ->getRepository('WallabagUserBundle:User')
950 ->find($this->getLoggedInUserId());
951
952 if (!$user) {
953 $this->markTestSkipped('No user found in db.');
954 }
955
956 // Redirect to current page
957 $config = $user->getConfig();
958 $config->setActionMarkAsRead(Config::REDIRECT_TO_CURRENT_PAGE);
959 $em->persist($config);
960 $em->flush();
961
962 $content = $client->getContainer()
963 ->get('doctrine.orm.entity_manager')
964 ->getRepository('WallabagCoreBundle:Entry')
965 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
966
967 $client->request('GET', '/view/'.$content->getId());
968 $client->request('GET', '/archive/'.$content->getId());
969
970 $this->assertEquals(302, $client->getResponse()->getStatusCode());
971 $this->assertContains('/view/'.$content->getId(), $client->getResponse()->headers->get('location'));
972 }
973
974 public function testFilterOnHttpStatus()
975 {
976 $this->logInAs('admin');
977 $client = $this->getClient();
978
979 $crawler = $client->request('GET', '/new');
980 $form = $crawler->filter('form[name=entry]')->form();
981
982 $data = [
983 'entry[url]' => 'http://www.lemonde.fr/incorrect-url/',
984 ];
985
986 $client->submit($form, $data);
987
988 $crawler = $client->request('GET', '/all/list');
989 $form = $crawler->filter('button[id=submit-filter]')->form();
990
991 $data = [
992 'entry_filter[httpStatus]' => 404,
993 ];
994
995 $crawler = $client->submit($form, $data);
996
997 $this->assertCount(1, $crawler->filter('div[class=entry]'));
998
999 $crawler = $client->request('GET', '/new');
1000 $form = $crawler->filter('form[name=entry]')->form();
1001
1002 $data = [
1003 'entry[url]' => 'http://www.nextinpact.com/news/101235-wallabag-alternative-libre-a-pocket-creuse-petit-a-petit-son-nid.htm',
1004 ];
1005
1006 $client->submit($form, $data);
1007
1008 $crawler = $client->request('GET', '/all/list');
1009 $form = $crawler->filter('button[id=submit-filter]')->form();
1010
1011 $data = [
1012 'entry_filter[httpStatus]' => 200,
1013 ];
1014
1015 $crawler = $client->submit($form, $data);
1016
1017 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1018
1019 $crawler = $client->request('GET', '/all/list');
1020 $form = $crawler->filter('button[id=submit-filter]')->form();
1021
1022 $data = [
1023 'entry_filter[httpStatus]' => 1024,
1024 ];
1025
1026 $crawler = $client->submit($form, $data);
1027
1028 $this->assertCount(7, $crawler->filter('div[class=entry]'));
1029 }
1030
1031 public function testSearch()
1032 {
1033 $this->logInAs('admin');
1034 $client = $this->getClient();
1035
1036 // Search on unread list
1037 $crawler = $client->request('GET', '/unread/list');
1038
1039 $form = $crawler->filter('form[name=search]')->form();
1040 $data = [
1041 'search_entry[term]' => 'title',
1042 ];
1043
1044 $crawler = $client->submit($form, $data);
1045
1046 $this->assertCount(5, $crawler->filter('div[class=entry]'));
1047
1048 // Search on starred list
1049 $crawler = $client->request('GET', '/starred/list');
1050
1051 $form = $crawler->filter('form[name=search]')->form();
1052 $data = [
1053 'search_entry[term]' => 'title',
1054 ];
1055
1056 $crawler = $client->submit($form, $data);
1057
1058 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1059
1060 // Added new article to test on archive list
1061 $crawler = $client->request('GET', '/new');
1062 $form = $crawler->filter('form[name=entry]')->form();
1063 $data = [
1064 'entry[url]' => $this->url,
1065 ];
1066 $client->submit($form, $data);
1067 $content = $client->getContainer()
1068 ->get('doctrine.orm.entity_manager')
1069 ->getRepository('WallabagCoreBundle:Entry')
1070 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
1071 $client->request('GET', '/archive/'.$content->getId());
1072
1073 $crawler = $client->request('GET', '/archive/list');
1074
1075 $form = $crawler->filter('form[name=search]')->form();
1076 $data = [
1077 'search_entry[term]' => 'manège',
1078 ];
1079
1080 $crawler = $client->submit($form, $data);
1081
1082 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1083 $client->request('GET', '/delete/'.$content->getId());
1084
1085 // test on list of all articles
1086 $crawler = $client->request('GET', '/all/list');
1087
1088 $form = $crawler->filter('form[name=search]')->form();
1089 $data = [
1090 'search_entry[term]' => 'wxcvbnqsdf', // a string not available in the database
1091 ];
1092
1093 $crawler = $client->submit($form, $data);
1094
1095 $this->assertCount(0, $crawler->filter('div[class=entry]'));
1096 }
839} 1097}
diff --git a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php
index 5ca886bd..32a18e26 100644
--- a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php
@@ -119,7 +119,7 @@ class ExportControllerTest extends WallabagCoreTestCase
119 $this->assertEquals('binary', $headers->get('content-transfer-encoding')); 119 $this->assertEquals('binary', $headers->get('content-transfer-encoding'));
120 120
121 ob_start(); 121 ob_start();
122 $crawler = $client->request('GET', '/export/tag_entries.pdf?tag=foo'); 122 $crawler = $client->request('GET', '/export/tag_entries.pdf?tag=foo-bar');
123 ob_end_clean(); 123 ob_end_clean();
124 124
125 $this->assertEquals(200, $client->getResponse()->getStatusCode()); 125 $this->assertEquals(200, $client->getResponse()->getStatusCode());
@@ -241,7 +241,7 @@ class ExportControllerTest extends WallabagCoreTestCase
241 $this->assertEquals($contentInDB->getLanguage(), $content[0]['language']); 241 $this->assertEquals($contentInDB->getLanguage(), $content[0]['language']);
242 $this->assertEquals($contentInDB->getReadingtime(), $content[0]['reading_time']); 242 $this->assertEquals($contentInDB->getReadingtime(), $content[0]['reading_time']);
243 $this->assertEquals($contentInDB->getDomainname(), $content[0]['domain_name']); 243 $this->assertEquals($contentInDB->getDomainname(), $content[0]['domain_name']);
244 $this->assertEquals(['foo', 'baz'], $content[0]['tags']); 244 $this->assertEquals(['foo bar', 'baz'], $content[0]['tags']);
245 } 245 }
246 246
247 public function testXmlExport() 247 public function testXmlExport()
diff --git a/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php b/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php
index fb6fe06a..5a59654d 100644
--- a/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php
@@ -6,7 +6,7 @@ use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
6 6
7class RssControllerTest extends WallabagCoreTestCase 7class RssControllerTest extends WallabagCoreTestCase
8{ 8{
9 public function validateDom($xml, $nb = null) 9 public function validateDom($xml, $type, $nb = null)
10 { 10 {
11 $doc = new \DOMDocument(); 11 $doc = new \DOMDocument();
12 $doc->loadXML($xml); 12 $doc->loadXML($xml);
@@ -22,6 +22,23 @@ class RssControllerTest extends WallabagCoreTestCase
22 $this->assertEquals(1, $xpath->query('/rss')->length); 22 $this->assertEquals(1, $xpath->query('/rss')->length);
23 $this->assertEquals(1, $xpath->query('/rss/channel')->length); 23 $this->assertEquals(1, $xpath->query('/rss/channel')->length);
24 24
25 $this->assertEquals(1, $xpath->query('/rss/channel/title')->length);
26 $this->assertEquals('wallabag — '.$type.' feed', $xpath->query('/rss/channel/title')->item(0)->nodeValue);
27
28 $this->assertEquals(1, $xpath->query('/rss/channel/pubDate')->length);
29
30 $this->assertEquals(1, $xpath->query('/rss/channel/generator')->length);
31 $this->assertEquals('wallabag', $xpath->query('/rss/channel/generator')->item(0)->nodeValue);
32
33 $this->assertEquals(1, $xpath->query('/rss/channel/description')->length);
34 $this->assertEquals('wallabag '.$type.' elements', $xpath->query('/rss/channel/description')->item(0)->nodeValue);
35
36 $this->assertEquals(1, $xpath->query('/rss/channel/link[@rel="self"]')->length);
37 $this->assertContains($type.'.xml', $xpath->query('/rss/channel/link[@rel="self"]')->item(0)->getAttribute('href'));
38
39 $this->assertEquals(1, $xpath->query('/rss/channel/link[@rel="last"]')->length);
40 $this->assertContains($type.'.xml?page=', $xpath->query('/rss/channel/link[@rel="last"]')->item(0)->getAttribute('href'));
41
25 foreach ($xpath->query('//item') as $item) { 42 foreach ($xpath->query('//item') as $item) {
26 $this->assertEquals(1, $xpath->query('title', $item)->length); 43 $this->assertEquals(1, $xpath->query('title', $item)->length);
27 $this->assertEquals(1, $xpath->query('source', $item)->length); 44 $this->assertEquals(1, $xpath->query('source', $item)->length);
@@ -77,7 +94,7 @@ class RssControllerTest extends WallabagCoreTestCase
77 94
78 $this->assertEquals(200, $client->getResponse()->getStatusCode()); 95 $this->assertEquals(200, $client->getResponse()->getStatusCode());
79 96
80 $this->validateDom($client->getResponse()->getContent(), 2); 97 $this->validateDom($client->getResponse()->getContent(), 'unread', 2);
81 } 98 }
82 99
83 public function testStarred() 100 public function testStarred()
@@ -99,7 +116,7 @@ class RssControllerTest extends WallabagCoreTestCase
99 116
100 $this->assertEquals(200, $client->getResponse()->getStatusCode(), 1); 117 $this->assertEquals(200, $client->getResponse()->getStatusCode(), 1);
101 118
102 $this->validateDom($client->getResponse()->getContent()); 119 $this->validateDom($client->getResponse()->getContent(), 'starred');
103 } 120 }
104 121
105 public function testArchives() 122 public function testArchives()
@@ -121,6 +138,34 @@ class RssControllerTest extends WallabagCoreTestCase
121 138
122 $this->assertEquals(200, $client->getResponse()->getStatusCode()); 139 $this->assertEquals(200, $client->getResponse()->getStatusCode());
123 140
124 $this->validateDom($client->getResponse()->getContent()); 141 $this->validateDom($client->getResponse()->getContent(), 'archive');
142 }
143
144 public function testPagination()
145 {
146 $client = $this->getClient();
147 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
148 $user = $em
149 ->getRepository('WallabagUserBundle:User')
150 ->findOneByUsername('admin');
151
152 $config = $user->getConfig();
153 $config->setRssToken('SUPERTOKEN');
154 $config->setRssLimit(1);
155 $em->persist($config);
156 $em->flush();
157
158 $client = $this->getClient();
159
160 $client->request('GET', '/admin/SUPERTOKEN/unread.xml');
161 $this->assertEquals(200, $client->getResponse()->getStatusCode());
162 $this->validateDom($client->getResponse()->getContent(), 'unread');
163
164 $client->request('GET', '/admin/SUPERTOKEN/unread.xml?page=2');
165 $this->assertEquals(200, $client->getResponse()->getStatusCode());
166 $this->validateDom($client->getResponse()->getContent(), 'unread');
167
168 $client->request('GET', '/admin/SUPERTOKEN/unread.xml?page=3000');
169 $this->assertEquals(302, $client->getResponse()->getStatusCode());
125 } 170 }
126} 171}
diff --git a/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php b/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php
index 08f4676e..2cf596d4 100644
--- a/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php
@@ -82,6 +82,6 @@ class SecurityControllerTest extends WallabagCoreTestCase
82 82
83 $client->followRedirects(); 83 $client->followRedirects();
84 $crawler = $client->request('GET', '/register'); 84 $crawler = $client->request('GET', '/register');
85 $this->assertContains('registration.submit', $crawler->filter('body')->extract(['_text'])[0]); 85 $this->assertContains('registration.submit', $client->getResponse()->getContent());
86 } 86 }
87} 87}
diff --git a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php
index 769ce66e..fa1a3539 100644
--- a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php
@@ -61,7 +61,7 @@ class TagControllerTest extends WallabagCoreTestCase
61 61
62 // tag already exists but still not assigned to this entry 62 // tag already exists but still not assigned to this entry
63 $data = [ 63 $data = [
64 'tag[label]' => 'foo', 64 'tag[label]' => 'foo bar',
65 ]; 65 ];
66 66
67 $client->submit($form, $data); 67 $client->submit($form, $data);
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/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php b/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php
new file mode 100644
index 00000000..aee67259
--- /dev/null
+++ b/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php
@@ -0,0 +1,85 @@
1<?php
2
3namespace Tests\Wallabag\CoreBundle\GuzzleSiteAuthenticator;
4
5use BD\GuzzleSiteAuthenticator\SiteConfig\SiteConfig;
6use Graby\SiteConfig\SiteConfig as GrabySiteConfig;
7use PHPUnit_Framework_TestCase;
8use Wallabag\CoreBundle\GuzzleSiteAuthenticator\GrabySiteConfigBuilder;
9
10class GrabySiteConfigBuilderTest extends PHPUnit_Framework_TestCase
11{
12 /** @var \Wallabag\CoreBundle\GuzzleSiteAuthenticator\GrabySiteConfigBuilder */
13 protected $builder;
14
15 public function testBuildConfigExists()
16 {
17 /* @var \Graby\SiteConfig\ConfigBuilder|\PHPUnit_Framework_MockObject_MockObject */
18 $grabyConfigBuilderMock = $this->getMockBuilder('\Graby\SiteConfig\ConfigBuilder')
19 ->disableOriginalConstructor()
20 ->getMock();
21
22 $grabySiteConfig = new GrabySiteConfig();
23 $grabySiteConfig->requires_login = true;
24 $grabySiteConfig->login_uri = 'http://example.com/login';
25 $grabySiteConfig->login_username_field = 'login';
26 $grabySiteConfig->login_password_field = 'password';
27 $grabySiteConfig->login_extra_fields = ['field' => 'value'];
28 $grabySiteConfig->not_logged_in_xpath = '//div[@class="need-login"]';
29
30 $grabyConfigBuilderMock
31 ->method('buildForHost')
32 ->with('example.com')
33 ->will($this->returnValue($grabySiteConfig));
34
35 $this->builder = new GrabySiteConfigBuilder(
36 $grabyConfigBuilderMock,
37 ['example.com' => ['username' => 'foo', 'password' => 'bar']]
38 );
39
40 $config = $this->builder->buildForHost('example.com');
41
42 self::assertEquals(
43 new SiteConfig([
44 'host' => 'example.com',
45 'requiresLogin' => true,
46 'loginUri' => 'http://example.com/login',
47 'usernameField' => 'login',
48 'passwordField' => 'password',
49 'extraFields' => ['field' => 'value'],
50 'notLoggedInXpath' => '//div[@class="need-login"]',
51 'username' => 'foo',
52 'password' => 'bar',
53 ]),
54 $config
55 );
56 }
57
58 public function testBuildConfigDoesntExist()
59 {
60 /* @var \Graby\SiteConfig\ConfigBuilder|\PHPUnit_Framework_MockObject_MockObject */
61 $grabyConfigBuilderMock = $this->getMockBuilder('\Graby\SiteConfig\ConfigBuilder')
62 ->disableOriginalConstructor()
63 ->getMock();
64
65 $grabyConfigBuilderMock
66 ->method('buildForHost')
67 ->with('unknown.com')
68 ->will($this->returnValue(new GrabySiteConfig()));
69
70 $this->builder = new GrabySiteConfigBuilder($grabyConfigBuilderMock, []);
71
72 $config = $this->builder->buildForHost('unknown.com');
73
74 self::assertEquals(
75 new SiteConfig([
76 'host' => 'unknown.com',
77 'requiresLogin' => false,
78 'username' => null,
79 'password' => null,
80 'extraFields' => [],
81 ]),
82 $config
83 );
84 }
85}
diff --git a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php
index 5d772602..5956b502 100644
--- a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php
+++ b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php
@@ -10,6 +10,8 @@ use Wallabag\UserBundle\Entity\User;
10 10
11class ContentProxyTest extends \PHPUnit_Framework_TestCase 11class ContentProxyTest extends \PHPUnit_Framework_TestCase
12{ 12{
13 private $fetchingErrorMessage = 'wallabag can\'t retrieve contents for this article. Please <a href="http://doc.wallabag.org/en/master/user/errors_during_fetching.html#how-can-i-help-to-fix-that">troubleshoot this issue</a>.';
14
13 public function testWithBadUrl() 15 public function testWithBadUrl()
14 { 16 {
15 $tagger = $this->getTaggerMock(); 17 $tagger = $this->getTaggerMock();
@@ -31,12 +33,12 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
31 'language' => '', 33 'language' => '',
32 ]); 34 ]);
33 35
34 $proxy = new ContentProxy($graby, $tagger, $this->getTagRepositoryMock(), $this->getLogger()); 36 $proxy = new ContentProxy($graby, $tagger, $this->getTagRepositoryMock(), $this->getLogger(), $this->fetchingErrorMessage);
35 $entry = $proxy->updateEntry(new Entry(new User()), 'http://user@:80'); 37 $entry = $proxy->updateEntry(new Entry(new User()), 'http://user@:80');
36 38
37 $this->assertEquals('http://user@:80', $entry->getUrl()); 39 $this->assertEquals('http://user@:80', $entry->getUrl());
38 $this->assertEmpty($entry->getTitle()); 40 $this->assertEmpty($entry->getTitle());
39 $this->assertEquals('<p>Unable to retrieve readable content.</p>', $entry->getContent()); 41 $this->assertEquals($this->fetchingErrorMessage, $entry->getContent());
40 $this->assertEmpty($entry->getPreviewPicture()); 42 $this->assertEmpty($entry->getPreviewPicture());
41 $this->assertEmpty($entry->getMimetype()); 43 $this->assertEmpty($entry->getMimetype());
42 $this->assertEmpty($entry->getLanguage()); 44 $this->assertEmpty($entry->getLanguage());
@@ -65,12 +67,12 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
65 'language' => '', 67 'language' => '',
66 ]); 68 ]);
67 69
68 $proxy = new ContentProxy($graby, $tagger, $this->getTagRepositoryMock(), $this->getLogger()); 70 $proxy = new ContentProxy($graby, $tagger, $this->getTagRepositoryMock(), $this->getLogger(), $this->fetchingErrorMessage);
69 $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0'); 71 $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0');
70 72
71 $this->assertEquals('http://0.0.0.0', $entry->getUrl()); 73 $this->assertEquals('http://0.0.0.0', $entry->getUrl());
72 $this->assertEmpty($entry->getTitle()); 74 $this->assertEmpty($entry->getTitle());
73 $this->assertEquals('<p>Unable to retrieve readable content.</p>', $entry->getContent()); 75 $this->assertEquals($this->fetchingErrorMessage, $entry->getContent());
74 $this->assertEmpty($entry->getPreviewPicture()); 76 $this->assertEmpty($entry->getPreviewPicture());
75 $this->assertEmpty($entry->getMimetype()); 77 $this->assertEmpty($entry->getMimetype());
76 $this->assertEmpty($entry->getLanguage()); 78 $this->assertEmpty($entry->getLanguage());
@@ -97,20 +99,22 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
97 'url' => '', 99 'url' => '',
98 'content_type' => '', 100 'content_type' => '',
99 'language' => '', 101 'language' => '',
102 'status' => '',
100 'open_graph' => [ 103 'open_graph' => [
101 'og_title' => 'my title', 104 'og_title' => 'my title',
102 'og_description' => 'desc', 105 'og_description' => 'desc',
103 ], 106 ],
104 ]); 107 ]);
105 108
106 $proxy = new ContentProxy($graby, $tagger, $this->getTagRepositoryMock(), $this->getLogger()); 109 $proxy = new ContentProxy($graby, $tagger, $this->getTagRepositoryMock(), $this->getLogger(), $this->fetchingErrorMessage);
107 $entry = $proxy->updateEntry(new Entry(new User()), 'http://domain.io'); 110 $entry = $proxy->updateEntry(new Entry(new User()), 'http://domain.io');
108 111
109 $this->assertEquals('http://domain.io', $entry->getUrl()); 112 $this->assertEquals('http://domain.io', $entry->getUrl());
110 $this->assertEquals('my title', $entry->getTitle()); 113 $this->assertEquals('my title', $entry->getTitle());
111 $this->assertEquals('<p>Unable to retrieve readable content.</p><p><i>But we found a short description: </i></p>desc', $entry->getContent()); 114 $this->assertEquals($this->fetchingErrorMessage . '<p><i>But we found a short description: </i></p>desc', $entry->getContent());
112 $this->assertEmpty($entry->getPreviewPicture()); 115 $this->assertEmpty($entry->getPreviewPicture());
113 $this->assertEmpty($entry->getLanguage()); 116 $this->assertEmpty($entry->getLanguage());
117 $this->assertEmpty($entry->getHttpStatus());
114 $this->assertEmpty($entry->getMimetype()); 118 $this->assertEmpty($entry->getMimetype());
115 $this->assertEquals(0.0, $entry->getReadingTime()); 119 $this->assertEquals(0.0, $entry->getReadingTime());
116 $this->assertEquals('domain.io', $entry->getDomainName()); 120 $this->assertEquals('domain.io', $entry->getDomainName());
@@ -135,6 +139,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
135 'url' => 'http://1.1.1.1', 139 'url' => 'http://1.1.1.1',
136 'content_type' => 'text/html', 140 'content_type' => 'text/html',
137 'language' => 'fr', 141 'language' => 'fr',
142 'status' => '200',
138 'open_graph' => [ 143 'open_graph' => [
139 'og_title' => 'my OG title', 144 'og_title' => 'my OG title',
140 'og_description' => 'OG desc', 145 'og_description' => 'OG desc',
@@ -142,7 +147,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
142 ], 147 ],
143 ]); 148 ]);
144 149
145 $proxy = new ContentProxy($graby, $tagger, $this->getTagRepositoryMock(), $this->getLogger()); 150 $proxy = new ContentProxy($graby, $tagger, $this->getTagRepositoryMock(), $this->getLogger(), $this->fetchingErrorMessage);
146 $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0'); 151 $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0');
147 152
148 $this->assertEquals('http://1.1.1.1', $entry->getUrl()); 153 $this->assertEquals('http://1.1.1.1', $entry->getUrl());
@@ -151,6 +156,48 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
151 $this->assertEquals('http://3.3.3.3/cover.jpg', $entry->getPreviewPicture()); 156 $this->assertEquals('http://3.3.3.3/cover.jpg', $entry->getPreviewPicture());
152 $this->assertEquals('text/html', $entry->getMimetype()); 157 $this->assertEquals('text/html', $entry->getMimetype());
153 $this->assertEquals('fr', $entry->getLanguage()); 158 $this->assertEquals('fr', $entry->getLanguage());
159 $this->assertEquals('200', $entry->getHttpStatus());
160 $this->assertEquals(4.0, $entry->getReadingTime());
161 $this->assertEquals('1.1.1.1', $entry->getDomainName());
162 }
163
164 public function testWithContentAndNoOgImage()
165 {
166 $tagger = $this->getTaggerMock();
167 $tagger->expects($this->once())
168 ->method('tag');
169
170 $graby = $this->getMockBuilder('Graby\Graby')
171 ->setMethods(['fetchContent'])
172 ->disableOriginalConstructor()
173 ->getMock();
174
175 $graby->expects($this->any())
176 ->method('fetchContent')
177 ->willReturn([
178 'html' => str_repeat('this is my content', 325),
179 'title' => 'this is my title',
180 'url' => 'http://1.1.1.1',
181 'content_type' => 'text/html',
182 'language' => 'fr',
183 'status' => '200',
184 'open_graph' => [
185 'og_title' => 'my OG title',
186 'og_description' => 'OG desc',
187 'og_image' => false,
188 ],
189 ]);
190
191 $proxy = new ContentProxy($graby, $tagger, $this->getTagRepositoryMock(), $this->getLogger(), $this->fetchingErrorMessage);
192 $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0');
193
194 $this->assertEquals('http://1.1.1.1', $entry->getUrl());
195 $this->assertEquals('this is my title', $entry->getTitle());
196 $this->assertContains('this is my content', $entry->getContent());
197 $this->assertNull($entry->getPreviewPicture());
198 $this->assertEquals('text/html', $entry->getMimetype());
199 $this->assertEquals('fr', $entry->getLanguage());
200 $this->assertEquals('200', $entry->getHttpStatus());
154 $this->assertEquals(4.0, $entry->getReadingTime()); 201 $this->assertEquals(4.0, $entry->getReadingTime());
155 $this->assertEquals('1.1.1.1', $entry->getDomainName()); 202 $this->assertEquals('1.1.1.1', $entry->getDomainName());
156 } 203 }
@@ -163,7 +210,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
163 210
164 $graby = $this->getMockBuilder('Graby\Graby')->getMock(); 211 $graby = $this->getMockBuilder('Graby\Graby')->getMock();
165 212
166 $proxy = new ContentProxy($graby, $tagger, $this->getTagRepositoryMock(), $this->getLogger()); 213 $proxy = new ContentProxy($graby, $tagger, $this->getTagRepositoryMock(), $this->getLogger(), $this->fetchingErrorMessage);
167 $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0', [ 214 $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0', [
168 'html' => str_repeat('this is my content', 325), 215 'html' => str_repeat('this is my content', 325),
169 'title' => 'this is my title', 216 'title' => 'this is my title',
@@ -193,7 +240,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
193 ->will($this->throwException(new \Exception())); 240 ->will($this->throwException(new \Exception()));
194 241
195 $tagRepo = $this->getTagRepositoryMock(); 242 $tagRepo = $this->getTagRepositoryMock();
196 $proxy = new ContentProxy($graby, $tagger, $tagRepo, $this->getLogger()); 243 $proxy = new ContentProxy($graby, $tagger, $tagRepo, $this->getLogger(), $this->fetchingErrorMessage);
197 244
198 $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0', [ 245 $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0', [
199 'html' => str_repeat('this is my content', 325), 246 'html' => str_repeat('this is my content', 325),
@@ -213,7 +260,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
213 ->getMock(); 260 ->getMock();
214 261
215 $tagRepo = $this->getTagRepositoryMock(); 262 $tagRepo = $this->getTagRepositoryMock();
216 $proxy = new ContentProxy($graby, $this->getTaggerMock(), $tagRepo, $this->getLogger()); 263 $proxy = new ContentProxy($graby, $this->getTaggerMock(), $tagRepo, $this->getLogger(), $this->fetchingErrorMessage);
217 264
218 $entry = new Entry(new User()); 265 $entry = new Entry(new User());
219 266
@@ -231,7 +278,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
231 ->getMock(); 278 ->getMock();
232 279
233 $tagRepo = $this->getTagRepositoryMock(); 280 $tagRepo = $this->getTagRepositoryMock();
234 $proxy = new ContentProxy($graby, $this->getTaggerMock(), $tagRepo, $this->getLogger()); 281 $proxy = new ContentProxy($graby, $this->getTaggerMock(), $tagRepo, $this->getLogger(), $this->fetchingErrorMessage);
235 282
236 $entry = new Entry(new User()); 283 $entry = new Entry(new User());
237 284
@@ -249,7 +296,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
249 ->getMock(); 296 ->getMock();
250 297
251 $tagRepo = $this->getTagRepositoryMock(); 298 $tagRepo = $this->getTagRepositoryMock();
252 $proxy = new ContentProxy($graby, $this->getTaggerMock(), $tagRepo, $this->getLogger()); 299 $proxy = new ContentProxy($graby, $this->getTaggerMock(), $tagRepo, $this->getLogger(), $this->fetchingErrorMessage);
253 300
254 $entry = new Entry(new User()); 301 $entry = new Entry(new User());
255 302
@@ -265,7 +312,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
265 ->getMock(); 312 ->getMock();
266 313
267 $tagRepo = $this->getTagRepositoryMock(); 314 $tagRepo = $this->getTagRepositoryMock();
268 $proxy = new ContentProxy($graby, $this->getTaggerMock(), $tagRepo, $this->getLogger()); 315 $proxy = new ContentProxy($graby, $this->getTaggerMock(), $tagRepo, $this->getLogger(), $this->fetchingErrorMessage);
269 316
270 $entry = new Entry(new User()); 317 $entry = new Entry(new User());
271 318
@@ -281,7 +328,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
281 ->getMock(); 328 ->getMock();
282 329
283 $tagRepo = $this->getTagRepositoryMock(); 330 $tagRepo = $this->getTagRepositoryMock();
284 $proxy = new ContentProxy($graby, $this->getTaggerMock(), $tagRepo, $this->getLogger()); 331 $proxy = new ContentProxy($graby, $this->getTaggerMock(), $tagRepo, $this->getLogger(), $this->fetchingErrorMessage);
285 332
286 $tagEntity = new Tag(); 333 $tagEntity = new Tag();
287 $tagEntity->setLabel('tag1'); 334 $tagEntity->setLabel('tag1');
@@ -306,7 +353,7 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase
306 $tagRepo->expects($this->never()) 353 $tagRepo->expects($this->never())
307 ->method('__call'); 354 ->method('__call');
308 355
309 $proxy = new ContentProxy($graby, $this->getTaggerMock(), $tagRepo, $this->getLogger()); 356 $proxy = new ContentProxy($graby, $this->getTaggerMock(), $tagRepo, $this->getLogger(), $this->fetchingErrorMessage);
310 357
311 $tagEntity = new Tag(); 358 $tagEntity = new Tag();
312 $tagEntity->setLabel('tag1'); 359 $tagEntity->setLabel('tag1');
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/Tools/UtilsTest.php b/tests/Wallabag/CoreBundle/Tools/UtilsTest.php
new file mode 100644
index 00000000..435c25ca
--- /dev/null
+++ b/tests/Wallabag/CoreBundle/Tools/UtilsTest.php
@@ -0,0 +1,28 @@
1<?php
2
3namespace Tests\Wallabag\CoreBundle\Tools;
4
5use Symfony\Component\Finder\Finder;
6use Wallabag\CoreBundle\Tools\Utils;
7
8class UtilsTest extends \PHPUnit_Framework_TestCase
9{
10 /**
11 * @dataProvider examples
12 */
13 public function testCorrectWordsCountForDifferentLanguages($text, $expectedCount)
14 {
15 static::assertEquals((float) $expectedCount, Utils::getReadingTime($text));
16 }
17
18 public function examples()
19 {
20 $examples = [];
21 $finder = (new Finder())->in(__DIR__.'/samples');
22 foreach ($finder->getIterator() as $file) {
23 $examples[] = [$file->getContents(), 1];
24 }
25
26 return $examples;
27 }
28}
diff --git a/tests/Wallabag/CoreBundle/Tools/samples/cyrillic.txt b/tests/Wallabag/CoreBundle/Tools/samples/cyrillic.txt
new file mode 100644
index 00000000..7b904da4
--- /dev/null
+++ b/tests/Wallabag/CoreBundle/Tools/samples/cyrillic.txt
@@ -0,0 +1,7 @@
1Лорем ипсум долор сит амет, ех цум иллуд деленит, пер регионе фацилис те. Еи мел видит саепе интеллегам, яуас маиестатис цонституам яуо ат, цивибус реформиданс нецесситатибус ид яуи. Импетус тациматес пертинах ад еум. Усу еу легере бландит.
2
3Ан меа тритани иуварет, иллум сцаевола легендос ат меа, дебитис импедит нусяуам ест ад. Не маиорум молестие цотидиеяуе вис. Иисяуе цонцлудатуряуе меи еу, татион цонсецтетуер еи про. Либер риденс ид хас, ид цонсул сенсерит пертинациа меа. Фацер молестиае цомпрехенсам ад еум, ин хис апеириан вивендум. Яуи аудире епицуреи иудицабит ат, веро хабео вертерем ад иус. Бонорум плацерат ин вис, сеа но оцурререт принципес интерессет, хас ет дицерет диспутандо.
4
5Яуо цу цлита оцурререт. Сонет менандри ин сеа. Еум те нонумы вертерем. Вирис еяуидем фацилиси ет вим, делицата интеллегат иус ин. Ид дицат суммо витае вел, алияуип делецтус те дуо, цу вих хинц дуис видиссе. Нец цу фацилис урбанитас, алиа инсоленс ассуеверит при ут.
6
7Яуаеяуе абхорреант инцоррупте не сеа, еу еирмод ерудити вих. Вел оптион тритани цоррумпит те. Поссе сусципит губергрен ут мел, ет еос ириуре менандри еффициенди. Те сале нулла цонсецтетуер сеа, меа не прима алиенум еффициантур. При ет воцибус реформиданс, темпор албуциус сед ан. Еи утрояуе волумус иус, атяуи цонгуе но меи. \ No newline at end of file
diff --git a/tests/Wallabag/CoreBundle/Tools/samples/greek.txt b/tests/Wallabag/CoreBundle/Tools/samples/greek.txt
new file mode 100644
index 00000000..59f15b8b
--- /dev/null
+++ b/tests/Wallabag/CoreBundle/Tools/samples/greek.txt
@@ -0,0 +1,9 @@
1Λορεμ ιπσθμ δολορ σιτ αμετ, ηασ νο θταμθρ qθαεqθε ρεπρεηενδθντ. Ναμ λατινε προμπτα qθαερενδθμ ιδ. Νεc ει φαcερ cονcλθδατθρqθε, vολθπτθα vολθπταρια εφφιcιενδι αδ προ, νε σεα ασσεντιορ δεφινιεβασ. Μεα αγαμ ειθσ δολορε ετ, ηισ ει cορπορα περφεcτο. Vιξ cιβο δελενιτ νε, jθστο ριδενσ οπορτερε σεδ ιδ.
2
3Ηισ νισλ ιθvαρετ γθβεργρεν εξ. Εθμ ιμπεδιτ δετραξιτ ινιμιcθσ ατ, αλια βλανδιτ δθο εα, μεα ιλλθδ επιcθρι cονσετετθρ αδ. Ιλλθδ γραεcε δελενιτι ηισ νο. Νεc ιδ ριδενσ εθισμοδ περιcθλισ, vισ αδ λαβοραμθσ περσεcθτι. Ιθσ εα λθπτατθμ αλιqθανδο δισπθτανδο.
4
5Νεc εθ σθασ θτιναμ cονcεπταμ, σεα φεθγαιτ φιερεντ νε, σθμο ταμqθαμ περ ετ. Ελιτ θτροqθε ατομορθμ ιν δθο, εθ μεα λιβρισ ορνατθσ ταcιματεσ. Cθ σολεατ cονστιτθαμ νεc, τε σεα εξερcι αλιενθμ ρεcτεqθε. Σεα θτιναμ ινcορρθπτε αδ, δελενιτ cονcλθσιονεμqθε ναμ αν, διαμ γθβεργρεν cθ σιτ.
6
7Cθ σεδ αλβθcιθσ ποστθλαντ. Vιξ ιδ ηομερο περcιπιτ cονcεπταμ. Ιν vιμ λιβρισ vιδερερ, εξ vισ αλιι ερρορ. Vιξ λοβορτισ ασσεντιορ cοντεντιονεσ τε, νε ηασ δεcορε περcιπιτθρ. Εστ εξ δισπθτατιονι δεφινιτιονεμ, qθοδ πηαεδρθμ προ εθ, εξ ηασ ιντεγρε ελιγενδι cονσεcτετθερ.
8
9Ιθσ μολλισ ειρμοδ νο, vιξ νοστρθμ cονσετετθρ ει. Ιθδιcο vερτερεμ λθcιλιθσ qθι τε, νε προμπτα θτροqθε αccομμοδαρε περ. Φαcετε μανδαμθσ ηασ εξ, λιβερ δεβετ εθμ εξ, vιξ ιδ διcερετ σιγνιφερθμqθε. Εθ vιξ vοcεντ. \ No newline at end of file
diff --git a/tests/Wallabag/CoreBundle/Tools/samples/latin.txt b/tests/Wallabag/CoreBundle/Tools/samples/latin.txt
new file mode 100644
index 00000000..605cc40e
--- /dev/null
+++ b/tests/Wallabag/CoreBundle/Tools/samples/latin.txt
@@ -0,0 +1,9 @@
1Lorem ipsum dolor sit amet, pro vivendo oporteat pertinacia ei. Vim fabellas molestiae cu, vel nibh legimus ea, in qui atomorum democritum. Ius ne agam soluta ignota, his sale aperiri complectitur te, omnis volumus accusam an eos. Ut mentitum appetere mel, minim temporibus eloquentiam sea ea.
2
3Tation nominati pro ad. Pri eros eloquentiam reformidans ea, et liber epicurei erroribus pro, pri patrioque repudiandae et. Cetero perfecto at eam. Eros hendrerit constituto vix at, brute aperiri adolescens pro eu. Vix lucilius consulatu ei, ullum tantas munere vel in, regione feugiat eligendi at eam.
4
5Eam an lucilius iracundia, audire diceret facilisi his in, ex paulo pertinacia pro. Ei nec dolorum prodesset, adhuc tacimates argumentum sit ad. Vim te hinc scriptorem, ad labores perpetua nec. Sit no legimus fierent, epicuri partiendo reformidans ne mea, per assum animal mnesarchum no. Cum cetero apeirian at. Ne altera feugait vim, pri purto accumsan at, causae mentitum epicurei eam ad.
6
7Nec ut quod probo eligendi, cu dico iriure aperiam vis. Augue causae abhorreant per ut, iriure repudiandae no nam, exerci equidem deleniti nam te. Et duo saperet debitis adipiscing, quo odio audiam no, ex iudico delenit propriae duo. Eu eum eros abhorreant, an tractatos expetendis est.
8
9Vix. \ No newline at end of file
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..acc39997 100644
--- a/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php
+++ b/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php
@@ -112,7 +112,7 @@ class WallabagV1ControllerTest extends WallabagCoreTestCase
112 ->get('doctrine.orm.entity_manager') 112 ->get('doctrine.orm.entity_manager')
113 ->getRepository('WallabagCoreBundle:Entry') 113 ->getRepository('WallabagCoreBundle:Entry')
114 ->findByUrlAndUserId( 114 ->findByUrlAndUserId(
115 'http://www.framablog.org/index.php/post/2014/02/05/Framabag-service-libre-gratuit-interview-developpeur', 115 'https://framablog.org/2014/02/05/framabag-service-libre-gratuit-interview-developpeur/',
116 $this->getLoggedInUserId() 116 $this->getLoggedInUserId()
117 ); 117 );
118 118
@@ -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->assertNotEmpty($content->getMimetype(), 'Mimetype for http://www.framablog.org is ok');
130 $this->assertEmpty($content->getPreviewPicture()); 130 $this->assertNotEmpty($content->getPreviewPicture(), 'Preview picture for http://www.framablog.org is ok');
131 $this->assertEmpty($content->getLanguage()); 131 $this->assertNotEmpty($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"}]
diff --git a/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php b/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php
index 243a4459..4faddfc4 100644
--- a/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php
+++ b/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php
@@ -49,7 +49,6 @@ class ManageControllerTest extends WallabagCoreTestCase
49 'user[username]' => 'test_user', 49 'user[username]' => 'test_user',
50 'user[email]' => 'test@test.io', 50 'user[email]' => 'test@test.io',
51 'user[enabled]' => true, 51 'user[enabled]' => true,
52 'user[locked]' => false,
53 )); 52 ));
54 53
55 $client->submit($form); 54 $client->submit($form);
diff --git a/tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php b/tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php
index a78b77bc..01796ded 100644
--- a/tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php
+++ b/tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php
@@ -31,6 +31,8 @@ class CreateConfigListenerTest extends \PHPUnit_Framework_TestCase
31 20, 31 20,
32 50, 32 50,
33 'fr', 33 'fr',
34 1,
35 1,
34 1 36 1
35 ); 37 );
36 38