diff options
Diffstat (limited to 'tests/Wallabag')
56 files changed, 2177 insertions, 801 deletions
diff --git a/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php b/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php index 96474468..260edd77 100644 --- a/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php +++ b/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php | |||
@@ -1,6 +1,6 @@ | |||
1 | <?php | 1 | <?php |
2 | 2 | ||
3 | namespace Tests\AnnotationBundle\Controller; | 3 | namespace Tests\Wallabag\AnnotationBundle\Controller; |
4 | 4 | ||
5 | use Tests\Wallabag\AnnotationBundle\WallabagAnnotationTestCase; | 5 | use Tests\Wallabag\AnnotationBundle\WallabagAnnotationTestCase; |
6 | use Wallabag\AnnotationBundle\Entity\Annotation; | 6 | use Wallabag\AnnotationBundle\Entity\Annotation; |
@@ -100,14 +100,70 @@ class AnnotationControllerTest extends WallabagAnnotationTestCase | |||
100 | $this->assertSame('my quote', $content['quote']); | 100 | $this->assertSame('my quote', $content['quote']); |
101 | 101 | ||
102 | /** @var Annotation $annotation */ | 102 | /** @var Annotation $annotation */ |
103 | $annotation = $this->client->getContainer() | 103 | $annotation = $em |
104 | ->get('doctrine.orm.entity_manager') | ||
105 | ->getRepository('WallabagAnnotationBundle:Annotation') | 104 | ->getRepository('WallabagAnnotationBundle:Annotation') |
106 | ->findLastAnnotationByPageId($entry->getId(), 1); | 105 | ->findLastAnnotationByPageId($entry->getId(), 1); |
107 | 106 | ||
108 | $this->assertSame('my annotation', $annotation->getText()); | 107 | $this->assertSame('my annotation', $annotation->getText()); |
109 | } | 108 | } |
110 | 109 | ||
110 | public function testAllowEmptyQuote() | ||
111 | { | ||
112 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); | ||
113 | |||
114 | /** @var Entry $entry */ | ||
115 | $entry = $em | ||
116 | ->getRepository('WallabagCoreBundle:Entry') | ||
117 | ->findOneByUsernameAndNotArchived('admin'); | ||
118 | |||
119 | $headers = ['CONTENT_TYPE' => 'application/json']; | ||
120 | $content = json_encode([ | ||
121 | 'text' => 'my annotation', | ||
122 | 'quote' => null, | ||
123 | 'ranges' => [ | ||
124 | ['start' => '', 'startOffset' => 24, 'end' => '', 'endOffset' => 31], | ||
125 | ], | ||
126 | ]); | ||
127 | $this->client->request('POST', '/api/annotations/' . $entry->getId() . '.json', [], [], $headers, $content); | ||
128 | |||
129 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); | ||
130 | |||
131 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
132 | |||
133 | $this->assertSame('Big boss', $content['user']); | ||
134 | $this->assertSame('v1.0', $content['annotator_schema_version']); | ||
135 | $this->assertSame('my annotation', $content['text']); | ||
136 | $this->assertSame('', $content['quote']); | ||
137 | } | ||
138 | |||
139 | public function testAllowOmmittedQuote() | ||
140 | { | ||
141 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); | ||
142 | |||
143 | /** @var Entry $entry */ | ||
144 | $entry = $em | ||
145 | ->getRepository('WallabagCoreBundle:Entry') | ||
146 | ->findOneByUsernameAndNotArchived('admin'); | ||
147 | |||
148 | $headers = ['CONTENT_TYPE' => 'application/json']; | ||
149 | $content = json_encode([ | ||
150 | 'text' => 'my new annotation', | ||
151 | 'ranges' => [ | ||
152 | ['start' => '', 'startOffset' => 25, 'end' => '', 'endOffset' => 32], | ||
153 | ], | ||
154 | ]); | ||
155 | $this->client->request('POST', '/api/annotations/' . $entry->getId() . '.json', [], [], $headers, $content); | ||
156 | |||
157 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); | ||
158 | |||
159 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
160 | |||
161 | $this->assertSame('Big boss', $content['user']); | ||
162 | $this->assertSame('v1.0', $content['annotator_schema_version']); | ||
163 | $this->assertSame('my new annotation', $content['text']); | ||
164 | $this->assertSame('', $content['quote']); | ||
165 | } | ||
166 | |||
111 | /** | 167 | /** |
112 | * @dataProvider dataForEachAnnotations | 168 | * @dataProvider dataForEachAnnotations |
113 | */ | 169 | */ |
diff --git a/tests/Wallabag/AnnotationBundle/WallabagAnnotationTestCase.php b/tests/Wallabag/AnnotationBundle/WallabagAnnotationTestCase.php index 105e8add..9c7aba6b 100644 --- a/tests/Wallabag/AnnotationBundle/WallabagAnnotationTestCase.php +++ b/tests/Wallabag/AnnotationBundle/WallabagAnnotationTestCase.php | |||
@@ -43,9 +43,9 @@ abstract class WallabagAnnotationTestCase extends WebTestCase | |||
43 | $container = $client->getContainer(); | 43 | $container = $client->getContainer(); |
44 | 44 | ||
45 | /** @var $userManager \FOS\UserBundle\Doctrine\UserManager */ | 45 | /** @var $userManager \FOS\UserBundle\Doctrine\UserManager */ |
46 | $userManager = $container->get('fos_user.user_manager'); | 46 | $userManager = $container->get('fos_user.user_manager.test'); |
47 | /** @var $loginManager \FOS\UserBundle\Security\LoginManager */ | 47 | /** @var $loginManager \FOS\UserBundle\Security\LoginManager */ |
48 | $loginManager = $container->get('fos_user.security.login_manager'); | 48 | $loginManager = $container->get('fos_user.security.login_manager.test'); |
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']); |
diff --git a/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php b/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php index f58d1c12..e3d69290 100644 --- a/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php | |||
@@ -30,7 +30,7 @@ class DeveloperControllerTest extends WallabagCoreTestCase | |||
30 | $newNbClients = $em->getRepository('WallabagApiBundle:Client')->findAll(); | 30 | $newNbClients = $em->getRepository('WallabagApiBundle:Client')->findAll(); |
31 | $this->assertGreaterThan(\count($nbClients), \count($newNbClients)); | 31 | $this->assertGreaterThan(\count($nbClients), \count($newNbClients)); |
32 | 32 | ||
33 | $this->assertGreaterThan(1, $alert = $crawler->filter('.settings ul li strong')->extract(['_text'])); | 33 | $this->assertGreaterThan(1, $alert = $crawler->filter('.settings table strong')->extract(['_text'])); |
34 | $this->assertContains('My app', $alert[0]); | 34 | $this->assertContains('My app', $alert[0]); |
35 | } | 35 | } |
36 | 36 | ||
@@ -56,6 +56,20 @@ class DeveloperControllerTest extends WallabagCoreTestCase | |||
56 | $this->assertArrayHasKey('refresh_token', $data); | 56 | $this->assertArrayHasKey('refresh_token', $data); |
57 | } | 57 | } |
58 | 58 | ||
59 | public function testCreateTokenWithBadClientId() | ||
60 | { | ||
61 | $client = $this->getClient(); | ||
62 | $client->request('POST', '/oauth/v2/token', [ | ||
63 | 'grant_type' => 'password', | ||
64 | 'client_id' => '$WALLABAG_CLIENT_ID', | ||
65 | 'client_secret' => 'secret', | ||
66 | 'username' => 'admin', | ||
67 | 'password' => 'mypassword', | ||
68 | ]); | ||
69 | |||
70 | $this->assertSame(400, $client->getResponse()->getStatusCode()); | ||
71 | } | ||
72 | |||
59 | public function testListingClient() | 73 | public function testListingClient() |
60 | { | 74 | { |
61 | $this->logInAs('admin'); | 75 | $this->logInAs('admin'); |
@@ -121,7 +135,7 @@ class DeveloperControllerTest extends WallabagCoreTestCase | |||
121 | { | 135 | { |
122 | $client = $this->getClient(); | 136 | $client = $this->getClient(); |
123 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | 137 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); |
124 | $userManager = $client->getContainer()->get('fos_user.user_manager'); | 138 | $userManager = $client->getContainer()->get('fos_user.user_manager.test'); |
125 | $user = $userManager->findUserBy(['username' => $username]); | 139 | $user = $userManager->findUserBy(['username' => $username]); |
126 | $apiClient = new Client($user); | 140 | $apiClient = new Client($user); |
127 | $apiClient->setName('My app'); | 141 | $apiClient->setName('My app'); |
diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index 58b617f3..8b7898ee 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php | |||
@@ -15,7 +15,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
15 | $entry = $this->client->getContainer() | 15 | $entry = $this->client->getContainer() |
16 | ->get('doctrine.orm.entity_manager') | 16 | ->get('doctrine.orm.entity_manager') |
17 | ->getRepository('WallabagCoreBundle:Entry') | 17 | ->getRepository('WallabagCoreBundle:Entry') |
18 | ->findOneBy(['user' => 1, 'isArchived' => false]); | 18 | ->findOneBy(['user' => $this->getUserId(), 'isArchived' => false]); |
19 | 19 | ||
20 | if (!$entry) { | 20 | if (!$entry) { |
21 | $this->markTestSkipped('No content found in db.'); | 21 | $this->markTestSkipped('No content found in db.'); |
@@ -41,7 +41,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
41 | $entry = $this->client->getContainer() | 41 | $entry = $this->client->getContainer() |
42 | ->get('doctrine.orm.entity_manager') | 42 | ->get('doctrine.orm.entity_manager') |
43 | ->getRepository('WallabagCoreBundle:Entry') | 43 | ->getRepository('WallabagCoreBundle:Entry') |
44 | ->findOneBy(['user' => 1, 'url' => 'http://0.0.0.0/entry2']); | 44 | ->findOneBy(['user' => $this->getUserId(), 'url' => 'http://0.0.0.0/entry2']); |
45 | 45 | ||
46 | if (!$entry) { | 46 | if (!$entry) { |
47 | $this->markTestSkipped('No content found in db.'); | 47 | $this->markTestSkipped('No content found in db.'); |
@@ -60,7 +60,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
60 | $entry = $this->client->getContainer() | 60 | $entry = $this->client->getContainer() |
61 | ->get('doctrine.orm.entity_manager') | 61 | ->get('doctrine.orm.entity_manager') |
62 | ->getRepository('WallabagCoreBundle:Entry') | 62 | ->getRepository('WallabagCoreBundle:Entry') |
63 | ->findOneBy(['user' => 1, 'isArchived' => false]); | 63 | ->findOneBy(['user' => $this->getUserId(), 'isArchived' => false]); |
64 | 64 | ||
65 | if (!$entry) { | 65 | if (!$entry) { |
66 | $this->markTestSkipped('No content found in db.'); | 66 | $this->markTestSkipped('No content found in db.'); |
@@ -108,7 +108,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
108 | $entry = $this->client->getContainer() | 108 | $entry = $this->client->getContainer() |
109 | ->get('doctrine.orm.entity_manager') | 109 | ->get('doctrine.orm.entity_manager') |
110 | ->getRepository('WallabagCoreBundle:Entry') | 110 | ->getRepository('WallabagCoreBundle:Entry') |
111 | ->findOneBy(['user' => 2, 'isArchived' => false]); | 111 | ->findOneBy(['user' => $this->getUserId('bob'), 'isArchived' => false]); |
112 | 112 | ||
113 | if (!$entry) { | 113 | if (!$entry) { |
114 | $this->markTestSkipped('No content found in db.'); | 114 | $this->markTestSkipped('No content found in db.'); |
@@ -133,6 +133,27 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
133 | $this->assertSame(1, $content['page']); | 133 | $this->assertSame(1, $content['page']); |
134 | $this->assertGreaterThanOrEqual(1, $content['pages']); | 134 | $this->assertGreaterThanOrEqual(1, $content['pages']); |
135 | 135 | ||
136 | $this->assertNotNull($content['_embedded']['items'][0]['content']); | ||
137 | |||
138 | $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type')); | ||
139 | } | ||
140 | |||
141 | public function testGetEntriesDetailMetadata() | ||
142 | { | ||
143 | $this->client->request('GET', '/api/entries?detail=metadata'); | ||
144 | |||
145 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); | ||
146 | |||
147 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
148 | |||
149 | $this->assertGreaterThanOrEqual(1, \count($content)); | ||
150 | $this->assertNotEmpty($content['_embedded']['items']); | ||
151 | $this->assertGreaterThanOrEqual(1, $content['total']); | ||
152 | $this->assertSame(1, $content['page']); | ||
153 | $this->assertGreaterThanOrEqual(1, $content['pages']); | ||
154 | |||
155 | $this->assertNull($content['_embedded']['items'][0]['content']); | ||
156 | |||
136 | $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type')); | 157 | $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type')); |
137 | } | 158 | } |
138 | 159 | ||
@@ -185,7 +206,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
185 | $entry = $this->client->getContainer() | 206 | $entry = $this->client->getContainer() |
186 | ->get('doctrine.orm.entity_manager') | 207 | ->get('doctrine.orm.entity_manager') |
187 | ->getRepository('WallabagCoreBundle:Entry') | 208 | ->getRepository('WallabagCoreBundle:Entry') |
188 | ->findOneByUser(1); | 209 | ->findOneByUser($this->getUserId()); |
189 | 210 | ||
190 | if (!$entry) { | 211 | if (!$entry) { |
191 | $this->markTestSkipped('No content found in db.'); | 212 | $this->markTestSkipped('No content found in db.'); |
@@ -242,6 +263,15 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
242 | $this->assertSame(2, $content['limit']); | 263 | $this->assertSame(2, $content['limit']); |
243 | } | 264 | } |
244 | 265 | ||
266 | public function testGetStarredEntriesWithBadSort() | ||
267 | { | ||
268 | $this->client->request('GET', '/api/entries', ['starred' => 1, 'sort' => 'updated', 'order' => 'unknown']); | ||
269 | |||
270 | $this->assertSame(400, $this->client->getResponse()->getStatusCode()); | ||
271 | |||
272 | $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type')); | ||
273 | } | ||
274 | |||
245 | public function testGetStarredEntries() | 275 | public function testGetStarredEntries() |
246 | { | 276 | { |
247 | $this->client->request('GET', '/api/entries', ['starred' => 1, 'sort' => 'updated']); | 277 | $this->client->request('GET', '/api/entries', ['starred' => 1, 'sort' => 'updated']); |
@@ -391,29 +421,71 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
391 | 421 | ||
392 | public function testDeleteEntry() | 422 | public function testDeleteEntry() |
393 | { | 423 | { |
394 | $entry = $this->client->getContainer() | 424 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); |
395 | ->get('doctrine.orm.entity_manager') | 425 | $entry = new Entry($em->getReference(User::class, 1)); |
396 | ->getRepository('WallabagCoreBundle:Entry') | 426 | $entry->setUrl('http://0.0.0.0/test-delete-entry'); |
397 | ->findOneByUser(1, ['id' => 'asc']); | 427 | $entry->setTitle('Test delete entry'); |
428 | $em->persist($entry); | ||
429 | $em->flush(); | ||
398 | 430 | ||
399 | if (!$entry) { | 431 | $em->clear(); |
400 | $this->markTestSkipped('No content found in db.'); | ||
401 | } | ||
402 | 432 | ||
403 | $this->client->request('DELETE', '/api/entries/' . $entry->getId() . '.json'); | 433 | $e = [ |
434 | 'title' => $entry->getTitle(), | ||
435 | 'url' => $entry->getUrl(), | ||
436 | 'id' => $entry->getId(), | ||
437 | ]; | ||
438 | |||
439 | $this->client->request('DELETE', '/api/entries/' . $e['id'] . '.json'); | ||
404 | 440 | ||
405 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); | 441 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); |
406 | 442 | ||
407 | $content = json_decode($this->client->getResponse()->getContent(), true); | 443 | $content = json_decode($this->client->getResponse()->getContent(), true); |
408 | 444 | ||
409 | $this->assertSame($entry->getTitle(), $content['title']); | 445 | $this->assertSame($e['title'], $content['title']); |
410 | $this->assertSame($entry->getUrl(), $content['url']); | 446 | $this->assertSame($e['url'], $content['url']); |
411 | $this->assertSame($entry->getId(), $content['id']); | 447 | $this->assertSame($e['id'], $content['id']); |
448 | |||
449 | // We'll try to delete this entry again | ||
450 | $client = $this->createAuthorizedClient(); | ||
451 | $client->request('DELETE', '/api/entries/' . $e['id'] . '.json'); | ||
452 | |||
453 | $this->assertSame(404, $client->getResponse()->getStatusCode()); | ||
454 | } | ||
455 | |||
456 | public function testDeleteEntryExpectId() | ||
457 | { | ||
458 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); | ||
459 | $entry = new Entry($em->getReference(User::class, 1)); | ||
460 | $entry->setUrl('http://0.0.0.0/test-delete-entry-id'); | ||
461 | $em->persist($entry); | ||
462 | $em->flush(); | ||
463 | |||
464 | $em->clear(); | ||
465 | |||
466 | $id = $entry->getId(); | ||
467 | |||
468 | $this->client->request('DELETE', '/api/entries/' . $id . '.json?expect=id'); | ||
469 | |||
470 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); | ||
471 | |||
472 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
473 | |||
474 | $this->assertSame($id, $content['id']); | ||
475 | $this->assertArrayNotHasKey('url', $content); | ||
412 | 476 | ||
413 | // We'll try to delete this entry again | 477 | // We'll try to delete this entry again |
414 | $this->client->request('DELETE', '/api/entries/' . $entry->getId() . '.json'); | 478 | $client = $this->createAuthorizedClient(); |
479 | $client->request('DELETE', '/api/entries/' . $id . '.json'); | ||
415 | 480 | ||
416 | $this->assertSame(404, $this->client->getResponse()->getStatusCode()); | 481 | $this->assertSame(404, $client->getResponse()->getStatusCode()); |
482 | } | ||
483 | |||
484 | public function testDeleteEntryExpectBadRequest() | ||
485 | { | ||
486 | $this->client->request('DELETE', '/api/entries/1.json?expect=badrequest'); | ||
487 | |||
488 | $this->assertSame(400, $this->client->getResponse()->getStatusCode()); | ||
417 | } | 489 | } |
418 | 490 | ||
419 | public function testPostEntry() | 491 | public function testPostEntry() |
@@ -438,8 +510,9 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
438 | $this->assertSame(0, $content['is_archived']); | 510 | $this->assertSame(0, $content['is_archived']); |
439 | $this->assertSame(0, $content['is_starred']); | 511 | $this->assertSame(0, $content['is_starred']); |
440 | $this->assertNull($content['starred_at']); | 512 | $this->assertNull($content['starred_at']); |
513 | $this->assertNull($content['archived_at']); | ||
441 | $this->assertSame('New title for my article', $content['title']); | 514 | $this->assertSame('New title for my article', $content['title']); |
442 | $this->assertSame(1, $content['user_id']); | 515 | $this->assertSame($this->getUserId(), $content['user_id']); |
443 | $this->assertCount(2, $content['tags']); | 516 | $this->assertCount(2, $content['tags']); |
444 | $this->assertNull($content['origin_url']); | 517 | $this->assertNull($content['origin_url']); |
445 | $this->assertSame('my content', $content['content']); | 518 | $this->assertSame('my content', $content['content']); |
@@ -454,7 +527,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
454 | public function testPostSameEntry() | 527 | public function testPostSameEntry() |
455 | { | 528 | { |
456 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); | 529 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); |
457 | $entry = new Entry($em->getReference(User::class, 1)); | 530 | $entry = new Entry($em->getReference(User::class, $this->getUserId())); |
458 | $entry->setUrl('https://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'); | 531 | $entry->setUrl('https://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'); |
459 | $entry->setArchived(true); | 532 | $entry->setArchived(true); |
460 | $entry->addTag((new Tag())->setLabel('google')); | 533 | $entry->addTag((new Tag())->setLabel('google')); |
@@ -533,7 +606,8 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
533 | $this->assertSame(1, $content['is_archived']); | 606 | $this->assertSame(1, $content['is_archived']); |
534 | $this->assertSame(1, $content['is_starred']); | 607 | $this->assertSame(1, $content['is_starred']); |
535 | $this->assertGreaterThanOrEqual($now->getTimestamp(), (new \DateTime($content['starred_at']))->getTimestamp()); | 608 | $this->assertGreaterThanOrEqual($now->getTimestamp(), (new \DateTime($content['starred_at']))->getTimestamp()); |
536 | $this->assertSame(1, $content['user_id']); | 609 | $this->assertGreaterThanOrEqual($now->getTimestamp(), (new \DateTime($content['archived_at']))->getTimestamp()); |
610 | $this->assertSame($this->getUserId(), $content['user_id']); | ||
537 | } | 611 | } |
538 | 612 | ||
539 | public function testPostArchivedAndStarredEntryWithoutQuotes() | 613 | public function testPostArchivedAndStarredEntryWithoutQuotes() |
@@ -582,7 +656,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
582 | $entry = $this->client->getContainer() | 656 | $entry = $this->client->getContainer() |
583 | ->get('doctrine.orm.entity_manager') | 657 | ->get('doctrine.orm.entity_manager') |
584 | ->getRepository('WallabagCoreBundle:Entry') | 658 | ->getRepository('WallabagCoreBundle:Entry') |
585 | ->findOneByUser(1); | 659 | ->findOneByUser($this->getUserId()); |
586 | 660 | ||
587 | if (!$entry) { | 661 | if (!$entry) { |
588 | $this->markTestSkipped('No content found in db.'); | 662 | $this->markTestSkipped('No content found in db.'); |
@@ -609,7 +683,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
609 | $this->assertSame($entry->getUrl(), $content['url']); | 683 | $this->assertSame($entry->getUrl(), $content['url']); |
610 | $this->assertSame('New awesome title', $content['title']); | 684 | $this->assertSame('New awesome title', $content['title']); |
611 | $this->assertGreaterThanOrEqual(1, \count($content['tags']), 'We force only one tag'); | 685 | $this->assertGreaterThanOrEqual(1, \count($content['tags']), 'We force only one tag'); |
612 | $this->assertSame(1, $content['user_id']); | 686 | $this->assertSame($this->getUserId(), $content['user_id']); |
613 | $this->assertSame('de_AT', $content['language']); | 687 | $this->assertSame('de_AT', $content['language']); |
614 | $this->assertSame('http://preview.io/picture.jpg', $content['preview_picture']); | 688 | $this->assertSame('http://preview.io/picture.jpg', $content['preview_picture']); |
615 | $this->assertContains('sponge', $content['published_by']); | 689 | $this->assertContains('sponge', $content['published_by']); |
@@ -624,7 +698,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
624 | $entry = $this->client->getContainer() | 698 | $entry = $this->client->getContainer() |
625 | ->get('doctrine.orm.entity_manager') | 699 | ->get('doctrine.orm.entity_manager') |
626 | ->getRepository('WallabagCoreBundle:Entry') | 700 | ->getRepository('WallabagCoreBundle:Entry') |
627 | ->findOneByUser(1); | 701 | ->findOneByUser($this->getUserId()); |
628 | 702 | ||
629 | if (!$entry) { | 703 | if (!$entry) { |
630 | $this->markTestSkipped('No content found in db.'); | 704 | $this->markTestSkipped('No content found in db.'); |
@@ -658,7 +732,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
658 | $entry = $this->client->getContainer() | 732 | $entry = $this->client->getContainer() |
659 | ->get('doctrine.orm.entity_manager') | 733 | ->get('doctrine.orm.entity_manager') |
660 | ->getRepository('WallabagCoreBundle:Entry') | 734 | ->getRepository('WallabagCoreBundle:Entry') |
661 | ->findOneByUser(1); | 735 | ->findOneByUser($this->getUserId()); |
662 | 736 | ||
663 | if (!$entry) { | 737 | if (!$entry) { |
664 | $this->markTestSkipped('No content found in db.'); | 738 | $this->markTestSkipped('No content found in db.'); |
@@ -689,7 +763,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
689 | $entry = $this->client->getContainer() | 763 | $entry = $this->client->getContainer() |
690 | ->get('doctrine.orm.entity_manager') | 764 | ->get('doctrine.orm.entity_manager') |
691 | ->getRepository('WallabagCoreBundle:Entry') | 765 | ->getRepository('WallabagCoreBundle:Entry') |
692 | ->findOneByUser(1); | 766 | ->findOneByUser($this->getUserId()); |
693 | 767 | ||
694 | if (!$entry) { | 768 | if (!$entry) { |
695 | $this->markTestSkipped('No content found in db.'); | 769 | $this->markTestSkipped('No content found in db.'); |
@@ -721,7 +795,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
721 | $entry = $this->client->getContainer() | 795 | $entry = $this->client->getContainer() |
722 | ->get('doctrine.orm.entity_manager') | 796 | ->get('doctrine.orm.entity_manager') |
723 | ->getRepository('WallabagCoreBundle:Entry') | 797 | ->getRepository('WallabagCoreBundle:Entry') |
724 | ->findOneByUser(1); | 798 | ->findOneByUser($this->getUserId()); |
725 | 799 | ||
726 | if (!$entry) { | 800 | if (!$entry) { |
727 | $this->markTestSkipped('No content found in db.'); | 801 | $this->markTestSkipped('No content found in db.'); |
@@ -766,7 +840,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
766 | $entry = $this->client->getContainer() | 840 | $entry = $this->client->getContainer() |
767 | ->get('doctrine.orm.entity_manager') | 841 | ->get('doctrine.orm.entity_manager') |
768 | ->getRepository('WallabagCoreBundle:Entry') | 842 | ->getRepository('WallabagCoreBundle:Entry') |
769 | ->findOneByUser(1); | 843 | ->findOneByUser($this->getUserId()); |
770 | 844 | ||
771 | if (!$entry) { | 845 | if (!$entry) { |
772 | $this->markTestSkipped('No content found in db.'); | 846 | $this->markTestSkipped('No content found in db.'); |
@@ -783,7 +857,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
783 | $content = json_decode($this->client->getResponse()->getContent(), true); | 857 | $content = json_decode($this->client->getResponse()->getContent(), true); |
784 | 858 | ||
785 | $this->assertArrayHasKey('tags', $content); | 859 | $this->assertArrayHasKey('tags', $content); |
786 | $this->assertSame($nbTags + 3, \count($content['tags'])); | 860 | $this->assertCount($nbTags + 3, $content['tags']); |
787 | 861 | ||
788 | $entryDB = $this->client->getContainer() | 862 | $entryDB = $this->client->getContainer() |
789 | ->get('doctrine.orm.entity_manager') | 863 | ->get('doctrine.orm.entity_manager') |
@@ -823,7 +897,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
823 | $content = json_decode($this->client->getResponse()->getContent(), true); | 897 | $content = json_decode($this->client->getResponse()->getContent(), true); |
824 | 898 | ||
825 | $this->assertArrayHasKey('tags', $content); | 899 | $this->assertArrayHasKey('tags', $content); |
826 | $this->assertSame($nbTags - 1, \count($content['tags'])); | 900 | $this->assertCount($nbTags - 1, $content['tags']); |
827 | } | 901 | } |
828 | 902 | ||
829 | public function testSaveIsArchivedAfterPost() | 903 | public function testSaveIsArchivedAfterPost() |
@@ -831,7 +905,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
831 | $entry = $this->client->getContainer() | 905 | $entry = $this->client->getContainer() |
832 | ->get('doctrine.orm.entity_manager') | 906 | ->get('doctrine.orm.entity_manager') |
833 | ->getRepository('WallabagCoreBundle:Entry') | 907 | ->getRepository('WallabagCoreBundle:Entry') |
834 | ->findOneBy(['user' => 1, 'isArchived' => true]); | 908 | ->findOneBy(['user' => $this->getUserId(), 'isArchived' => true]); |
835 | 909 | ||
836 | if (!$entry) { | 910 | if (!$entry) { |
837 | $this->markTestSkipped('No content found in db.'); | 911 | $this->markTestSkipped('No content found in db.'); |
@@ -853,7 +927,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
853 | $entry = $this->client->getContainer() | 927 | $entry = $this->client->getContainer() |
854 | ->get('doctrine.orm.entity_manager') | 928 | ->get('doctrine.orm.entity_manager') |
855 | ->getRepository('WallabagCoreBundle:Entry') | 929 | ->getRepository('WallabagCoreBundle:Entry') |
856 | ->findOneBy(['user' => 1, 'isStarred' => true]); | 930 | ->findOneBy(['user' => $this->getUserId(), 'isStarred' => true]); |
857 | 931 | ||
858 | if (!$entry) { | 932 | if (!$entry) { |
859 | $this->markTestSkipped('No content found in db.'); | 933 | $this->markTestSkipped('No content found in db.'); |
@@ -875,7 +949,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
875 | $entry = $this->client->getContainer() | 949 | $entry = $this->client->getContainer() |
876 | ->get('doctrine.orm.entity_manager') | 950 | ->get('doctrine.orm.entity_manager') |
877 | ->getRepository('WallabagCoreBundle:Entry') | 951 | ->getRepository('WallabagCoreBundle:Entry') |
878 | ->findOneBy(['user' => 1, 'isArchived' => true]); | 952 | ->findOneBy(['user' => $this->getUserId(), 'isArchived' => true]); |
879 | 953 | ||
880 | if (!$entry) { | 954 | if (!$entry) { |
881 | $this->markTestSkipped('No content found in db.'); | 955 | $this->markTestSkipped('No content found in db.'); |
@@ -901,7 +975,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
901 | $entry = $this->client->getContainer() | 975 | $entry = $this->client->getContainer() |
902 | ->get('doctrine.orm.entity_manager') | 976 | ->get('doctrine.orm.entity_manager') |
903 | ->getRepository('WallabagCoreBundle:Entry') | 977 | ->getRepository('WallabagCoreBundle:Entry') |
904 | ->findOneBy(['user' => 1, 'isStarred' => true]); | 978 | ->findOneBy(['user' => $this->getUserId(), 'isStarred' => true]); |
905 | 979 | ||
906 | if (!$entry) { | 980 | if (!$entry) { |
907 | $this->markTestSkipped('No content found in db.'); | 981 | $this->markTestSkipped('No content found in db.'); |
@@ -920,6 +994,8 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
920 | 994 | ||
921 | public function dataForEntriesExistWithUrl() | 995 | public function dataForEntriesExistWithUrl() |
922 | { | 996 | { |
997 | $url = hash('sha1', 'http://0.0.0.0/entry2'); | ||
998 | |||
923 | return [ | 999 | return [ |
924 | 'with_id' => [ | 1000 | 'with_id' => [ |
925 | 'url' => '/api/entries/exists?url=http://0.0.0.0/entry2&return_id=1', | 1001 | 'url' => '/api/entries/exists?url=http://0.0.0.0/entry2&return_id=1', |
@@ -929,6 +1005,14 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
929 | 'url' => '/api/entries/exists?url=http://0.0.0.0/entry2', | 1005 | 'url' => '/api/entries/exists?url=http://0.0.0.0/entry2', |
930 | 'expectedValue' => true, | 1006 | 'expectedValue' => true, |
931 | ], | 1007 | ], |
1008 | 'hashed_url_with_id' => [ | ||
1009 | 'url' => '/api/entries/exists?hashed_url=' . $url . '&return_id=1', | ||
1010 | 'expectedValue' => 2, | ||
1011 | ], | ||
1012 | 'hashed_url_without_id' => [ | ||
1013 | 'url' => '/api/entries/exists?hashed_url=' . $url . '', | ||
1014 | 'expectedValue' => true, | ||
1015 | ], | ||
932 | ]; | 1016 | ]; |
933 | } | 1017 | } |
934 | 1018 | ||
@@ -950,6 +1034,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
950 | { | 1034 | { |
951 | $url1 = 'http://0.0.0.0/entry2'; | 1035 | $url1 = 'http://0.0.0.0/entry2'; |
952 | $url2 = 'http://0.0.0.0/entry10'; | 1036 | $url2 = 'http://0.0.0.0/entry10'; |
1037 | |||
953 | $this->client->request('GET', '/api/entries/exists?urls[]=' . $url1 . '&urls[]=' . $url2 . '&return_id=1'); | 1038 | $this->client->request('GET', '/api/entries/exists?urls[]=' . $url1 . '&urls[]=' . $url2 . '&return_id=1'); |
954 | 1039 | ||
955 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); | 1040 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); |
@@ -958,7 +1043,8 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
958 | 1043 | ||
959 | $this->assertArrayHasKey($url1, $content); | 1044 | $this->assertArrayHasKey($url1, $content); |
960 | $this->assertArrayHasKey($url2, $content); | 1045 | $this->assertArrayHasKey($url2, $content); |
961 | $this->assertSame(2, $content[$url1]); | 1046 | // it returns a database id, we don't know it, so we only check it's greater than the lowest possible value |
1047 | $this->assertGreaterThan(1, $content[$url1]); | ||
962 | $this->assertNull($content[$url2]); | 1048 | $this->assertNull($content[$url2]); |
963 | } | 1049 | } |
964 | 1050 | ||
@@ -978,6 +1064,38 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
978 | $this->assertFalse($content[$url2]); | 1064 | $this->assertFalse($content[$url2]); |
979 | } | 1065 | } |
980 | 1066 | ||
1067 | public function testGetEntriesExistsWithManyUrlsHashed() | ||
1068 | { | ||
1069 | $url1 = 'http://0.0.0.0/entry2'; | ||
1070 | $url2 = 'http://0.0.0.0/entry10'; | ||
1071 | $this->client->request('GET', '/api/entries/exists?hashed_urls[]=' . hash('sha1', $url1) . '&hashed_urls[]=' . hash('sha1', $url2) . '&return_id=1'); | ||
1072 | |||
1073 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); | ||
1074 | |||
1075 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
1076 | |||
1077 | $this->assertArrayHasKey(hash('sha1', $url1), $content); | ||
1078 | $this->assertArrayHasKey(hash('sha1', $url2), $content); | ||
1079 | $this->assertSame(2, $content[hash('sha1', $url1)]); | ||
1080 | $this->assertNull($content[hash('sha1', $url2)]); | ||
1081 | } | ||
1082 | |||
1083 | public function testGetEntriesExistsWithManyUrlsHashedReturnBool() | ||
1084 | { | ||
1085 | $url1 = 'http://0.0.0.0/entry2'; | ||
1086 | $url2 = 'http://0.0.0.0/entry10'; | ||
1087 | $this->client->request('GET', '/api/entries/exists?hashed_urls[]=' . hash('sha1', $url1) . '&hashed_urls[]=' . hash('sha1', $url2)); | ||
1088 | |||
1089 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); | ||
1090 | |||
1091 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
1092 | |||
1093 | $this->assertArrayHasKey(hash('sha1', $url1), $content); | ||
1094 | $this->assertArrayHasKey(hash('sha1', $url2), $content); | ||
1095 | $this->assertTrue($content[hash('sha1', $url1)]); | ||
1096 | $this->assertFalse($content[hash('sha1', $url2)]); | ||
1097 | } | ||
1098 | |||
981 | public function testGetEntriesExistsWhichDoesNotExists() | 1099 | public function testGetEntriesExistsWhichDoesNotExists() |
982 | { | 1100 | { |
983 | $this->client->request('GET', '/api/entries/exists?url=http://google.com/entry2'); | 1101 | $this->client->request('GET', '/api/entries/exists?url=http://google.com/entry2'); |
@@ -989,6 +1107,17 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
989 | $this->assertFalse($content['exists']); | 1107 | $this->assertFalse($content['exists']); |
990 | } | 1108 | } |
991 | 1109 | ||
1110 | public function testGetEntriesExistsWhichDoesNotExistsWithHashedUrl() | ||
1111 | { | ||
1112 | $this->client->request('GET', '/api/entries/exists?hashed_url=' . hash('sha1', 'http://google.com/entry2')); | ||
1113 | |||
1114 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); | ||
1115 | |||
1116 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
1117 | |||
1118 | $this->assertFalse($content['exists']); | ||
1119 | } | ||
1120 | |||
992 | public function testGetEntriesExistsWithNoUrl() | 1121 | public function testGetEntriesExistsWithNoUrl() |
993 | { | 1122 | { |
994 | $this->client->request('GET', '/api/entries/exists?url='); | 1123 | $this->client->request('GET', '/api/entries/exists?url='); |
@@ -996,11 +1125,18 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
996 | $this->assertSame(403, $this->client->getResponse()->getStatusCode()); | 1125 | $this->assertSame(403, $this->client->getResponse()->getStatusCode()); |
997 | } | 1126 | } |
998 | 1127 | ||
1128 | public function testGetEntriesExistsWithNoHashedUrl() | ||
1129 | { | ||
1130 | $this->client->request('GET', '/api/entries/exists?hashed_url='); | ||
1131 | |||
1132 | $this->assertSame(403, $this->client->getResponse()->getStatusCode()); | ||
1133 | } | ||
1134 | |||
999 | public function testReloadEntryErrorWhileFetching() | 1135 | public function testReloadEntryErrorWhileFetching() |
1000 | { | 1136 | { |
1001 | $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager') | 1137 | $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager') |
1002 | ->getRepository('WallabagCoreBundle:Entry') | 1138 | ->getRepository('WallabagCoreBundle:Entry') |
1003 | ->findByUrlAndUserId('http://0.0.0.0/entry4', 1); | 1139 | ->findByUrlAndUserId('http://0.0.0.0/entry4', $this->getUserId()); |
1004 | 1140 | ||
1005 | if (!$entry) { | 1141 | if (!$entry) { |
1006 | $this->markTestSkipped('No content found in db.'); | 1142 | $this->markTestSkipped('No content found in db.'); |
@@ -1036,7 +1172,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
1036 | { | 1172 | { |
1037 | $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager') | 1173 | $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager') |
1038 | ->getRepository('WallabagCoreBundle:Entry') | 1174 | ->getRepository('WallabagCoreBundle:Entry') |
1039 | ->findByUrlAndUserId('http://0.0.0.0/entry4', 1); | 1175 | ->findByUrlAndUserId('http://0.0.0.0/entry4', $this->getUserId()); |
1040 | 1176 | ||
1041 | $tags = $entry->getTags(); | 1177 | $tags = $entry->getTags(); |
1042 | 1178 | ||
@@ -1060,7 +1196,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
1060 | 1196 | ||
1061 | $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager') | 1197 | $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager') |
1062 | ->getRepository('WallabagCoreBundle:Entry') | 1198 | ->getRepository('WallabagCoreBundle:Entry') |
1063 | ->findByUrlAndUserId('http://0.0.0.0/entry4', 1); | 1199 | ->findByUrlAndUserId('http://0.0.0.0/entry4', $this->getUserId()); |
1064 | 1200 | ||
1065 | $tags = $entry->getTags(); | 1201 | $tags = $entry->getTags(); |
1066 | $this->assertCount(4, $tags); | 1202 | $this->assertCount(4, $tags); |
@@ -1080,7 +1216,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
1080 | public function testDeleteEntriesTagsListAction() | 1216 | public function testDeleteEntriesTagsListAction() |
1081 | { | 1217 | { |
1082 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); | 1218 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); |
1083 | $entry = new Entry($em->getReference(User::class, 1)); | 1219 | $entry = new Entry($em->getReference(User::class, $this->getUserId())); |
1084 | $entry->setUrl('http://0.0.0.0/test-entry'); | 1220 | $entry->setUrl('http://0.0.0.0/test-entry'); |
1085 | $entry->addTag((new Tag())->setLabel('foo-tag')); | 1221 | $entry->addTag((new Tag())->setLabel('foo-tag')); |
1086 | $entry->addTag((new Tag())->setLabel('bar-tag')); | 1222 | $entry->addTag((new Tag())->setLabel('bar-tag')); |
@@ -1148,7 +1284,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
1148 | public function testDeleteEntriesListAction() | 1284 | public function testDeleteEntriesListAction() |
1149 | { | 1285 | { |
1150 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); | 1286 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); |
1151 | $em->persist((new Entry($em->getReference(User::class, 1)))->setUrl('http://0.0.0.0/test-entry1')); | 1287 | $em->persist((new Entry($em->getReference(User::class, $this->getUserId())))->setUrl('http://0.0.0.0/test-entry1')); |
1152 | 1288 | ||
1153 | $em->flush(); | 1289 | $em->flush(); |
1154 | $em->clear(); | 1290 | $em->clear(); |
@@ -1206,7 +1342,7 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
1206 | public function testRePostEntryAndReUsePublishedAt() | 1342 | public function testRePostEntryAndReUsePublishedAt() |
1207 | { | 1343 | { |
1208 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); | 1344 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); |
1209 | $entry = new Entry($em->getReference(User::class, 1)); | 1345 | $entry = new Entry($em->getReference(User::class, $this->getUserId())); |
1210 | $entry->setTitle('Antoine de Caunes : « Je veux avoir le droit de tâtonner »'); | 1346 | $entry->setTitle('Antoine de Caunes : « Je veux avoir le droit de tâtonner »'); |
1211 | $entry->setContent('hihi'); | 1347 | $entry->setContent('hihi'); |
1212 | $entry->setUrl('https://www.lemonde.fr/m-perso/article/2017/06/25/antoine-de-caunes-je-veux-avoir-le-droit-de-tatonner_5150728_4497916.html'); | 1348 | $entry->setUrl('https://www.lemonde.fr/m-perso/article/2017/06/25/antoine-de-caunes-je-veux-avoir-le-droit-de-tatonner_5150728_4497916.html'); |
diff --git a/tests/Wallabag/ApiBundle/Controller/SearchRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/SearchRestControllerTest.php new file mode 100644 index 00000000..fd524639 --- /dev/null +++ b/tests/Wallabag/ApiBundle/Controller/SearchRestControllerTest.php | |||
@@ -0,0 +1,69 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Tests\Wallabag\ApiBundle\Controller; | ||
4 | |||
5 | use Tests\Wallabag\ApiBundle\WallabagApiTestCase; | ||
6 | |||
7 | class SearchRestControllerTest extends WallabagApiTestCase | ||
8 | { | ||
9 | public function testGetSearchWithFullOptions() | ||
10 | { | ||
11 | $this->client->request('GET', '/api/search', [ | ||
12 | 'page' => 1, | ||
13 | 'perPage' => 2, | ||
14 | 'term' => 'entry', // 6 results | ||
15 | ]); | ||
16 | |||
17 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); | ||
18 | |||
19 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
20 | |||
21 | $this->assertGreaterThanOrEqual(1, \count($content)); | ||
22 | $this->assertArrayHasKey('items', $content['_embedded']); | ||
23 | $this->assertGreaterThanOrEqual(0, $content['total']); | ||
24 | $this->assertSame(1, $content['page']); | ||
25 | $this->assertSame(2, $content['limit']); | ||
26 | $this->assertGreaterThanOrEqual(1, $content['pages']); | ||
27 | |||
28 | $this->assertArrayHasKey('_links', $content); | ||
29 | $this->assertArrayHasKey('self', $content['_links']); | ||
30 | $this->assertArrayHasKey('first', $content['_links']); | ||
31 | $this->assertArrayHasKey('last', $content['_links']); | ||
32 | |||
33 | foreach (['self', 'first', 'last'] as $link) { | ||
34 | $this->assertArrayHasKey('href', $content['_links'][$link]); | ||
35 | $this->assertContains('term=entry', $content['_links'][$link]['href']); | ||
36 | } | ||
37 | |||
38 | $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type')); | ||
39 | } | ||
40 | |||
41 | public function testGetSearchWithNoLimit() | ||
42 | { | ||
43 | $this->client->request('GET', '/api/search', [ | ||
44 | 'term' => 'entry', | ||
45 | ]); | ||
46 | |||
47 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); | ||
48 | |||
49 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
50 | |||
51 | $this->assertGreaterThanOrEqual(1, \count($content)); | ||
52 | $this->assertArrayHasKey('items', $content['_embedded']); | ||
53 | $this->assertGreaterThanOrEqual(0, $content['total']); | ||
54 | $this->assertSame(1, $content['page']); | ||
55 | $this->assertGreaterThanOrEqual(1, $content['pages']); | ||
56 | |||
57 | $this->assertArrayHasKey('_links', $content); | ||
58 | $this->assertArrayHasKey('self', $content['_links']); | ||
59 | $this->assertArrayHasKey('first', $content['_links']); | ||
60 | $this->assertArrayHasKey('last', $content['_links']); | ||
61 | |||
62 | foreach (['self', 'first', 'last'] as $link) { | ||
63 | $this->assertArrayHasKey('href', $content['_links'][$link]); | ||
64 | $this->assertContains('term=entry', $content['_links'][$link]['href']); | ||
65 | } | ||
66 | |||
67 | $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type')); | ||
68 | } | ||
69 | } | ||
diff --git a/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php index 430e548d..9daa94cd 100644 --- a/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php | |||
@@ -7,6 +7,8 @@ use Wallabag\CoreBundle\Entity\Tag; | |||
7 | 7 | ||
8 | class TagRestControllerTest extends WallabagApiTestCase | 8 | class TagRestControllerTest extends WallabagApiTestCase |
9 | { | 9 | { |
10 | private $otherUserTagLabel = 'bob'; | ||
11 | |||
10 | public function testGetUserTags() | 12 | public function testGetUserTags() |
11 | { | 13 | { |
12 | $this->client->request('GET', '/api/tags.json'); | 14 | $this->client->request('GET', '/api/tags.json'); |
@@ -19,17 +21,33 @@ class TagRestControllerTest extends WallabagApiTestCase | |||
19 | $this->assertArrayHasKey('id', $content[0]); | 21 | $this->assertArrayHasKey('id', $content[0]); |
20 | $this->assertArrayHasKey('label', $content[0]); | 22 | $this->assertArrayHasKey('label', $content[0]); |
21 | 23 | ||
24 | $tagLabels = array_map(function ($i) { | ||
25 | return $i['label']; | ||
26 | }, $content); | ||
27 | |||
28 | $this->assertNotContains($this->otherUserTagLabel, $tagLabels, 'There is a possible tag leak'); | ||
29 | |||
22 | return end($content); | 30 | return end($content); |
23 | } | 31 | } |
24 | 32 | ||
25 | public function testDeleteUserTag() | 33 | public function testDeleteUserTag() |
26 | { | 34 | { |
35 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); | ||
36 | $entry = $this->client->getContainer() | ||
37 | ->get('doctrine.orm.entity_manager') | ||
38 | ->getRepository('WallabagCoreBundle:Entry') | ||
39 | ->findOneWithTags($this->user->getId()); | ||
40 | |||
41 | $entry = $entry[0]; | ||
42 | |||
27 | $tagLabel = 'tagtest'; | 43 | $tagLabel = 'tagtest'; |
28 | $tag = new Tag(); | 44 | $tag = new Tag(); |
29 | $tag->setLabel($tagLabel); | 45 | $tag->setLabel($tagLabel); |
30 | |||
31 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); | ||
32 | $em->persist($tag); | 46 | $em->persist($tag); |
47 | |||
48 | $entry->addTag($tag); | ||
49 | |||
50 | $em->persist($entry); | ||
33 | $em->flush(); | 51 | $em->flush(); |
34 | $em->clear(); | 52 | $em->clear(); |
35 | 53 | ||
@@ -53,6 +71,16 @@ class TagRestControllerTest extends WallabagApiTestCase | |||
53 | $this->assertNull($tag, $tagLabel . ' was removed because it begun an orphan tag'); | 71 | $this->assertNull($tag, $tagLabel . ' was removed because it begun an orphan tag'); |
54 | } | 72 | } |
55 | 73 | ||
74 | public function testDeleteOtherUserTag() | ||
75 | { | ||
76 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); | ||
77 | $tag = $em->getRepository('WallabagCoreBundle:Tag')->findOneByLabel($this->otherUserTagLabel); | ||
78 | |||
79 | $this->client->request('DELETE', '/api/tags/' . $tag->getId() . '.json'); | ||
80 | |||
81 | $this->assertSame(404, $this->client->getResponse()->getStatusCode()); | ||
82 | } | ||
83 | |||
56 | public function dataForDeletingTagByLabel() | 84 | public function dataForDeletingTagByLabel() |
57 | { | 85 | { |
58 | return [ | 86 | return [ |
@@ -112,6 +140,13 @@ class TagRestControllerTest extends WallabagApiTestCase | |||
112 | $this->assertSame(404, $this->client->getResponse()->getStatusCode()); | 140 | $this->assertSame(404, $this->client->getResponse()->getStatusCode()); |
113 | } | 141 | } |
114 | 142 | ||
143 | public function testDeleteTagByLabelOtherUser() | ||
144 | { | ||
145 | $this->client->request('DELETE', '/api/tag/label.json', ['tag' => $this->otherUserTagLabel]); | ||
146 | |||
147 | $this->assertSame(404, $this->client->getResponse()->getStatusCode()); | ||
148 | } | ||
149 | |||
115 | /** | 150 | /** |
116 | * @dataProvider dataForDeletingTagByLabel | 151 | * @dataProvider dataForDeletingTagByLabel |
117 | */ | 152 | */ |
@@ -180,4 +215,11 @@ class TagRestControllerTest extends WallabagApiTestCase | |||
180 | 215 | ||
181 | $this->assertSame(404, $this->client->getResponse()->getStatusCode()); | 216 | $this->assertSame(404, $this->client->getResponse()->getStatusCode()); |
182 | } | 217 | } |
218 | |||
219 | public function testDeleteTagsByLabelOtherUser() | ||
220 | { | ||
221 | $this->client->request('DELETE', '/api/tags/label.json', ['tags' => $this->otherUserTagLabel]); | ||
222 | |||
223 | $this->assertSame(404, $this->client->getResponse()->getStatusCode()); | ||
224 | } | ||
183 | } | 225 | } |
diff --git a/tests/Wallabag/ApiBundle/Controller/TaggingRuleRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/TaggingRuleRestControllerTest.php new file mode 100644 index 00000000..b6477256 --- /dev/null +++ b/tests/Wallabag/ApiBundle/Controller/TaggingRuleRestControllerTest.php | |||
@@ -0,0 +1,15 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Tests\Wallabag\ApiBundle\Controller; | ||
4 | |||
5 | use Tests\Wallabag\ApiBundle\WallabagApiTestCase; | ||
6 | |||
7 | class TaggingRuleRestControllerTest extends WallabagApiTestCase | ||
8 | { | ||
9 | public function testExportEntry() | ||
10 | { | ||
11 | $this->client->request('GET', '/api/taggingrule/export'); | ||
12 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); | ||
13 | $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type')); | ||
14 | } | ||
15 | } | ||
diff --git a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php index ac4d6cdc..8b49c0ae 100644 --- a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php | |||
@@ -18,4 +18,21 @@ class WallabagRestControllerTest extends WallabagApiTestCase | |||
18 | 18 | ||
19 | $this->assertSame($client->getContainer()->getParameter('wallabag_core.version'), $content); | 19 | $this->assertSame($client->getContainer()->getParameter('wallabag_core.version'), $content); |
20 | } | 20 | } |
21 | |||
22 | public function testGetInfo() | ||
23 | { | ||
24 | // create a new client instead of using $this->client to be sure client isn't authenticated | ||
25 | $client = static::createClient(); | ||
26 | $client->request('GET', '/api/info'); | ||
27 | |||
28 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | ||
29 | |||
30 | $content = json_decode($client->getResponse()->getContent(), true); | ||
31 | |||
32 | $this->assertArrayHasKey('appname', $content); | ||
33 | $this->assertArrayHasKey('version', $content); | ||
34 | $this->assertArrayHasKey('allowed_registration', $content); | ||
35 | |||
36 | $this->assertSame('wallabag', $content['appname']); | ||
37 | } | ||
21 | } | 38 | } |
diff --git a/tests/Wallabag/ApiBundle/WallabagApiTestCase.php b/tests/Wallabag/ApiBundle/WallabagApiTestCase.php index 8a188e1c..fd2e113e 100644 --- a/tests/Wallabag/ApiBundle/WallabagApiTestCase.php +++ b/tests/Wallabag/ApiBundle/WallabagApiTestCase.php | |||
@@ -31,9 +31,9 @@ abstract class WallabagApiTestCase extends WebTestCase | |||
31 | $container = $client->getContainer(); | 31 | $container = $client->getContainer(); |
32 | 32 | ||
33 | /** @var $userManager \FOS\UserBundle\Doctrine\UserManager */ | 33 | /** @var $userManager \FOS\UserBundle\Doctrine\UserManager */ |
34 | $userManager = $container->get('fos_user.user_manager'); | 34 | $userManager = $container->get('fos_user.user_manager.test'); |
35 | /** @var $loginManager \FOS\UserBundle\Security\LoginManager */ | 35 | /** @var $loginManager \FOS\UserBundle\Security\LoginManager */ |
36 | $loginManager = $container->get('fos_user.security.login_manager'); | 36 | $loginManager = $container->get('fos_user.security.login_manager.test'); |
37 | $firewallName = $container->getParameter('fos_user.firewall_name'); | 37 | $firewallName = $container->getParameter('fos_user.firewall_name'); |
38 | 38 | ||
39 | $this->user = $userManager->findUserBy(['username' => 'admin']); | 39 | $this->user = $userManager->findUserBy(['username' => 'admin']); |
@@ -48,4 +48,23 @@ abstract class WallabagApiTestCase extends WebTestCase | |||
48 | 48 | ||
49 | return $client; | 49 | return $client; |
50 | } | 50 | } |
51 | |||
52 | /** | ||
53 | * Return the ID for the user admin. | ||
54 | * Used because on heavy testing we don't want to re-create the database on each run. | ||
55 | * Which means "admin" user won't have id 1 all the time. | ||
56 | * | ||
57 | * @param string $username | ||
58 | * | ||
59 | * @return int | ||
60 | */ | ||
61 | protected function getUserId($username = 'admin') | ||
62 | { | ||
63 | return $this->client | ||
64 | ->getContainer() | ||
65 | ->get('doctrine.orm.entity_manager') | ||
66 | ->getRepository('WallabagUserBundle:User') | ||
67 | ->findOneByUserName($username) | ||
68 | ->getId(); | ||
69 | } | ||
51 | } | 70 | } |
diff --git a/tests/Wallabag/CoreBundle/Command/GenerateUrlHashesCommandTest.php b/tests/Wallabag/CoreBundle/Command/GenerateUrlHashesCommandTest.php new file mode 100644 index 00000000..17eed210 --- /dev/null +++ b/tests/Wallabag/CoreBundle/Command/GenerateUrlHashesCommandTest.php | |||
@@ -0,0 +1,98 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Tests\Wallabag\CoreBundle\Command; | ||
4 | |||
5 | use Symfony\Bundle\FrameworkBundle\Console\Application; | ||
6 | use Symfony\Component\Console\Tester\CommandTester; | ||
7 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | ||
8 | use Wallabag\CoreBundle\Command\GenerateUrlHashesCommand; | ||
9 | use Wallabag\CoreBundle\Entity\Entry; | ||
10 | |||
11 | class GenerateUrlHashesCommandTest extends WallabagCoreTestCase | ||
12 | { | ||
13 | public function testRunGenerateUrlHashesCommand() | ||
14 | { | ||
15 | $application = new Application($this->getClient()->getKernel()); | ||
16 | $application->add(new GenerateUrlHashesCommand()); | ||
17 | |||
18 | $command = $application->find('wallabag:generate-hashed-urls'); | ||
19 | |||
20 | $tester = new CommandTester($command); | ||
21 | $tester->execute([ | ||
22 | 'command' => $command->getName(), | ||
23 | ]); | ||
24 | |||
25 | $this->assertContains('Generating hashed urls for "3" users', $tester->getDisplay()); | ||
26 | $this->assertContains('Finished generated hashed urls', $tester->getDisplay()); | ||
27 | } | ||
28 | |||
29 | public function testRunGenerateUrlHashesCommandWithBadUsername() | ||
30 | { | ||
31 | $application = new Application($this->getClient()->getKernel()); | ||
32 | $application->add(new GenerateUrlHashesCommand()); | ||
33 | |||
34 | $command = $application->find('wallabag:generate-hashed-urls'); | ||
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 testRunGenerateUrlHashesCommandForUser() | ||
46 | { | ||
47 | $application = new Application($this->getClient()->getKernel()); | ||
48 | $application->add(new GenerateUrlHashesCommand()); | ||
49 | |||
50 | $command = $application->find('wallabag:generate-hashed-urls'); | ||
51 | |||
52 | $tester = new CommandTester($command); | ||
53 | $tester->execute([ | ||
54 | 'command' => $command->getName(), | ||
55 | 'username' => 'admin', | ||
56 | ]); | ||
57 | |||
58 | $this->assertContains('Generated hashed urls for user: admin', $tester->getDisplay()); | ||
59 | } | ||
60 | |||
61 | public function testGenerateUrls() | ||
62 | { | ||
63 | $url = 'http://www.lemonde.fr/sport/visuel/2017/05/05/rondelle-prison-blanchissage-comprendre-le-hockey-sur-glace_5122587_3242.html'; | ||
64 | $client = $this->getClient(); | ||
65 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
66 | |||
67 | $this->logInAs('admin'); | ||
68 | |||
69 | $user = $em->getRepository('WallabagUserBundle:User')->findOneById($this->getLoggedInUserId()); | ||
70 | |||
71 | $entry1 = new Entry($user); | ||
72 | $entry1->setUrl($url); | ||
73 | |||
74 | $em->persist($entry1); | ||
75 | $em->flush(); | ||
76 | |||
77 | $application = new Application($this->getClient()->getKernel()); | ||
78 | $application->add(new GenerateUrlHashesCommand()); | ||
79 | |||
80 | $command = $application->find('wallabag:generate-hashed-urls'); | ||
81 | |||
82 | $tester = new CommandTester($command); | ||
83 | $tester->execute([ | ||
84 | 'command' => $command->getName(), | ||
85 | 'username' => 'admin', | ||
86 | ]); | ||
87 | |||
88 | $this->assertContains('Generated hashed urls for user: admin', $tester->getDisplay()); | ||
89 | |||
90 | $entry = $em->getRepository('WallabagCoreBundle:Entry')->findOneByUrl($url); | ||
91 | |||
92 | $this->assertSame($entry->getHashedUrl(), hash('sha1', $url)); | ||
93 | |||
94 | $query = $em->createQuery('DELETE FROM Wallabag\CoreBundle\Entity\Entry e WHERE e.url = :url'); | ||
95 | $query->setParameter('url', $url); | ||
96 | $query->execute(); | ||
97 | } | ||
98 | } | ||
diff --git a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php index bd351b18..d8928451 100644 --- a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php | |||
@@ -18,6 +18,18 @@ use Wallabag\CoreBundle\Command\InstallCommand; | |||
18 | 18 | ||
19 | class InstallCommandTest extends WallabagCoreTestCase | 19 | class InstallCommandTest extends WallabagCoreTestCase |
20 | { | 20 | { |
21 | public static function setUpBeforeClass() | ||
22 | { | ||
23 | // disable doctrine-test-bundle | ||
24 | StaticDriver::setKeepStaticConnections(false); | ||
25 | } | ||
26 | |||
27 | public static function tearDownAfterClass() | ||
28 | { | ||
29 | // enable doctrine-test-bundle | ||
30 | StaticDriver::setKeepStaticConnections(true); | ||
31 | } | ||
32 | |||
21 | public function setUp() | 33 | public function setUp() |
22 | { | 34 | { |
23 | parent::setUp(); | 35 | parent::setUp(); |
@@ -51,9 +63,6 @@ class InstallCommandTest extends WallabagCoreTestCase | |||
51 | parent::setUp(); | 63 | parent::setUp(); |
52 | } | 64 | } |
53 | 65 | ||
54 | // disable doctrine-test-bundle | ||
55 | StaticDriver::setKeepStaticConnections(false); | ||
56 | |||
57 | $this->resetDatabase($this->getClient()); | 66 | $this->resetDatabase($this->getClient()); |
58 | } | 67 | } |
59 | 68 | ||
@@ -62,6 +71,7 @@ class InstallCommandTest extends WallabagCoreTestCase | |||
62 | $databasePath = getenv('TEST_DATABASE_PATH'); | 71 | $databasePath = getenv('TEST_DATABASE_PATH'); |
63 | // Remove variable environnement | 72 | // Remove variable environnement |
64 | putenv('TEST_DATABASE_PATH'); | 73 | putenv('TEST_DATABASE_PATH'); |
74 | |||
65 | if ($databasePath && file_exists($databasePath)) { | 75 | if ($databasePath && file_exists($databasePath)) { |
66 | unlink($databasePath); | 76 | unlink($databasePath); |
67 | } else { | 77 | } else { |
@@ -71,8 +81,6 @@ class InstallCommandTest extends WallabagCoreTestCase | |||
71 | $this->resetDatabase($client); | 81 | $this->resetDatabase($client); |
72 | } | 82 | } |
73 | 83 | ||
74 | // enable doctrine-test-bundle | ||
75 | StaticDriver::setKeepStaticConnections(true); | ||
76 | parent::tearDown(); | 84 | parent::tearDown(); |
77 | } | 85 | } |
78 | 86 | ||
diff --git a/tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php b/tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php index b13f6519..c4bd6dac 100644 --- a/tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/ReloadEntryCommandTest.php | |||
@@ -26,7 +26,7 @@ class ReloadEntryCommandTest extends WallabagCoreTestCase | |||
26 | { | 26 | { |
27 | parent::setUp(); | 27 | parent::setUp(); |
28 | 28 | ||
29 | $userRepository = $this->getClient()->getContainer()->get('wallabag_user.user_repository'); | 29 | $userRepository = $this->getClient()->getContainer()->get('wallabag_user.user_repository.test'); |
30 | 30 | ||
31 | $user = $userRepository->findOneByUserName('admin'); | 31 | $user = $userRepository->findOneByUserName('admin'); |
32 | $this->adminEntry = new Entry($user); | 32 | $this->adminEntry = new Entry($user); |
@@ -60,7 +60,7 @@ class ReloadEntryCommandTest extends WallabagCoreTestCase | |||
60 | 60 | ||
61 | $reloadedEntries = $this->getClient() | 61 | $reloadedEntries = $this->getClient() |
62 | ->getContainer() | 62 | ->getContainer() |
63 | ->get('wallabag_core.entry_repository') | 63 | ->get('wallabag_core.entry_repository.test') |
64 | ->findById([$this->adminEntry->getId(), $this->bobEntry->getId()]); | 64 | ->findById([$this->adminEntry->getId(), $this->bobEntry->getId()]); |
65 | 65 | ||
66 | foreach ($reloadedEntries as $reloadedEntry) { | 66 | foreach ($reloadedEntries as $reloadedEntry) { |
@@ -84,7 +84,7 @@ class ReloadEntryCommandTest extends WallabagCoreTestCase | |||
84 | 'interactive' => false, | 84 | 'interactive' => false, |
85 | ]); | 85 | ]); |
86 | 86 | ||
87 | $entryRepository = $this->getClient()->getContainer()->get('wallabag_core.entry_repository'); | 87 | $entryRepository = $this->getClient()->getContainer()->get('wallabag_core.entry_repository.test'); |
88 | 88 | ||
89 | $reloadedAdminEntry = $entryRepository->find($this->adminEntry->getId()); | 89 | $reloadedAdminEntry = $entryRepository->find($this->adminEntry->getId()); |
90 | $this->assertNotEmpty($reloadedAdminEntry->getContent()); | 90 | $this->assertNotEmpty($reloadedAdminEntry->getContent()); |
diff --git a/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php b/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php index 9b34f2a0..ed383a2c 100644 --- a/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php +++ b/tests/Wallabag/CoreBundle/Command/ShowUserCommandTest.php | |||
@@ -59,7 +59,8 @@ class ShowUserCommandTest extends WallabagCoreTestCase | |||
59 | $this->assertContains('Username: admin', $tester->getDisplay()); | 59 | $this->assertContains('Username: admin', $tester->getDisplay()); |
60 | $this->assertContains('Email: bigboss@wallabag.org', $tester->getDisplay()); | 60 | $this->assertContains('Email: bigboss@wallabag.org', $tester->getDisplay()); |
61 | $this->assertContains('Display name: Big boss', $tester->getDisplay()); | 61 | $this->assertContains('Display name: Big boss', $tester->getDisplay()); |
62 | $this->assertContains('2FA activated: no', $tester->getDisplay()); | 62 | $this->assertContains('2FA (email) activated', $tester->getDisplay()); |
63 | $this->assertContains('2FA (OTP) activated', $tester->getDisplay()); | ||
63 | } | 64 | } |
64 | 65 | ||
65 | public function testShowUser() | 66 | public function testShowUser() |
diff --git a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php index e07c57dd..fa93c9c2 100644 --- a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php | |||
@@ -1,7 +1,8 @@ | |||
1 | <?php | 1 | <?php |
2 | 2 | ||
3 | namespace tests\Wallabag\CoreBundle\Controller; | 3 | namespace Tests\Wallabag\CoreBundle\Controller; |
4 | 4 | ||
5 | use Symfony\Component\HttpFoundation\File\UploadedFile; | ||
5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | 6 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; |
6 | use Wallabag\AnnotationBundle\Entity\Annotation; | 7 | use Wallabag\AnnotationBundle\Entity\Annotation; |
7 | use Wallabag\CoreBundle\Entity\Config; | 8 | use Wallabag\CoreBundle\Entity\Config; |
@@ -33,7 +34,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
33 | $this->assertCount(1, $crawler->filter('button[id=config_save]')); | 34 | $this->assertCount(1, $crawler->filter('button[id=config_save]')); |
34 | $this->assertCount(1, $crawler->filter('button[id=change_passwd_save]')); | 35 | $this->assertCount(1, $crawler->filter('button[id=change_passwd_save]')); |
35 | $this->assertCount(1, $crawler->filter('button[id=update_user_save]')); | 36 | $this->assertCount(1, $crawler->filter('button[id=update_user_save]')); |
36 | $this->assertCount(1, $crawler->filter('button[id=rss_config_save]')); | 37 | $this->assertCount(1, $crawler->filter('button[id=feed_config_save]')); |
37 | } | 38 | } |
38 | 39 | ||
39 | public function testUpdate() | 40 | public function testUpdate() |
@@ -50,7 +51,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
50 | $data = [ | 51 | $data = [ |
51 | 'config[theme]' => 'baggy', | 52 | 'config[theme]' => 'baggy', |
52 | 'config[items_per_page]' => '30', | 53 | 'config[items_per_page]' => '30', |
53 | 'config[reading_speed]' => '0.5', | 54 | 'config[reading_speed]' => '100', |
54 | 'config[action_mark_as_read]' => '0', | 55 | 'config[action_mark_as_read]' => '0', |
55 | 'config[language]' => 'en', | 56 | 'config[language]' => 'en', |
56 | ]; | 57 | ]; |
@@ -91,7 +92,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
91 | $crawler = $client->request('GET', '/config'); | 92 | $crawler = $client->request('GET', '/config'); |
92 | $form = $crawler->filter('button[id=config_save]')->form(); | 93 | $form = $crawler->filter('button[id=config_save]')->form(); |
93 | $data = [ | 94 | $data = [ |
94 | 'config[reading_speed]' => '2', | 95 | 'config[reading_speed]' => '400', |
95 | ]; | 96 | ]; |
96 | $client->submit($form, $data); | 97 | $client->submit($form, $data); |
97 | 98 | ||
@@ -105,7 +106,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
105 | $crawler = $client->request('GET', '/config'); | 106 | $crawler = $client->request('GET', '/config'); |
106 | $form = $crawler->filter('button[id=config_save]')->form(); | 107 | $form = $crawler->filter('button[id=config_save]')->form(); |
107 | $data = [ | 108 | $data = [ |
108 | 'config[reading_speed]' => '0.5', | 109 | 'config[reading_speed]' => '100', |
109 | ]; | 110 | ]; |
110 | $client->submit($form, $data); | 111 | $client->submit($form, $data); |
111 | } | 112 | } |
@@ -297,7 +298,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
297 | $this->assertContains('flashes.config.notice.user_updated', $alert[0]); | 298 | $this->assertContains('flashes.config.notice.user_updated', $alert[0]); |
298 | } | 299 | } |
299 | 300 | ||
300 | public function testRssUpdateResetToken() | 301 | public function testFeedUpdateResetToken() |
301 | { | 302 | { |
302 | $this->logInAs('admin'); | 303 | $this->logInAs('admin'); |
303 | $client = $this->getClient(); | 304 | $client = $this->getClient(); |
@@ -313,7 +314,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
313 | } | 314 | } |
314 | 315 | ||
315 | $config = $user->getConfig(); | 316 | $config = $user->getConfig(); |
316 | $config->setRssToken(null); | 317 | $config->setFeedToken(null); |
317 | $em->persist($config); | 318 | $em->persist($config); |
318 | $em->flush(); | 319 | $em->flush(); |
319 | 320 | ||
@@ -322,7 +323,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
322 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | 323 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
323 | 324 | ||
324 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | 325 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); |
325 | $this->assertContains('config.form_rss.no_token', $body[0]); | 326 | $this->assertContains('config.form_feed.no_token', $body[0]); |
326 | 327 | ||
327 | $client->request('GET', '/generate-token'); | 328 | $client->request('GET', '/generate-token'); |
328 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | 329 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
@@ -330,7 +331,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
330 | $crawler = $client->followRedirect(); | 331 | $crawler = $client->followRedirect(); |
331 | 332 | ||
332 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | 333 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); |
333 | $this->assertNotContains('config.form_rss.no_token', $body[0]); | 334 | $this->assertContains('config.form_feed.token_reset', $body[0]); |
334 | } | 335 | } |
335 | 336 | ||
336 | public function testGenerateTokenAjax() | 337 | public function testGenerateTokenAjax() |
@@ -351,7 +352,23 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
351 | $this->assertArrayHasKey('token', $content); | 352 | $this->assertArrayHasKey('token', $content); |
352 | } | 353 | } |
353 | 354 | ||
354 | public function testRssUpdate() | 355 | public function testRevokeTokenAjax() |
356 | { | ||
357 | $this->logInAs('admin'); | ||
358 | $client = $this->getClient(); | ||
359 | |||
360 | $client->request( | ||
361 | 'GET', | ||
362 | '/revoke-token', | ||
363 | [], | ||
364 | [], | ||
365 | ['HTTP_X-Requested-With' => 'XMLHttpRequest'] | ||
366 | ); | ||
367 | |||
368 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | ||
369 | } | ||
370 | |||
371 | public function testFeedUpdate() | ||
355 | { | 372 | { |
356 | $this->logInAs('admin'); | 373 | $this->logInAs('admin'); |
357 | $client = $this->getClient(); | 374 | $client = $this->getClient(); |
@@ -360,10 +377,10 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
360 | 377 | ||
361 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | 378 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
362 | 379 | ||
363 | $form = $crawler->filter('button[id=rss_config_save]')->form(); | 380 | $form = $crawler->filter('button[id=feed_config_save]')->form(); |
364 | 381 | ||
365 | $data = [ | 382 | $data = [ |
366 | 'rss_config[rss_limit]' => 12, | 383 | 'feed_config[feed_limit]' => 12, |
367 | ]; | 384 | ]; |
368 | 385 | ||
369 | $client->submit($form, $data); | 386 | $client->submit($form, $data); |
@@ -372,31 +389,31 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
372 | 389 | ||
373 | $crawler = $client->followRedirect(); | 390 | $crawler = $client->followRedirect(); |
374 | 391 | ||
375 | $this->assertContains('flashes.config.notice.rss_updated', $crawler->filter('body')->extract(['_text'])[0]); | 392 | $this->assertContains('flashes.config.notice.feed_updated', $crawler->filter('body')->extract(['_text'])[0]); |
376 | } | 393 | } |
377 | 394 | ||
378 | public function dataForRssFailed() | 395 | public function dataForFeedFailed() |
379 | { | 396 | { |
380 | return [ | 397 | return [ |
381 | [ | 398 | [ |
382 | [ | 399 | [ |
383 | 'rss_config[rss_limit]' => 0, | 400 | 'feed_config[feed_limit]' => 0, |
384 | ], | 401 | ], |
385 | 'This value should be 1 or more.', | 402 | 'This value should be 1 or more.', |
386 | ], | 403 | ], |
387 | [ | 404 | [ |
388 | [ | 405 | [ |
389 | 'rss_config[rss_limit]' => 1000000000000, | 406 | 'feed_config[feed_limit]' => 1000000000000, |
390 | ], | 407 | ], |
391 | 'validator.rss_limit_too_high', | 408 | 'validator.feed_limit_too_high', |
392 | ], | 409 | ], |
393 | ]; | 410 | ]; |
394 | } | 411 | } |
395 | 412 | ||
396 | /** | 413 | /** |
397 | * @dataProvider dataForRssFailed | 414 | * @dataProvider dataForFeedFailed |
398 | */ | 415 | */ |
399 | public function testRssFailed($data, $expectedMessage) | 416 | public function testFeedFailed($data, $expectedMessage) |
400 | { | 417 | { |
401 | $this->logInAs('admin'); | 418 | $this->logInAs('admin'); |
402 | $client = $this->getClient(); | 419 | $client = $this->getClient(); |
@@ -405,7 +422,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
405 | 422 | ||
406 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | 423 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
407 | 424 | ||
408 | $form = $crawler->filter('button[id=rss_config_save]')->form(); | 425 | $form = $crawler->filter('button[id=feed_config_save]')->form(); |
409 | 426 | ||
410 | $crawler = $client->submit($form, $data); | 427 | $crawler = $client->submit($form, $data); |
411 | 428 | ||
@@ -678,7 +695,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
678 | 695 | ||
679 | $config->setTheme('material'); | 696 | $config->setTheme('material'); |
680 | $config->setItemsPerPage(30); | 697 | $config->setItemsPerPage(30); |
681 | $config->setReadingSpeed(1); | 698 | $config->setReadingSpeed(200); |
682 | $config->setLanguage('en'); | 699 | $config->setLanguage('en'); |
683 | $config->setPocketConsumerKey('xxxxx'); | 700 | $config->setPocketConsumerKey('xxxxx'); |
684 | 701 | ||
@@ -849,7 +866,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
849 | $entryArchived->setContent('Youhou'); | 866 | $entryArchived->setContent('Youhou'); |
850 | $entryArchived->setTitle('Youhou'); | 867 | $entryArchived->setTitle('Youhou'); |
851 | $entryArchived->addTag($tagArchived); | 868 | $entryArchived->addTag($tagArchived); |
852 | $entryArchived->setArchived(true); | 869 | $entryArchived->updateArchived(true); |
853 | $em->persist($entryArchived); | 870 | $em->persist($entryArchived); |
854 | 871 | ||
855 | $annotationArchived = new Annotation($user); | 872 | $annotationArchived = new Annotation($user); |
@@ -965,4 +982,183 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
965 | 982 | ||
966 | $client->request('GET', '/config/view-mode'); | 983 | $client->request('GET', '/config/view-mode'); |
967 | } | 984 | } |
985 | |||
986 | public function testChangeLocaleWithoutReferer() | ||
987 | { | ||
988 | $client = $this->getClient(); | ||
989 | |||
990 | $client->request('GET', '/locale/de'); | ||
991 | $client->followRedirect(); | ||
992 | |||
993 | $this->assertSame('de', $client->getRequest()->getLocale()); | ||
994 | $this->assertSame('de', $client->getContainer()->get('session')->get('_locale')); | ||
995 | } | ||
996 | |||
997 | public function testChangeLocaleWithReferer() | ||
998 | { | ||
999 | $client = $this->getClient(); | ||
1000 | |||
1001 | $client->request('GET', '/login'); | ||
1002 | $client->request('GET', '/locale/de'); | ||
1003 | $client->followRedirect(); | ||
1004 | |||
1005 | $this->assertSame('de', $client->getRequest()->getLocale()); | ||
1006 | $this->assertSame('de', $client->getContainer()->get('session')->get('_locale')); | ||
1007 | } | ||
1008 | |||
1009 | public function testChangeLocaleToBadLocale() | ||
1010 | { | ||
1011 | $client = $this->getClient(); | ||
1012 | |||
1013 | $client->request('GET', '/login'); | ||
1014 | $client->request('GET', '/locale/yuyuyuyu'); | ||
1015 | $client->followRedirect(); | ||
1016 | |||
1017 | $this->assertNotSame('yuyuyuyu', $client->getRequest()->getLocale()); | ||
1018 | $this->assertNotSame('yuyuyuyu', $client->getContainer()->get('session')->get('_locale')); | ||
1019 | } | ||
1020 | |||
1021 | public function testUserEnable2faEmail() | ||
1022 | { | ||
1023 | $this->logInAs('admin'); | ||
1024 | $client = $this->getClient(); | ||
1025 | |||
1026 | $crawler = $client->request('GET', '/config/otp/email'); | ||
1027 | |||
1028 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | ||
1029 | |||
1030 | $crawler = $client->followRedirect(); | ||
1031 | |||
1032 | $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text'])); | ||
1033 | $this->assertContains('flashes.config.notice.otp_enabled', $alert[0]); | ||
1034 | |||
1035 | // restore user | ||
1036 | $em = $this->getEntityManager(); | ||
1037 | $user = $em | ||
1038 | ->getRepository('WallabagUserBundle:User') | ||
1039 | ->findOneByUsername('admin'); | ||
1040 | |||
1041 | $this->assertTrue($user->isEmailTwoFactor()); | ||
1042 | |||
1043 | $user->setEmailTwoFactor(false); | ||
1044 | $em->persist($user); | ||
1045 | $em->flush(); | ||
1046 | } | ||
1047 | |||
1048 | public function testUserEnable2faGoogle() | ||
1049 | { | ||
1050 | $this->logInAs('admin'); | ||
1051 | $client = $this->getClient(); | ||
1052 | |||
1053 | $crawler = $client->request('GET', '/config/otp/app'); | ||
1054 | |||
1055 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | ||
1056 | |||
1057 | // restore user | ||
1058 | $em = $this->getEntityManager(); | ||
1059 | $user = $em | ||
1060 | ->getRepository('WallabagUserBundle:User') | ||
1061 | ->findOneByUsername('admin'); | ||
1062 | |||
1063 | $this->assertTrue($user->isGoogleTwoFactor()); | ||
1064 | $this->assertGreaterThan(0, $user->getBackupCodes()); | ||
1065 | |||
1066 | $user->setGoogleAuthenticatorSecret(false); | ||
1067 | $user->setBackupCodes(null); | ||
1068 | $em->persist($user); | ||
1069 | $em->flush(); | ||
1070 | } | ||
1071 | |||
1072 | public function testUserEnable2faGoogleCancel() | ||
1073 | { | ||
1074 | $this->logInAs('admin'); | ||
1075 | $client = $this->getClient(); | ||
1076 | |||
1077 | $crawler = $client->request('GET', '/config/otp/app'); | ||
1078 | |||
1079 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | ||
1080 | |||
1081 | // restore user | ||
1082 | $em = $this->getEntityManager(); | ||
1083 | $user = $em | ||
1084 | ->getRepository('WallabagUserBundle:User') | ||
1085 | ->findOneByUsername('admin'); | ||
1086 | |||
1087 | $this->assertTrue($user->isGoogleTwoFactor()); | ||
1088 | $this->assertGreaterThan(0, $user->getBackupCodes()); | ||
1089 | |||
1090 | $crawler = $client->request('GET', '/config/otp/app/cancel'); | ||
1091 | |||
1092 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | ||
1093 | |||
1094 | $user = $em | ||
1095 | ->getRepository('WallabagUserBundle:User') | ||
1096 | ->findOneByUsername('admin'); | ||
1097 | |||
1098 | $this->assertFalse($user->isGoogleTwoFactor()); | ||
1099 | $this->assertEmpty($user->getBackupCodes()); | ||
1100 | } | ||
1101 | |||
1102 | public function testExportTaggingRule() | ||
1103 | { | ||
1104 | $this->logInAs('admin'); | ||
1105 | $client = $this->getClient(); | ||
1106 | |||
1107 | ob_start(); | ||
1108 | $crawler = $client->request('GET', '/tagging-rule/export'); | ||
1109 | ob_end_clean(); | ||
1110 | |||
1111 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | ||
1112 | |||
1113 | $headers = $client->getResponse()->headers; | ||
1114 | $this->assertSame('application/json', $headers->get('content-type')); | ||
1115 | $this->assertSame('attachment; filename="tagging_rules_admin.json"', $headers->get('content-disposition')); | ||
1116 | $this->assertSame('UTF-8', $headers->get('content-transfer-encoding')); | ||
1117 | |||
1118 | $content = json_decode($client->getResponse()->getContent(), true); | ||
1119 | |||
1120 | $this->assertCount(4, $content); | ||
1121 | $this->assertSame('content matches "spurs"', $content[0]['rule']); | ||
1122 | $this->assertSame('sport', $content[0]['tags'][0]); | ||
1123 | } | ||
1124 | |||
1125 | public function testImportTagginfRuleBadFile() | ||
1126 | { | ||
1127 | $this->logInAs('admin'); | ||
1128 | $client = $this->getClient(); | ||
1129 | |||
1130 | $crawler = $client->request('GET', '/config'); | ||
1131 | $form = $crawler->filter('form[name=upload_tagging_rule_file] > button[type=submit]')->form(); | ||
1132 | |||
1133 | $data = [ | ||
1134 | 'upload_tagging_rule_file[file]' => '', | ||
1135 | ]; | ||
1136 | |||
1137 | $client->submit($form, $data); | ||
1138 | |||
1139 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | ||
1140 | } | ||
1141 | |||
1142 | public function testImportTagginfRuleFile() | ||
1143 | { | ||
1144 | $this->logInAs('admin'); | ||
1145 | $client = $this->getClient(); | ||
1146 | |||
1147 | $crawler = $client->request('GET', '/config'); | ||
1148 | $form = $crawler->filter('form[name=upload_tagging_rule_file] > button[type=submit]')->form(); | ||
1149 | |||
1150 | $file = new UploadedFile(__DIR__ . '/../fixtures/tagging_rules_admin.json', 'tagging_rules_admin.json'); | ||
1151 | |||
1152 | $data = [ | ||
1153 | 'upload_tagging_rule_file[file]' => $file, | ||
1154 | ]; | ||
1155 | |||
1156 | $client->submit($form, $data); | ||
1157 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | ||
1158 | |||
1159 | $user = $client->getContainer()->get('fos_user.user_manager.test')->findUserBy(['username' => 'admin']); | ||
1160 | $taggingRules = $user->getConfig()->getTaggingRules()->toArray(); | ||
1161 | $this->assertCount(5, $taggingRules); | ||
1162 | $this->assertSame('title matches "football"', $taggingRules[4]->getRule()); | ||
1163 | } | ||
968 | } | 1164 | } |
diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index 479e0700..3a8f92e7 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php | |||
@@ -13,7 +13,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
13 | { | 13 | { |
14 | const AN_URL_CONTAINING_AN_ARTICLE_WITH_IMAGE = 'https://www.lemonde.fr/judo/article/2017/11/11/judo-la-decima-de-teddy-riner_5213605_1556020.html'; | 14 | const AN_URL_CONTAINING_AN_ARTICLE_WITH_IMAGE = 'https://www.lemonde.fr/judo/article/2017/11/11/judo-la-decima-de-teddy-riner_5213605_1556020.html'; |
15 | public $downloadImagesEnabled = false; | 15 | public $downloadImagesEnabled = false; |
16 | public $url = 'https://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'; | 16 | public $url = 'https://www.lemonde.fr/pixels/article/2019/06/18/ce-qu-il-faut-savoir-sur-le-libra-la-cryptomonnaie-de-facebook_5477887_4408996.html'; |
17 | 17 | ||
18 | /** | 18 | /** |
19 | * @after | 19 | * @after |
@@ -164,9 +164,8 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
164 | 164 | ||
165 | $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); | 165 | $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); |
166 | $this->assertSame($this->url, $content->getUrl()); | 166 | $this->assertSame($this->url, $content->getUrl()); |
167 | $this->assertContains('Google', $content->getTitle()); | 167 | $this->assertContains('la cryptomonnaie de Facebook', $content->getTitle()); |
168 | $this->assertSame('fr', $content->getLanguage()); | 168 | $this->assertSame('fr', $content->getLanguage()); |
169 | $this->assertSame('2016-04-07 19:01:35', $content->getPublishedAt()->format('Y-m-d H:i:s')); | ||
170 | $this->assertArrayHasKey('x-frame-options', $content->getHeaders()); | 169 | $this->assertArrayHasKey('x-frame-options', $content->getHeaders()); |
171 | $client->getContainer()->get('craue_config')->set('store_article_headers', 0); | 170 | $client->getContainer()->get('craue_config')->set('store_article_headers', 0); |
172 | } | 171 | } |
@@ -200,8 +199,8 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
200 | $authors = $content->getPublishedBy(); | 199 | $authors = $content->getPublishedBy(); |
201 | $this->assertSame('2017-04-05 19:26:13', $content->getPublishedAt()->format('Y-m-d H:i:s')); | 200 | $this->assertSame('2017-04-05 19:26:13', $content->getPublishedAt()->format('Y-m-d H:i:s')); |
202 | $this->assertSame('fr', $content->getLanguage()); | 201 | $this->assertSame('fr', $content->getLanguage()); |
203 | $this->assertSame('Raphaël Balenieri, correspondant à Pékin', $authors[0]); | 202 | $this->assertSame('Raphaël Balenieri', $authors[0]); |
204 | $this->assertSame('Frédéric Autran, correspondant à New York', $authors[1]); | 203 | $this->assertSame('Frédéric Autran', $authors[1]); |
205 | } | 204 | } |
206 | 205 | ||
207 | public function testPostNewOkUrlExist() | 206 | public function testPostNewOkUrlExist() |
@@ -236,7 +235,45 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
236 | $this->logInAs('admin'); | 235 | $this->logInAs('admin'); |
237 | $client = $this->getClient(); | 236 | $client = $this->getClient(); |
238 | 237 | ||
239 | $url = 'http://www.aritylabs.com/post/106091708292/des-contr%C3%B4leurs-optionnels-gr%C3%A2ce-%C3%A0-constmissing'; | 238 | $url = 'https://www.aritylabs.com/post/106091708292/des-contr%C3%B4leurs-optionnels-gr%C3%A2ce-%C3%A0-constmissing'; |
239 | |||
240 | $crawler = $client->request('GET', '/new'); | ||
241 | |||
242 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | ||
243 | |||
244 | $form = $crawler->filter('form[name=entry]')->form(); | ||
245 | |||
246 | $data = [ | ||
247 | 'entry[url]' => $url, | ||
248 | ]; | ||
249 | |||
250 | $client->submit($form, $data); | ||
251 | |||
252 | $crawler = $client->request('GET', '/new'); | ||
253 | |||
254 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | ||
255 | |||
256 | $form = $crawler->filter('form[name=entry]')->form(); | ||
257 | |||
258 | $data = [ | ||
259 | 'entry[url]' => $url, | ||
260 | ]; | ||
261 | |||
262 | $client->submit($form, $data); | ||
263 | |||
264 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | ||
265 | $this->assertContains('/view/', $client->getResponse()->getTargetUrl()); | ||
266 | } | ||
267 | |||
268 | /** | ||
269 | * This test will require an internet connection. | ||
270 | */ | ||
271 | public function testPostNewOkUrlExistWithRedirection() | ||
272 | { | ||
273 | $this->logInAs('admin'); | ||
274 | $client = $this->getClient(); | ||
275 | |||
276 | $url = 'https://wllbg.org/test-redirect/c51c'; | ||
240 | 277 | ||
241 | $crawler = $client->request('GET', '/new'); | 278 | $crawler = $client->request('GET', '/new'); |
242 | 279 | ||
@@ -522,9 +559,12 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
522 | 559 | ||
523 | $crawler = $client->followRedirect(); | 560 | $crawler = $client->followRedirect(); |
524 | 561 | ||
525 | $this->assertGreaterThan(1, $title = $crawler->filter('div[id=article] h1')->extract(['_text'])); | 562 | $title = $crawler->filter('div[id=article] h1')->extract(['_text']); |
563 | $this->assertGreaterThan(1, $title); | ||
526 | $this->assertContains('My updated title hehe :)', $title[0]); | 564 | $this->assertContains('My updated title hehe :)', $title[0]); |
527 | $this->assertSame(1, \count($stats = $crawler->filter('div[class=tools] ul[class=stats] li a[class=tool]')->extract(['_text']))); | 565 | |
566 | $stats = $crawler->filter('div[class=tools] ul[class=stats] li a[class=tool]')->extract(['_text']); | ||
567 | $this->assertCount(1, $stats); | ||
528 | $this->assertNotContains('example.io', trim($stats[0])); | 568 | $this->assertNotContains('example.io', trim($stats[0])); |
529 | } | 569 | } |
530 | 570 | ||
@@ -620,7 +660,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
620 | $content->setMimetype('text/html'); | 660 | $content->setMimetype('text/html'); |
621 | $content->setTitle('test title entry'); | 661 | $content->setTitle('test title entry'); |
622 | $content->setContent('This is my content /o/'); | 662 | $content->setContent('This is my content /o/'); |
623 | $content->setArchived(true); | 663 | $content->updateArchived(true); |
624 | $content->setLanguage('fr'); | 664 | $content->setLanguage('fr'); |
625 | 665 | ||
626 | $em->persist($content); | 666 | $em->persist($content); |
@@ -773,7 +813,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
773 | 813 | ||
774 | $entry = new Entry($this->getLoggedInUser()); | 814 | $entry = new Entry($this->getLoggedInUser()); |
775 | $entry->setUrl($this->url); | 815 | $entry->setUrl($this->url); |
776 | $entry->setArchived(false); | 816 | $entry->updateArchived(false); |
777 | $this->getEntityManager()->persist($entry); | 817 | $this->getEntityManager()->persist($entry); |
778 | $this->getEntityManager()->flush(); | 818 | $this->getEntityManager()->flush(); |
779 | 819 | ||
@@ -984,8 +1024,13 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
984 | $client->request('GET', '/share/' . $content->getId()); | 1024 | $client->request('GET', '/share/' . $content->getId()); |
985 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | 1025 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
986 | 1026 | ||
987 | // follow link with uid | 1027 | $shareUrl = $client->getResponse()->getTargetUrl(); |
988 | $crawler = $client->followRedirect(); | 1028 | |
1029 | // use a new client to have a fresh empty session (instead of a logged one from the previous client) | ||
1030 | $client->restart(); | ||
1031 | |||
1032 | $client->request('GET', $shareUrl); | ||
1033 | |||
989 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | 1034 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
990 | $this->assertContains('max-age=25200', $client->getResponse()->headers->get('cache-control')); | 1035 | $this->assertContains('max-age=25200', $client->getResponse()->headers->get('cache-control')); |
991 | $this->assertContains('public', $client->getResponse()->headers->get('cache-control')); | 1036 | $this->assertContains('public', $client->getResponse()->headers->get('cache-control')); |
@@ -1001,9 +1046,6 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
1001 | $client->request('GET', '/share/' . $content->getUid()); | 1046 | $client->request('GET', '/share/' . $content->getUid()); |
1002 | $this->assertSame(404, $client->getResponse()->getStatusCode()); | 1047 | $this->assertSame(404, $client->getResponse()->getStatusCode()); |
1003 | 1048 | ||
1004 | $client->request('GET', '/view/' . $content->getId()); | ||
1005 | $this->assertContains('no-cache', $client->getResponse()->headers->get('cache-control')); | ||
1006 | |||
1007 | // removing the share | 1049 | // removing the share |
1008 | $client->request('GET', '/share/delete/' . $content->getId()); | 1050 | $client->request('GET', '/share/delete/' . $content->getId()); |
1009 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | 1051 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
@@ -1244,7 +1286,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
1244 | $entry = new Entry($this->getLoggedInUser()); | 1286 | $entry = new Entry($this->getLoggedInUser()); |
1245 | $entry->setUrl('http://0.0.0.0/foo/baz/qux'); | 1287 | $entry->setUrl('http://0.0.0.0/foo/baz/qux'); |
1246 | $entry->setTitle('Le manège'); | 1288 | $entry->setTitle('Le manège'); |
1247 | $entry->setArchived(true); | 1289 | $entry->updateArchived(true); |
1248 | $this->getEntityManager()->persist($entry); | 1290 | $this->getEntityManager()->persist($entry); |
1249 | $this->getEntityManager()->flush(); | 1291 | $this->getEntityManager()->flush(); |
1250 | 1292 | ||
@@ -1274,7 +1316,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
1274 | $entry = new Entry($this->getLoggedInUser()); | 1316 | $entry = new Entry($this->getLoggedInUser()); |
1275 | $entry->setUrl('http://domain/qux'); | 1317 | $entry->setUrl('http://domain/qux'); |
1276 | $entry->setTitle('Le manège'); | 1318 | $entry->setTitle('Le manège'); |
1277 | $entry->setArchived(true); | 1319 | $entry->updateArchived(true); |
1278 | $this->getEntityManager()->persist($entry); | 1320 | $this->getEntityManager()->persist($entry); |
1279 | $this->getEntityManager()->flush(); | 1321 | $this->getEntityManager()->flush(); |
1280 | 1322 | ||
@@ -1325,10 +1367,6 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
1325 | 'http://www.hao123.com/shequ?__noscript__-=1', | 1367 | 'http://www.hao123.com/shequ?__noscript__-=1', |
1326 | 'zh_CN', | 1368 | 'zh_CN', |
1327 | ], | 1369 | ], |
1328 | 'ru' => [ | ||
1329 | 'https://www.kp.ru/daily/26879.7/3921982/', | ||
1330 | 'ru', | ||
1331 | ], | ||
1332 | 'pt_BR' => [ | 1370 | 'pt_BR' => [ |
1333 | 'https://politica.estadao.com.br/noticias/eleicoes,campanha-catatonica,70002491983', | 1371 | 'https://politica.estadao.com.br/noticias/eleicoes,campanha-catatonica,70002491983', |
1334 | 'pt_BR', | 1372 | 'pt_BR', |
@@ -1339,7 +1377,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
1339 | ], | 1377 | ], |
1340 | 'es-ES' => [ | 1378 | 'es-ES' => [ |
1341 | 'https://www.20minutos.es/noticia/3360685/0/gobierno-sanchez-primero-historia-mas-mujeres-que-hombres/', | 1379 | 'https://www.20minutos.es/noticia/3360685/0/gobierno-sanchez-primero-historia-mas-mujeres-que-hombres/', |
1342 | 'es', | 1380 | 'es_ES', |
1343 | ], | 1381 | ], |
1344 | ]; | 1382 | ]; |
1345 | } | 1383 | } |
@@ -1494,4 +1532,30 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
1494 | 1532 | ||
1495 | $this->assertSame(sprintf('/remove-tag/%s/%s', $entry->getId(), $tag->getId()), $link); | 1533 | $this->assertSame(sprintf('/remove-tag/%s/%s', $entry->getId(), $tag->getId()), $link); |
1496 | } | 1534 | } |
1535 | |||
1536 | public function testRandom() | ||
1537 | { | ||
1538 | $this->logInAs('admin'); | ||
1539 | $client = $this->getClient(); | ||
1540 | |||
1541 | $client->request('GET', '/unread/random'); | ||
1542 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | ||
1543 | $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Unread random'); | ||
1544 | |||
1545 | $client->request('GET', '/starred/random'); | ||
1546 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | ||
1547 | $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Starred random'); | ||
1548 | |||
1549 | $client->request('GET', '/archive/random'); | ||
1550 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | ||
1551 | $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Archive random'); | ||
1552 | |||
1553 | $client->request('GET', '/untagged/random'); | ||
1554 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | ||
1555 | $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Untagged random'); | ||
1556 | |||
1557 | $client->request('GET', '/all/random'); | ||
1558 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | ||
1559 | $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'All random'); | ||
1560 | } | ||
1497 | } | 1561 | } |
diff --git a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php index 6f3308e5..d7ce7c45 100644 --- a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php | |||
@@ -98,7 +98,7 @@ class ExportControllerTest extends WallabagCoreTestCase | |||
98 | 98 | ||
99 | $headers = $client->getResponse()->headers; | 99 | $headers = $client->getResponse()->headers; |
100 | $this->assertSame('application/x-mobipocket-ebook', $headers->get('content-type')); | 100 | $this->assertSame('application/x-mobipocket-ebook', $headers->get('content-type')); |
101 | $this->assertSame('attachment; filename="' . preg_replace('/[^A-Za-z0-9\-]/', '', $content->getTitle()) . '.mobi"', $headers->get('content-disposition')); | 101 | $this->assertSame('attachment; filename="' . $this->getSanitizedFilename($content->getTitle()) . '.mobi"', $headers->get('content-disposition')); |
102 | $this->assertSame('binary', $headers->get('content-transfer-encoding')); | 102 | $this->assertSame('binary', $headers->get('content-transfer-encoding')); |
103 | } | 103 | } |
104 | 104 | ||
@@ -126,7 +126,7 @@ class ExportControllerTest extends WallabagCoreTestCase | |||
126 | 126 | ||
127 | $headers = $client->getResponse()->headers; | 127 | $headers = $client->getResponse()->headers; |
128 | $this->assertSame('application/pdf', $headers->get('content-type')); | 128 | $this->assertSame('application/pdf', $headers->get('content-type')); |
129 | $this->assertSame('attachment; filename="Tag_entries articles.pdf"', $headers->get('content-disposition')); | 129 | $this->assertSame('attachment; filename="Tag foo bar articles.pdf"', $headers->get('content-disposition')); |
130 | $this->assertSame('binary', $headers->get('content-transfer-encoding')); | 130 | $this->assertSame('binary', $headers->get('content-transfer-encoding')); |
131 | } | 131 | } |
132 | 132 | ||
@@ -180,7 +180,7 @@ class ExportControllerTest extends WallabagCoreTestCase | |||
180 | 180 | ||
181 | $this->assertGreaterThan(1, $csv); | 181 | $this->assertGreaterThan(1, $csv); |
182 | // +1 for title line | 182 | // +1 for title line |
183 | $this->assertSame(\count($contentInDB) + 1, \count($csv)); | 183 | $this->assertCount(\count($contentInDB) + 1, $csv); |
184 | $this->assertSame('Title;URL;Content;Tags;"MIME Type";Language;"Creation date"', $csv[0]); | 184 | $this->assertSame('Title;URL;Content;Tags;"MIME Type";Language;"Creation date"', $csv[0]); |
185 | $this->assertContains($contentInDB[0]['title'], $csv[1]); | 185 | $this->assertContains($contentInDB[0]['title'], $csv[1]); |
186 | $this->assertContains($contentInDB[0]['url'], $csv[1]); | 186 | $this->assertContains($contentInDB[0]['url'], $csv[1]); |
@@ -212,7 +212,7 @@ class ExportControllerTest extends WallabagCoreTestCase | |||
212 | 212 | ||
213 | $headers = $client->getResponse()->headers; | 213 | $headers = $client->getResponse()->headers; |
214 | $this->assertSame('application/json', $headers->get('content-type')); | 214 | $this->assertSame('application/json', $headers->get('content-type')); |
215 | $this->assertSame('attachment; filename="' . $contentInDB->getTitle() . '.json"', $headers->get('content-disposition')); | 215 | $this->assertSame('attachment; filename="' . $this->getSanitizedFilename($contentInDB->getTitle()) . '.json"', $headers->get('content-disposition')); |
216 | $this->assertSame('UTF-8', $headers->get('content-transfer-encoding')); | 216 | $this->assertSame('UTF-8', $headers->get('content-transfer-encoding')); |
217 | 217 | ||
218 | $content = json_decode($client->getResponse()->getContent(), true); | 218 | $content = json_decode($client->getResponse()->getContent(), true); |
@@ -281,4 +281,9 @@ class ExportControllerTest extends WallabagCoreTestCase | |||
281 | $this->assertNotEmpty('created_at', (string) $content->entry[0]->created_at); | 281 | $this->assertNotEmpty('created_at', (string) $content->entry[0]->created_at); |
282 | $this->assertNotEmpty('updated_at', (string) $content->entry[0]->updated_at); | 282 | $this->assertNotEmpty('updated_at', (string) $content->entry[0]->updated_at); |
283 | } | 283 | } |
284 | |||
285 | private function getSanitizedFilename($title) | ||
286 | { | ||
287 | return preg_replace('/[^A-Za-z0-9\- \']/', '', iconv('utf-8', 'us-ascii//TRANSLIT', $title)); | ||
288 | } | ||
284 | } | 289 | } |
diff --git a/tests/Wallabag/CoreBundle/Controller/FeedControllerTest.php b/tests/Wallabag/CoreBundle/Controller/FeedControllerTest.php new file mode 100644 index 00000000..d52d7bb8 --- /dev/null +++ b/tests/Wallabag/CoreBundle/Controller/FeedControllerTest.php | |||
@@ -0,0 +1,261 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Tests\Wallabag\CoreBundle\Controller; | ||
4 | |||
5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | ||
6 | |||
7 | class FeedControllerTest extends WallabagCoreTestCase | ||
8 | { | ||
9 | public function validateDom($xml, $type, $nb = null, $tagValue = null) | ||
10 | { | ||
11 | $doc = new \DOMDocument(); | ||
12 | $doc->loadXML($xml); | ||
13 | |||
14 | $xpath = new \DOMXPath($doc); | ||
15 | $xpath->registerNamespace('a', 'http://www.w3.org/2005/Atom'); | ||
16 | |||
17 | if (null === $nb) { | ||
18 | $this->assertGreaterThan(0, $xpath->query('//a:entry')->length); | ||
19 | } else { | ||
20 | $this->assertSame($nb, $xpath->query('//a:entry')->length); | ||
21 | } | ||
22 | |||
23 | $this->assertSame(1, $xpath->query('/a:feed')->length); | ||
24 | |||
25 | $this->assertSame(1, $xpath->query('/a:feed/a:title')->length); | ||
26 | $this->assertContains('favicon.ico', $xpath->query('/a:feed/a:icon')->item(0)->nodeValue); | ||
27 | $this->assertContains('logo-square.png', $xpath->query('/a:feed/a:logo')->item(0)->nodeValue); | ||
28 | |||
29 | $this->assertSame(1, $xpath->query('/a:feed/a:updated')->length); | ||
30 | |||
31 | $this->assertSame(1, $xpath->query('/a:feed/a:generator')->length); | ||
32 | $this->assertSame('wallabag', $xpath->query('/a:feed/a:generator')->item(0)->nodeValue); | ||
33 | $this->assertSame('admin', $xpath->query('/a:feed/a:author/a:name')->item(0)->nodeValue); | ||
34 | |||
35 | $this->assertSame(1, $xpath->query('/a:feed/a:subtitle')->length); | ||
36 | if (null !== $tagValue && 0 === strpos($type, 'tag')) { | ||
37 | $this->assertSame('wallabag — ' . $type . ' ' . $tagValue . ' feed', $xpath->query('/a:feed/a:title')->item(0)->nodeValue); | ||
38 | $this->assertSame('Atom feed for entries tagged with ' . $tagValue, $xpath->query('/a:feed/a:subtitle')->item(0)->nodeValue); | ||
39 | } else { | ||
40 | $this->assertSame('wallabag — ' . $type . ' feed', $xpath->query('/a:feed/a:title')->item(0)->nodeValue); | ||
41 | $this->assertSame('Atom feed for ' . $type . ' entries', $xpath->query('/a:feed/a:subtitle')->item(0)->nodeValue); | ||
42 | } | ||
43 | |||
44 | $this->assertSame(1, $xpath->query('/a:feed/a:link[@rel="self"]')->length); | ||
45 | $this->assertContains($type, $xpath->query('/a:feed/a:link[@rel="self"]')->item(0)->getAttribute('href')); | ||
46 | |||
47 | $this->assertSame(1, $xpath->query('/a:feed/a:link[@rel="last"]')->length); | ||
48 | |||
49 | foreach ($xpath->query('//a:entry') as $item) { | ||
50 | $this->assertSame(1, $xpath->query('a:title', $item)->length); | ||
51 | $this->assertSame(1, $xpath->query('a:link[@rel="via"]', $item)->length); | ||
52 | $this->assertSame(1, $xpath->query('a:link[@rel="alternate"]', $item)->length); | ||
53 | $this->assertSame(1, $xpath->query('a:id', $item)->length); | ||
54 | $this->assertSame(1, $xpath->query('a:published', $item)->length); | ||
55 | $this->assertSame(1, $xpath->query('a:content', $item)->length); | ||
56 | } | ||
57 | } | ||
58 | |||
59 | public function dataForBadUrl() | ||
60 | { | ||
61 | return [ | ||
62 | [ | ||
63 | '/feed/admin/YZIOAUZIAO/unread', | ||
64 | ], | ||
65 | [ | ||
66 | '/feed/wallace/YZIOAUZIAO/starred', | ||
67 | ], | ||
68 | [ | ||
69 | '/feed/wallace/YZIOAUZIAO/archives', | ||
70 | ], | ||
71 | [ | ||
72 | '/feed/wallace/YZIOAUZIAO/all', | ||
73 | ], | ||
74 | ]; | ||
75 | } | ||
76 | |||
77 | /** | ||
78 | * @dataProvider dataForBadUrl | ||
79 | */ | ||
80 | public function testBadUrl($url) | ||
81 | { | ||
82 | $client = $this->getClient(); | ||
83 | |||
84 | $client->request('GET', $url); | ||
85 | |||
86 | $this->assertSame(404, $client->getResponse()->getStatusCode()); | ||
87 | } | ||
88 | |||
89 | public function testUnread() | ||
90 | { | ||
91 | $client = $this->getClient(); | ||
92 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
93 | $user = $em | ||
94 | ->getRepository('WallabagUserBundle:User') | ||
95 | ->findOneByUsername('admin'); | ||
96 | |||
97 | $config = $user->getConfig(); | ||
98 | $config->setFeedToken('SUPERTOKEN'); | ||
99 | $config->setFeedLimit(2); | ||
100 | $em->persist($config); | ||
101 | $em->flush(); | ||
102 | |||
103 | $client->request('GET', '/feed/admin/SUPERTOKEN/unread'); | ||
104 | |||
105 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | ||
106 | |||
107 | $this->validateDom($client->getResponse()->getContent(), 'unread', 2); | ||
108 | } | ||
109 | |||
110 | public function testStarred() | ||
111 | { | ||
112 | $client = $this->getClient(); | ||
113 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
114 | $user = $em | ||
115 | ->getRepository('WallabagUserBundle:User') | ||
116 | ->findOneByUsername('admin'); | ||
117 | |||
118 | $config = $user->getConfig(); | ||
119 | $config->setFeedToken('SUPERTOKEN'); | ||
120 | $config->setFeedLimit(1); | ||
121 | $em->persist($config); | ||
122 | $em->flush(); | ||
123 | |||
124 | $client = $this->getClient(); | ||
125 | $client->request('GET', '/feed/admin/SUPERTOKEN/starred'); | ||
126 | |||
127 | $this->assertSame(200, $client->getResponse()->getStatusCode(), 1); | ||
128 | |||
129 | $this->validateDom($client->getResponse()->getContent(), 'starred'); | ||
130 | } | ||
131 | |||
132 | public function testArchives() | ||
133 | { | ||
134 | $client = $this->getClient(); | ||
135 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
136 | $user = $em | ||
137 | ->getRepository('WallabagUserBundle:User') | ||
138 | ->findOneByUsername('admin'); | ||
139 | |||
140 | $config = $user->getConfig(); | ||
141 | $config->setFeedToken('SUPERTOKEN'); | ||
142 | $config->setFeedLimit(null); | ||
143 | $em->persist($config); | ||
144 | $em->flush(); | ||
145 | |||
146 | $client = $this->getClient(); | ||
147 | $client->request('GET', '/feed/admin/SUPERTOKEN/archive'); | ||
148 | |||
149 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | ||
150 | |||
151 | $this->validateDom($client->getResponse()->getContent(), 'archive'); | ||
152 | } | ||
153 | |||
154 | public function testAll() | ||
155 | { | ||
156 | $client = $this->getClient(); | ||
157 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
158 | $user = $em | ||
159 | ->getRepository('WallabagUserBundle:User') | ||
160 | ->findOneByUsername('admin'); | ||
161 | |||
162 | $config = $user->getConfig(); | ||
163 | $config->setFeedToken('SUPERTOKEN'); | ||
164 | $config->setFeedLimit(null); | ||
165 | $em->persist($config); | ||
166 | $em->flush(); | ||
167 | |||
168 | $client = $this->getClient(); | ||
169 | $client->request('GET', '/feed/admin/SUPERTOKEN/all'); | ||
170 | |||
171 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | ||
172 | |||
173 | $this->validateDom($client->getResponse()->getContent(), 'all'); | ||
174 | } | ||
175 | |||
176 | public function testPagination() | ||
177 | { | ||
178 | $client = $this->getClient(); | ||
179 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
180 | $user = $em | ||
181 | ->getRepository('WallabagUserBundle:User') | ||
182 | ->findOneByUsername('admin'); | ||
183 | |||
184 | $config = $user->getConfig(); | ||
185 | $config->setFeedToken('SUPERTOKEN'); | ||
186 | $config->setFeedLimit(1); | ||
187 | $em->persist($config); | ||
188 | $em->flush(); | ||
189 | |||
190 | $client = $this->getClient(); | ||
191 | |||
192 | $client->request('GET', '/feed/admin/SUPERTOKEN/unread'); | ||
193 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | ||
194 | $this->validateDom($client->getResponse()->getContent(), 'unread'); | ||
195 | |||
196 | $client->request('GET', '/feed/admin/SUPERTOKEN/unread/2'); | ||
197 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | ||
198 | $this->validateDom($client->getResponse()->getContent(), 'unread'); | ||
199 | |||
200 | $client->request('GET', '/feed/admin/SUPERTOKEN/unread/3000'); | ||
201 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | ||
202 | } | ||
203 | |||
204 | public function testTags() | ||
205 | { | ||
206 | $client = $this->getClient(); | ||
207 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
208 | $user = $em | ||
209 | ->getRepository('WallabagUserBundle:User') | ||
210 | ->findOneByUsername('admin'); | ||
211 | |||
212 | $config = $user->getConfig(); | ||
213 | $config->setFeedToken('SUPERTOKEN'); | ||
214 | $config->setFeedLimit(null); | ||
215 | $em->persist($config); | ||
216 | $em->flush(); | ||
217 | |||
218 | $client = $this->getClient(); | ||
219 | $client->request('GET', '/feed/admin/SUPERTOKEN/tags/foo'); | ||
220 | |||
221 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | ||
222 | |||
223 | $this->validateDom($client->getResponse()->getContent(), 'tag', 2, 'foo'); | ||
224 | |||
225 | $client->request('GET', '/feed/admin/SUPERTOKEN/tags/foo/3000'); | ||
226 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | ||
227 | } | ||
228 | |||
229 | public function dataForRedirect() | ||
230 | { | ||
231 | return [ | ||
232 | [ | ||
233 | '/admin/YZIOAUZIAO/unread.xml', | ||
234 | ], | ||
235 | [ | ||
236 | '/admin/YZIOAUZIAO/starred.xml', | ||
237 | ], | ||
238 | [ | ||
239 | '/admin/YZIOAUZIAO/archive.xml', | ||
240 | ], | ||
241 | [ | ||
242 | '/admin/YZIOAUZIAO/all.xml', | ||
243 | ], | ||
244 | [ | ||
245 | '/admin/YZIOAUZIAO/tags/foo.xml', | ||
246 | ], | ||
247 | ]; | ||
248 | } | ||
249 | |||
250 | /** | ||
251 | * @dataProvider dataForRedirect | ||
252 | */ | ||
253 | public function testRedirectFromRssToAtom($url) | ||
254 | { | ||
255 | $client = $this->getClient(); | ||
256 | |||
257 | $client->request('GET', $url); | ||
258 | |||
259 | $this->assertSame(301, $client->getResponse()->getStatusCode()); | ||
260 | } | ||
261 | } | ||
diff --git a/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php b/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php deleted file mode 100644 index 2af6e14f..00000000 --- a/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php +++ /dev/null | |||
@@ -1,221 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Tests\Wallabag\CoreBundle\Controller; | ||
4 | |||
5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | ||
6 | |||
7 | class RssControllerTest extends WallabagCoreTestCase | ||
8 | { | ||
9 | public function validateDom($xml, $type, $urlPagination, $nb = null) | ||
10 | { | ||
11 | $doc = new \DOMDocument(); | ||
12 | $doc->loadXML($xml); | ||
13 | |||
14 | $xpath = new \DOMXpath($doc); | ||
15 | |||
16 | if (null === $nb) { | ||
17 | $this->assertGreaterThan(0, $xpath->query('//item')->length); | ||
18 | } else { | ||
19 | $this->assertSame($nb, $xpath->query('//item')->length); | ||
20 | } | ||
21 | |||
22 | $this->assertSame(1, $xpath->query('/rss')->length); | ||
23 | $this->assertSame(1, $xpath->query('/rss/channel')->length); | ||
24 | |||
25 | $this->assertSame(1, $xpath->query('/rss/channel/title')->length); | ||
26 | $this->assertSame('wallabag - ' . $type . ' feed', $xpath->query('/rss/channel/title')->item(0)->nodeValue); | ||
27 | |||
28 | $this->assertSame(1, $xpath->query('/rss/channel/pubDate')->length); | ||
29 | |||
30 | $this->assertSame(1, $xpath->query('/rss/channel/generator')->length); | ||
31 | $this->assertSame('wallabag', $xpath->query('/rss/channel/generator')->item(0)->nodeValue); | ||
32 | |||
33 | $this->assertSame(1, $xpath->query('/rss/channel/description')->length); | ||
34 | $this->assertSame('wallabag ' . $type . ' elements', $xpath->query('/rss/channel/description')->item(0)->nodeValue); | ||
35 | |||
36 | $this->assertSame(1, $xpath->query('/rss/channel/link[@rel="self"]')->length); | ||
37 | $this->assertContains($urlPagination . '.xml', $xpath->query('/rss/channel/link[@rel="self"]')->item(0)->getAttribute('href')); | ||
38 | |||
39 | $this->assertSame(1, $xpath->query('/rss/channel/link[@rel="last"]')->length); | ||
40 | $this->assertContains($urlPagination . '.xml?page=', $xpath->query('/rss/channel/link[@rel="last"]')->item(0)->getAttribute('href')); | ||
41 | |||
42 | foreach ($xpath->query('//item') as $item) { | ||
43 | $this->assertSame(1, $xpath->query('title', $item)->length); | ||
44 | $this->assertSame(1, $xpath->query('source', $item)->length); | ||
45 | $this->assertSame(1, $xpath->query('link', $item)->length); | ||
46 | $this->assertSame(1, $xpath->query('guid', $item)->length); | ||
47 | $this->assertSame(1, $xpath->query('pubDate', $item)->length); | ||
48 | $this->assertSame(1, $xpath->query('description', $item)->length); | ||
49 | } | ||
50 | } | ||
51 | |||
52 | public function dataForBadUrl() | ||
53 | { | ||
54 | return [ | ||
55 | [ | ||
56 | '/admin/YZIOAUZIAO/unread.xml', | ||
57 | ], | ||
58 | [ | ||
59 | '/wallace/YZIOAUZIAO/starred.xml', | ||
60 | ], | ||
61 | [ | ||
62 | '/wallace/YZIOAUZIAO/archives.xml', | ||
63 | ], | ||
64 | [ | ||
65 | '/wallace/YZIOAUZIAO/all.xml', | ||
66 | ], | ||
67 | ]; | ||
68 | } | ||
69 | |||
70 | /** | ||
71 | * @dataProvider dataForBadUrl | ||
72 | */ | ||
73 | public function testBadUrl($url) | ||
74 | { | ||
75 | $client = $this->getClient(); | ||
76 | |||
77 | $client->request('GET', $url); | ||
78 | |||
79 | $this->assertSame(404, $client->getResponse()->getStatusCode()); | ||
80 | } | ||
81 | |||
82 | public function testUnread() | ||
83 | { | ||
84 | $client = $this->getClient(); | ||
85 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
86 | $user = $em | ||
87 | ->getRepository('WallabagUserBundle:User') | ||
88 | ->findOneByUsername('admin'); | ||
89 | |||
90 | $config = $user->getConfig(); | ||
91 | $config->setRssToken('SUPERTOKEN'); | ||
92 | $config->setRssLimit(2); | ||
93 | $em->persist($config); | ||
94 | $em->flush(); | ||
95 | |||
96 | $client->request('GET', '/admin/SUPERTOKEN/unread.xml'); | ||
97 | |||
98 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | ||
99 | |||
100 | $this->validateDom($client->getResponse()->getContent(), 'unread', 'unread', 2); | ||
101 | } | ||
102 | |||
103 | public function testStarred() | ||
104 | { | ||
105 | $client = $this->getClient(); | ||
106 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
107 | $user = $em | ||
108 | ->getRepository('WallabagUserBundle:User') | ||
109 | ->findOneByUsername('admin'); | ||
110 | |||
111 | $config = $user->getConfig(); | ||
112 | $config->setRssToken('SUPERTOKEN'); | ||
113 | $config->setRssLimit(1); | ||
114 | $em->persist($config); | ||
115 | $em->flush(); | ||
116 | |||
117 | $client = $this->getClient(); | ||
118 | $client->request('GET', '/admin/SUPERTOKEN/starred.xml'); | ||
119 | |||
120 | $this->assertSame(200, $client->getResponse()->getStatusCode(), 1); | ||
121 | |||
122 | $this->validateDom($client->getResponse()->getContent(), 'starred', 'starred'); | ||
123 | } | ||
124 | |||
125 | public function testArchives() | ||
126 | { | ||
127 | $client = $this->getClient(); | ||
128 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
129 | $user = $em | ||
130 | ->getRepository('WallabagUserBundle:User') | ||
131 | ->findOneByUsername('admin'); | ||
132 | |||
133 | $config = $user->getConfig(); | ||
134 | $config->setRssToken('SUPERTOKEN'); | ||
135 | $config->setRssLimit(null); | ||
136 | $em->persist($config); | ||
137 | $em->flush(); | ||
138 | |||
139 | $client = $this->getClient(); | ||
140 | $client->request('GET', '/admin/SUPERTOKEN/archive.xml'); | ||
141 | |||
142 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | ||
143 | |||
144 | $this->validateDom($client->getResponse()->getContent(), 'archive', 'archive'); | ||
145 | } | ||
146 | |||
147 | public function testAll() | ||
148 | { | ||
149 | $client = $this->getClient(); | ||
150 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
151 | $user = $em | ||
152 | ->getRepository('WallabagUserBundle:User') | ||
153 | ->findOneByUsername('admin'); | ||
154 | |||
155 | $config = $user->getConfig(); | ||
156 | $config->setRssToken('SUPERTOKEN'); | ||
157 | $config->setRssLimit(null); | ||
158 | $em->persist($config); | ||
159 | $em->flush(); | ||
160 | |||
161 | $client = $this->getClient(); | ||
162 | $client->request('GET', '/admin/SUPERTOKEN/all.xml'); | ||
163 | |||
164 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | ||
165 | |||
166 | $this->validateDom($client->getResponse()->getContent(), 'all', 'all'); | ||
167 | } | ||
168 | |||
169 | public function testPagination() | ||
170 | { | ||
171 | $client = $this->getClient(); | ||
172 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
173 | $user = $em | ||
174 | ->getRepository('WallabagUserBundle:User') | ||
175 | ->findOneByUsername('admin'); | ||
176 | |||
177 | $config = $user->getConfig(); | ||
178 | $config->setRssToken('SUPERTOKEN'); | ||
179 | $config->setRssLimit(1); | ||
180 | $em->persist($config); | ||
181 | $em->flush(); | ||
182 | |||
183 | $client = $this->getClient(); | ||
184 | |||
185 | $client->request('GET', '/admin/SUPERTOKEN/unread.xml'); | ||
186 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | ||
187 | $this->validateDom($client->getResponse()->getContent(), 'unread', 'unread'); | ||
188 | |||
189 | $client->request('GET', '/admin/SUPERTOKEN/unread.xml?page=2'); | ||
190 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | ||
191 | $this->validateDom($client->getResponse()->getContent(), 'unread', 'unread'); | ||
192 | |||
193 | $client->request('GET', '/admin/SUPERTOKEN/unread.xml?page=3000'); | ||
194 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | ||
195 | } | ||
196 | |||
197 | public function testTags() | ||
198 | { | ||
199 | $client = $this->getClient(); | ||
200 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
201 | $user = $em | ||
202 | ->getRepository('WallabagUserBundle:User') | ||
203 | ->findOneByUsername('admin'); | ||
204 | |||
205 | $config = $user->getConfig(); | ||
206 | $config->setRssToken('SUPERTOKEN'); | ||
207 | $config->setRssLimit(null); | ||
208 | $em->persist($config); | ||
209 | $em->flush(); | ||
210 | |||
211 | $client = $this->getClient(); | ||
212 | $client->request('GET', '/admin/SUPERTOKEN/tags/foo.xml'); | ||
213 | |||
214 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | ||
215 | |||
216 | $this->validateDom($client->getResponse()->getContent(), 'tag (foo)', 'tags/foo'); | ||
217 | |||
218 | $client->request('GET', '/admin/SUPERTOKEN/tags/foo.xml?page=3000'); | ||
219 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | ||
220 | } | ||
221 | } | ||
diff --git a/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php b/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php index 395208a2..6b51f403 100644 --- a/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php | |||
@@ -13,7 +13,7 @@ class SecurityControllerTest extends WallabagCoreTestCase | |||
13 | $client->followRedirects(); | 13 | $client->followRedirects(); |
14 | 14 | ||
15 | $crawler = $client->request('GET', '/config'); | 15 | $crawler = $client->request('GET', '/config'); |
16 | $this->assertContains('config.form_rss.description', $crawler->filter('body')->extract(['_text'])[0]); | 16 | $this->assertContains('config.form_feed.description', $crawler->filter('body')->extract(['_text'])[0]); |
17 | } | 17 | } |
18 | 18 | ||
19 | public function testLoginWithout2Factor() | 19 | public function testLoginWithout2Factor() |
@@ -23,10 +23,10 @@ class SecurityControllerTest extends WallabagCoreTestCase | |||
23 | $client->followRedirects(); | 23 | $client->followRedirects(); |
24 | 24 | ||
25 | $crawler = $client->request('GET', '/config'); | 25 | $crawler = $client->request('GET', '/config'); |
26 | $this->assertContains('config.form_rss.description', $crawler->filter('body')->extract(['_text'])[0]); | 26 | $this->assertContains('config.form_feed.description', $crawler->filter('body')->extract(['_text'])[0]); |
27 | } | 27 | } |
28 | 28 | ||
29 | public function testLoginWith2Factor() | 29 | public function testLoginWith2FactorEmail() |
30 | { | 30 | { |
31 | $client = $this->getClient(); | 31 | $client = $this->getClient(); |
32 | 32 | ||
@@ -42,24 +42,24 @@ class SecurityControllerTest extends WallabagCoreTestCase | |||
42 | $user = $em | 42 | $user = $em |
43 | ->getRepository('WallabagUserBundle:User') | 43 | ->getRepository('WallabagUserBundle:User') |
44 | ->findOneByUsername('admin'); | 44 | ->findOneByUsername('admin'); |
45 | $user->setTwoFactorAuthentication(true); | 45 | $user->setEmailTwoFactor(true); |
46 | $em->persist($user); | 46 | $em->persist($user); |
47 | $em->flush(); | 47 | $em->flush(); |
48 | 48 | ||
49 | $this->logInAsUsingHttp('admin'); | 49 | $this->logInAsUsingHttp('admin'); |
50 | $crawler = $client->request('GET', '/config'); | 50 | $crawler = $client->request('GET', '/config'); |
51 | $this->assertContains('scheb_two_factor.trusted', $crawler->filter('body')->extract(['_text'])[0]); | 51 | $this->assertContains('trusted', $crawler->filter('body')->extract(['_text'])[0]); |
52 | 52 | ||
53 | // restore user | 53 | // restore user |
54 | $user = $em | 54 | $user = $em |
55 | ->getRepository('WallabagUserBundle:User') | 55 | ->getRepository('WallabagUserBundle:User') |
56 | ->findOneByUsername('admin'); | 56 | ->findOneByUsername('admin'); |
57 | $user->setTwoFactorAuthentication(false); | 57 | $user->setEmailTwoFactor(false); |
58 | $em->persist($user); | 58 | $em->persist($user); |
59 | $em->flush(); | 59 | $em->flush(); |
60 | } | 60 | } |
61 | 61 | ||
62 | public function testTrustedComputer() | 62 | public function testLoginWith2FactorGoogle() |
63 | { | 63 | { |
64 | $client = $this->getClient(); | 64 | $client = $this->getClient(); |
65 | 65 | ||
@@ -69,15 +69,27 @@ class SecurityControllerTest extends WallabagCoreTestCase | |||
69 | return; | 69 | return; |
70 | } | 70 | } |
71 | 71 | ||
72 | $client->followRedirects(); | ||
73 | |||
72 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | 74 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); |
73 | $user = $em | 75 | $user = $em |
74 | ->getRepository('WallabagUserBundle:User') | 76 | ->getRepository('WallabagUserBundle:User') |
75 | ->findOneByUsername('admin'); | 77 | ->findOneByUsername('admin'); |
78 | $user->setGoogleAuthenticatorSecret('26LDIHYGHNELOQEM'); | ||
79 | $em->persist($user); | ||
80 | $em->flush(); | ||
81 | |||
82 | $this->logInAsUsingHttp('admin'); | ||
83 | $crawler = $client->request('GET', '/config'); | ||
84 | $this->assertContains('trusted', $crawler->filter('body')->extract(['_text'])[0]); | ||
76 | 85 | ||
77 | $date = new \DateTime(); | 86 | // restore user |
78 | $user->addTrustedComputer('ABCDEF', $date->add(new \DateInterval('P1M'))); | 87 | $user = $em |
79 | $this->assertTrue($user->isTrustedComputer('ABCDEF')); | 88 | ->getRepository('WallabagUserBundle:User') |
80 | $this->assertFalse($user->isTrustedComputer('FEDCBA')); | 89 | ->findOneByUsername('admin'); |
90 | $user->setGoogleAuthenticatorSecret(null); | ||
91 | $em->persist($user); | ||
92 | $em->flush(); | ||
81 | } | 93 | } |
82 | 94 | ||
83 | public function testEnabledRegistration() | 95 | public function testEnabledRegistration() |
diff --git a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php index 768f4c07..47c83a7b 100644 --- a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php | |||
@@ -176,4 +176,95 @@ class TagControllerTest extends WallabagCoreTestCase | |||
176 | $em->remove($tag); | 176 | $em->remove($tag); |
177 | $em->flush(); | 177 | $em->flush(); |
178 | } | 178 | } |
179 | |||
180 | public function testRenameTagUsingTheFormInsideTagList() | ||
181 | { | ||
182 | $this->logInAs('admin'); | ||
183 | $client = $this->getClient(); | ||
184 | |||
185 | $tag = new Tag(); | ||
186 | $tag->setLabel($this->tagName); | ||
187 | $entry = new Entry($this->getLoggedInUser()); | ||
188 | $entry->setUrl('http://0.0.0.0/foo'); | ||
189 | $entry->addTag($tag); | ||
190 | $this->getEntityManager()->persist($entry); | ||
191 | $this->getEntityManager()->flush(); | ||
192 | $this->getEntityManager()->clear(); | ||
193 | |||
194 | // We make a first request to set an history and test redirection after tag deletion | ||
195 | $crawler = $client->request('GET', '/tag/list'); | ||
196 | $form = $crawler->filter('#tag-' . $tag->getId() . ' form')->form(); | ||
197 | |||
198 | $data = [ | ||
199 | 'tag[label]' => 'specific label', | ||
200 | ]; | ||
201 | |||
202 | $client->submit($form, $data); | ||
203 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | ||
204 | |||
205 | $freshEntry = $client->getContainer() | ||
206 | ->get('doctrine.orm.entity_manager') | ||
207 | ->getRepository('WallabagCoreBundle:Entry') | ||
208 | ->find($entry->getId()); | ||
209 | |||
210 | $tags = $freshEntry->getTags()->toArray(); | ||
211 | foreach ($tags as $key => $item) { | ||
212 | $tags[$key] = $item->getLabel(); | ||
213 | } | ||
214 | |||
215 | $this->assertFalse(array_search($tag->getLabel(), $tags, true), 'Previous tag is not attach to entry anymore.'); | ||
216 | |||
217 | $newTag = $client->getContainer() | ||
218 | ->get('doctrine.orm.entity_manager') | ||
219 | ->getRepository('WallabagCoreBundle:Tag') | ||
220 | ->findOneByLabel('specific label'); | ||
221 | $this->assertInstanceOf(Tag::class, $newTag, 'Tag "specific label" exists.'); | ||
222 | $this->assertTrue($newTag->hasEntry($freshEntry), 'Tag "specific label" is assigned to the entry.'); | ||
223 | } | ||
224 | |||
225 | public function testAddUnicodeTagLabel() | ||
226 | { | ||
227 | $this->logInAs('admin'); | ||
228 | $client = $this->getClient(); | ||
229 | |||
230 | $entry = new Entry($this->getLoggedInUser()); | ||
231 | $entry->setUrl('http://0.0.0.0/tag-caché'); | ||
232 | $this->getEntityManager()->persist($entry); | ||
233 | $this->getEntityManager()->flush(); | ||
234 | $this->getEntityManager()->clear(); | ||
235 | |||
236 | $crawler = $client->request('GET', '/view/' . $entry->getId()); | ||
237 | |||
238 | $form = $crawler->filter('form[name=tag]')->form(); | ||
239 | |||
240 | $data = [ | ||
241 | 'tag[label]' => 'cache', | ||
242 | ]; | ||
243 | |||
244 | $client->submit($form, $data); | ||
245 | |||
246 | $crawler = $client->request('GET', '/view/' . $entry->getId()); | ||
247 | |||
248 | $form = $crawler->filter('form[name=tag]')->form(); | ||
249 | |||
250 | $data = [ | ||
251 | 'tag[label]' => 'caché', | ||
252 | ]; | ||
253 | |||
254 | $client->submit($form, $data); | ||
255 | |||
256 | $newEntry = $client->getContainer() | ||
257 | ->get('doctrine.orm.entity_manager') | ||
258 | ->getRepository('WallabagCoreBundle:Entry') | ||
259 | ->find($entry->getId()); | ||
260 | |||
261 | $tags = $newEntry->getTags()->toArray(); | ||
262 | foreach ($tags as $key => $tag) { | ||
263 | $tags[$key] = $tag->getLabel(); | ||
264 | } | ||
265 | |||
266 | $this->assertGreaterThanOrEqual(2, \count($tags)); | ||
267 | $this->assertNotFalse(array_search('cache', $tags, true), 'Tag cache is assigned to the entry'); | ||
268 | $this->assertNotFalse(array_search('caché', $tags, true), 'Tag caché is assigned to the entry'); | ||
269 | } | ||
179 | } | 270 | } |
diff --git a/tests/Wallabag/CoreBundle/Entity/EntryTest.php b/tests/Wallabag/CoreBundle/Entity/EntryTest.php new file mode 100644 index 00000000..d400636e --- /dev/null +++ b/tests/Wallabag/CoreBundle/Entity/EntryTest.php | |||
@@ -0,0 +1,28 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Tests\Wallabag\CoreBundle\Entity; | ||
4 | |||
5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | ||
6 | use Wallabag\CoreBundle\Entity\Entry; | ||
7 | |||
8 | class EntryTest extends WallabagCoreTestCase | ||
9 | { | ||
10 | public function testGetLanguage() | ||
11 | { | ||
12 | $this->logInAs('admin'); | ||
13 | $entry = new Entry($this->getLoggedInUser()); | ||
14 | $languages = [ | ||
15 | 'en_GB' => 'en-GB', | ||
16 | 'en_US' => 'en-US', | ||
17 | 'en-gb' => 'en-GB', | ||
18 | 'en-US' => 'en-US', | ||
19 | 'fr' => 'fr', | ||
20 | 'fr_FR' => 'fr-FR', | ||
21 | 'ja' => 'ja', | ||
22 | ]; | ||
23 | foreach ($languages as $entryLang => $lang) { | ||
24 | $entry->setLanguage($entryLang); | ||
25 | $this->assertSame($lang, $entry->getHTMLLanguage()); | ||
26 | } | ||
27 | } | ||
28 | } | ||
diff --git a/tests/Wallabag/CoreBundle/Event/Listener/UserLocaleListenerTest.php b/tests/Wallabag/CoreBundle/Event/Listener/UserLocaleListenerTest.php index 93edfde8..ff0a9602 100644 --- a/tests/Wallabag/CoreBundle/Event/Listener/UserLocaleListenerTest.php +++ b/tests/Wallabag/CoreBundle/Event/Listener/UserLocaleListenerTest.php | |||
@@ -56,4 +56,27 @@ class UserLocaleListenerTest extends TestCase | |||
56 | 56 | ||
57 | $this->assertNull($session->get('_locale')); | 57 | $this->assertNull($session->get('_locale')); |
58 | } | 58 | } |
59 | |||
60 | public function testWithLanguageFromSession() | ||
61 | { | ||
62 | $session = new Session(new MockArraySessionStorage()); | ||
63 | $listener = new UserLocaleListener($session); | ||
64 | $session->set('_locale', 'de'); | ||
65 | |||
66 | $user = new User(); | ||
67 | $user->setEnabled(true); | ||
68 | |||
69 | $config = new Config($user); | ||
70 | $config->setLanguage('fr'); | ||
71 | |||
72 | $user->setConfig($config); | ||
73 | |||
74 | $userToken = new UsernamePasswordToken($user, '', 'test'); | ||
75 | $request = Request::create('/'); | ||
76 | $event = new InteractiveLoginEvent($request, $userToken); | ||
77 | |||
78 | $listener->onInteractiveLogin($event); | ||
79 | |||
80 | $this->assertSame('de', $session->get('_locale')); | ||
81 | } | ||
59 | } | 82 | } |
diff --git a/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php b/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php index 1173fc3d..9e0a9136 100644 --- a/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php +++ b/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php | |||
@@ -5,26 +5,24 @@ namespace Tests\Wallabag\CoreBundle\GuzzleSiteAuthenticator; | |||
5 | use Graby\SiteConfig\SiteConfig as GrabySiteConfig; | 5 | use Graby\SiteConfig\SiteConfig as GrabySiteConfig; |
6 | use Monolog\Handler\TestHandler; | 6 | use Monolog\Handler\TestHandler; |
7 | use Monolog\Logger; | 7 | use Monolog\Logger; |
8 | use PHPUnit\Framework\TestCase; | ||
9 | use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; | 8 | use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; |
10 | use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; | 9 | use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; |
10 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | ||
11 | use Wallabag\CoreBundle\GuzzleSiteAuthenticator\GrabySiteConfigBuilder; | 11 | use Wallabag\CoreBundle\GuzzleSiteAuthenticator\GrabySiteConfigBuilder; |
12 | 12 | ||
13 | class GrabySiteConfigBuilderTest extends TestCase | 13 | class GrabySiteConfigBuilderTest extends WallabagCoreTestCase |
14 | { | 14 | { |
15 | /** @var \Wallabag\CoreBundle\GuzzleSiteAuthenticator\GrabySiteConfigBuilder */ | 15 | private $builder; |
16 | protected $builder; | ||
17 | 16 | ||
18 | public function testBuildConfigExists() | 17 | public function testBuildConfigExists() |
19 | { | 18 | { |
20 | /* @var \Graby\SiteConfig\ConfigBuilder|\PHPUnit_Framework_MockObject_MockObject */ | ||
21 | $grabyConfigBuilderMock = $this->getMockBuilder('Graby\SiteConfig\ConfigBuilder') | 19 | $grabyConfigBuilderMock = $this->getMockBuilder('Graby\SiteConfig\ConfigBuilder') |
22 | ->disableOriginalConstructor() | 20 | ->disableOriginalConstructor() |
23 | ->getMock(); | 21 | ->getMock(); |
24 | 22 | ||
25 | $grabySiteConfig = new GrabySiteConfig(); | 23 | $grabySiteConfig = new GrabySiteConfig(); |
26 | $grabySiteConfig->requires_login = true; | 24 | $grabySiteConfig->requires_login = true; |
27 | $grabySiteConfig->login_uri = 'http://www.example.com/login'; | 25 | $grabySiteConfig->login_uri = 'http://api.example.com/login'; |
28 | $grabySiteConfig->login_username_field = 'login'; | 26 | $grabySiteConfig->login_username_field = 'login'; |
29 | $grabySiteConfig->login_password_field = 'password'; | 27 | $grabySiteConfig->login_password_field = 'password'; |
30 | $grabySiteConfig->login_extra_fields = ['field=value']; | 28 | $grabySiteConfig->login_extra_fields = ['field=value']; |
@@ -32,8 +30,8 @@ class GrabySiteConfigBuilderTest extends TestCase | |||
32 | 30 | ||
33 | $grabyConfigBuilderMock | 31 | $grabyConfigBuilderMock |
34 | ->method('buildForHost') | 32 | ->method('buildForHost') |
35 | ->with('example.com') | 33 | ->with('api.example.com') |
36 | ->will($this->returnValue($grabySiteConfig)); | 34 | ->willReturn($grabySiteConfig); |
37 | 35 | ||
38 | $logger = new Logger('foo'); | 36 | $logger = new Logger('foo'); |
39 | $handler = new TestHandler(); | 37 | $handler = new TestHandler(); |
@@ -43,8 +41,8 @@ class GrabySiteConfigBuilderTest extends TestCase | |||
43 | ->disableOriginalConstructor() | 41 | ->disableOriginalConstructor() |
44 | ->getMock(); | 42 | ->getMock(); |
45 | $siteCrentialRepo->expects($this->once()) | 43 | $siteCrentialRepo->expects($this->once()) |
46 | ->method('findOneByHostAndUser') | 44 | ->method('findOneByHostsAndUser') |
47 | ->with('example.com', 1) | 45 | ->with(['api.example.com', '.example.com'], 1) |
48 | ->willReturn(['username' => 'foo', 'password' => 'bar']); | 46 | ->willReturn(['username' => 'foo', 'password' => 'bar']); |
49 | 47 | ||
50 | $user = $this->getMockBuilder('Wallabag\UserBundle\Entity\User') | 48 | $user = $this->getMockBuilder('Wallabag\UserBundle\Entity\User') |
@@ -59,18 +57,18 @@ class GrabySiteConfigBuilderTest extends TestCase | |||
59 | $tokenStorage = new TokenStorage(); | 57 | $tokenStorage = new TokenStorage(); |
60 | $tokenStorage->setToken($token); | 58 | $tokenStorage->setToken($token); |
61 | 59 | ||
62 | $this->builder = new GrabySiteConfigBuilder( | 60 | $builder = new GrabySiteConfigBuilder( |
63 | $grabyConfigBuilderMock, | 61 | $grabyConfigBuilderMock, |
64 | $tokenStorage, | 62 | $tokenStorage, |
65 | $siteCrentialRepo, | 63 | $siteCrentialRepo, |
66 | $logger | 64 | $logger |
67 | ); | 65 | ); |
68 | 66 | ||
69 | $config = $this->builder->buildForHost('www.example.com'); | 67 | $config = $builder->buildForHost('api.example.com'); |
70 | 68 | ||
71 | $this->assertSame('example.com', $config->getHost()); | 69 | $this->assertSame('api.example.com', $config->getHost()); |
72 | $this->assertTrue($config->requiresLogin()); | 70 | $this->assertTrue($config->requiresLogin()); |
73 | $this->assertSame('http://www.example.com/login', $config->getLoginUri()); | 71 | $this->assertSame('http://api.example.com/login', $config->getLoginUri()); |
74 | $this->assertSame('login', $config->getUsernameField()); | 72 | $this->assertSame('login', $config->getUsernameField()); |
75 | $this->assertSame('password', $config->getPasswordField()); | 73 | $this->assertSame('password', $config->getPasswordField()); |
76 | $this->assertSame(['field' => 'value'], $config->getExtraFields()); | 74 | $this->assertSame(['field' => 'value'], $config->getExtraFields()); |
@@ -85,7 +83,6 @@ class GrabySiteConfigBuilderTest extends TestCase | |||
85 | 83 | ||
86 | public function testBuildConfigDoesntExist() | 84 | public function testBuildConfigDoesntExist() |
87 | { | 85 | { |
88 | /* @var \Graby\SiteConfig\ConfigBuilder|\PHPUnit_Framework_MockObject_MockObject */ | ||
89 | $grabyConfigBuilderMock = $this->getMockBuilder('\Graby\SiteConfig\ConfigBuilder') | 86 | $grabyConfigBuilderMock = $this->getMockBuilder('\Graby\SiteConfig\ConfigBuilder') |
90 | ->disableOriginalConstructor() | 87 | ->disableOriginalConstructor() |
91 | ->getMock(); | 88 | ->getMock(); |
@@ -93,7 +90,7 @@ class GrabySiteConfigBuilderTest extends TestCase | |||
93 | $grabyConfigBuilderMock | 90 | $grabyConfigBuilderMock |
94 | ->method('buildForHost') | 91 | ->method('buildForHost') |
95 | ->with('unknown.com') | 92 | ->with('unknown.com') |
96 | ->will($this->returnValue(new GrabySiteConfig())); | 93 | ->willReturn(new GrabySiteConfig()); |
97 | 94 | ||
98 | $logger = new Logger('foo'); | 95 | $logger = new Logger('foo'); |
99 | $handler = new TestHandler(); | 96 | $handler = new TestHandler(); |
@@ -103,8 +100,8 @@ class GrabySiteConfigBuilderTest extends TestCase | |||
103 | ->disableOriginalConstructor() | 100 | ->disableOriginalConstructor() |
104 | ->getMock(); | 101 | ->getMock(); |
105 | $siteCrentialRepo->expects($this->once()) | 102 | $siteCrentialRepo->expects($this->once()) |
106 | ->method('findOneByHostAndUser') | 103 | ->method('findOneByHostsAndUser') |
107 | ->with('unknown.com', 1) | 104 | ->with(['unknown.com', '.com'], 1) |
108 | ->willReturn(null); | 105 | ->willReturn(null); |
109 | 106 | ||
110 | $user = $this->getMockBuilder('Wallabag\UserBundle\Entity\User') | 107 | $user = $this->getMockBuilder('Wallabag\UserBundle\Entity\User') |
@@ -119,14 +116,14 @@ class GrabySiteConfigBuilderTest extends TestCase | |||
119 | $tokenStorage = new TokenStorage(); | 116 | $tokenStorage = new TokenStorage(); |
120 | $tokenStorage->setToken($token); | 117 | $tokenStorage->setToken($token); |
121 | 118 | ||
122 | $this->builder = new GrabySiteConfigBuilder( | 119 | $builder = new GrabySiteConfigBuilder( |
123 | $grabyConfigBuilderMock, | 120 | $grabyConfigBuilderMock, |
124 | $tokenStorage, | 121 | $tokenStorage, |
125 | $siteCrentialRepo, | 122 | $siteCrentialRepo, |
126 | $logger | 123 | $logger |
127 | ); | 124 | ); |
128 | 125 | ||
129 | $config = $this->builder->buildForHost('unknown.com'); | 126 | $config = $builder->buildForHost('unknown.com'); |
130 | 127 | ||
131 | $this->assertFalse($config); | 128 | $this->assertFalse($config); |
132 | 129 | ||
@@ -134,4 +131,188 @@ class GrabySiteConfigBuilderTest extends TestCase | |||
134 | 131 | ||
135 | $this->assertCount(1, $records, 'One log was recorded'); | 132 | $this->assertCount(1, $records, 'One log was recorded'); |
136 | } | 133 | } |
134 | |||
135 | public function testBuildConfigWithBadExtraFields() | ||
136 | { | ||
137 | $grabyConfigBuilderMock = $this->getMockBuilder('Graby\SiteConfig\ConfigBuilder') | ||
138 | ->disableOriginalConstructor() | ||
139 | ->getMock(); | ||
140 | |||
141 | $grabySiteConfig = new GrabySiteConfig(); | ||
142 | $grabySiteConfig->requires_login = true; | ||
143 | $grabySiteConfig->login_uri = 'http://www.example.com/login'; | ||
144 | $grabySiteConfig->login_username_field = 'login'; | ||
145 | $grabySiteConfig->login_password_field = 'password'; | ||
146 | $grabySiteConfig->login_extra_fields = ['field']; | ||
147 | $grabySiteConfig->not_logged_in_xpath = '//div[@class="need-login"]'; | ||
148 | |||
149 | $grabyConfigBuilderMock | ||
150 | ->method('buildForHost') | ||
151 | ->with('example.com') | ||
152 | ->willReturn($grabySiteConfig); | ||
153 | |||
154 | $logger = new Logger('foo'); | ||
155 | $handler = new TestHandler(); | ||
156 | $logger->pushHandler($handler); | ||
157 | |||
158 | $siteCrentialRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\SiteCredentialRepository') | ||
159 | ->disableOriginalConstructor() | ||
160 | ->getMock(); | ||
161 | $siteCrentialRepo->expects($this->once()) | ||
162 | ->method('findOneByHostsAndUser') | ||
163 | ->with(['example.com', '.com'], 1) | ||
164 | ->willReturn(['username' => 'foo', 'password' => 'bar']); | ||
165 | |||
166 | $user = $this->getMockBuilder('Wallabag\UserBundle\Entity\User') | ||
167 | ->disableOriginalConstructor() | ||
168 | ->getMock(); | ||
169 | $user->expects($this->once()) | ||
170 | ->method('getId') | ||
171 | ->willReturn(1); | ||
172 | |||
173 | $token = new UsernamePasswordToken($user, 'pass', 'provider'); | ||
174 | |||
175 | $tokenStorage = new TokenStorage(); | ||
176 | $tokenStorage->setToken($token); | ||
177 | |||
178 | $this->builder = new GrabySiteConfigBuilder( | ||
179 | $grabyConfigBuilderMock, | ||
180 | $tokenStorage, | ||
181 | $siteCrentialRepo, | ||
182 | $logger | ||
183 | ); | ||
184 | |||
185 | $config = $this->builder->buildForHost('www.example.com'); | ||
186 | |||
187 | $this->assertSame('example.com', $config->getHost()); | ||
188 | $this->assertTrue($config->requiresLogin()); | ||
189 | $this->assertSame('http://www.example.com/login', $config->getLoginUri()); | ||
190 | $this->assertSame('login', $config->getUsernameField()); | ||
191 | $this->assertSame('password', $config->getPasswordField()); | ||
192 | $this->assertSame([], $config->getExtraFields()); | ||
193 | $this->assertSame('//div[@class="need-login"]', $config->getNotLoggedInXpath()); | ||
194 | $this->assertSame('foo', $config->getUsername()); | ||
195 | $this->assertSame('bar', $config->getPassword()); | ||
196 | |||
197 | $records = $handler->getRecords(); | ||
198 | |||
199 | $this->assertCount(1, $records, 'One log was recorded'); | ||
200 | } | ||
201 | |||
202 | public function testBuildConfigUserNotDefined() | ||
203 | { | ||
204 | $grabyConfigBuilderMock = $this->getMockBuilder('\Graby\SiteConfig\ConfigBuilder') | ||
205 | ->disableOriginalConstructor() | ||
206 | ->getMock(); | ||
207 | |||
208 | $grabyConfigBuilderMock | ||
209 | ->method('buildForHost') | ||
210 | ->with('unknown.com') | ||
211 | ->willReturn(new GrabySiteConfig()); | ||
212 | |||
213 | $logger = new Logger('foo'); | ||
214 | $handler = new TestHandler(); | ||
215 | $logger->pushHandler($handler); | ||
216 | |||
217 | $siteCrentialRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\SiteCredentialRepository') | ||
218 | ->disableOriginalConstructor() | ||
219 | ->getMock(); | ||
220 | |||
221 | $tokenStorage = new TokenStorage(); | ||
222 | |||
223 | $builder = new GrabySiteConfigBuilder( | ||
224 | $grabyConfigBuilderMock, | ||
225 | $tokenStorage, | ||
226 | $siteCrentialRepo, | ||
227 | $logger | ||
228 | ); | ||
229 | |||
230 | $config = $builder->buildForHost('unknown.com'); | ||
231 | |||
232 | $this->assertFalse($config); | ||
233 | } | ||
234 | |||
235 | public function dataProviderCredentials() | ||
236 | { | ||
237 | return [ | ||
238 | [ | ||
239 | 'host' => 'example.com', | ||
240 | ], | ||
241 | [ | ||
242 | 'host' => 'other.example.com', | ||
243 | ], | ||
244 | [ | ||
245 | 'host' => 'paywall.example.com', | ||
246 | 'expectedUsername' => 'paywall.example', | ||
247 | 'expectedPassword' => 'bar', | ||
248 | ], | ||
249 | [ | ||
250 | 'host' => 'api.super.com', | ||
251 | 'expectedUsername' => '.super', | ||
252 | 'expectedPassword' => 'bar', | ||
253 | ], | ||
254 | [ | ||
255 | 'host' => '.super.com', | ||
256 | 'expectedUsername' => '.super', | ||
257 | 'expectedPassword' => 'bar', | ||
258 | ], | ||
259 | ]; | ||
260 | } | ||
261 | |||
262 | /** | ||
263 | * @dataProvider dataProviderCredentials | ||
264 | */ | ||
265 | public function testBuildConfigWithDbAccess($host, $expectedUsername = null, $expectedPassword = null) | ||
266 | { | ||
267 | $grabyConfigBuilderMock = $this->getMockBuilder('Graby\SiteConfig\ConfigBuilder') | ||
268 | ->disableOriginalConstructor() | ||
269 | ->getMock(); | ||
270 | |||
271 | $grabySiteConfig = new GrabySiteConfig(); | ||
272 | $grabySiteConfig->requires_login = true; | ||
273 | $grabySiteConfig->login_uri = 'http://api.example.com/login'; | ||
274 | $grabySiteConfig->login_username_field = 'login'; | ||
275 | $grabySiteConfig->login_password_field = 'password'; | ||
276 | $grabySiteConfig->login_extra_fields = ['field=value']; | ||
277 | $grabySiteConfig->not_logged_in_xpath = '//div[@class="need-login"]'; | ||
278 | |||
279 | $grabyConfigBuilderMock | ||
280 | ->method('buildForHost') | ||
281 | ->with($host) | ||
282 | ->willReturn($grabySiteConfig); | ||
283 | |||
284 | $user = $this->getMockBuilder('Wallabag\UserBundle\Entity\User') | ||
285 | ->disableOriginalConstructor() | ||
286 | ->getMock(); | ||
287 | $user->expects($this->once()) | ||
288 | ->method('getId') | ||
289 | ->willReturn(1); | ||
290 | |||
291 | $token = new UsernamePasswordToken($user, 'pass', 'provider'); | ||
292 | |||
293 | $tokenStorage = new TokenStorage(); | ||
294 | $tokenStorage->setToken($token); | ||
295 | |||
296 | $logger = new Logger('foo'); | ||
297 | $handler = new TestHandler(); | ||
298 | $logger->pushHandler($handler); | ||
299 | |||
300 | $builder = new GrabySiteConfigBuilder( | ||
301 | $grabyConfigBuilderMock, | ||
302 | $tokenStorage, | ||
303 | $this->getClient()->getContainer()->get('wallabag_core.site_credential_repository'), | ||
304 | $logger | ||
305 | ); | ||
306 | |||
307 | $config = $builder->buildForHost($host); | ||
308 | |||
309 | if (null === $expectedUsername && null === $expectedPassword) { | ||
310 | $this->assertFalse($config); | ||
311 | |||
312 | return; | ||
313 | } | ||
314 | |||
315 | $this->assertSame($expectedUsername, $config->getUsername()); | ||
316 | $this->assertSame($expectedPassword, $config->getPassword()); | ||
317 | } | ||
137 | } | 318 | } |
diff --git a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php index 3dd9273c..9ce72c79 100644 --- a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php +++ b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php | |||
@@ -36,7 +36,9 @@ class ContentProxyTest extends TestCase | |||
36 | 'html' => false, | 36 | 'html' => false, |
37 | 'title' => '', | 37 | 'title' => '', |
38 | 'url' => '', | 38 | 'url' => '', |
39 | 'content_type' => '', | 39 | 'headers' => [ |
40 | 'content-type' => '', | ||
41 | ], | ||
40 | 'language' => '', | 42 | 'language' => '', |
41 | ]); | 43 | ]); |
42 | 44 | ||
@@ -71,7 +73,9 @@ class ContentProxyTest extends TestCase | |||
71 | 'html' => false, | 73 | 'html' => false, |
72 | 'title' => '', | 74 | 'title' => '', |
73 | 'url' => '', | 75 | 'url' => '', |
74 | 'content_type' => '', | 76 | 'headers' => [ |
77 | 'content-type' => '', | ||
78 | ], | ||
75 | 'language' => '', | 79 | 'language' => '', |
76 | ]); | 80 | ]); |
77 | 81 | ||
@@ -104,15 +108,14 @@ class ContentProxyTest extends TestCase | |||
104 | ->method('fetchContent') | 108 | ->method('fetchContent') |
105 | ->willReturn([ | 109 | ->willReturn([ |
106 | 'html' => false, | 110 | 'html' => false, |
107 | 'title' => '', | 111 | 'title' => 'my title', |
108 | 'url' => '', | 112 | 'url' => '', |
109 | 'content_type' => '', | 113 | 'headers' => [ |
114 | 'content-type' => '', | ||
115 | ], | ||
110 | 'language' => '', | 116 | 'language' => '', |
111 | 'status' => '', | 117 | 'status' => '', |
112 | 'open_graph' => [ | 118 | 'description' => 'desc', |
113 | 'og_title' => 'my title', | ||
114 | 'og_description' => 'desc', | ||
115 | ], | ||
116 | ]); | 119 | ]); |
117 | 120 | ||
118 | $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); | 121 | $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); |
@@ -147,13 +150,12 @@ class ContentProxyTest extends TestCase | |||
147 | 'html' => str_repeat('this is my content', 325), | 150 | 'html' => str_repeat('this is my content', 325), |
148 | 'title' => 'this is my title', | 151 | 'title' => 'this is my title', |
149 | 'url' => 'http://1.1.1.1', | 152 | 'url' => 'http://1.1.1.1', |
150 | 'content_type' => 'text/html', | ||
151 | 'language' => 'fr', | 153 | 'language' => 'fr', |
152 | 'status' => '200', | 154 | 'status' => '200', |
153 | 'open_graph' => [ | 155 | 'description' => 'OG desc', |
154 | 'og_title' => 'my OG title', | 156 | 'image' => 'http://3.3.3.3/cover.jpg', |
155 | 'og_description' => 'OG desc', | 157 | 'headers' => [ |
156 | 'og_image' => 'http://3.3.3.3/cover.jpg', | 158 | 'content-type' => 'text/html', |
157 | ], | 159 | ], |
158 | ]); | 160 | ]); |
159 | 161 | ||
@@ -163,7 +165,7 @@ class ContentProxyTest extends TestCase | |||
163 | 165 | ||
164 | $this->assertSame('http://1.1.1.1', $entry->getUrl()); | 166 | $this->assertSame('http://1.1.1.1', $entry->getUrl()); |
165 | $this->assertSame('this is my title', $entry->getTitle()); | 167 | $this->assertSame('this is my title', $entry->getTitle()); |
166 | $this->assertContains('this is my content', $entry->getContent()); | 168 | $this->assertContains('content', $entry->getContent()); |
167 | $this->assertSame('http://3.3.3.3/cover.jpg', $entry->getPreviewPicture()); | 169 | $this->assertSame('http://3.3.3.3/cover.jpg', $entry->getPreviewPicture()); |
168 | $this->assertSame('text/html', $entry->getMimetype()); | 170 | $this->assertSame('text/html', $entry->getMimetype()); |
169 | $this->assertSame('fr', $entry->getLanguage()); | 171 | $this->assertSame('fr', $entry->getLanguage()); |
@@ -189,13 +191,12 @@ class ContentProxyTest extends TestCase | |||
189 | 'html' => str_repeat('this is my content', 325), | 191 | 'html' => str_repeat('this is my content', 325), |
190 | 'title' => 'this is my title', | 192 | 'title' => 'this is my title', |
191 | 'url' => 'http://1.1.1.1', | 193 | 'url' => 'http://1.1.1.1', |
192 | 'content_type' => 'text/html', | ||
193 | 'language' => 'fr', | 194 | 'language' => 'fr', |
194 | 'status' => '200', | 195 | 'status' => '200', |
195 | 'open_graph' => [ | 196 | 'description' => 'OG desc', |
196 | 'og_title' => 'my OG title', | 197 | 'image' => null, |
197 | 'og_description' => 'OG desc', | 198 | 'headers' => [ |
198 | 'og_image' => null, | 199 | 'content-type' => 'text/html', |
199 | ], | 200 | ], |
200 | ]); | 201 | ]); |
201 | 202 | ||
@@ -205,7 +206,7 @@ class ContentProxyTest extends TestCase | |||
205 | 206 | ||
206 | $this->assertSame('http://1.1.1.1', $entry->getUrl()); | 207 | $this->assertSame('http://1.1.1.1', $entry->getUrl()); |
207 | $this->assertSame('this is my title', $entry->getTitle()); | 208 | $this->assertSame('this is my title', $entry->getTitle()); |
208 | $this->assertContains('this is my content', $entry->getContent()); | 209 | $this->assertContains('content', $entry->getContent()); |
209 | $this->assertNull($entry->getPreviewPicture()); | 210 | $this->assertNull($entry->getPreviewPicture()); |
210 | $this->assertSame('text/html', $entry->getMimetype()); | 211 | $this->assertSame('text/html', $entry->getMimetype()); |
211 | $this->assertSame('fr', $entry->getLanguage()); | 212 | $this->assertSame('fr', $entry->getLanguage()); |
@@ -214,6 +215,86 @@ class ContentProxyTest extends TestCase | |||
214 | $this->assertSame('1.1.1.1', $entry->getDomainName()); | 215 | $this->assertSame('1.1.1.1', $entry->getDomainName()); |
215 | } | 216 | } |
216 | 217 | ||
218 | public function testWithContentAndContentImage() | ||
219 | { | ||
220 | $tagger = $this->getTaggerMock(); | ||
221 | $tagger->expects($this->once()) | ||
222 | ->method('tag'); | ||
223 | |||
224 | $graby = $this->getMockBuilder('Graby\Graby') | ||
225 | ->setMethods(['fetchContent']) | ||
226 | ->disableOriginalConstructor() | ||
227 | ->getMock(); | ||
228 | |||
229 | $graby->expects($this->any()) | ||
230 | ->method('fetchContent') | ||
231 | ->willReturn([ | ||
232 | 'html' => "<h1>Test</h1><p><img src='http://3.3.3.3/cover.jpg'/></p>", | ||
233 | 'title' => 'this is my title', | ||
234 | 'url' => 'http://1.1.1.1', | ||
235 | 'headers' => [ | ||
236 | 'content-type' => 'text/html', | ||
237 | ], | ||
238 | 'language' => 'fr', | ||
239 | 'status' => '200', | ||
240 | 'image' => null, | ||
241 | ]); | ||
242 | |||
243 | $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); | ||
244 | $entry = new Entry(new User()); | ||
245 | $proxy->updateEntry($entry, 'http://0.0.0.0'); | ||
246 | |||
247 | $this->assertSame('http://1.1.1.1', $entry->getUrl()); | ||
248 | $this->assertSame('this is my title', $entry->getTitle()); | ||
249 | $this->assertSame("<h1>Test</h1><p><img src='http://3.3.3.3/cover.jpg'/></p>", $entry->getContent()); | ||
250 | $this->assertSame('http://3.3.3.3/cover.jpg', $entry->getPreviewPicture()); | ||
251 | $this->assertSame('text/html', $entry->getMimetype()); | ||
252 | $this->assertSame('fr', $entry->getLanguage()); | ||
253 | $this->assertSame('200', $entry->getHttpStatus()); | ||
254 | $this->assertSame(0.0, $entry->getReadingTime()); | ||
255 | $this->assertSame('1.1.1.1', $entry->getDomainName()); | ||
256 | } | ||
257 | |||
258 | public function testWithContentImageAndOgImage() | ||
259 | { | ||
260 | $tagger = $this->getTaggerMock(); | ||
261 | $tagger->expects($this->once()) | ||
262 | ->method('tag'); | ||
263 | |||
264 | $graby = $this->getMockBuilder('Graby\Graby') | ||
265 | ->setMethods(['fetchContent']) | ||
266 | ->disableOriginalConstructor() | ||
267 | ->getMock(); | ||
268 | |||
269 | $graby->expects($this->any()) | ||
270 | ->method('fetchContent') | ||
271 | ->willReturn([ | ||
272 | 'html' => "<h1>Test</h1><p><img src='http://3.3.3.3/nevermind.jpg'/></p>", | ||
273 | 'title' => 'this is my title', | ||
274 | 'url' => 'http://1.1.1.1', | ||
275 | 'headers' => [ | ||
276 | 'content-type' => 'text/html', | ||
277 | ], | ||
278 | 'language' => 'fr', | ||
279 | 'status' => '200', | ||
280 | 'image' => 'http://3.3.3.3/cover.jpg', | ||
281 | ]); | ||
282 | |||
283 | $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); | ||
284 | $entry = new Entry(new User()); | ||
285 | $proxy->updateEntry($entry, 'http://0.0.0.0'); | ||
286 | |||
287 | $this->assertSame('http://1.1.1.1', $entry->getUrl()); | ||
288 | $this->assertSame('this is my title', $entry->getTitle()); | ||
289 | $this->assertSame("<h1>Test</h1><p><img src='http://3.3.3.3/nevermind.jpg'/></p>", $entry->getContent()); | ||
290 | $this->assertSame('http://3.3.3.3/cover.jpg', $entry->getPreviewPicture()); | ||
291 | $this->assertSame('text/html', $entry->getMimetype()); | ||
292 | $this->assertSame('fr', $entry->getLanguage()); | ||
293 | $this->assertSame('200', $entry->getHttpStatus()); | ||
294 | $this->assertSame(0.0, $entry->getReadingTime()); | ||
295 | $this->assertSame('1.1.1.1', $entry->getDomainName()); | ||
296 | } | ||
297 | |||
217 | public function testWithContentAndBadLanguage() | 298 | public function testWithContentAndBadLanguage() |
218 | { | 299 | { |
219 | $tagger = $this->getTaggerMock(); | 300 | $tagger = $this->getTaggerMock(); |
@@ -236,9 +317,11 @@ class ContentProxyTest extends TestCase | |||
236 | 'html' => str_repeat('this is my content', 325), | 317 | 'html' => str_repeat('this is my content', 325), |
237 | 'title' => 'this is my title', | 318 | 'title' => 'this is my title', |
238 | 'url' => 'http://1.1.1.1', | 319 | 'url' => 'http://1.1.1.1', |
239 | 'content_type' => 'text/html', | ||
240 | 'language' => 'dontexist', | 320 | 'language' => 'dontexist', |
241 | 'status' => '200', | 321 | 'status' => '200', |
322 | 'headers' => [ | ||
323 | 'content-type' => 'text/html', | ||
324 | ], | ||
242 | ]); | 325 | ]); |
243 | 326 | ||
244 | $proxy = new ContentProxy($graby, $tagger, $validator, $this->getLogger(), $this->fetchingErrorMessage); | 327 | $proxy = new ContentProxy($graby, $tagger, $validator, $this->getLogger(), $this->fetchingErrorMessage); |
@@ -247,7 +330,7 @@ class ContentProxyTest extends TestCase | |||
247 | 330 | ||
248 | $this->assertSame('http://1.1.1.1', $entry->getUrl()); | 331 | $this->assertSame('http://1.1.1.1', $entry->getUrl()); |
249 | $this->assertSame('this is my title', $entry->getTitle()); | 332 | $this->assertSame('this is my title', $entry->getTitle()); |
250 | $this->assertContains('this is my content', $entry->getContent()); | 333 | $this->assertContains('content', $entry->getContent()); |
251 | $this->assertSame('text/html', $entry->getMimetype()); | 334 | $this->assertSame('text/html', $entry->getMimetype()); |
252 | $this->assertNull($entry->getLanguage()); | 335 | $this->assertNull($entry->getLanguage()); |
253 | $this->assertSame('200', $entry->getHttpStatus()); | 336 | $this->assertSame('200', $entry->getHttpStatus()); |
@@ -280,14 +363,13 @@ class ContentProxyTest extends TestCase | |||
280 | 'html' => str_repeat('this is my content', 325), | 363 | 'html' => str_repeat('this is my content', 325), |
281 | 'title' => 'this is my title', | 364 | 'title' => 'this is my title', |
282 | 'url' => 'http://1.1.1.1', | 365 | 'url' => 'http://1.1.1.1', |
283 | 'content_type' => 'text/html', | 366 | 'headers' => [ |
367 | 'content-type' => 'text/html', | ||
368 | ], | ||
284 | 'language' => 'fr', | 369 | 'language' => 'fr', |
285 | 'status' => '200', | 370 | 'status' => '200', |
286 | 'open_graph' => [ | 371 | 'description' => 'OG desc', |
287 | 'og_title' => 'my OG title', | 372 | 'image' => 'https://', |
288 | 'og_description' => 'OG desc', | ||
289 | 'og_image' => 'https://', | ||
290 | ], | ||
291 | ]); | 373 | ]); |
292 | 374 | ||
293 | $proxy = new ContentProxy($graby, $tagger, $validator, $this->getLogger(), $this->fetchingErrorMessage); | 375 | $proxy = new ContentProxy($graby, $tagger, $validator, $this->getLogger(), $this->fetchingErrorMessage); |
@@ -296,7 +378,7 @@ class ContentProxyTest extends TestCase | |||
296 | 378 | ||
297 | $this->assertSame('http://1.1.1.1', $entry->getUrl()); | 379 | $this->assertSame('http://1.1.1.1', $entry->getUrl()); |
298 | $this->assertSame('this is my title', $entry->getTitle()); | 380 | $this->assertSame('this is my title', $entry->getTitle()); |
299 | $this->assertContains('this is my content', $entry->getContent()); | 381 | $this->assertContains('content', $entry->getContent()); |
300 | $this->assertNull($entry->getPreviewPicture()); | 382 | $this->assertNull($entry->getPreviewPicture()); |
301 | $this->assertSame('text/html', $entry->getMimetype()); | 383 | $this->assertSame('text/html', $entry->getMimetype()); |
302 | $this->assertSame('fr', $entry->getLanguage()); | 384 | $this->assertSame('fr', $entry->getLanguage()); |
@@ -320,19 +402,19 @@ class ContentProxyTest extends TestCase | |||
320 | 'html' => str_repeat('this is my content', 325), | 402 | 'html' => str_repeat('this is my content', 325), |
321 | 'title' => 'this is my title', | 403 | 'title' => 'this is my title', |
322 | 'url' => 'http://1.1.1.1', | 404 | 'url' => 'http://1.1.1.1', |
323 | 'content_type' => 'text/html', | ||
324 | 'language' => 'fr', | 405 | 'language' => 'fr', |
325 | 'date' => '1395635872', | 406 | 'date' => '1395635872', |
326 | 'authors' => ['Jeremy', 'Nico', 'Thomas'], | 407 | 'authors' => ['Jeremy', 'Nico', 'Thomas'], |
327 | 'all_headers' => [ | 408 | 'headers' => [ |
328 | 'Cache-Control' => 'no-cache', | 409 | 'cache-control' => 'no-cache', |
410 | 'content-type' => 'text/html', | ||
329 | ], | 411 | ], |
330 | ] | 412 | ] |
331 | ); | 413 | ); |
332 | 414 | ||
333 | $this->assertSame('http://1.1.1.1', $entry->getUrl()); | 415 | $this->assertSame('http://1.1.1.1', $entry->getUrl()); |
334 | $this->assertSame('this is my title', $entry->getTitle()); | 416 | $this->assertSame('this is my title', $entry->getTitle()); |
335 | $this->assertContains('this is my content', $entry->getContent()); | 417 | $this->assertContains('content', $entry->getContent()); |
336 | $this->assertSame('text/html', $entry->getMimetype()); | 418 | $this->assertSame('text/html', $entry->getMimetype()); |
337 | $this->assertSame('fr', $entry->getLanguage()); | 419 | $this->assertSame('fr', $entry->getLanguage()); |
338 | $this->assertSame(4.0, $entry->getReadingTime()); | 420 | $this->assertSame(4.0, $entry->getReadingTime()); |
@@ -363,15 +445,17 @@ class ContentProxyTest extends TestCase | |||
363 | 'html' => str_repeat('this is my content', 325), | 445 | 'html' => str_repeat('this is my content', 325), |
364 | 'title' => 'this is my title', | 446 | 'title' => 'this is my title', |
365 | 'url' => 'http://1.1.1.1', | 447 | 'url' => 'http://1.1.1.1', |
366 | 'content_type' => 'text/html', | ||
367 | 'language' => 'fr', | 448 | 'language' => 'fr', |
368 | 'date' => '2016-09-08T11:55:58+0200', | 449 | 'date' => '2016-09-08T11:55:58+0200', |
450 | 'headers' => [ | ||
451 | 'content-type' => 'text/html', | ||
452 | ], | ||
369 | ] | 453 | ] |
370 | ); | 454 | ); |
371 | 455 | ||
372 | $this->assertSame('http://1.1.1.1', $entry->getUrl()); | 456 | $this->assertSame('http://1.1.1.1', $entry->getUrl()); |
373 | $this->assertSame('this is my title', $entry->getTitle()); | 457 | $this->assertSame('this is my title', $entry->getTitle()); |
374 | $this->assertContains('this is my content', $entry->getContent()); | 458 | $this->assertContains('content', $entry->getContent()); |
375 | $this->assertSame('text/html', $entry->getMimetype()); | 459 | $this->assertSame('text/html', $entry->getMimetype()); |
376 | $this->assertSame('fr', $entry->getLanguage()); | 460 | $this->assertSame('fr', $entry->getLanguage()); |
377 | $this->assertSame(4.0, $entry->getReadingTime()); | 461 | $this->assertSame(4.0, $entry->getReadingTime()); |
@@ -398,15 +482,17 @@ class ContentProxyTest extends TestCase | |||
398 | 'html' => str_repeat('this is my content', 325), | 482 | 'html' => str_repeat('this is my content', 325), |
399 | 'title' => 'this is my title', | 483 | 'title' => 'this is my title', |
400 | 'url' => 'http://1.1.1.1', | 484 | 'url' => 'http://1.1.1.1', |
401 | 'content_type' => 'text/html', | ||
402 | 'language' => 'fr', | 485 | 'language' => 'fr', |
403 | 'date' => '01 02 2012', | 486 | 'date' => '01 02 2012', |
487 | 'headers' => [ | ||
488 | 'content-type' => 'text/html', | ||
489 | ], | ||
404 | ] | 490 | ] |
405 | ); | 491 | ); |
406 | 492 | ||
407 | $this->assertSame('http://1.1.1.1', $entry->getUrl()); | 493 | $this->assertSame('http://1.1.1.1', $entry->getUrl()); |
408 | $this->assertSame('this is my title', $entry->getTitle()); | 494 | $this->assertSame('this is my title', $entry->getTitle()); |
409 | $this->assertContains('this is my content', $entry->getContent()); | 495 | $this->assertContains('content', $entry->getContent()); |
410 | $this->assertSame('text/html', $entry->getMimetype()); | 496 | $this->assertSame('text/html', $entry->getMimetype()); |
411 | $this->assertSame('fr', $entry->getLanguage()); | 497 | $this->assertSame('fr', $entry->getLanguage()); |
412 | $this->assertSame(4.0, $entry->getReadingTime()); | 498 | $this->assertSame(4.0, $entry->getReadingTime()); |
@@ -415,7 +501,7 @@ class ContentProxyTest extends TestCase | |||
415 | 501 | ||
416 | $records = $handler->getRecords(); | 502 | $records = $handler->getRecords(); |
417 | 503 | ||
418 | $this->assertCount(1, $records); | 504 | $this->assertCount(3, $records); |
419 | $this->assertContains('Error while defining date', $records[0]['message']); | 505 | $this->assertContains('Error while defining date', $records[0]['message']); |
420 | } | 506 | } |
421 | 507 | ||
@@ -435,8 +521,10 @@ class ContentProxyTest extends TestCase | |||
435 | 'html' => str_repeat('this is my content', 325), | 521 | 'html' => str_repeat('this is my content', 325), |
436 | 'title' => 'this is my title', | 522 | 'title' => 'this is my title', |
437 | 'url' => 'http://1.1.1.1', | 523 | 'url' => 'http://1.1.1.1', |
438 | 'content_type' => 'text/html', | ||
439 | 'language' => 'fr', | 524 | 'language' => 'fr', |
525 | 'headers' => [ | ||
526 | 'content-type' => 'text/html', | ||
527 | ], | ||
440 | ] | 528 | ] |
441 | ); | 529 | ); |
442 | 530 | ||
@@ -475,13 +563,13 @@ class ContentProxyTest extends TestCase | |||
475 | 'html' => $html, | 563 | 'html' => $html, |
476 | 'title' => 'this is my title', | 564 | 'title' => 'this is my title', |
477 | 'url' => 'http://1.1.1.1', | 565 | 'url' => 'http://1.1.1.1', |
478 | 'content_type' => 'text/html', | ||
479 | 'language' => 'fr', | 566 | 'language' => 'fr', |
480 | 'status' => '200', | 567 | 'status' => '200', |
481 | 'open_graph' => [ | 568 | //'og_title' => 'my OG title', |
482 | 'og_title' => 'my OG title', | 569 | 'description' => 'OG desc', |
483 | 'og_description' => 'OG desc', | 570 | 'image' => 'http://3.3.3.3/cover.jpg', |
484 | 'og_image' => 'http://3.3.3.3/cover.jpg', | 571 | 'headers' => [ |
572 | 'content-type' => 'text/html', | ||
485 | ], | 573 | ], |
486 | ] | 574 | ] |
487 | ); | 575 | ); |
@@ -513,9 +601,10 @@ class ContentProxyTest extends TestCase | |||
513 | 'html' => '<p><img src="http://1.1.1.1/image.jpg" /></p>', | 601 | 'html' => '<p><img src="http://1.1.1.1/image.jpg" /></p>', |
514 | 'title' => 'this is my title', | 602 | 'title' => 'this is my title', |
515 | 'url' => 'http://1.1.1.1/image.jpg', | 603 | 'url' => 'http://1.1.1.1/image.jpg', |
516 | 'content_type' => 'image/jpeg', | ||
517 | 'status' => '200', | 604 | 'status' => '200', |
518 | 'open_graph' => [], | 605 | 'headers' => [ |
606 | 'content-type' => 'image/jpeg', | ||
607 | ], | ||
519 | ]); | 608 | ]); |
520 | 609 | ||
521 | $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); | 610 | $proxy = new ContentProxy($graby, $tagger, $this->getValidator(), $this->getLogger(), $this->fetchingErrorMessage); |
@@ -553,7 +642,9 @@ class ContentProxyTest extends TestCase | |||
553 | 'html' => false, | 642 | 'html' => false, |
554 | 'title' => $actualTitle, | 643 | 'title' => $actualTitle, |
555 | 'url' => '', | 644 | 'url' => '', |
556 | 'content_type' => 'text/html', | 645 | 'headers' => [ |
646 | 'content-type' => 'text/html', | ||
647 | ], | ||
557 | 'language' => '', | 648 | 'language' => '', |
558 | ]); | 649 | ]); |
559 | 650 | ||
@@ -588,7 +679,9 @@ class ContentProxyTest extends TestCase | |||
588 | 'html' => false, | 679 | 'html' => false, |
589 | 'title' => $actualTitle, | 680 | 'title' => $actualTitle, |
590 | 'url' => '', | 681 | 'url' => '', |
591 | 'content_type' => 'text/html', | 682 | 'headers' => [ |
683 | 'content-type' => 'text/html', | ||
684 | ], | ||
592 | 'language' => '', | 685 | 'language' => '', |
593 | ]); | 686 | ]); |
594 | 687 | ||
@@ -622,7 +715,9 @@ class ContentProxyTest extends TestCase | |||
622 | 'html' => false, | 715 | 'html' => false, |
623 | 'title' => $actualTitle, | 716 | 'title' => $actualTitle, |
624 | 'url' => '', | 717 | 'url' => '', |
625 | 'content_type' => 'application/pdf', | 718 | 'headers' => [ |
719 | 'content-type' => 'application/pdf', | ||
720 | ], | ||
626 | 'language' => '', | 721 | 'language' => '', |
627 | ]); | 722 | ]); |
628 | 723 | ||
@@ -656,7 +751,9 @@ class ContentProxyTest extends TestCase | |||
656 | 'html' => false, | 751 | 'html' => false, |
657 | 'title' => $actualTitle, | 752 | 'title' => $actualTitle, |
658 | 'url' => '', | 753 | 'url' => '', |
659 | 'content_type' => 'application/pdf', | 754 | 'headers' => [ |
755 | 'content-type' => 'application/pdf', | ||
756 | ], | ||
660 | 'language' => '', | 757 | 'language' => '', |
661 | ]); | 758 | ]); |
662 | 759 | ||
@@ -690,7 +787,9 @@ class ContentProxyTest extends TestCase | |||
690 | 'html' => false, | 787 | 'html' => false, |
691 | 'title' => $actualTitle, | 788 | 'title' => $actualTitle, |
692 | 'url' => '', | 789 | 'url' => '', |
693 | 'content_type' => 'application/pdf', | 790 | 'headers' => [ |
791 | 'content-type' => 'application/pdf', | ||
792 | ], | ||
694 | 'language' => '', | 793 | 'language' => '', |
695 | ]); | 794 | ]); |
696 | 795 | ||
@@ -725,7 +824,9 @@ class ContentProxyTest extends TestCase | |||
725 | 'html' => false, | 824 | 'html' => false, |
726 | 'title' => $actualTitle, | 825 | 'title' => $actualTitle, |
727 | 'url' => '', | 826 | 'url' => '', |
728 | 'content_type' => 'application/pdf', | 827 | 'headers' => [ |
828 | 'content-type' => 'application/pdf', | ||
829 | ], | ||
729 | 'language' => '', | 830 | 'language' => '', |
730 | ]); | 831 | ]); |
731 | 832 | ||
@@ -855,7 +956,9 @@ class ContentProxyTest extends TestCase | |||
855 | 'html' => false, | 956 | 'html' => false, |
856 | 'title' => '', | 957 | 'title' => '', |
857 | 'url' => $content_url, | 958 | 'url' => $content_url, |
858 | 'content_type' => '', | 959 | 'headers' => [ |
960 | 'content-type' => '', | ||
961 | ], | ||
859 | 'language' => '', | 962 | 'language' => '', |
860 | ], | 963 | ], |
861 | true | 964 | true |
@@ -886,7 +989,9 @@ class ContentProxyTest extends TestCase | |||
886 | } | 989 | } |
887 | 990 | ||
888 | /** | 991 | /** |
889 | * https://stackoverflow.com/a/18506801. | 992 | * Convert hex to string. |
993 | * | ||
994 | * @see https://stackoverflow.com/a/18506801 | ||
890 | * | 995 | * |
891 | * @param $hex | 996 | * @param $hex |
892 | * | 997 | * |
diff --git a/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php b/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php index cda5f843..3c720425 100644 --- a/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php +++ b/tests/Wallabag/CoreBundle/Helper/DownloadImagesTest.php | |||
@@ -2,10 +2,8 @@ | |||
2 | 2 | ||
3 | namespace Tests\Wallabag\CoreBundle\Helper; | 3 | namespace Tests\Wallabag\CoreBundle\Helper; |
4 | 4 | ||
5 | use GuzzleHttp\Client; | 5 | use GuzzleHttp\Psr7\Response; |
6 | use GuzzleHttp\Message\Response; | 6 | use Http\Mock\Client as HttpMockClient; |
7 | use GuzzleHttp\Stream\Stream; | ||
8 | use GuzzleHttp\Subscriber\Mock; | ||
9 | use Monolog\Handler\TestHandler; | 7 | use Monolog\Handler\TestHandler; |
10 | use Monolog\Logger; | 8 | use Monolog\Logger; |
11 | use PHPUnit\Framework\TestCase; | 9 | use PHPUnit\Framework\TestCase; |
@@ -32,18 +30,14 @@ class DownloadImagesTest extends TestCase | |||
32 | */ | 30 | */ |
33 | public function testProcessHtml($html, $url) | 31 | public function testProcessHtml($html, $url) |
34 | { | 32 | { |
35 | $client = new Client(); | 33 | $httpMockClient = new HttpMockClient(); |
36 | 34 | ||
37 | $mock = new Mock([ | 35 | $httpMockClient->addResponse(new Response(200, ['content-type' => 'image/png'], file_get_contents(__DIR__ . '/../fixtures/unnamed.png'))); |
38 | new Response(200, ['content-type' => 'image/png'], Stream::factory(file_get_contents(__DIR__ . '/../fixtures/unnamed.png'))), | ||
39 | ]); | ||
40 | |||
41 | $client->getEmitter()->attach($mock); | ||
42 | 36 | ||
43 | $logHandler = new TestHandler(); | 37 | $logHandler = new TestHandler(); |
44 | $logger = new Logger('test', [$logHandler]); | 38 | $logger = new Logger('test', [$logHandler]); |
45 | 39 | ||
46 | $download = new DownloadImages($client, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); | 40 | $download = new DownloadImages($httpMockClient, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); |
47 | 41 | ||
48 | $res = $download->processHtml(123, $html, $url); | 42 | $res = $download->processHtml(123, $html, $url); |
49 | 43 | ||
@@ -53,18 +47,13 @@ class DownloadImagesTest extends TestCase | |||
53 | 47 | ||
54 | public function testProcessHtmlWithBadImage() | 48 | public function testProcessHtmlWithBadImage() |
55 | { | 49 | { |
56 | $client = new Client(); | 50 | $httpMockClient = new HttpMockClient(); |
57 | 51 | $httpMockClient->addResponse(new Response(200, ['content-type' => 'application/json'], '')); | |
58 | $mock = new Mock([ | ||
59 | new Response(200, ['content-type' => 'application/json'], Stream::factory('')), | ||
60 | ]); | ||
61 | |||
62 | $client->getEmitter()->attach($mock); | ||
63 | 52 | ||
64 | $logHandler = new TestHandler(); | 53 | $logHandler = new TestHandler(); |
65 | $logger = new Logger('test', [$logHandler]); | 54 | $logger = new Logger('test', [$logHandler]); |
66 | 55 | ||
67 | $download = new DownloadImages($client, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); | 56 | $download = new DownloadImages($httpMockClient, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); |
68 | $res = $download->processHtml(123, '<div><img src="http://i.imgur.com/T9qgcHc.jpg" /></div>', 'http://imgur.com/gallery/WxtWY'); | 57 | $res = $download->processHtml(123, '<div><img src="http://i.imgur.com/T9qgcHc.jpg" /></div>', 'http://imgur.com/gallery/WxtWY'); |
69 | 58 | ||
70 | $this->assertContains('http://i.imgur.com/T9qgcHc.jpg', $res, 'Image were not replace because of content-type'); | 59 | $this->assertContains('http://i.imgur.com/T9qgcHc.jpg', $res, 'Image were not replace because of content-type'); |
@@ -85,18 +74,13 @@ class DownloadImagesTest extends TestCase | |||
85 | */ | 74 | */ |
86 | public function testProcessSingleImage($header, $extension) | 75 | public function testProcessSingleImage($header, $extension) |
87 | { | 76 | { |
88 | $client = new Client(); | 77 | $httpMockClient = new HttpMockClient(); |
89 | 78 | $httpMockClient->addResponse(new Response(200, ['content-type' => $header], file_get_contents(__DIR__ . '/../fixtures/unnamed.png'))); | |
90 | $mock = new Mock([ | ||
91 | new Response(200, ['content-type' => $header], Stream::factory(file_get_contents(__DIR__ . '/../fixtures/unnamed.png'))), | ||
92 | ]); | ||
93 | |||
94 | $client->getEmitter()->attach($mock); | ||
95 | 79 | ||
96 | $logHandler = new TestHandler(); | 80 | $logHandler = new TestHandler(); |
97 | $logger = new Logger('test', [$logHandler]); | 81 | $logger = new Logger('test', [$logHandler]); |
98 | 82 | ||
99 | $download = new DownloadImages($client, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); | 83 | $download = new DownloadImages($httpMockClient, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); |
100 | $res = $download->processSingleImage(123, 'T9qgcHc.jpg', 'http://imgur.com/gallery/WxtWY'); | 84 | $res = $download->processSingleImage(123, 'T9qgcHc.jpg', 'http://imgur.com/gallery/WxtWY'); |
101 | 85 | ||
102 | $this->assertContains('/assets/images/9/b/9b0ead26/ebe60399.' . $extension, $res); | 86 | $this->assertContains('/assets/images/9/b/9b0ead26/ebe60399.' . $extension, $res); |
@@ -104,18 +88,13 @@ class DownloadImagesTest extends TestCase | |||
104 | 88 | ||
105 | public function testProcessSingleImageWithBadUrl() | 89 | public function testProcessSingleImageWithBadUrl() |
106 | { | 90 | { |
107 | $client = new Client(); | 91 | $httpMockClient = new HttpMockClient(); |
108 | 92 | $httpMockClient->addResponse(new Response(404, [])); | |
109 | $mock = new Mock([ | ||
110 | new Response(404, []), | ||
111 | ]); | ||
112 | |||
113 | $client->getEmitter()->attach($mock); | ||
114 | 93 | ||
115 | $logHandler = new TestHandler(); | 94 | $logHandler = new TestHandler(); |
116 | $logger = new Logger('test', [$logHandler]); | 95 | $logger = new Logger('test', [$logHandler]); |
117 | 96 | ||
118 | $download = new DownloadImages($client, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); | 97 | $download = new DownloadImages($httpMockClient, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); |
119 | $res = $download->processSingleImage(123, 'T9qgcHc.jpg', 'http://imgur.com/gallery/WxtWY'); | 98 | $res = $download->processSingleImage(123, 'T9qgcHc.jpg', 'http://imgur.com/gallery/WxtWY'); |
120 | 99 | ||
121 | $this->assertFalse($res, 'Image can not be found, so it will not be replaced'); | 100 | $this->assertFalse($res, 'Image can not be found, so it will not be replaced'); |
@@ -123,18 +102,13 @@ class DownloadImagesTest extends TestCase | |||
123 | 102 | ||
124 | public function testProcessSingleImageWithBadImage() | 103 | public function testProcessSingleImageWithBadImage() |
125 | { | 104 | { |
126 | $client = new Client(); | 105 | $httpMockClient = new HttpMockClient(); |
127 | 106 | $httpMockClient->addResponse(new Response(200, ['content-type' => 'image/png'], '')); | |
128 | $mock = new Mock([ | ||
129 | new Response(200, ['content-type' => 'image/png'], Stream::factory('')), | ||
130 | ]); | ||
131 | |||
132 | $client->getEmitter()->attach($mock); | ||
133 | 107 | ||
134 | $logHandler = new TestHandler(); | 108 | $logHandler = new TestHandler(); |
135 | $logger = new Logger('test', [$logHandler]); | 109 | $logger = new Logger('test', [$logHandler]); |
136 | 110 | ||
137 | $download = new DownloadImages($client, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); | 111 | $download = new DownloadImages($httpMockClient, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); |
138 | $res = $download->processSingleImage(123, 'http://i.imgur.com/T9qgcHc.jpg', 'http://imgur.com/gallery/WxtWY'); | 112 | $res = $download->processSingleImage(123, 'http://i.imgur.com/T9qgcHc.jpg', 'http://imgur.com/gallery/WxtWY'); |
139 | 113 | ||
140 | $this->assertFalse($res, 'Image can not be loaded, so it will not be replaced'); | 114 | $this->assertFalse($res, 'Image can not be loaded, so it will not be replaced'); |
@@ -142,18 +116,13 @@ class DownloadImagesTest extends TestCase | |||
142 | 116 | ||
143 | public function testProcessSingleImageFailAbsolute() | 117 | public function testProcessSingleImageFailAbsolute() |
144 | { | 118 | { |
145 | $client = new Client(); | 119 | $httpMockClient = new HttpMockClient(); |
146 | 120 | $httpMockClient->addResponse(new Response(200, ['content-type' => 'image/png'], file_get_contents(__DIR__ . '/../fixtures/unnamed.png'))); | |
147 | $mock = new Mock([ | ||
148 | new Response(200, ['content-type' => 'image/png'], Stream::factory(file_get_contents(__DIR__ . '/../fixtures/unnamed.png'))), | ||
149 | ]); | ||
150 | |||
151 | $client->getEmitter()->attach($mock); | ||
152 | 121 | ||
153 | $logHandler = new TestHandler(); | 122 | $logHandler = new TestHandler(); |
154 | $logger = new Logger('test', [$logHandler]); | 123 | $logger = new Logger('test', [$logHandler]); |
155 | 124 | ||
156 | $download = new DownloadImages($client, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); | 125 | $download = new DownloadImages($httpMockClient, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); |
157 | $res = $download->processSingleImage(123, '/i.imgur.com/T9qgcHc.jpg', 'imgur.com/gallery/WxtWY'); | 126 | $res = $download->processSingleImage(123, '/i.imgur.com/T9qgcHc.jpg', 'imgur.com/gallery/WxtWY'); |
158 | 127 | ||
159 | $this->assertFalse($res, 'Absolute image can not be determined, so it will not be replaced'); | 128 | $this->assertFalse($res, 'Absolute image can not be determined, so it will not be replaced'); |
@@ -161,18 +130,13 @@ class DownloadImagesTest extends TestCase | |||
161 | 130 | ||
162 | public function testProcessRealImage() | 131 | public function testProcessRealImage() |
163 | { | 132 | { |
164 | $client = new Client(); | 133 | $httpMockClient = new HttpMockClient(); |
165 | 134 | $httpMockClient->addResponse(new Response(200, ['content-type' => null], file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))); | |
166 | $mock = new Mock([ | ||
167 | new Response(200, ['content-type' => null], Stream::factory(file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))), | ||
168 | ]); | ||
169 | |||
170 | $client->getEmitter()->attach($mock); | ||
171 | 135 | ||
172 | $logHandler = new TestHandler(); | 136 | $logHandler = new TestHandler(); |
173 | $logger = new Logger('test', [$logHandler]); | 137 | $logger = new Logger('test', [$logHandler]); |
174 | 138 | ||
175 | $download = new DownloadImages($client, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); | 139 | $download = new DownloadImages($httpMockClient, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); |
176 | 140 | ||
177 | $res = $download->processSingleImage( | 141 | $res = $download->processSingleImage( |
178 | 123, | 142 | 123, |
@@ -186,20 +150,15 @@ class DownloadImagesTest extends TestCase | |||
186 | 150 | ||
187 | public function testProcessImageWithSrcset() | 151 | public function testProcessImageWithSrcset() |
188 | { | 152 | { |
189 | $client = new Client(); | 153 | $httpMockClient = new HttpMockClient(); |
190 | 154 | $httpMockClient->addResponse(new Response(200, ['content-type' => null], file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))); | |
191 | $mock = new Mock([ | 155 | $httpMockClient->addResponse(new Response(200, ['content-type' => null], file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))); |
192 | new Response(200, ['content-type' => 'image/jpeg'], Stream::factory(file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))), | 156 | $httpMockClient->addResponse(new Response(200, ['content-type' => null], file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))); |
193 | new Response(200, ['content-type' => 'image/jpeg'], Stream::factory(file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))), | ||
194 | new Response(200, ['content-type' => 'image/jpeg'], Stream::factory(file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))), | ||
195 | ]); | ||
196 | |||
197 | $client->getEmitter()->attach($mock); | ||
198 | 157 | ||
199 | $logHandler = new TestHandler(); | 158 | $logHandler = new TestHandler(); |
200 | $logger = new Logger('test', [$logHandler]); | 159 | $logger = new Logger('test', [$logHandler]); |
201 | 160 | ||
202 | $download = new DownloadImages($client, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); | 161 | $download = new DownloadImages($httpMockClient, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); |
203 | $res = $download->processHtml(123, '<p><img class="alignnone wp-image-1153" src="http://piketty.blog.lemonde.fr/files/2017/10/F1FR-530x375.jpg" alt="" width="628" height="444" srcset="http://piketty.blog.lemonde.fr/files/2017/10/F1FR-530x375.jpg 530w, http://piketty.blog.lemonde.fr/files/2017/10/F1FR-768x543.jpg 768w, http://piketty.blog.lemonde.fr/files/2017/10/F1FR-900x636.jpg 900w" sizes="(max-width: 628px) 100vw, 628px" /></p>', 'http://piketty.blog.lemonde.fr/2017/10/12/budget-2018-la-jeunesse-sacrifiee/'); | 162 | $res = $download->processHtml(123, '<p><img class="alignnone wp-image-1153" src="http://piketty.blog.lemonde.fr/files/2017/10/F1FR-530x375.jpg" alt="" width="628" height="444" srcset="http://piketty.blog.lemonde.fr/files/2017/10/F1FR-530x375.jpg 530w, http://piketty.blog.lemonde.fr/files/2017/10/F1FR-768x543.jpg 768w, http://piketty.blog.lemonde.fr/files/2017/10/F1FR-900x636.jpg 900w" sizes="(max-width: 628px) 100vw, 628px" /></p>', 'http://piketty.blog.lemonde.fr/2017/10/12/budget-2018-la-jeunesse-sacrifiee/'); |
204 | 163 | ||
205 | $this->assertNotContains('http://piketty.blog.lemonde.fr/', $res, 'Image srcset attribute were not replaced'); | 164 | $this->assertNotContains('http://piketty.blog.lemonde.fr/', $res, 'Image srcset attribute were not replaced'); |
@@ -207,20 +166,15 @@ class DownloadImagesTest extends TestCase | |||
207 | 166 | ||
208 | public function testProcessImageWithTrickySrcset() | 167 | public function testProcessImageWithTrickySrcset() |
209 | { | 168 | { |
210 | $client = new Client(); | 169 | $httpMockClient = new HttpMockClient(); |
211 | 170 | $httpMockClient->addResponse(new Response(200, ['content-type' => null], file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))); | |
212 | $mock = new Mock([ | 171 | $httpMockClient->addResponse(new Response(200, ['content-type' => null], file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))); |
213 | new Response(200, ['content-type' => 'image/jpeg'], Stream::factory(file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))), | 172 | $httpMockClient->addResponse(new Response(200, ['content-type' => null], file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))); |
214 | new Response(200, ['content-type' => 'image/jpeg'], Stream::factory(file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))), | ||
215 | new Response(200, ['content-type' => 'image/jpeg'], Stream::factory(file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))), | ||
216 | ]); | ||
217 | |||
218 | $client->getEmitter()->attach($mock); | ||
219 | 173 | ||
220 | $logHandler = new TestHandler(); | 174 | $logHandler = new TestHandler(); |
221 | $logger = new Logger('test', [$logHandler]); | 175 | $logger = new Logger('test', [$logHandler]); |
222 | 176 | ||
223 | $download = new DownloadImages($client, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); | 177 | $download = new DownloadImages($httpMockClient, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); |
224 | $res = $download->processHtml(123, '<figure id="post-257260" class="align-none media-257260"><img src="https://cdn.css-tricks.com/wp-content/uploads/2017/08/the-critical-request.png" srcset="https://res.cloudinary.com/css-tricks/image/upload/c_scale,w_1000,f_auto,q_auto/v1501594717/the-critical-request_bqdfaa.png 1000w, https://res.cloudinary.com/css-tricks/image/upload/c_scale,w_200,f_auto,q_auto/v1501594717/the-critical-request_bqdfaa.png 200w" sizes="(min-width: 1850px) calc( (100vw - 555px) / 3 ) | 178 | $res = $download->processHtml(123, '<figure id="post-257260" class="align-none media-257260"><img src="https://cdn.css-tricks.com/wp-content/uploads/2017/08/the-critical-request.png" srcset="https://res.cloudinary.com/css-tricks/image/upload/c_scale,w_1000,f_auto,q_auto/v1501594717/the-critical-request_bqdfaa.png 1000w, https://res.cloudinary.com/css-tricks/image/upload/c_scale,w_200,f_auto,q_auto/v1501594717/the-critical-request_bqdfaa.png 200w" sizes="(min-width: 1850px) calc( (100vw - 555px) / 3 ) |
225 | (min-width: 1251px) calc( (100vw - 530px) / 2 ) | 179 | (min-width: 1251px) calc( (100vw - 530px) / 2 ) |
226 | (min-width: 1086px) calc(100vw - 480px) | 180 | (min-width: 1086px) calc(100vw - 480px) |
@@ -232,18 +186,13 @@ class DownloadImagesTest extends TestCase | |||
232 | 186 | ||
233 | public function testProcessImageWithNullPath() | 187 | public function testProcessImageWithNullPath() |
234 | { | 188 | { |
235 | $client = new Client(); | 189 | $httpMockClient = new HttpMockClient(); |
236 | 190 | $httpMockClient->addResponse(new Response(200, ['content-type' => null], file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))); | |
237 | $mock = new Mock([ | ||
238 | new Response(200, ['content-type' => null], Stream::factory(file_get_contents(__DIR__ . '/../fixtures/image-no-content-type.jpg'))), | ||
239 | ]); | ||
240 | |||
241 | $client->getEmitter()->attach($mock); | ||
242 | 191 | ||
243 | $logHandler = new TestHandler(); | 192 | $logHandler = new TestHandler(); |
244 | $logger = new Logger('test', [$logHandler]); | 193 | $logger = new Logger('test', [$logHandler]); |
245 | 194 | ||
246 | $download = new DownloadImages($client, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); | 195 | $download = new DownloadImages($httpMockClient, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger); |
247 | 196 | ||
248 | $res = $download->processSingleImage( | 197 | $res = $download->processSingleImage( |
249 | 123, | 198 | 123, |
diff --git a/tests/Wallabag/CoreBundle/Helper/RedirectTest.php b/tests/Wallabag/CoreBundle/Helper/RedirectTest.php index 04e1a59c..021efa46 100644 --- a/tests/Wallabag/CoreBundle/Helper/RedirectTest.php +++ b/tests/Wallabag/CoreBundle/Helper/RedirectTest.php | |||
@@ -17,6 +17,9 @@ class RedirectTest extends TestCase | |||
17 | /** @var Redirect */ | 17 | /** @var Redirect */ |
18 | private $redirect; | 18 | private $redirect; |
19 | 19 | ||
20 | /** @var UsernamePasswordToken */ | ||
21 | private $token; | ||
22 | |||
20 | public function setUp() | 23 | public function setUp() |
21 | { | 24 | { |
22 | $this->routerMock = $this->getMockBuilder('Symfony\Component\Routing\Router') | 25 | $this->routerMock = $this->getMockBuilder('Symfony\Component\Routing\Router') |
@@ -39,7 +42,7 @@ class RedirectTest extends TestCase | |||
39 | $config = new Config($user); | 42 | $config = new Config($user); |
40 | $config->setTheme('material'); | 43 | $config->setTheme('material'); |
41 | $config->setItemsPerPage(30); | 44 | $config->setItemsPerPage(30); |
42 | $config->setReadingSpeed(1); | 45 | $config->setReadingSpeed(200); |
43 | $config->setLanguage('en'); | 46 | $config->setLanguage('en'); |
44 | $config->setPocketConsumerKey('xxxxx'); | 47 | $config->setPocketConsumerKey('xxxxx'); |
45 | $config->setActionMarkAsRead(Config::REDIRECT_TO_CURRENT_PAGE); | 48 | $config->setActionMarkAsRead(Config::REDIRECT_TO_CURRENT_PAGE); |
diff --git a/tests/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php b/tests/Wallabag/CoreBundle/ParamConverter/UsernameFeedTokenConverterTest.php index b044a700..48c82dde 100644 --- a/tests/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php +++ b/tests/Wallabag/CoreBundle/ParamConverter/UsernameFeedTokenConverterTest.php | |||
@@ -1,19 +1,19 @@ | |||
1 | <?php | 1 | <?php |
2 | 2 | ||
3 | namespace Tests\Wallabag\CoreBundle\Command; | 3 | namespace Tests\Wallabag\CoreBundle\ParamConverter; |
4 | 4 | ||
5 | use PHPUnit\Framework\TestCase; | 5 | use PHPUnit\Framework\TestCase; |
6 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; | 6 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; |
7 | use Symfony\Component\HttpFoundation\Request; | 7 | use Symfony\Component\HttpFoundation\Request; |
8 | use Wallabag\CoreBundle\ParamConverter\UsernameRssTokenConverter; | 8 | use Wallabag\CoreBundle\ParamConverter\UsernameFeedTokenConverter; |
9 | use Wallabag\UserBundle\Entity\User; | 9 | use Wallabag\UserBundle\Entity\User; |
10 | 10 | ||
11 | class UsernameRssTokenConverterTest extends TestCase | 11 | class UsernameFeedTokenConverterTest extends TestCase |
12 | { | 12 | { |
13 | public function testSupportsWithNoRegistry() | 13 | public function testSupportsWithNoRegistry() |
14 | { | 14 | { |
15 | $params = new ParamConverter([]); | 15 | $params = new ParamConverter([]); |
16 | $converter = new UsernameRssTokenConverter(); | 16 | $converter = new UsernameFeedTokenConverter(); |
17 | 17 | ||
18 | $this->assertFalse($converter->supports($params)); | 18 | $this->assertFalse($converter->supports($params)); |
19 | } | 19 | } |
@@ -26,10 +26,10 @@ class UsernameRssTokenConverterTest extends TestCase | |||
26 | 26 | ||
27 | $registry->expects($this->once()) | 27 | $registry->expects($this->once()) |
28 | ->method('getManagers') | 28 | ->method('getManagers') |
29 | ->will($this->returnValue([])); | 29 | ->willReturn([]); |
30 | 30 | ||
31 | $params = new ParamConverter([]); | 31 | $params = new ParamConverter([]); |
32 | $converter = new UsernameRssTokenConverter($registry); | 32 | $converter = new UsernameFeedTokenConverter($registry); |
33 | 33 | ||
34 | $this->assertFalse($converter->supports($params)); | 34 | $this->assertFalse($converter->supports($params)); |
35 | } | 35 | } |
@@ -42,10 +42,10 @@ class UsernameRssTokenConverterTest extends TestCase | |||
42 | 42 | ||
43 | $registry->expects($this->once()) | 43 | $registry->expects($this->once()) |
44 | ->method('getManagers') | 44 | ->method('getManagers') |
45 | ->will($this->returnValue(['default' => null])); | 45 | ->willReturn(['default' => null]); |
46 | 46 | ||
47 | $params = new ParamConverter([]); | 47 | $params = new ParamConverter([]); |
48 | $converter = new UsernameRssTokenConverter($registry); | 48 | $converter = new UsernameFeedTokenConverter($registry); |
49 | 49 | ||
50 | $this->assertFalse($converter->supports($params)); | 50 | $this->assertFalse($converter->supports($params)); |
51 | } | 51 | } |
@@ -58,7 +58,7 @@ class UsernameRssTokenConverterTest extends TestCase | |||
58 | 58 | ||
59 | $meta->expects($this->once()) | 59 | $meta->expects($this->once()) |
60 | ->method('getName') | 60 | ->method('getName') |
61 | ->will($this->returnValue('nothingrelated')); | 61 | ->willReturn('nothingrelated'); |
62 | 62 | ||
63 | $em = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager') | 63 | $em = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager') |
64 | ->disableOriginalConstructor() | 64 | ->disableOriginalConstructor() |
@@ -67,7 +67,7 @@ class UsernameRssTokenConverterTest extends TestCase | |||
67 | $em->expects($this->once()) | 67 | $em->expects($this->once()) |
68 | ->method('getClassMetadata') | 68 | ->method('getClassMetadata') |
69 | ->with('superclass') | 69 | ->with('superclass') |
70 | ->will($this->returnValue($meta)); | 70 | ->willReturn($meta); |
71 | 71 | ||
72 | $registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry') | 72 | $registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry') |
73 | ->disableOriginalConstructor() | 73 | ->disableOriginalConstructor() |
@@ -75,15 +75,15 @@ class UsernameRssTokenConverterTest extends TestCase | |||
75 | 75 | ||
76 | $registry->expects($this->once()) | 76 | $registry->expects($this->once()) |
77 | ->method('getManagers') | 77 | ->method('getManagers') |
78 | ->will($this->returnValue(['default' => null])); | 78 | ->willReturn(['default' => null]); |
79 | 79 | ||
80 | $registry->expects($this->once()) | 80 | $registry->expects($this->once()) |
81 | ->method('getManagerForClass') | 81 | ->method('getManagerForClass') |
82 | ->with('superclass') | 82 | ->with('superclass') |
83 | ->will($this->returnValue($em)); | 83 | ->willReturn($em); |
84 | 84 | ||
85 | $params = new ParamConverter(['class' => 'superclass']); | 85 | $params = new ParamConverter(['class' => 'superclass']); |
86 | $converter = new UsernameRssTokenConverter($registry); | 86 | $converter = new UsernameFeedTokenConverter($registry); |
87 | 87 | ||
88 | $this->assertFalse($converter->supports($params)); | 88 | $this->assertFalse($converter->supports($params)); |
89 | } | 89 | } |
@@ -96,7 +96,7 @@ class UsernameRssTokenConverterTest extends TestCase | |||
96 | 96 | ||
97 | $meta->expects($this->once()) | 97 | $meta->expects($this->once()) |
98 | ->method('getName') | 98 | ->method('getName') |
99 | ->will($this->returnValue('Wallabag\UserBundle\Entity\User')); | 99 | ->willReturn('Wallabag\UserBundle\Entity\User'); |
100 | 100 | ||
101 | $em = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager') | 101 | $em = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager') |
102 | ->disableOriginalConstructor() | 102 | ->disableOriginalConstructor() |
@@ -105,7 +105,7 @@ class UsernameRssTokenConverterTest extends TestCase | |||
105 | $em->expects($this->once()) | 105 | $em->expects($this->once()) |
106 | ->method('getClassMetadata') | 106 | ->method('getClassMetadata') |
107 | ->with('WallabagUserBundle:User') | 107 | ->with('WallabagUserBundle:User') |
108 | ->will($this->returnValue($meta)); | 108 | ->willReturn($meta); |
109 | 109 | ||
110 | $registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry') | 110 | $registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry') |
111 | ->disableOriginalConstructor() | 111 | ->disableOriginalConstructor() |
@@ -113,15 +113,15 @@ class UsernameRssTokenConverterTest extends TestCase | |||
113 | 113 | ||
114 | $registry->expects($this->once()) | 114 | $registry->expects($this->once()) |
115 | ->method('getManagers') | 115 | ->method('getManagers') |
116 | ->will($this->returnValue(['default' => null])); | 116 | ->willReturn(['default' => null]); |
117 | 117 | ||
118 | $registry->expects($this->once()) | 118 | $registry->expects($this->once()) |
119 | ->method('getManagerForClass') | 119 | ->method('getManagerForClass') |
120 | ->with('WallabagUserBundle:User') | 120 | ->with('WallabagUserBundle:User') |
121 | ->will($this->returnValue($em)); | 121 | ->willReturn($em); |
122 | 122 | ||
123 | $params = new ParamConverter(['class' => 'WallabagUserBundle:User']); | 123 | $params = new ParamConverter(['class' => 'WallabagUserBundle:User']); |
124 | $converter = new UsernameRssTokenConverter($registry); | 124 | $converter = new UsernameFeedTokenConverter($registry); |
125 | 125 | ||
126 | $this->assertTrue($converter->supports($params)); | 126 | $this->assertTrue($converter->supports($params)); |
127 | } | 127 | } |
@@ -129,7 +129,7 @@ class UsernameRssTokenConverterTest extends TestCase | |||
129 | public function testApplyEmptyRequest() | 129 | public function testApplyEmptyRequest() |
130 | { | 130 | { |
131 | $params = new ParamConverter([]); | 131 | $params = new ParamConverter([]); |
132 | $converter = new UsernameRssTokenConverter(); | 132 | $converter = new UsernameFeedTokenConverter(); |
133 | 133 | ||
134 | $res = $converter->apply(new Request(), $params); | 134 | $res = $converter->apply(new Request(), $params); |
135 | 135 | ||
@@ -147,9 +147,9 @@ class UsernameRssTokenConverterTest extends TestCase | |||
147 | ->getMock(); | 147 | ->getMock(); |
148 | 148 | ||
149 | $repo->expects($this->once()) | 149 | $repo->expects($this->once()) |
150 | ->method('findOneByUsernameAndRsstoken') | 150 | ->method('findOneByUsernameAndFeedToken') |
151 | ->with('test', 'test') | 151 | ->with('test', 'test') |
152 | ->will($this->returnValue(null)); | 152 | ->willReturn(null); |
153 | 153 | ||
154 | $em = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager') | 154 | $em = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager') |
155 | ->disableOriginalConstructor() | 155 | ->disableOriginalConstructor() |
@@ -158,7 +158,7 @@ class UsernameRssTokenConverterTest extends TestCase | |||
158 | $em->expects($this->once()) | 158 | $em->expects($this->once()) |
159 | ->method('getRepository') | 159 | ->method('getRepository') |
160 | ->with('WallabagUserBundle:User') | 160 | ->with('WallabagUserBundle:User') |
161 | ->will($this->returnValue($repo)); | 161 | ->willReturn($repo); |
162 | 162 | ||
163 | $registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry') | 163 | $registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry') |
164 | ->disableOriginalConstructor() | 164 | ->disableOriginalConstructor() |
@@ -167,10 +167,10 @@ class UsernameRssTokenConverterTest extends TestCase | |||
167 | $registry->expects($this->once()) | 167 | $registry->expects($this->once()) |
168 | ->method('getManagerForClass') | 168 | ->method('getManagerForClass') |
169 | ->with('WallabagUserBundle:User') | 169 | ->with('WallabagUserBundle:User') |
170 | ->will($this->returnValue($em)); | 170 | ->willReturn($em); |
171 | 171 | ||
172 | $params = new ParamConverter(['class' => 'WallabagUserBundle:User']); | 172 | $params = new ParamConverter(['class' => 'WallabagUserBundle:User']); |
173 | $converter = new UsernameRssTokenConverter($registry); | 173 | $converter = new UsernameFeedTokenConverter($registry); |
174 | $request = new Request([], [], ['username' => 'test', 'token' => 'test']); | 174 | $request = new Request([], [], ['username' => 'test', 'token' => 'test']); |
175 | 175 | ||
176 | $converter->apply($request, $params); | 176 | $converter->apply($request, $params); |
@@ -185,9 +185,9 @@ class UsernameRssTokenConverterTest extends TestCase | |||
185 | ->getMock(); | 185 | ->getMock(); |
186 | 186 | ||
187 | $repo->expects($this->once()) | 187 | $repo->expects($this->once()) |
188 | ->method('findOneByUsernameAndRsstoken') | 188 | ->method('findOneByUsernameAndFeedtoken') |
189 | ->with('test', 'test') | 189 | ->with('test', 'test') |
190 | ->will($this->returnValue($user)); | 190 | ->willReturn($user); |
191 | 191 | ||
192 | $em = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager') | 192 | $em = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager') |
193 | ->disableOriginalConstructor() | 193 | ->disableOriginalConstructor() |
@@ -196,7 +196,7 @@ class UsernameRssTokenConverterTest extends TestCase | |||
196 | $em->expects($this->once()) | 196 | $em->expects($this->once()) |
197 | ->method('getRepository') | 197 | ->method('getRepository') |
198 | ->with('WallabagUserBundle:User') | 198 | ->with('WallabagUserBundle:User') |
199 | ->will($this->returnValue($repo)); | 199 | ->willReturn($repo); |
200 | 200 | ||
201 | $registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry') | 201 | $registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry') |
202 | ->disableOriginalConstructor() | 202 | ->disableOriginalConstructor() |
@@ -205,10 +205,10 @@ class UsernameRssTokenConverterTest extends TestCase | |||
205 | $registry->expects($this->once()) | 205 | $registry->expects($this->once()) |
206 | ->method('getManagerForClass') | 206 | ->method('getManagerForClass') |
207 | ->with('WallabagUserBundle:User') | 207 | ->with('WallabagUserBundle:User') |
208 | ->will($this->returnValue($em)); | 208 | ->willReturn($em); |
209 | 209 | ||
210 | $params = new ParamConverter(['class' => 'WallabagUserBundle:User', 'name' => 'user']); | 210 | $params = new ParamConverter(['class' => 'WallabagUserBundle:User', 'name' => 'user']); |
211 | $converter = new UsernameRssTokenConverter($registry); | 211 | $converter = new UsernameFeedTokenConverter($registry); |
212 | $request = new Request([], [], ['username' => 'test', 'token' => 'test']); | 212 | $request = new Request([], [], ['username' => 'test', 'token' => 'test']); |
213 | 213 | ||
214 | $converter->apply($request, $params); | 214 | $converter->apply($request, $params); |
diff --git a/tests/Wallabag/CoreBundle/Tools/UtilsTest.php b/tests/Wallabag/CoreBundle/Tools/UtilsTest.php index 952d076d..c6ed74f0 100644 --- a/tests/Wallabag/CoreBundle/Tools/UtilsTest.php +++ b/tests/Wallabag/CoreBundle/Tools/UtilsTest.php | |||
@@ -11,9 +11,9 @@ class UtilsTest extends TestCase | |||
11 | /** | 11 | /** |
12 | * @dataProvider examples | 12 | * @dataProvider examples |
13 | */ | 13 | */ |
14 | public function testCorrectWordsCountForDifferentLanguages($text, $expectedCount) | 14 | public function testCorrectWordsCountForDifferentLanguages($filename, $text, $expectedCount) |
15 | { | 15 | { |
16 | static::assertSame((float) $expectedCount, Utils::getReadingTime($text)); | 16 | static::assertSame((float) $expectedCount, Utils::getReadingTime($text), 'Reading time for: ' . $filename); |
17 | } | 17 | } |
18 | 18 | ||
19 | public function examples() | 19 | public function examples() |
@@ -21,7 +21,17 @@ class UtilsTest extends TestCase | |||
21 | $examples = []; | 21 | $examples = []; |
22 | $finder = (new Finder())->in(__DIR__ . '/samples'); | 22 | $finder = (new Finder())->in(__DIR__ . '/samples'); |
23 | foreach ($finder->getIterator() as $file) { | 23 | foreach ($finder->getIterator() as $file) { |
24 | $examples[] = [$file->getContents(), 1]; | 24 | preg_match('/-----CONTENT-----\s*(.*?)\s*-----READING_TIME-----\s*(.*)/sx', $file->getContents(), $match); |
25 | |||
26 | if (3 !== \count($match)) { | ||
27 | throw new \Exception('Sample file "' . $file->getRelativePathname() . '" as wrong definition, see README.'); | ||
28 | } | ||
29 | |||
30 | $examples[] = [ | ||
31 | $file->getRelativePathname(), | ||
32 | $match[1], // content | ||
33 | $match[2], // reading time | ||
34 | ]; | ||
25 | } | 35 | } |
26 | 36 | ||
27 | return $examples; | 37 | return $examples; |
diff --git a/tests/Wallabag/CoreBundle/Tools/samples/README b/tests/Wallabag/CoreBundle/Tools/samples/README new file mode 100644 index 00000000..e8f946c0 --- /dev/null +++ b/tests/Wallabag/CoreBundle/Tools/samples/README | |||
@@ -0,0 +1,5 @@ | |||
1 | Defined language sample should use the following structure: | ||
2 | |||
3 | -----CONTENT----- | ||
4 | |||
5 | -----READING_TIME----- | ||
diff --git a/tests/Wallabag/CoreBundle/Tools/samples/chinese.txt b/tests/Wallabag/CoreBundle/Tools/samples/chinese.txt new file mode 100644 index 00000000..864603cb --- /dev/null +++ b/tests/Wallabag/CoreBundle/Tools/samples/chinese.txt | |||
@@ -0,0 +1,10 @@ | |||
1 | -----CONTENT----- | ||
2 | 职然问讲念谷月挂大报住本読能录要褐込。料士纸木陈与兴组静终図问有。今観深车相环学俳健越増职県県多券报。雪月批导掲稿家缝城间真中崩図人连。前担写治芸面毎作似水州稿注球戦頃。済方宮安目垣強入料会先呼略。計定設負財作覧経己員事田事球岡示差学。最院書模婚金回禁朝船教任分禁検理慮宿。 | ||
3 | |||
4 | 変送调指式真気交现上様女限宅复。禁业稿者普视想来木残止者済断式安。万致相领鉄再改界逮由竹式元最台変。済问活助库脳部风政京転说区変。文図化仙政常地里芸上褒前読望误记温政信土。惑育候当人万部逮重申結標番業望般。断瀬後社天打日資交献秀世覧第。補当編里身社記利件部夜中心掲大。 | ||
5 | |||
6 | 时大栗夜测署市要纯京挙化済负品。天最场情算掲放故手茨指岛然渡活民年。第纯交一特问明室试賛际者建。论铜所常縄一広気特秋提公茶可満编旅相変権。 | ||
7 | |||
8 | 兵线済来先决模入供定树希逮技鉄多连写塩。着刊禁浩歩人仕设谢争关周徒今高。十育幕桂球门载任快毎社洋着道育纸格幻末。关机高害通方纳狱社州要北相持中表。郎市真提里过何连地更重都山割周。 | ||
9 | -----READING_TIME----- | ||
10 | 1 | ||
diff --git a/tests/Wallabag/CoreBundle/Tools/samples/cyrillic.txt b/tests/Wallabag/CoreBundle/Tools/samples/cyrillic.txt index 7b904da4..90906d04 100644 --- a/tests/Wallabag/CoreBundle/Tools/samples/cyrillic.txt +++ b/tests/Wallabag/CoreBundle/Tools/samples/cyrillic.txt | |||
@@ -1,7 +1,10 @@ | |||
1 | -----CONTENT----- | ||
1 | Лорем ипсум долор сит амет, ех цум иллуд деленит, пер регионе фацилис те. Еи мел видит саепе интеллегам, яуас маиестатис цонституам яуо ат, цивибус реформиданс нецесситатибус ид яуи. Импетус тациматес пертинах ад еум. Усу еу легере бландит. | 2 | Лорем ипсум долор сит амет, ех цум иллуд деленит, пер регионе фацилис те. Еи мел видит саепе интеллегам, яуас маиестатис цонституам яуо ат, цивибус реформиданс нецесситатибус ид яуи. Импетус тациматес пертинах ад еум. Усу еу легере бландит. |
2 | 3 | ||
3 | Ан меа тритани иуварет, иллум сцаевола легендос ат меа, дебитис импедит нусяуам ест ад. Не маиорум молестие цотидиеяуе вис. Иисяуе цонцлудатуряуе меи еу, татион цонсецтетуер еи про. Либер риденс ид хас, ид цонсул сенсерит пертинациа меа. Фацер молестиае цомпрехенсам ад еум, ин хис апеириан вивендум. Яуи аудире епицуреи иудицабит ат, веро хабео вертерем ад иус. Бонорум плацерат ин вис, сеа но оцурререт принципес интерессет, хас ет дицерет диспутандо. | 4 | Ан меа тритани иуварет, иллум сцаевола легендос ат меа, дебитис импедит нусяуам ест ад. Не маиорум молестие цотидиеяуе вис. Иисяуе цонцлудатуряуе меи еу, татион цонсецтетуер еи про. Либер риденс ид хас, ид цонсул сенсерит пертинациа меа. Фацер молестиае цомпрехенсам ад еум, ин хис апеириан вивендум. Яуи аудире епицуреи иудицабит ат, веро хабео вертерем ад иус. Бонорум плацерат ин вис, сеа но оцурререт принципес интерессет, хас ет дицерет диспутандо. |
4 | 5 | ||
5 | Яуо цу цлита оцурререт. Сонет менандри ин сеа. Еум те нонумы вертерем. Вирис еяуидем фацилиси ет вим, делицата интеллегат иус ин. Ид дицат суммо витае вел, алияуип делецтус те дуо, цу вих хинц дуис видиссе. Нец цу фацилис урбанитас, алиа инсоленс ассуеверит при ут. | 6 | Яуо цу цлита оцурререт. Сонет менандри ин сеа. Еум те нонумы вертерем. Вирис еяуидем фацилиси ет вим, делицата интеллегат иус ин. Ид дицат суммо витае вел, алияуип делецтус те дуо, цу вих хинц дуис видиссе. Нец цу фацилис урбанитас, алиа инсоленс ассуеверит при ут. |
6 | 7 | ||
7 | Яуаеяуе абхорреант инцоррупте не сеа, еу еирмод ерудити вих. Вел оптион тритани цоррумпит те. Поссе сусципит губергрен ут мел, ет еос ириуре менандри еффициенди. Те сале нулла цонсецтетуер сеа, меа не прима алиенум еффициантур. При ет воцибус реформиданс, темпор албуциус сед ан. Еи утрояуе волумус иус, атяуи цонгуе но меи. \ No newline at end of file | 8 | Яуаеяуе абхорреант инцоррупте не сеа, еу еирмод ерудити вих. Вел оптион тритани цоррумпит те. Поссе сусципит губергрен ут мел, ет еос ириуре менандри еффициенди. Те сале нулла цонсецтетуер сеа, меа не прима алиенум еффициантур. При ет воцибус реформиданс, темпор албуциус сед ан. Еи утрояуе волумус иус, атяуи цонгуе но меи. |
9 | -----READING_TIME----- | ||
10 | 1 | ||
diff --git a/tests/Wallabag/CoreBundle/Tools/samples/greek.txt b/tests/Wallabag/CoreBundle/Tools/samples/greek.txt index 59f15b8b..f8ade0d7 100644 --- a/tests/Wallabag/CoreBundle/Tools/samples/greek.txt +++ b/tests/Wallabag/CoreBundle/Tools/samples/greek.txt | |||
@@ -1,3 +1,4 @@ | |||
1 | -----CONTENT----- | ||
1 | Λορεμ ιπσθμ δολορ σιτ αμετ, ηασ νο θταμθρ qθαεqθε ρεπρεηενδθντ. Ναμ λατινε προμπτα qθαερενδθμ ιδ. Νεc ει φαcερ cονcλθδατθρqθε, vολθπτθα vολθπταρια εφφιcιενδι αδ προ, νε σεα ασσεντιορ δεφινιεβασ. Μεα αγαμ ειθσ δολορε ετ, ηισ ει cορπορα περφεcτο. Vιξ cιβο δελενιτ νε, jθστο ριδενσ οπορτερε σεδ ιδ. | 2 | Λορεμ ιπσθμ δολορ σιτ αμετ, ηασ νο θταμθρ qθαεqθε ρεπρεηενδθντ. Ναμ λατινε προμπτα qθαερενδθμ ιδ. Νεc ει φαcερ cονcλθδατθρqθε, vολθπτθα vολθπταρια εφφιcιενδι αδ προ, νε σεα ασσεντιορ δεφινιεβασ. Μεα αγαμ ειθσ δολορε ετ, ηισ ει cορπορα περφεcτο. Vιξ cιβο δελενιτ νε, jθστο ριδενσ οπορτερε σεδ ιδ. |
2 | 3 | ||
3 | Ηισ νισλ ιθvαρετ γθβεργρεν εξ. Εθμ ιμπεδιτ δετραξιτ ινιμιcθσ ατ, αλια βλανδιτ δθο εα, μεα ιλλθδ επιcθρι cονσετετθρ αδ. Ιλλθδ γραεcε δελενιτι ηισ νο. Νεc ιδ ριδενσ εθισμοδ περιcθλισ, vισ αδ λαβοραμθσ περσεcθτι. Ιθσ εα λθπτατθμ αλιqθανδο δισπθτανδο. | 4 | Ηισ νισλ ιθvαρετ γθβεργρεν εξ. Εθμ ιμπεδιτ δετραξιτ ινιμιcθσ ατ, αλια βλανδιτ δθο εα, μεα ιλλθδ επιcθρι cονσετετθρ αδ. Ιλλθδ γραεcε δελενιτι ηισ νο. Νεc ιδ ριδενσ εθισμοδ περιcθλισ, vισ αδ λαβοραμθσ περσεcθτι. Ιθσ εα λθπτατθμ αλιqθανδο δισπθτανδο. |
@@ -6,4 +7,6 @@ | |||
6 | 7 | ||
7 | Cθ σεδ αλβθcιθσ ποστθλαντ. Vιξ ιδ ηομερο περcιπιτ cονcεπταμ. Ιν vιμ λιβρισ vιδερερ, εξ vισ αλιι ερρορ. Vιξ λοβορτισ ασσεντιορ cοντεντιονεσ τε, νε ηασ δεcορε περcιπιτθρ. Εστ εξ δισπθτατιονι δεφινιτιονεμ, qθοδ πηαεδρθμ προ εθ, εξ ηασ ιντεγρε ελιγενδι cονσεcτετθερ. | 8 | Cθ σεδ αλβθcιθσ ποστθλαντ. Vιξ ιδ ηομερο περcιπιτ cονcεπταμ. Ιν vιμ λιβρισ vιδερερ, εξ vισ αλιι ερρορ. Vιξ λοβορτισ ασσεντιορ cοντεντιονεσ τε, νε ηασ δεcορε περcιπιτθρ. Εστ εξ δισπθτατιονι δεφινιτιονεμ, qθοδ πηαεδρθμ προ εθ, εξ ηασ ιντεγρε ελιγενδι cονσεcτετθερ. |
8 | 9 | ||
9 | Ιθσ μολλισ ειρμοδ νο, vιξ νοστρθμ cονσετετθρ ει. Ιθδιcο vερτερεμ λθcιλιθσ qθι τε, νε προμπτα θτροqθε αccομμοδαρε περ. Φαcετε μανδαμθσ ηασ εξ, λιβερ δεβετ εθμ εξ, vιξ ιδ διcερετ σιγνιφερθμqθε. Εθ vιξ vοcεντ. \ No newline at end of file | 10 | Ιθσ μολλισ ειρμοδ νο, vιξ νοστρθμ cονσετετθρ ει. Ιθδιcο vερτερεμ λθcιλιθσ qθι τε, νε προμπτα θτροqθε αccομμοδαρε περ. Φαcετε μανδαμθσ ηασ εξ, λιβερ δεβετ εθμ εξ, vιξ ιδ διcερετ σιγνιφερθμqθε. Εθ vιξ vοcεντ. |
11 | -----READING_TIME----- | ||
12 | 1 | ||
diff --git a/tests/Wallabag/CoreBundle/Tools/samples/japanese.txt b/tests/Wallabag/CoreBundle/Tools/samples/japanese.txt new file mode 100644 index 00000000..013a8d74 --- /dev/null +++ b/tests/Wallabag/CoreBundle/Tools/samples/japanese.txt | |||
@@ -0,0 +1,10 @@ | |||
1 | -----CONTENT----- | ||
2 | 聞7配なク時初かきぴ触整ヨ国鴨覧女ミ将増3部ゅ見荷や言企まげやラ千第ロル企族リた期寄け。戦ト理載コミチヒ芸面だ会入テヒロソ一期ナトヒ試鮮せお天出並ぞる体森ヘツノ決市ね地各ナク強町ず前目とまなを活直オ携握湯りよ。 | ||
3 | |||
4 | 流ムワ作大禁ヒフ断日ヱ断千ね消諸もとぐろ中勧リ配年リ文7茅ろへりめ辺渡フ三負安ぼ国撮ライム以逃めじット州67棋うきゃ。催キケ者乗フヒソツ染64崎ク捉示よぴふら道世へび属品おく西捕ニレ交重イフ式買散ル展五めづっイ鎧属ざごび数開キハツ聞続表クシタ補球ソウ禁源託ひれも。 | ||
5 | |||
6 | 季手ッがふ挙思メ勢1使すけねげ日熱争らあふか位義エコ望桑安く決管ーひ広間キヱ皇北ょはこ養山ミ放見負さぞて故携訃畑港ひわン。著支にふみ意豊ラだ球監トクユ馬惨が抱審リヒ労厚ゅぽひ継貸ミノ果疑文キヤ闘府兼ユカシト多不っあ財責エ速訴径猶げすぽ。 | ||
7 | |||
8 | 了摘見いぶころ会料へゆぱ法利コツハリ統財千りイ伝年りぜ提社ロ片追ごー合作イカシニ感山よち真器敗香レれさ。視シ探大イ令69真ケトヱ便都ケホワナ境号ヱカオハ一助む関念ろんび幼脚要だ客投ヱハイ針教ヒノウラ階担うスりね袖陸ょげけ同講ノ料全ヤ催宮補ゆ徳就画圧愛め。 | ||
9 | -----READING_TIME----- | ||
10 | 1 | ||
diff --git a/tests/Wallabag/CoreBundle/Tools/samples/korean.txt b/tests/Wallabag/CoreBundle/Tools/samples/korean.txt new file mode 100644 index 00000000..e3ef2af6 --- /dev/null +++ b/tests/Wallabag/CoreBundle/Tools/samples/korean.txt | |||
@@ -0,0 +1,10 @@ | |||
1 | -----CONTENT----- | ||
2 | 국군은 국가의 안전보장과 국토방위의 신성한 의무를 수행함을 사명으로 하며, 대통령이 임시회의 집회를 요구할 때에는 기간과 집회요구의 이유를 명시하여야 한다. 정당의 목적이나 활동이 민주적 기본질서에 위배될 때에는 정부는 헌법재판소에 그 해산을 제소할 수 있고. 감사위원은 원장의 제청으로 대통령이 임명하고. | ||
3 | |||
4 | 대한민국의 주권은 국민에게 있고, 국회는 국민의 보통·평등·직접·비밀선거에 의하여 선출된 국회의원으로 구성한다. 국가는 농업 및 어업을 보호·육성하기 위하여 농·어촌종합개발과 그 지원등 필요한 계획을 수립·시행하여야 한다. 대통령의 임기연장 또는 중임변경을 위한 헌법개정은 그 헌법개정 제안 당시의 대통령에 대하여는 효력이 없다. | ||
5 | |||
6 | 국회가 재적의원 과반수의 찬성으로 계엄의 해제를 요구한 때에는 대통령은 이를 해제하여야 한다, 선거에 관한 경비는 법률이 정하는 경우를 제외하고는 정당 또는 후보자에게 부담시킬 수 없다. 그 정치적 중립성은 준수된다. 헌법개정안은 국회가 의결한 후 30일 이내에 국민투표에 붙여 국회의원선거권자 과반수의 투표와 투표자 과반수의 찬성을 얻어야 한다. | ||
7 | |||
8 | 내부규율과 사무처리에 관한 규칙을 제정할 수 있다. 대통령에 대한 탄핵소추는 국회재적의원 과반수의 발의와 국회재적의원 3분의 2 이상의 찬성이 있어야 한다. 대통령은 국가의 원수이며. 대통령이 궐위된 때 또는 대통령 당선자가 사망하거나 판결 기타의 사유로 그 자격을 상실한 때에는 60일 이내에 후임자를 선거한다. | ||
9 | -----READING_TIME----- | ||
10 | 2 | ||
diff --git a/tests/Wallabag/CoreBundle/Tools/samples/latin.txt b/tests/Wallabag/CoreBundle/Tools/samples/latin.txt index 605cc40e..27988597 100644 --- a/tests/Wallabag/CoreBundle/Tools/samples/latin.txt +++ b/tests/Wallabag/CoreBundle/Tools/samples/latin.txt | |||
@@ -1,3 +1,4 @@ | |||
1 | -----CONTENT----- | ||
1 | Lorem 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 | Lorem 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 | 3 | ||
3 | Tation 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 | Tation 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. |
@@ -6,4 +7,6 @@ Eam an lucilius iracundia, audire diceret facilisi his in, ex paulo pertinacia p | |||
6 | 7 | ||
7 | Nec 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 | Nec 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 | 9 | ||
9 | Vix. \ No newline at end of file | 10 | Vix. |
11 | -----READING_TIME----- | ||
12 | 1 | ||
diff --git a/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php b/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php index bb92f745..39fcec16 100644 --- a/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php +++ b/tests/Wallabag/CoreBundle/Twig/WallabagExtensionTest.php | |||
@@ -32,6 +32,31 @@ class WallabagExtensionTest extends TestCase | |||
32 | $this->assertSame('gist.github.com', $extension->removeWww('gist.github.com')); | 32 | $this->assertSame('gist.github.com', $extension->removeWww('gist.github.com')); |
33 | } | 33 | } |
34 | 34 | ||
35 | public function testRemoveScheme() | ||
36 | { | ||
37 | $entryRepository = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') | ||
38 | ->disableOriginalConstructor() | ||
39 | ->getMock(); | ||
40 | |||
41 | $tagRepository = $this->getMockBuilder('Wallabag\CoreBundle\Repository\TagRepository') | ||
42 | ->disableOriginalConstructor() | ||
43 | ->getMock(); | ||
44 | |||
45 | $tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface') | ||
46 | ->disableOriginalConstructor() | ||
47 | ->getMock(); | ||
48 | |||
49 | $translator = $this->getMockBuilder('Symfony\Component\Translation\TranslatorInterface') | ||
50 | ->disableOriginalConstructor() | ||
51 | ->getMock(); | ||
52 | |||
53 | $extension = new WallabagExtension($entryRepository, $tagRepository, $tokenStorage, 0, $translator); | ||
54 | |||
55 | $this->assertSame('lemonde.fr', $extension->removeScheme('lemonde.fr')); | ||
56 | $this->assertSame('gist.github.com', $extension->removeScheme('gist.github.com')); | ||
57 | $this->assertSame('gist.github.com', $extension->removeScheme('https://gist.github.com')); | ||
58 | } | ||
59 | |||
35 | public function testRemoveSchemeAndWww() | 60 | public function testRemoveSchemeAndWww() |
36 | { | 61 | { |
37 | $entryRepository = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') | 62 | $entryRepository = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') |
diff --git a/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php b/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php index 6e1163c5..816d22f4 100644 --- a/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php +++ b/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php | |||
@@ -84,8 +84,8 @@ abstract class WallabagCoreTestCase extends WebTestCase | |||
84 | $container = $this->client->getContainer(); | 84 | $container = $this->client->getContainer(); |
85 | $session = $container->get('session'); | 85 | $session = $container->get('session'); |
86 | 86 | ||
87 | $userManager = $container->get('fos_user.user_manager'); | 87 | $userManager = $container->get('fos_user.user_manager.test'); |
88 | $loginManager = $container->get('fos_user.security.login_manager'); | 88 | $loginManager = $container->get('fos_user.security.login_manager.test'); |
89 | $firewallName = $container->getParameter('fos_user.firewall_name'); | 89 | $firewallName = $container->getParameter('fos_user.firewall_name'); |
90 | 90 | ||
91 | $user = $userManager->findUserBy(['username' => $username]); | 91 | $user = $userManager->findUserBy(['username' => $username]); |
diff --git a/tests/Wallabag/CoreBundle/fixtures/tagging_rules_admin.json b/tests/Wallabag/CoreBundle/fixtures/tagging_rules_admin.json new file mode 100644 index 00000000..a54824e2 --- /dev/null +++ b/tests/Wallabag/CoreBundle/fixtures/tagging_rules_admin.json | |||
@@ -0,0 +1,4 @@ | |||
1 | [{ | ||
2 | "rule": "title matches \"football\"", | ||
3 | "tags": ["football"] | ||
4 | }] | ||
diff --git a/tests/Wallabag/ImportBundle/Command/ImportCommandTest.php b/tests/Wallabag/ImportBundle/Command/ImportCommandTest.php index f95320a4..8e1c528d 100644 --- a/tests/Wallabag/ImportBundle/Command/ImportCommandTest.php +++ b/tests/Wallabag/ImportBundle/Command/ImportCommandTest.php | |||
@@ -84,6 +84,8 @@ class ImportCommandTest extends WallabagCoreTestCase | |||
84 | 84 | ||
85 | public function testRunImportCommandWithUserId() | 85 | public function testRunImportCommandWithUserId() |
86 | { | 86 | { |
87 | $this->logInAs('admin'); | ||
88 | |||
87 | $application = new Application($this->getClient()->getKernel()); | 89 | $application = new Application($this->getClient()->getKernel()); |
88 | $application->add(new ImportCommand()); | 90 | $application->add(new ImportCommand()); |
89 | 91 | ||
@@ -92,7 +94,7 @@ class ImportCommandTest extends WallabagCoreTestCase | |||
92 | $tester = new CommandTester($command); | 94 | $tester = new CommandTester($command); |
93 | $tester->execute([ | 95 | $tester->execute([ |
94 | 'command' => $command->getName(), | 96 | 'command' => $command->getName(), |
95 | 'username' => 1, | 97 | 'username' => $this->getLoggedInUserId(), |
96 | 'filepath' => $application->getKernel()->getContainer()->getParameter('kernel.project_dir') . '/tests/Wallabag/ImportBundle/fixtures/wallabag-v2-read.json', | 98 | 'filepath' => $application->getKernel()->getContainer()->getParameter('kernel.project_dir') . '/tests/Wallabag/ImportBundle/fixtures/wallabag-v2-read.json', |
97 | '--useUserId' => true, | 99 | '--useUserId' => true, |
98 | '--importer' => 'v2', | 100 | '--importer' => 'v2', |
diff --git a/tests/Wallabag/ImportBundle/Consumer/AMQPEntryConsumerTest.php b/tests/Wallabag/ImportBundle/Consumer/AMQPEntryConsumerTest.php index b2141c04..b7f6192d 100644 --- a/tests/Wallabag/ImportBundle/Consumer/AMQPEntryConsumerTest.php +++ b/tests/Wallabag/ImportBundle/Consumer/AMQPEntryConsumerTest.php | |||
@@ -1,6 +1,6 @@ | |||
1 | <?php | 1 | <?php |
2 | 2 | ||
3 | namespace Tests\Wallabag\ImportBundle\Consumer\AMQP; | 3 | namespace Tests\Wallabag\ImportBundle\Consumer; |
4 | 4 | ||
5 | use PhpAmqpLib\Message\AMQPMessage; | 5 | use PhpAmqpLib\Message\AMQPMessage; |
6 | use PHPUnit\Framework\TestCase; | 6 | use PHPUnit\Framework\TestCase; |
diff --git a/tests/Wallabag/ImportBundle/Consumer/RedisEntryConsumerTest.php b/tests/Wallabag/ImportBundle/Consumer/RedisEntryConsumerTest.php index 61337e47..e1bd8827 100644 --- a/tests/Wallabag/ImportBundle/Consumer/RedisEntryConsumerTest.php +++ b/tests/Wallabag/ImportBundle/Consumer/RedisEntryConsumerTest.php | |||
@@ -1,6 +1,6 @@ | |||
1 | <?php | 1 | <?php |
2 | 2 | ||
3 | namespace Tests\Wallabag\ImportBundle\Consumer\AMQP; | 3 | namespace Tests\Wallabag\ImportBundle\Consumer; |
4 | 4 | ||
5 | use PHPUnit\Framework\TestCase; | 5 | use PHPUnit\Framework\TestCase; |
6 | use Wallabag\CoreBundle\Entity\Entry; | 6 | use Wallabag\CoreBundle\Entity\Entry; |
diff --git a/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php index cd3e41e9..d3ffbb6d 100644 --- a/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php | |||
@@ -121,7 +121,7 @@ class ChromeControllerTest extends WallabagCoreTestCase | |||
121 | $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); | 121 | $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); |
122 | $this->assertNotEmpty($content->getPreviewPicture(), 'Preview picture for http://www.usinenouvelle.com is ok'); | 122 | $this->assertNotEmpty($content->getPreviewPicture(), 'Preview picture for http://www.usinenouvelle.com is ok'); |
123 | $this->assertNotEmpty($content->getLanguage(), 'Language for http://www.usinenouvelle.com is ok'); | 123 | $this->assertNotEmpty($content->getLanguage(), 'Language for http://www.usinenouvelle.com is ok'); |
124 | $this->assertSame(1, \count($content->getTags())); | 124 | $this->assertCount(1, $content->getTags()); |
125 | 125 | ||
126 | $createdAt = $content->getCreatedAt(); | 126 | $createdAt = $content->getCreatedAt(); |
127 | $this->assertSame('2011', $createdAt->format('Y')); | 127 | $this->assertSame('2011', $createdAt->format('Y')); |
diff --git a/tests/Wallabag/ImportBundle/Controller/ElcuratorControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ElcuratorControllerTest.php new file mode 100644 index 00000000..b9919f8f --- /dev/null +++ b/tests/Wallabag/ImportBundle/Controller/ElcuratorControllerTest.php | |||
@@ -0,0 +1,132 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Tests\Wallabag\ImportBundle\Controller; | ||
4 | |||
5 | use Symfony\Component\HttpFoundation\File\UploadedFile; | ||
6 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | ||
7 | |||
8 | class ElcuratorControllerTest extends WallabagCoreTestCase | ||
9 | { | ||
10 | public function testImportElcurator() | ||
11 | { | ||
12 | $this->logInAs('admin'); | ||
13 | $client = $this->getClient(); | ||
14 | |||
15 | $crawler = $client->request('GET', '/import/elcurator'); | ||
16 | |||
17 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | ||
18 | $this->assertSame(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); | ||
19 | $this->assertSame(1, $crawler->filter('input[type=file]')->count()); | ||
20 | } | ||
21 | |||
22 | public function testImportElcuratorWithRabbitEnabled() | ||
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/elcurator'); | ||
30 | |||
31 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | ||
32 | $this->assertSame(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); | ||
33 | $this->assertSame(1, $crawler->filter('input[type=file]')->count()); | ||
34 | |||
35 | $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 0); | ||
36 | } | ||
37 | |||
38 | public function testImportElcuratorBadFile() | ||
39 | { | ||
40 | $this->logInAs('admin'); | ||
41 | $client = $this->getClient(); | ||
42 | |||
43 | $crawler = $client->request('GET', '/import/elcurator'); | ||
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->assertSame(200, $client->getResponse()->getStatusCode()); | ||
53 | } | ||
54 | |||
55 | public function testImportElcuratorWithRedisEnabled() | ||
56 | { | ||
57 | $this->checkRedis(); | ||
58 | $this->logInAs('admin'); | ||
59 | $client = $this->getClient(); | ||
60 | |||
61 | $client->getContainer()->get('craue_config')->set('import_with_redis', 1); | ||
62 | |||
63 | $crawler = $client->request('GET', '/import/elcurator'); | ||
64 | |||
65 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | ||
66 | $this->assertSame(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); | ||
67 | $this->assertSame(1, $crawler->filter('input[type=file]')->count()); | ||
68 | |||
69 | $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); | ||
70 | |||
71 | $file = new UploadedFile(__DIR__ . '/../fixtures/elcurator.json', 'elcurator.json'); | ||
72 | |||
73 | $data = [ | ||
74 | 'upload_import_file[file]' => $file, | ||
75 | ]; | ||
76 | |||
77 | $client->submit($form, $data); | ||
78 | |||
79 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | ||
80 | |||
81 | $crawler = $client->followRedirect(); | ||
82 | |||
83 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | ||
84 | $this->assertContains('flashes.import.notice.summary', $body[0]); | ||
85 | |||
86 | $this->assertNotEmpty($client->getContainer()->get('wallabag_core.redis.client')->lpop('wallabag.import.elcurator')); | ||
87 | |||
88 | $client->getContainer()->get('craue_config')->set('import_with_redis', 0); | ||
89 | } | ||
90 | |||
91 | public function testImportElcuratorWithFile() | ||
92 | { | ||
93 | $this->logInAs('admin'); | ||
94 | $client = $this->getClient(); | ||
95 | |||
96 | $crawler = $client->request('GET', '/import/elcurator'); | ||
97 | $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); | ||
98 | |||
99 | $file = new UploadedFile(__DIR__ . '/../fixtures/elcurator.json', 'elcurator.json'); | ||
100 | |||
101 | $data = [ | ||
102 | 'upload_import_file[file]' => $file, | ||
103 | ]; | ||
104 | |||
105 | $client->submit($form, $data); | ||
106 | |||
107 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | ||
108 | |||
109 | $crawler = $client->followRedirect(); | ||
110 | |||
111 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | ||
112 | $this->assertContains('flashes.import.notice.summary', $body[0]); | ||
113 | |||
114 | $content = $client->getContainer() | ||
115 | ->get('doctrine.orm.entity_manager') | ||
116 | ->getRepository('WallabagCoreBundle:Entry') | ||
117 | ->findByUrlAndUserId( | ||
118 | 'https://devblog.lexik.fr/git/qualite-de-code-integration-de-php-git-hooks-dans-symfony2-2842', | ||
119 | $this->getLoggedInUserId() | ||
120 | ); | ||
121 | |||
122 | $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); | ||
123 | |||
124 | $this->assertSame('Qualité de code - Intégration de php-git-hooks dans Symfony2 - Experts Symfony et Drupal - Lexik', $content->getTitle()); | ||
125 | $this->assertSame('2015-09-09', $content->getCreatedAt()->format('Y-m-d')); | ||
126 | $this->assertTrue($content->isStarred(), 'Entry is starred'); | ||
127 | |||
128 | $tags = $content->getTags(); | ||
129 | $this->assertContains('tag1', $tags, 'It includes the "tag1" tag'); | ||
130 | $this->assertContains('tag2', $tags, 'It includes the "tag2" tag'); | ||
131 | } | ||
132 | } | ||
diff --git a/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php b/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php index dc5ed6d0..3e64f2e5 100644 --- a/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php | |||
@@ -122,7 +122,7 @@ class FirefoxControllerTest extends WallabagCoreTestCase | |||
122 | $this->assertNotEmpty($content->getMimetype(), 'Mimetype for http://lexpansion.lexpress.fr is ok'); | 122 | $this->assertNotEmpty($content->getMimetype(), 'Mimetype for http://lexpansion.lexpress.fr is ok'); |
123 | $this->assertNotEmpty($content->getPreviewPicture(), 'Preview picture for http://lexpansion.lexpress.fr is ok'); | 123 | $this->assertNotEmpty($content->getPreviewPicture(), 'Preview picture for http://lexpansion.lexpress.fr is ok'); |
124 | $this->assertNotEmpty($content->getLanguage(), 'Language for http://lexpansion.lexpress.fr is ok'); | 124 | $this->assertNotEmpty($content->getLanguage(), 'Language for http://lexpansion.lexpress.fr is ok'); |
125 | $this->assertSame(3, \count($content->getTags())); | 125 | $this->assertCount(3, $content->getTags()); |
126 | 126 | ||
127 | $content = $client->getContainer() | 127 | $content = $client->getContainer() |
128 | ->get('doctrine.orm.entity_manager') | 128 | ->get('doctrine.orm.entity_manager') |
diff --git a/tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php index e1ec7c65..f0edb78d 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->assertSame(200, $client->getResponse()->getStatusCode()); | 26 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
27 | $this->assertSame(8, $crawler->filter('blockquote')->count()); | 27 | $this->assertSame(9, $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 7390fa88..05347767 100644 --- a/tests/Wallabag/ImportBundle/Controller/InstapaperControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/InstapaperControllerTest.php | |||
@@ -124,7 +124,7 @@ class InstapaperControllerTest extends WallabagCoreTestCase | |||
124 | $this->assertNotEmpty($content->getPreviewPicture(), 'Preview picture for https://www.liberation.fr is ok'); | 124 | $this->assertNotEmpty($content->getPreviewPicture(), 'Preview picture for https://www.liberation.fr is ok'); |
125 | $this->assertNotEmpty($content->getLanguage(), 'Language for https://www.liberation.fr is ok'); | 125 | $this->assertNotEmpty($content->getLanguage(), 'Language for https://www.liberation.fr is ok'); |
126 | $this->assertContains('foot', $content->getTags(), 'It includes the "foot" tag'); | 126 | $this->assertContains('foot', $content->getTags(), 'It includes the "foot" tag'); |
127 | $this->assertSame(1, \count($content->getTags())); | 127 | $this->assertCount(1, $content->getTags()); |
128 | $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt()); | 128 | $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt()); |
129 | 129 | ||
130 | $content = $client->getContainer() | 130 | $content = $client->getContainer() |
@@ -138,7 +138,7 @@ class InstapaperControllerTest extends WallabagCoreTestCase | |||
138 | $this->assertContains('foot', $content->getTags()); | 138 | $this->assertContains('foot', $content->getTags()); |
139 | $this->assertContains('test_tag', $content->getTags()); | 139 | $this->assertContains('test_tag', $content->getTags()); |
140 | 140 | ||
141 | $this->assertSame(2, \count($content->getTags())); | 141 | $this->assertCount(2, $content->getTags()); |
142 | } | 142 | } |
143 | 143 | ||
144 | public function testImportInstapaperWithFileAndMarkAllAsRead() | 144 | public function testImportInstapaperWithFileAndMarkAllAsRead() |
diff --git a/tests/Wallabag/ImportBundle/Controller/PinboardControllerTest.php b/tests/Wallabag/ImportBundle/Controller/PinboardControllerTest.php index 80819f45..963759b1 100644 --- a/tests/Wallabag/ImportBundle/Controller/PinboardControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/PinboardControllerTest.php | |||
@@ -121,13 +121,13 @@ class PinboardControllerTest extends WallabagCoreTestCase | |||
121 | $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); | 121 | $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); |
122 | $this->assertNotEmpty($content->getMimetype(), 'Mimetype for https://ma.ttias.be is ok'); | 122 | $this->assertNotEmpty($content->getMimetype(), 'Mimetype for https://ma.ttias.be is ok'); |
123 | $this->assertNotEmpty($content->getPreviewPicture(), 'Preview picture for https://ma.ttias.be is ok'); | 123 | $this->assertNotEmpty($content->getPreviewPicture(), 'Preview picture for https://ma.ttias.be is ok'); |
124 | $this->assertNotEmpty($content->getLanguage(), 'Language for https://ma.ttias.be is ok'); | 124 | $this->assertNull($content->getLanguage(), 'Language for https://ma.ttias.be is null'); |
125 | 125 | ||
126 | $tags = $content->getTags(); | 126 | $tags = $content->getTags(); |
127 | $this->assertContains('foot', $tags, 'It includes the "foot" tag'); | 127 | $this->assertContains('foot', $tags, 'It includes the "foot" tag'); |
128 | $this->assertContains('varnish', $tags, 'It includes the "varnish" tag'); | 128 | $this->assertContains('varnish', $tags, 'It includes the "varnish" tag'); |
129 | $this->assertContains('php', $tags, 'It includes the "php" tag'); | 129 | $this->assertContains('php', $tags, 'It includes the "php" tag'); |
130 | $this->assertSame(3, \count($tags)); | 130 | $this->assertCount(3, $tags); |
131 | 131 | ||
132 | $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt()); | 132 | $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt()); |
133 | $this->assertSame('2016-10-26', $content->getCreatedAt()->format('Y-m-d')); | 133 | $this->assertSame('2016-10-26', $content->getCreatedAt()->format('Y-m-d')); |
diff --git a/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php index 5619659a..4f2f4053 100644 --- a/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php | |||
@@ -125,7 +125,7 @@ class ReadabilityControllerTest extends WallabagCoreTestCase | |||
125 | 125 | ||
126 | $tags = $content->getTags(); | 126 | $tags = $content->getTags(); |
127 | $this->assertContains('foot', $tags, 'It includes the "foot" tag'); | 127 | $this->assertContains('foot', $tags, 'It includes the "foot" tag'); |
128 | $this->assertSame(1, \count($tags)); | 128 | $this->assertCount(1, $tags); |
129 | 129 | ||
130 | $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt()); | 130 | $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt()); |
131 | $this->assertSame('2016-09-08', $content->getCreatedAt()->format('Y-m-d')); | 131 | $this->assertSame('2016-09-08', $content->getCreatedAt()->format('Y-m-d')); |
diff --git a/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php b/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php index c67941a7..2a8e7c89 100644 --- a/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php | |||
@@ -121,13 +121,13 @@ class WallabagV1ControllerTest extends WallabagCoreTestCase | |||
121 | 121 | ||
122 | $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); | 122 | $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); |
123 | $this->assertEmpty($content->getMimetype(), 'Mimetype for http://www.framablog.org is empty'); | 123 | $this->assertEmpty($content->getMimetype(), 'Mimetype for http://www.framablog.org is empty'); |
124 | $this->assertEmpty($content->getPreviewPicture(), 'Preview picture for http://www.framablog.org is empty'); | 124 | $this->assertSame($content->getPreviewPicture(), 'http://www.framablog.org/public/_img/framablog/wallaby_baby.jpg'); |
125 | $this->assertEmpty($content->getLanguage(), 'Language for http://www.framablog.org is empty'); | 125 | $this->assertEmpty($content->getLanguage(), 'Language for http://www.framablog.org is empty'); |
126 | 126 | ||
127 | $tags = $content->getTags(); | 127 | $tags = $content->getTags(); |
128 | $this->assertContains('foot', $tags, 'It includes the "foot" tag'); | 128 | $this->assertContains('foot', $tags, 'It includes the "foot" tag'); |
129 | $this->assertContains('framabag', $tags, 'It includes the "framabag" tag'); | 129 | $this->assertContains('framabag', $tags, 'It includes the "framabag" tag'); |
130 | $this->assertSame(2, \count($tags)); | 130 | $this->assertCount(2, $tags); |
131 | 131 | ||
132 | $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt()); | 132 | $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt()); |
133 | } | 133 | } |
diff --git a/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php b/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php index 822656ba..b606e26a 100644 --- a/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php | |||
@@ -128,7 +128,7 @@ class WallabagV2ControllerTest extends WallabagCoreTestCase | |||
128 | 128 | ||
129 | $tags = $content->getTags(); | 129 | $tags = $content->getTags(); |
130 | $this->assertContains('foot', $tags, 'It includes the "foot" tag'); | 130 | $this->assertContains('foot', $tags, 'It includes the "foot" tag'); |
131 | $this->assertSame(1, \count($tags)); | 131 | $this->assertCount(1, $tags); |
132 | 132 | ||
133 | $content = $client->getContainer() | 133 | $content = $client->getContainer() |
134 | ->get('doctrine.orm.entity_manager') | 134 | ->get('doctrine.orm.entity_manager') |
@@ -147,7 +147,7 @@ class WallabagV2ControllerTest extends WallabagCoreTestCase | |||
147 | $this->assertContains('foot', $tags, 'It includes the "foot" tag'); | 147 | $this->assertContains('foot', $tags, 'It includes the "foot" tag'); |
148 | $this->assertContains('mediapart', $tags, 'It includes the "mediapart" tag'); | 148 | $this->assertContains('mediapart', $tags, 'It includes the "mediapart" tag'); |
149 | $this->assertContains('blog', $tags, 'It includes the "blog" tag'); | 149 | $this->assertContains('blog', $tags, 'It includes the "blog" tag'); |
150 | $this->assertSame(3, \count($tags)); | 150 | $this->assertCount(3, $tags); |
151 | 151 | ||
152 | $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt()); | 152 | $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt()); |
153 | $this->assertSame('2016-09-08', $content->getCreatedAt()->format('Y-m-d')); | 153 | $this->assertSame('2016-09-08', $content->getCreatedAt()->format('Y-m-d')); |
diff --git a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php index baa5d905..40e1626b 100644 --- a/tests/Wallabag/ImportBundle/Import/PocketImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/PocketImportTest.php | |||
@@ -2,10 +2,8 @@ | |||
2 | 2 | ||
3 | namespace Tests\Wallabag\ImportBundle\Import; | 3 | namespace Tests\Wallabag\ImportBundle\Import; |
4 | 4 | ||
5 | use GuzzleHttp\Client; | 5 | use GuzzleHttp\Psr7\Response; |
6 | use GuzzleHttp\Message\Response; | 6 | use Http\Mock\Client as HttpMockClient; |
7 | use GuzzleHttp\Stream\Stream; | ||
8 | use GuzzleHttp\Subscriber\Mock; | ||
9 | use M6Web\Component\RedisMock\RedisMockFactory; | 7 | use M6Web\Component\RedisMock\RedisMockFactory; |
10 | use Monolog\Handler\TestHandler; | 8 | use Monolog\Handler\TestHandler; |
11 | use Monolog\Logger; | 9 | use Monolog\Logger; |
@@ -38,16 +36,11 @@ class PocketImportTest extends TestCase | |||
38 | 36 | ||
39 | public function testOAuthRequest() | 37 | public function testOAuthRequest() |
40 | { | 38 | { |
41 | $client = new Client(); | 39 | $httpMockClient = new HttpMockClient(); |
42 | 40 | $httpMockClient->addResponse(new Response(200, ['Content-Type' => 'application/json'], json_encode(['code' => 'wunderbar_code']))); | |
43 | $mock = new Mock([ | ||
44 | new Response(200, ['Content-Type' => 'application/json'], Stream::factory(json_encode(['code' => 'wunderbar_code']))), | ||
45 | ]); | ||
46 | |||
47 | $client->getEmitter()->attach($mock); | ||
48 | 41 | ||
49 | $pocketImport = $this->getPocketImport(); | 42 | $pocketImport = $this->getPocketImport(); |
50 | $pocketImport->setClient($client); | 43 | $pocketImport->setClient($httpMockClient); |
51 | 44 | ||
52 | $code = $pocketImport->getRequestToken('http://0.0.0.0/redirect'); | 45 | $code = $pocketImport->getRequestToken('http://0.0.0.0/redirect'); |
53 | 46 | ||
@@ -56,16 +49,11 @@ class PocketImportTest extends TestCase | |||
56 | 49 | ||
57 | public function testOAuthRequestBadResponse() | 50 | public function testOAuthRequestBadResponse() |
58 | { | 51 | { |
59 | $client = new Client(); | 52 | $httpMockClient = new HttpMockClient(); |
60 | 53 | $httpMockClient->addResponse(new Response(403)); | |
61 | $mock = new Mock([ | ||
62 | new Response(403), | ||
63 | ]); | ||
64 | |||
65 | $client->getEmitter()->attach($mock); | ||
66 | 54 | ||
67 | $pocketImport = $this->getPocketImport(); | 55 | $pocketImport = $this->getPocketImport(); |
68 | $pocketImport->setClient($client); | 56 | $pocketImport->setClient($httpMockClient); |
69 | 57 | ||
70 | $code = $pocketImport->getRequestToken('http://0.0.0.0/redirect'); | 58 | $code = $pocketImport->getRequestToken('http://0.0.0.0/redirect'); |
71 | 59 | ||
@@ -78,16 +66,11 @@ class PocketImportTest extends TestCase | |||
78 | 66 | ||
79 | public function testOAuthAuthorize() | 67 | public function testOAuthAuthorize() |
80 | { | 68 | { |
81 | $client = new Client(); | 69 | $httpMockClient = new HttpMockClient(); |
82 | 70 | $httpMockClient->addResponse(new Response(200, ['Content-Type' => 'application/json'], json_encode(['access_token' => 'wunderbar_token']))); | |
83 | $mock = new Mock([ | ||
84 | new Response(200, ['Content-Type' => 'application/json'], Stream::factory(json_encode(['access_token' => 'wunderbar_token']))), | ||
85 | ]); | ||
86 | |||
87 | $client->getEmitter()->attach($mock); | ||
88 | 71 | ||
89 | $pocketImport = $this->getPocketImport(); | 72 | $pocketImport = $this->getPocketImport(); |
90 | $pocketImport->setClient($client); | 73 | $pocketImport->setClient($httpMockClient); |
91 | 74 | ||
92 | $res = $pocketImport->authorize('wunderbar_code'); | 75 | $res = $pocketImport->authorize('wunderbar_code'); |
93 | 76 | ||
@@ -97,16 +80,11 @@ class PocketImportTest extends TestCase | |||
97 | 80 | ||
98 | public function testOAuthAuthorizeBadResponse() | 81 | public function testOAuthAuthorizeBadResponse() |
99 | { | 82 | { |
100 | $client = new Client(); | 83 | $httpMockClient = new HttpMockClient(); |
101 | 84 | $httpMockClient->addResponse(new Response(403)); | |
102 | $mock = new Mock([ | ||
103 | new Response(403), | ||
104 | ]); | ||
105 | |||
106 | $client->getEmitter()->attach($mock); | ||
107 | 85 | ||
108 | $pocketImport = $this->getPocketImport(); | 86 | $pocketImport = $this->getPocketImport(); |
109 | $pocketImport->setClient($client); | 87 | $pocketImport->setClient($httpMockClient); |
110 | 88 | ||
111 | $res = $pocketImport->authorize('wunderbar_code'); | 89 | $res = $pocketImport->authorize('wunderbar_code'); |
112 | 90 | ||
@@ -122,94 +100,90 @@ class PocketImportTest extends TestCase | |||
122 | */ | 100 | */ |
123 | public function testImport() | 101 | public function testImport() |
124 | { | 102 | { |
125 | $client = new Client(); | 103 | $httpMockClient = new HttpMockClient(); |
126 | 104 | $httpMockClient->addResponse(new Response(200, ['Content-Type' => 'application/json'], json_encode(['access_token' => 'wunderbar_token']))); | |
127 | $mock = new Mock([ | 105 | $httpMockClient->addResponse(new Response(200, ['Content-Type' => 'application/json'], <<<'JSON' |
128 | new Response(200, ['Content-Type' => 'application/json'], Stream::factory(json_encode(['access_token' => 'wunderbar_token']))), | 106 | { |
129 | new Response(200, ['Content-Type' => 'application/json'], Stream::factory(' | 107 | "status": 1, |
130 | { | 108 | "list": { |
131 | "status": 1, | 109 | "229279689": { |
132 | "list": { | 110 | "item_id": "229279689", |
133 | "229279689": { | 111 | "resolved_id": "229279689", |
134 | "item_id": "229279689", | 112 | "given_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview", |
135 | "resolved_id": "229279689", | 113 | "given_title": "The Massive Ryder Cup Preview - The Triangle Blog - Grantland", |
136 | "given_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview", | 114 | "favorite": "1", |
137 | "given_title": "The Massive Ryder Cup Preview - The Triangle Blog - Grantland", | 115 | "status": "1", |
138 | "favorite": "1", | 116 | "time_added": "1473020899", |
139 | "status": "1", | 117 | "time_updated": "1473020899", |
140 | "time_added": "1473020899", | 118 | "time_read": "0", |
141 | "time_updated": "1473020899", | 119 | "time_favorited": "0", |
142 | "time_read": "0", | 120 | "sort_id": 0, |
143 | "time_favorited": "0", | 121 | "resolved_title": "The Massive Ryder Cup Preview", |
144 | "sort_id": 0, | 122 | "resolved_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview", |
145 | "resolved_title": "The Massive Ryder Cup Preview", | 123 | "excerpt": "The list of things I love about the Ryder Cup is so long that it could fill a (tedious) novel, and golf fans can probably guess most of them.", |
146 | "resolved_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview", | 124 | "is_article": "1", |
147 | "excerpt": "The list of things I love about the Ryder Cup is so long that it could fill a (tedious) novel, and golf fans can probably guess most of them.", | 125 | "is_index": "0", |
148 | "is_article": "1", | 126 | "has_video": "1", |
149 | "is_index": "0", | 127 | "has_image": "1", |
150 | "has_video": "1", | 128 | "word_count": "3197", |
151 | "has_image": "1", | 129 | "images": { |
152 | "word_count": "3197", | 130 | "1": { |
153 | "images": { | 131 | "item_id": "229279689", |
154 | "1": { | 132 | "image_id": "1", |
155 | "item_id": "229279689", | 133 | "src": "http://a.espncdn.com/combiner/i?img=/photo/2012/0927/grant_g_ryder_cr_640.jpg&w=640&h=360", |
156 | "image_id": "1", | 134 | "width": "0", |
157 | "src": "http://a.espncdn.com/combiner/i?img=/photo/2012/0927/grant_g_ryder_cr_640.jpg&w=640&h=360", | 135 | "height": "0", |
158 | "width": "0", | 136 | "credit": "Jamie Squire/Getty Images", |
159 | "height": "0", | 137 | "caption": "" |
160 | "credit": "Jamie Squire/Getty Images", | 138 | } |
161 | "caption": "" | 139 | }, |
162 | } | 140 | "videos": { |
163 | }, | 141 | "1": { |
164 | "videos": { | 142 | "item_id": "229279689", |
165 | "1": { | 143 | "video_id": "1", |
166 | "item_id": "229279689", | 144 | "src": "http://www.youtube.com/v/Er34PbFkVGk?version=3&hl=en_US&rel=0", |
167 | "video_id": "1", | 145 | "width": "420", |
168 | "src": "http://www.youtube.com/v/Er34PbFkVGk?version=3&hl=en_US&rel=0", | 146 | "height": "315", |
169 | "width": "420", | 147 | "type": "1", |
170 | "height": "315", | 148 | "vid": "Er34PbFkVGk" |
171 | "type": "1", | ||
172 | "vid": "Er34PbFkVGk" | ||
173 | } | ||
174 | }, | ||
175 | "tags": { | ||
176 | "grantland": { | ||
177 | "item_id": "1147652870", | ||
178 | "tag": "grantland" | ||
179 | }, | ||
180 | "Ryder Cup": { | ||
181 | "item_id": "1147652870", | ||
182 | "tag": "Ryder Cup" | ||
183 | } | ||
184 | } | 149 | } |
185 | }, | 150 | }, |
186 | "229279690": { | 151 | "tags": { |
187 | "item_id": "229279689", | 152 | "grantland": { |
188 | "resolved_id": "229279689", | 153 | "item_id": "1147652870", |
189 | "given_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview", | 154 | "tag": "grantland" |
190 | "given_title": "The Massive Ryder Cup Preview - The Triangle Blog - Grantland", | 155 | }, |
191 | "favorite": "1", | 156 | "Ryder Cup": { |
192 | "status": "1", | 157 | "item_id": "1147652870", |
193 | "time_added": "1473020899", | 158 | "tag": "Ryder Cup" |
194 | "time_updated": "1473020899", | 159 | } |
195 | "time_read": "0", | ||
196 | "time_favorited": "0", | ||
197 | "sort_id": 1, | ||
198 | "resolved_title": "The Massive Ryder Cup Preview", | ||
199 | "resolved_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview", | ||
200 | "excerpt": "The list of things I love about the Ryder Cup is so long that it could fill a (tedious) novel, and golf fans can probably guess most of them.", | ||
201 | "is_article": "1", | ||
202 | "is_index": "0", | ||
203 | "has_video": "0", | ||
204 | "has_image": "0", | ||
205 | "word_count": "3197" | ||
206 | } | 160 | } |
161 | }, | ||
162 | "229279690": { | ||
163 | "item_id": "229279689", | ||
164 | "resolved_id": "229279689", | ||
165 | "given_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview", | ||
166 | "given_title": "The Massive Ryder Cup Preview - The Triangle Blog - Grantland", | ||
167 | "favorite": "1", | ||
168 | "status": "1", | ||
169 | "time_added": "1473020899", | ||
170 | "time_updated": "1473020899", | ||
171 | "time_read": "0", | ||
172 | "time_favorited": "0", | ||
173 | "sort_id": 1, | ||
174 | "resolved_title": "The Massive Ryder Cup Preview", | ||
175 | "resolved_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview", | ||
176 | "excerpt": "The list of things I love about the Ryder Cup is so long that it could fill a (tedious) novel, and golf fans can probably guess most of them.", | ||
177 | "is_article": "1", | ||
178 | "is_index": "0", | ||
179 | "has_video": "0", | ||
180 | "has_image": "0", | ||
181 | "word_count": "3197" | ||
207 | } | 182 | } |
208 | } | 183 | } |
209 | ')), | 184 | } |
210 | ]); | 185 | JSON |
211 | 186 | )); | |
212 | $client->getEmitter()->attach($mock); | ||
213 | 187 | ||
214 | $pocketImport = $this->getPocketImport('ConsumerKey', 1); | 188 | $pocketImport = $this->getPocketImport('ConsumerKey', 1); |
215 | 189 | ||
@@ -226,6 +200,13 @@ class PocketImportTest extends TestCase | |||
226 | ->method('getRepository') | 200 | ->method('getRepository') |
227 | ->willReturn($entryRepo); | 201 | ->willReturn($entryRepo); |
228 | 202 | ||
203 | $this->em | ||
204 | ->expects($this->any()) | ||
205 | ->method('persist') | ||
206 | ->with($this->callback(function ($persistedEntry) { | ||
207 | return $persistedEntry->isArchived() && $persistedEntry->isStarred(); | ||
208 | })); | ||
209 | |||
229 | $entry = new Entry($this->user); | 210 | $entry = new Entry($this->user); |
230 | 211 | ||
231 | $this->contentProxy | 212 | $this->contentProxy |
@@ -233,7 +214,7 @@ class PocketImportTest extends TestCase | |||
233 | ->method('updateEntry') | 214 | ->method('updateEntry') |
234 | ->willReturn($entry); | 215 | ->willReturn($entry); |
235 | 216 | ||
236 | $pocketImport->setClient($client); | 217 | $pocketImport->setClient($httpMockClient); |
237 | $pocketImport->authorize('wunderbar_code'); | 218 | $pocketImport->authorize('wunderbar_code'); |
238 | 219 | ||
239 | $res = $pocketImport->import(); | 220 | $res = $pocketImport->import(); |
@@ -247,56 +228,52 @@ class PocketImportTest extends TestCase | |||
247 | */ | 228 | */ |
248 | public function testImportAndMarkAllAsRead() | 229 | public function testImportAndMarkAllAsRead() |
249 | { | 230 | { |
250 | $client = new Client(); | 231 | $httpMockClient = new HttpMockClient(); |
251 | 232 | $httpMockClient->addResponse(new Response(200, ['Content-Type' => 'application/json'], json_encode(['access_token' => 'wunderbar_token']))); | |
252 | $mock = new Mock([ | 233 | $httpMockClient->addResponse(new Response(200, ['Content-Type' => 'application/json'], <<<'JSON' |
253 | new Response(200, ['Content-Type' => 'application/json'], Stream::factory(json_encode(['access_token' => 'wunderbar_token']))), | 234 | { |
254 | new Response(200, ['Content-Type' => 'application/json'], Stream::factory(' | 235 | "status": 1, |
255 | { | 236 | "list": { |
256 | "status": 1, | 237 | "229279689": { |
257 | "list": { | 238 | "item_id": "229279689", |
258 | "229279689": { | 239 | "resolved_id": "229279689", |
259 | "item_id": "229279689", | 240 | "given_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview", |
260 | "resolved_id": "229279689", | 241 | "given_title": "The Massive Ryder Cup Preview - The Triangle Blog - Grantland", |
261 | "given_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview", | 242 | "favorite": "1", |
262 | "given_title": "The Massive Ryder Cup Preview - The Triangle Blog - Grantland", | 243 | "status": "1", |
263 | "favorite": "1", | 244 | "time_added": "1473020899", |
264 | "status": "1", | 245 | "time_updated": "1473020899", |
265 | "time_added": "1473020899", | 246 | "time_read": "0", |
266 | "time_updated": "1473020899", | 247 | "time_favorited": "0", |
267 | "time_read": "0", | 248 | "sort_id": 0, |
268 | "time_favorited": "0", | 249 | "excerpt": "The list of things I love about the Ryder Cup is so long that it could fill a (tedious) novel, and golf fans can probably guess most of them.", |
269 | "sort_id": 0, | 250 | "is_article": "1", |
270 | "excerpt": "The list of things I love about the Ryder Cup is so long that it could fill a (tedious) novel, and golf fans can probably guess most of them.", | 251 | "has_video": "1", |
271 | "is_article": "1", | 252 | "has_image": "1", |
272 | "has_video": "1", | 253 | "word_count": "3197" |
273 | "has_image": "1", | 254 | }, |
274 | "word_count": "3197" | 255 | "229279690": { |
275 | }, | 256 | "item_id": "229279689", |
276 | "229279690": { | 257 | "resolved_id": "229279689", |
277 | "item_id": "229279689", | 258 | "given_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview/2", |
278 | "resolved_id": "229279689", | 259 | "given_title": "The Massive Ryder Cup Preview - The Triangle Blog - Grantland", |
279 | "given_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview/2", | 260 | "favorite": "1", |
280 | "given_title": "The Massive Ryder Cup Preview - The Triangle Blog - Grantland", | 261 | "status": "0", |
281 | "favorite": "1", | 262 | "time_added": "1473020899", |
282 | "status": "0", | 263 | "time_updated": "1473020899", |
283 | "time_added": "1473020899", | 264 | "time_read": "0", |
284 | "time_updated": "1473020899", | 265 | "time_favorited": "0", |
285 | "time_read": "0", | 266 | "sort_id": 1, |
286 | "time_favorited": "0", | 267 | "excerpt": "The list of things I love about the Ryder Cup is so long that it could fill a (tedious) novel, and golf fans can probably guess most of them.", |
287 | "sort_id": 1, | 268 | "is_article": "1", |
288 | "excerpt": "The list of things I love about the Ryder Cup is so long that it could fill a (tedious) novel, and golf fans can probably guess most of them.", | 269 | "has_video": "0", |
289 | "is_article": "1", | 270 | "has_image": "0", |
290 | "has_video": "0", | 271 | "word_count": "3197" |
291 | "has_image": "0", | ||
292 | "word_count": "3197" | ||
293 | } | ||
294 | } | 272 | } |
295 | } | 273 | } |
296 | ')), | 274 | } |
297 | ]); | 275 | JSON |
298 | 276 | )); | |
299 | $client->getEmitter()->attach($mock); | ||
300 | 277 | ||
301 | $pocketImport = $this->getPocketImport('ConsumerKey', 2); | 278 | $pocketImport = $this->getPocketImport('ConsumerKey', 2); |
302 | 279 | ||
@@ -328,7 +305,7 @@ class PocketImportTest extends TestCase | |||
328 | ->method('updateEntry') | 305 | ->method('updateEntry') |
329 | ->willReturn($entry); | 306 | ->willReturn($entry); |
330 | 307 | ||
331 | $pocketImport->setClient($client); | 308 | $pocketImport->setClient($httpMockClient); |
332 | $pocketImport->authorize('wunderbar_code'); | 309 | $pocketImport->authorize('wunderbar_code'); |
333 | 310 | ||
334 | $res = $pocketImport->setMarkAsRead(true)->import(); | 311 | $res = $pocketImport->setMarkAsRead(true)->import(); |
@@ -342,7 +319,7 @@ class PocketImportTest extends TestCase | |||
342 | */ | 319 | */ |
343 | public function testImportWithRabbit() | 320 | public function testImportWithRabbit() |
344 | { | 321 | { |
345 | $client = new Client(); | 322 | $httpMockClient = new HttpMockClient(); |
346 | 323 | ||
347 | $body = <<<'JSON' | 324 | $body = <<<'JSON' |
348 | { | 325 | { |
@@ -367,19 +344,16 @@ class PocketImportTest extends TestCase | |||
367 | } | 344 | } |
368 | JSON; | 345 | JSON; |
369 | 346 | ||
370 | $mock = new Mock([ | 347 | $httpMockClient->addResponse(new Response(200, ['Content-Type' => 'application/json'], json_encode(['access_token' => 'wunderbar_token']))); |
371 | new Response(200, ['Content-Type' => 'application/json'], Stream::factory(json_encode(['access_token' => 'wunderbar_token']))), | 348 | $httpMockClient->addResponse(new Response(200, ['Content-Type' => 'application/json'], <<<JSON |
372 | new Response(200, ['Content-Type' => 'application/json'], Stream::factory(' | 349 | { |
373 | { | 350 | "status": 1, |
374 | "status": 1, | 351 | "list": { |
375 | "list": { | 352 | "229279690": $body |
376 | "229279690": ' . $body . ' | ||
377 | } | ||
378 | } | 353 | } |
379 | ')), | 354 | } |
380 | ]); | 355 | JSON |
381 | 356 | )); | |
382 | $client->getEmitter()->attach($mock); | ||
383 | 357 | ||
384 | $pocketImport = $this->getPocketImport(); | 358 | $pocketImport = $this->getPocketImport(); |
385 | 359 | ||
@@ -413,7 +387,7 @@ JSON; | |||
413 | ->method('publish') | 387 | ->method('publish') |
414 | ->with(json_encode($bodyAsArray)); | 388 | ->with(json_encode($bodyAsArray)); |
415 | 389 | ||
416 | $pocketImport->setClient($client); | 390 | $pocketImport->setClient($httpMockClient); |
417 | $pocketImport->setProducer($producer); | 391 | $pocketImport->setProducer($producer); |
418 | $pocketImport->authorize('wunderbar_code'); | 392 | $pocketImport->authorize('wunderbar_code'); |
419 | 393 | ||
@@ -428,7 +402,7 @@ JSON; | |||
428 | */ | 402 | */ |
429 | public function testImportWithRedis() | 403 | public function testImportWithRedis() |
430 | { | 404 | { |
431 | $client = new Client(); | 405 | $httpMockClient = new HttpMockClient(); |
432 | 406 | ||
433 | $body = <<<'JSON' | 407 | $body = <<<'JSON' |
434 | { | 408 | { |
@@ -453,19 +427,16 @@ JSON; | |||
453 | } | 427 | } |
454 | JSON; | 428 | JSON; |
455 | 429 | ||
456 | $mock = new Mock([ | 430 | $httpMockClient->addResponse(new Response(200, ['Content-Type' => 'application/json'], json_encode(['access_token' => 'wunderbar_token']))); |
457 | new Response(200, ['Content-Type' => 'application/json'], Stream::factory(json_encode(['access_token' => 'wunderbar_token']))), | 431 | $httpMockClient->addResponse(new Response(200, ['Content-Type' => 'application/json'], <<<JSON |
458 | new Response(200, ['Content-Type' => 'application/json'], Stream::factory(' | 432 | { |
459 | { | 433 | "status": 1, |
460 | "status": 1, | 434 | "list": { |
461 | "list": { | 435 | "229279690": $body |
462 | "229279690": ' . $body . ' | ||
463 | } | ||
464 | } | 436 | } |
465 | ')), | 437 | } |
466 | ]); | 438 | JSON |
467 | 439 | )); | |
468 | $client->getEmitter()->attach($mock); | ||
469 | 440 | ||
470 | $pocketImport = $this->getPocketImport(); | 441 | $pocketImport = $this->getPocketImport(); |
471 | 442 | ||
@@ -492,7 +463,7 @@ JSON; | |||
492 | $queue = new RedisQueue($redisMock, 'pocket'); | 463 | $queue = new RedisQueue($redisMock, 'pocket'); |
493 | $producer = new Producer($queue); | 464 | $producer = new Producer($queue); |
494 | 465 | ||
495 | $pocketImport->setClient($client); | 466 | $pocketImport->setClient($httpMockClient); |
496 | $pocketImport->setProducer($producer); | 467 | $pocketImport->setProducer($producer); |
497 | $pocketImport->authorize('wunderbar_code'); | 468 | $pocketImport->authorize('wunderbar_code'); |
498 | 469 | ||
@@ -506,17 +477,13 @@ JSON; | |||
506 | 477 | ||
507 | public function testImportBadResponse() | 478 | public function testImportBadResponse() |
508 | { | 479 | { |
509 | $client = new Client(); | 480 | $httpMockClient = new HttpMockClient(); |
510 | 481 | ||
511 | $mock = new Mock([ | 482 | $httpMockClient->addResponse(new Response(200, ['Content-Type' => 'application/json'], json_encode(['access_token' => 'wunderbar_token']))); |
512 | new Response(200, ['Content-Type' => 'application/json'], Stream::factory(json_encode(['access_token' => 'wunderbar_token']))), | 483 | $httpMockClient->addResponse(new Response(403)); |
513 | new Response(403), | ||
514 | ]); | ||
515 | |||
516 | $client->getEmitter()->attach($mock); | ||
517 | 484 | ||
518 | $pocketImport = $this->getPocketImport(); | 485 | $pocketImport = $this->getPocketImport(); |
519 | $pocketImport->setClient($client); | 486 | $pocketImport->setClient($httpMockClient); |
520 | $pocketImport->authorize('wunderbar_code'); | 487 | $pocketImport->authorize('wunderbar_code'); |
521 | 488 | ||
522 | $res = $pocketImport->import(); | 489 | $res = $pocketImport->import(); |
@@ -530,25 +497,23 @@ JSON; | |||
530 | 497 | ||
531 | public function testImportWithExceptionFromGraby() | 498 | public function testImportWithExceptionFromGraby() |
532 | { | 499 | { |
533 | $client = new Client(); | 500 | $httpMockClient = new HttpMockClient(); |
534 | 501 | ||
535 | $mock = new Mock([ | 502 | $httpMockClient->addResponse(new Response(200, ['Content-Type' => 'application/json'], json_encode(['access_token' => 'wunderbar_token']))); |
536 | new Response(200, ['Content-Type' => 'application/json'], Stream::factory(json_encode(['access_token' => 'wunderbar_token']))), | 503 | $httpMockClient->addResponse(new Response(200, ['Content-Type' => 'application/json'], <<<'JSON' |
537 | new Response(200, ['Content-Type' => 'application/json'], Stream::factory(' | 504 | { |
538 | { | 505 | "status": 1, |
539 | "status": 1, | 506 | "list": { |
540 | "list": { | 507 | "229279689": { |
541 | "229279689": { | 508 | "status": "1", |
542 | "status": "1", | 509 | "favorite": "1", |
543 | "favorite": "1", | 510 | "resolved_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview" |
544 | "resolved_url": "http://www.grantland.com/blog/the-triangle/post/_/id/38347/ryder-cup-preview" | ||
545 | } | ||
546 | } | 511 | } |
547 | } | 512 | } |
548 | ')), | 513 | } |
549 | ]); | 514 | |
550 | 515 | JSON | |
551 | $client->getEmitter()->attach($mock); | 516 | )); |
552 | 517 | ||
553 | $pocketImport = $this->getPocketImport('ConsumerKey', 1); | 518 | $pocketImport = $this->getPocketImport('ConsumerKey', 1); |
554 | 519 | ||
@@ -572,7 +537,7 @@ JSON; | |||
572 | ->method('updateEntry') | 537 | ->method('updateEntry') |
573 | ->will($this->throwException(new \Exception())); | 538 | ->will($this->throwException(new \Exception())); |
574 | 539 | ||
575 | $pocketImport->setClient($client); | 540 | $pocketImport->setClient($httpMockClient); |
576 | $pocketImport->authorize('wunderbar_code'); | 541 | $pocketImport->authorize('wunderbar_code'); |
577 | 542 | ||
578 | $res = $pocketImport->import(); | 543 | $res = $pocketImport->import(); |
diff --git a/tests/Wallabag/ImportBundle/fixtures/elcurator.json b/tests/Wallabag/ImportBundle/fixtures/elcurator.json new file mode 100644 index 00000000..f6fb2dfb --- /dev/null +++ b/tests/Wallabag/ImportBundle/fixtures/elcurator.json | |||
@@ -0,0 +1,13 @@ | |||
1 | [ | ||
2 | { | ||
3 | "created_at": "2015-09-09 11:10:32 UTC", | ||
4 | "title": "Qualité de code - Intégration de php-git-hooks dans Symfony2 - Experts Symfony et Drupal - Lexik", | ||
5 | "url": "https://devblog.lexik.fr/git/qualite-de-code-integration-de-php-git-hooks-dans-symfony2-2842", | ||
6 | "description": null, | ||
7 | "tags": [ | ||
8 | "tag1", | ||
9 | "tag2" | ||
10 | ], | ||
11 | "is_saved": true | ||
12 | } | ||
13 | ] | ||
diff --git a/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php b/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php index adc2cf09..f44e6fbf 100644 --- a/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php +++ b/tests/Wallabag/UserBundle/Controller/ManageControllerTest.php | |||
@@ -1,6 +1,6 @@ | |||
1 | <?php | 1 | <?php |
2 | 2 | ||
3 | namespace Wallabag\UserBundle\Tests\Controller; | 3 | namespace Tests\Wallabag\UserBundle\Controller; |
4 | 4 | ||
5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | 5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; |
6 | 6 | ||
diff --git a/tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php b/tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php index 2b540fdf..8a8ec3cf 100644 --- a/tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php +++ b/tests/Wallabag/UserBundle/EventListener/CreateConfigListenerTest.php | |||
@@ -8,6 +8,8 @@ use PHPUnit\Framework\TestCase; | |||
8 | use Symfony\Component\EventDispatcher\EventDispatcher; | 8 | use Symfony\Component\EventDispatcher\EventDispatcher; |
9 | use Symfony\Component\HttpFoundation\Request; | 9 | use Symfony\Component\HttpFoundation\Request; |
10 | use Symfony\Component\HttpFoundation\Response; | 10 | use Symfony\Component\HttpFoundation\Response; |
11 | use Symfony\Component\HttpFoundation\Session\Session; | ||
12 | use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; | ||
11 | use Wallabag\CoreBundle\Entity\Config; | 13 | use Wallabag\CoreBundle\Entity\Config; |
12 | use Wallabag\UserBundle\Entity\User; | 14 | use Wallabag\UserBundle\Entity\User; |
13 | use Wallabag\UserBundle\EventListener\CreateConfigListener; | 15 | use Wallabag\UserBundle\EventListener\CreateConfigListener; |
@@ -22,6 +24,7 @@ class CreateConfigListenerTest extends TestCase | |||
22 | 24 | ||
23 | protected function setUp() | 25 | protected function setUp() |
24 | { | 26 | { |
27 | $session = new Session(new MockArraySessionStorage()); | ||
25 | $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') | 28 | $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') |
26 | ->disableOriginalConstructor() | 29 | ->disableOriginalConstructor() |
27 | ->getMock(); | 30 | ->getMock(); |
@@ -34,7 +37,8 @@ class CreateConfigListenerTest extends TestCase | |||
34 | 'fr', | 37 | 'fr', |
35 | 1, | 38 | 1, |
36 | 1, | 39 | 1, |
37 | 1 | 40 | 1, |
41 | $session | ||
38 | ); | 42 | ); |
39 | 43 | ||
40 | $this->dispatcher = new EventDispatcher(); | 44 | $this->dispatcher = new EventDispatcher(); |
@@ -58,13 +62,13 @@ class CreateConfigListenerTest extends TestCase | |||
58 | $config = new Config($user); | 62 | $config = new Config($user); |
59 | $config->setTheme('baggy'); | 63 | $config->setTheme('baggy'); |
60 | $config->setItemsPerPage(20); | 64 | $config->setItemsPerPage(20); |
61 | $config->setRssLimit(50); | 65 | $config->setFeedLimit(50); |
62 | $config->setLanguage('fr'); | 66 | $config->setLanguage('fr'); |
63 | $config->setReadingSpeed(1); | 67 | $config->setReadingSpeed(200); |
64 | 68 | ||
65 | $this->em->expects($this->once()) | 69 | $this->em->expects($this->once()) |
66 | ->method('persist') | 70 | ->method('persist') |
67 | ->will($this->returnValue($config)); | 71 | ->willReturn($config); |
68 | $this->em->expects($this->once()) | 72 | $this->em->expects($this->once()) |
69 | ->method('flush'); | 73 | ->method('flush'); |
70 | 74 | ||
diff --git a/tests/Wallabag/UserBundle/Mailer/AuthCodeMailerTest.php b/tests/Wallabag/UserBundle/Mailer/AuthCodeMailerTest.php index aa176068..4f93a92c 100644 --- a/tests/Wallabag/UserBundle/Mailer/AuthCodeMailerTest.php +++ b/tests/Wallabag/UserBundle/Mailer/AuthCodeMailerTest.php | |||
@@ -3,25 +3,11 @@ | |||
3 | namespace Tests\Wallabag\UserBundle\Mailer; | 3 | namespace Tests\Wallabag\UserBundle\Mailer; |
4 | 4 | ||
5 | use PHPUnit\Framework\TestCase; | 5 | use PHPUnit\Framework\TestCase; |
6 | use Twig\Environment; | ||
7 | use Twig\Loader\ArrayLoader; | ||
6 | use Wallabag\UserBundle\Entity\User; | 8 | use Wallabag\UserBundle\Entity\User; |
7 | use Wallabag\UserBundle\Mailer\AuthCodeMailer; | 9 | use Wallabag\UserBundle\Mailer\AuthCodeMailer; |
8 | 10 | ||
9 | /** | ||
10 | * @see https://www.pmg.com/blog/integration-testing-swift-mailer/ | ||
11 | */ | ||
12 | final class CountableMemorySpool extends \Swift_MemorySpool implements \Countable | ||
13 | { | ||
14 | public function count() | ||
15 | { | ||
16 | return \count($this->messages); | ||
17 | } | ||
18 | |||
19 | public function getMessages() | ||
20 | { | ||
21 | return $this->messages; | ||
22 | } | ||
23 | } | ||
24 | |||
25 | class AuthCodeMailerTest extends TestCase | 11 | class AuthCodeMailerTest extends TestCase |
26 | { | 12 | { |
27 | protected $mailer; | 13 | protected $mailer; |
@@ -43,13 +29,13 @@ class AuthCodeMailerTest extends TestCase | |||
43 | {% block body_text %}text body {{ support_url }}{% endblock %} | 29 | {% block body_text %}text body {{ support_url }}{% endblock %} |
44 | TWIG; | 30 | TWIG; |
45 | 31 | ||
46 | $this->twig = new \Twig_Environment(new \Twig_Loader_Array(['WallabagUserBundle:TwoFactor:email_auth_code.html.twig' => $twigTemplate])); | 32 | $this->twig = new Environment(new ArrayLoader(['WallabagUserBundle:TwoFactor:email_auth_code.html.twig' => $twigTemplate])); |
47 | } | 33 | } |
48 | 34 | ||
49 | public function testSendEmail() | 35 | public function testSendEmail() |
50 | { | 36 | { |
51 | $user = new User(); | 37 | $user = new User(); |
52 | $user->setTwoFactorAuthentication(true); | 38 | $user->setEmailTwoFactor(true); |
53 | $user->setEmailAuthCode(666666); | 39 | $user->setEmailAuthCode(666666); |
54 | $user->setEmail('test@wallabag.io'); | 40 | $user->setEmail('test@wallabag.io'); |
55 | $user->setName('Bob'); | 41 | $user->setName('Bob'); |
diff --git a/tests/Wallabag/UserBundle/Mailer/CountableMemorySpool.php b/tests/Wallabag/UserBundle/Mailer/CountableMemorySpool.php new file mode 100644 index 00000000..53f240a1 --- /dev/null +++ b/tests/Wallabag/UserBundle/Mailer/CountableMemorySpool.php | |||
@@ -0,0 +1,19 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Tests\Wallabag\UserBundle\Mailer; | ||
4 | |||
5 | /** | ||
6 | * @see https://www.pmg.com/blog/integration-testing-swift-mailer/ | ||
7 | */ | ||
8 | final class CountableMemorySpool extends \Swift_MemorySpool implements \Countable | ||
9 | { | ||
10 | public function count() | ||
11 | { | ||
12 | return \count($this->messages); | ||
13 | } | ||
14 | |||
15 | public function getMessages() | ||
16 | { | ||
17 | return $this->messages; | ||
18 | } | ||
19 | } | ||