aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php113
-rw-r--r--tests/Wallabag/CoreBundle/Command/InstallCommandTest.php2
-rw-r--r--tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php53
-rw-r--r--tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php15
-rw-r--r--tests/Wallabag/CoreBundle/Controller/TagControllerTest.php31
-rw-r--r--tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php2
-rw-r--r--tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php122
-rw-r--r--tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php150
-rw-r--r--tests/Wallabag/ImportBundle/fixtures/readability-read.json25
-rw-r--r--tests/Wallabag/ImportBundle/fixtures/readability.json25
10 files changed, 533 insertions, 5 deletions
diff --git a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php
index 528366af..ee5b2ab7 100644
--- a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php
+++ b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php
@@ -3,6 +3,7 @@
3namespace Tests\Wallabag\ApiBundle\Controller; 3namespace Tests\Wallabag\ApiBundle\Controller;
4 4
5use Tests\Wallabag\ApiBundle\WallabagApiTestCase; 5use Tests\Wallabag\ApiBundle\WallabagApiTestCase;
6use Wallabag\CoreBundle\Entity\Tag;
6 7
7class WallabagRestControllerTest extends WallabagApiTestCase 8class WallabagRestControllerTest extends WallabagApiTestCase
8{ 9{
@@ -359,7 +360,7 @@ class WallabagRestControllerTest extends WallabagApiTestCase
359 $entry = $this->client->getContainer() 360 $entry = $this->client->getContainer()
360 ->get('doctrine.orm.entity_manager') 361 ->get('doctrine.orm.entity_manager')
361 ->getRepository('WallabagCoreBundle:Entry') 362 ->getRepository('WallabagCoreBundle:Entry')
362 ->findOneWithTags(1); 363 ->findOneWithTags($this->user->getId());
363 364
364 $entry = $entry[0]; 365 $entry = $entry[0];
365 366
@@ -421,7 +422,7 @@ class WallabagRestControllerTest extends WallabagApiTestCase
421 $entry = $this->client->getContainer() 422 $entry = $this->client->getContainer()
422 ->get('doctrine.orm.entity_manager') 423 ->get('doctrine.orm.entity_manager')
423 ->getRepository('WallabagCoreBundle:Entry') 424 ->getRepository('WallabagCoreBundle:Entry')
424 ->findOneWithTags(1); 425 ->findOneWithTags($this->user->getId());
425 $entry = $entry[0]; 426 $entry = $entry[0];
426 427
427 if (!$entry) { 428 if (!$entry) {
@@ -472,7 +473,7 @@ class WallabagRestControllerTest extends WallabagApiTestCase
472 $this->assertEquals($tag['label'], $content['label']); 473 $this->assertEquals($tag['label'], $content['label']);
473 $this->assertEquals($tag['slug'], $content['slug']); 474 $this->assertEquals($tag['slug'], $content['slug']);
474 475
475 $entries = $entry = $this->client->getContainer() 476 $entries = $this->client->getContainer()
476 ->get('doctrine.orm.entity_manager') 477 ->get('doctrine.orm.entity_manager')
477 ->getRepository('WallabagCoreBundle:Entry') 478 ->getRepository('WallabagCoreBundle:Entry')
478 ->findAllByTagId($this->user->getId(), $tag['id']); 479 ->findAllByTagId($this->user->getId(), $tag['id']);
@@ -480,6 +481,112 @@ class WallabagRestControllerTest extends WallabagApiTestCase
480 $this->assertCount(0, $entries); 481 $this->assertCount(0, $entries);
481 } 482 }
482 483
484 public function testDeleteTagByLabel()
485 {
486 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
487 $entry = $this->client->getContainer()
488 ->get('doctrine.orm.entity_manager')
489 ->getRepository('WallabagCoreBundle:Entry')
490 ->findOneWithTags($this->user->getId());
491
492 $entry = $entry[0];
493
494 $tag = new Tag();
495 $tag->setLabel('Awesome tag for test');
496 $em->persist($tag);
497
498 $entry->addTag($tag);
499
500 $em->persist($entry);
501 $em->flush();
502
503 $this->client->request('DELETE', '/api/tag/label.json', ['tag' => $tag->getLabel()]);
504
505 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
506
507 $content = json_decode($this->client->getResponse()->getContent(), true);
508
509 $this->assertArrayHasKey('label', $content);
510 $this->assertEquals($tag->getLabel(), $content['label']);
511 $this->assertEquals($tag->getSlug(), $content['slug']);
512
513 $entries = $this->client->getContainer()
514 ->get('doctrine.orm.entity_manager')
515 ->getRepository('WallabagCoreBundle:Entry')
516 ->findAllByTagId($this->user->getId(), $tag->getId());
517
518 $this->assertCount(0, $entries);
519 }
520
521 public function testDeleteTagByLabelNotFound()
522 {
523 $this->client->request('DELETE', '/api/tag/label.json', ['tag' => 'does not exist']);
524
525 $this->assertEquals(404, $this->client->getResponse()->getStatusCode());
526 }
527
528 public function testDeleteTagsByLabel()
529 {
530 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
531 $entry = $this->client->getContainer()
532 ->get('doctrine.orm.entity_manager')
533 ->getRepository('WallabagCoreBundle:Entry')
534 ->findOneWithTags($this->user->getId());
535
536 $entry = $entry[0];
537
538 $tag = new Tag();
539 $tag->setLabel('Awesome tag for tagsLabel');
540 $em->persist($tag);
541
542 $tag2 = new Tag();
543 $tag2->setLabel('Awesome tag for tagsLabel 2');
544 $em->persist($tag2);
545
546 $entry->addTag($tag);
547 $entry->addTag($tag2);
548
549 $em->persist($entry);
550 $em->flush();
551
552 $this->client->request('DELETE', '/api/tags/label.json', ['tags' => $tag->getLabel().','.$tag2->getLabel()]);
553
554 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
555
556 $content = json_decode($this->client->getResponse()->getContent(), true);
557
558 $this->assertCount(2, $content);
559
560 $this->assertArrayHasKey('label', $content[0]);
561 $this->assertEquals($tag->getLabel(), $content[0]['label']);
562 $this->assertEquals($tag->getSlug(), $content[0]['slug']);
563
564 $this->assertArrayHasKey('label', $content[1]);
565 $this->assertEquals($tag2->getLabel(), $content[1]['label']);
566 $this->assertEquals($tag2->getSlug(), $content[1]['slug']);
567
568 $entries = $this->client->getContainer()
569 ->get('doctrine.orm.entity_manager')
570 ->getRepository('WallabagCoreBundle:Entry')
571 ->findAllByTagId($this->user->getId(), $tag->getId());
572
573 $this->assertCount(0, $entries);
574
575 $entries = $this->client->getContainer()
576 ->get('doctrine.orm.entity_manager')
577 ->getRepository('WallabagCoreBundle:Entry')
578 ->findAllByTagId($this->user->getId(), $tag2->getId());
579
580 $this->assertCount(0, $entries);
581 }
582
583 public function testDeleteTagsByLabelNotFound()
584 {
585 $this->client->request('DELETE', '/api/tags/label.json', ['tags' => 'does not exist']);
586
587 $this->assertEquals(404, $this->client->getResponse()->getStatusCode());
588 }
589
483 public function testGetVersion() 590 public function testGetVersion()
484 { 591 {
485 $this->client->request('GET', '/api/version'); 592 $this->client->request('GET', '/api/version');
diff --git a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php
index c0133af4..07ff2772 100644
--- a/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php
+++ b/tests/Wallabag/CoreBundle/Command/InstallCommandTest.php
@@ -33,7 +33,7 @@ class InstallCommandTest extends WallabagCoreTestCase
33 } 33 }
34 34
35 /** 35 /**
36 * Ensure next tests will have a clean database 36 * Ensure next tests will have a clean database.
37 */ 37 */
38 public static function tearDownAfterClass() 38 public static function tearDownAfterClass()
39 { 39 {
diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
index 5c739c78..a74c17d9 100644
--- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
@@ -236,6 +236,16 @@ class EntryControllerTest extends WallabagCoreTestCase
236 $this->assertEquals(200, $client->getResponse()->getStatusCode()); 236 $this->assertEquals(200, $client->getResponse()->getStatusCode());
237 } 237 }
238 238
239 public function testUntagged()
240 {
241 $this->logInAs('admin');
242 $client = $this->getClient();
243
244 $client->request('GET', '/untagged/list');
245
246 $this->assertEquals(200, $client->getResponse()->getStatusCode());
247 }
248
239 public function testStarred() 249 public function testStarred()
240 { 250 {
241 $this->logInAs('admin'); 251 $this->logInAs('admin');
@@ -698,4 +708,47 @@ class EntryControllerTest extends WallabagCoreTestCase
698 $crawler = $client->submit($form, $data); 708 $crawler = $client->submit($form, $data);
699 $this->assertCount(2, $crawler->filter('div[class=entry]')); 709 $this->assertCount(2, $crawler->filter('div[class=entry]'));
700 } 710 }
711
712 public function testCache()
713 {
714 $this->logInAs('admin');
715 $client = $this->getClient();
716
717 $content = $client->getContainer()
718 ->get('doctrine.orm.entity_manager')
719 ->getRepository('WallabagCoreBundle:Entry')
720 ->findOneByUser($this->getLoggedInUserId());
721
722 // no uuid
723 $client->request('GET', '/share/'.$content->getUuid());
724 $this->assertEquals(404, $client->getResponse()->getStatusCode());
725
726 // generating the uuid
727 $client->request('GET', '/share/'.$content->getId());
728 $this->assertEquals(302, $client->getResponse()->getStatusCode());
729
730 // follow link with uuid
731 $crawler = $client->followRedirect();
732 $this->assertEquals(200, $client->getResponse()->getStatusCode());
733 $this->assertContains('max-age=25200', $client->getResponse()->headers->get('cache-control'));
734 $this->assertContains('public', $client->getResponse()->headers->get('cache-control'));
735 $this->assertContains('s-maxage=25200', $client->getResponse()->headers->get('cache-control'));
736 $this->assertNotContains('no-cache', $client->getResponse()->headers->get('cache-control'));
737
738 // sharing is now disabled
739 $client->getContainer()->get('craue_config')->set('share_public', 0);
740 $client->request('GET', '/share/'.$content->getUuid());
741 $this->assertEquals(404, $client->getResponse()->getStatusCode());
742
743 $client->request('GET', '/view/'.$content->getId());
744 $this->assertContains('no-cache', $client->getResponse()->headers->get('cache-control'));
745
746 // removing the share
747 $client->request('GET', '/share/delete/'.$content->getId());
748 $this->assertEquals(302, $client->getResponse()->getStatusCode());
749
750 // share is now disable
751 $client->request('GET', '/share/'.$content->getUuid());
752 $this->assertEquals(404, $client->getResponse()->getStatusCode());
753 }
701} 754}
diff --git a/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php b/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php
index 03355f5a..08f4676e 100644
--- a/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/SecurityControllerTest.php
@@ -69,4 +69,19 @@ class SecurityControllerTest extends WallabagCoreTestCase
69 $this->assertTrue($user->isTrustedComputer('ABCDEF')); 69 $this->assertTrue($user->isTrustedComputer('ABCDEF'));
70 $this->assertFalse($user->isTrustedComputer('FEDCBA')); 70 $this->assertFalse($user->isTrustedComputer('FEDCBA'));
71 } 71 }
72
73 public function testEnabledRegistration()
74 {
75 $client = $this->getClient();
76
77 if (!$client->getContainer()->getParameter('fosuser_registration')) {
78 $this->markTestSkipped('fosuser_registration is not enabled.');
79
80 return;
81 }
82
83 $client->followRedirects();
84 $crawler = $client->request('GET', '/register');
85 $this->assertContains('registration.submit', $crawler->filter('body')->extract(['_text'])[0]);
86 }
72} 87}
diff --git a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php
index 58450e5f..71652760 100644
--- a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php
@@ -131,4 +131,35 @@ class TagControllerTest extends WallabagCoreTestCase
131 131
132 $this->assertEquals(404, $client->getResponse()->getStatusCode()); 132 $this->assertEquals(404, $client->getResponse()->getStatusCode());
133 } 133 }
134
135 public function testShowEntriesForTagAction()
136 {
137 $this->logInAs('admin');
138 $client = $this->getClient();
139
140 $entry = $client->getContainer()
141 ->get('doctrine.orm.entity_manager')
142 ->getRepository('WallabagCoreBundle:Entry')
143 ->findOneByUsernameAndNotArchived('admin');
144
145 $tag = $client->getContainer()
146 ->get('doctrine.orm.entity_manager')
147 ->getRepository('WallabagCoreBundle:Tag')
148 ->findOneByEntryAndTagLabel($entry, 'foo');
149
150 $crawler = $client->request('GET', '/tag/list/'.$tag->getSlug());
151
152 $this->assertEquals(200, $client->getResponse()->getStatusCode());
153 $this->assertCount(2, $crawler->filter('div[class=entry]'));
154
155 $tag = $client->getContainer()
156 ->get('doctrine.orm.entity_manager')
157 ->getRepository('WallabagCoreBundle:Tag')
158 ->findOneByLabel('baz');
159
160 $crawler = $client->request('GET', '/tag/list/'.$tag->getSlug());
161
162 $this->assertEquals(200, $client->getResponse()->getStatusCode());
163 $this->assertCount(0, $crawler->filter('div[class=entry]'));
164 }
134} 165}
diff --git a/tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php
index 96b5300b..d869cdf9 100644
--- a/tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php
+++ b/tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php
@@ -24,6 +24,6 @@ class ImportControllerTest extends WallabagCoreTestCase
24 $crawler = $client->request('GET', '/import/'); 24 $crawler = $client->request('GET', '/import/');
25 25
26 $this->assertEquals(200, $client->getResponse()->getStatusCode()); 26 $this->assertEquals(200, $client->getResponse()->getStatusCode());
27 $this->assertEquals(3, $crawler->filter('blockquote')->count()); 27 $this->assertEquals(4, $crawler->filter('blockquote')->count());
28 } 28 }
29} 29}
diff --git a/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php
new file mode 100644
index 00000000..92cf4bfc
--- /dev/null
+++ b/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php
@@ -0,0 +1,122 @@
1<?php
2
3namespace Tests\Wallabag\ImportBundle\Controller;
4
5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
6use Symfony\Component\HttpFoundation\File\UploadedFile;
7
8class ReadabilityControllerTest extends WallabagCoreTestCase
9{
10 public function testImportReadability()
11 {
12 $this->logInAs('admin');
13 $client = $this->getClient();
14
15 $crawler = $client->request('GET', '/import/readability');
16
17 $this->assertEquals(200, $client->getResponse()->getStatusCode());
18 $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count());
19 $this->assertEquals(1, $crawler->filter('input[type=file]')->count());
20 }
21
22 public function testImportReadabilityWithFile()
23 {
24 $this->logInAs('admin');
25 $client = $this->getClient();
26
27 $crawler = $client->request('GET', '/import/readability');
28 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
29
30 $file = new UploadedFile(__DIR__.'/../fixtures/readability.json', 'readability.json');
31
32 $data = [
33 'upload_import_file[file]' => $file,
34 ];
35
36 $client->submit($form, $data);
37
38 $this->assertEquals(302, $client->getResponse()->getStatusCode());
39
40 $crawler = $client->followRedirect();
41
42 $content = $client->getContainer()
43 ->get('doctrine.orm.entity_manager')
44 ->getRepository('WallabagCoreBundle:Entry')
45 ->findByUrlAndUserId(
46 'https://venngage.com/blog/hashtags-are-worthless/',
47 $this->getLoggedInUserId()
48 );
49
50 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
51 $this->assertContains('flashes.import.notice.summary', $body[0]);
52 }
53
54 public function testImportReadabilityWithFileAndMarkAllAsRead()
55 {
56 $this->logInAs('admin');
57 $client = $this->getClient();
58
59 $crawler = $client->request('GET', '/import/readability');
60 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
61
62 $file = new UploadedFile(__DIR__.'/../fixtures/readability-read.json', 'readability-read.json');
63
64 $data = [
65 'upload_import_file[file]' => $file,
66 'upload_import_file[mark_as_read]' => 1,
67 ];
68
69 $client->submit($form, $data);
70
71 $this->assertEquals(302, $client->getResponse()->getStatusCode());
72
73 $crawler = $client->followRedirect();
74
75 $content1 = $client->getContainer()
76 ->get('doctrine.orm.entity_manager')
77 ->getRepository('WallabagCoreBundle:Entry')
78 ->findByUrlAndUserId(
79 'https://blog.travis-ci.com/2016-07-28-what-we-learned-from-analyzing-2-million-travis-builds/',
80 $this->getLoggedInUserId()
81 );
82
83 $this->assertTrue($content1->isArchived());
84
85 $content2 = $client->getContainer()
86 ->get('doctrine.orm.entity_manager')
87 ->getRepository('WallabagCoreBundle:Entry')
88 ->findByUrlAndUserId(
89 'https://facebook.github.io/graphql/',
90 $this->getLoggedInUserId()
91 );
92
93 $this->assertTrue($content2->isArchived());
94
95 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
96 $this->assertContains('flashes.import.notice.summary', $body[0]);
97 }
98
99 public function testImportReadabilityWithEmptyFile()
100 {
101 $this->logInAs('admin');
102 $client = $this->getClient();
103
104 $crawler = $client->request('GET', '/import/readability');
105 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
106
107 $file = new UploadedFile(__DIR__.'/../fixtures/test.txt', 'test.txt');
108
109 $data = [
110 'upload_import_file[file]' => $file,
111 ];
112
113 $client->submit($form, $data);
114
115 $this->assertEquals(302, $client->getResponse()->getStatusCode());
116
117 $crawler = $client->followRedirect();
118
119 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
120 $this->assertContains('flashes.import.notice.failed', $body[0]);
121 }
122}
diff --git a/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php
new file mode 100644
index 00000000..706d707b
--- /dev/null
+++ b/tests/Wallabag/ImportBundle/Import/ReadabilityImportTest.php
@@ -0,0 +1,150 @@
1<?php
2
3namespace Tests\Wallabag\ImportBundle\Import;
4
5use Wallabag\ImportBundle\Import\ReadabilityImport;
6use Wallabag\UserBundle\Entity\User;
7use Wallabag\CoreBundle\Entity\Entry;
8use Monolog\Logger;
9use Monolog\Handler\TestHandler;
10
11class ReadabilityImportTest extends \PHPUnit_Framework_TestCase
12{
13 protected $user;
14 protected $em;
15 protected $logHandler;
16 protected $contentProxy;
17
18 private function getReadabilityImport($unsetUser = false)
19 {
20 $this->user = new User();
21
22 $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
23 ->disableOriginalConstructor()
24 ->getMock();
25
26 $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy')
27 ->disableOriginalConstructor()
28 ->getMock();
29
30 $wallabag = new ReadabilityImport($this->em, $this->contentProxy);
31
32 $this->logHandler = new TestHandler();
33 $logger = new Logger('test', [$this->logHandler]);
34 $wallabag->setLogger($logger);
35
36 if (false === $unsetUser) {
37 $wallabag->setUser($this->user);
38 }
39
40 return $wallabag;
41 }
42
43 public function testInit()
44 {
45 $readabilityImport = $this->getReadabilityImport();
46
47 $this->assertEquals('Readability', $readabilityImport->getName());
48 $this->assertNotEmpty($readabilityImport->getUrl());
49 $this->assertEquals('import.readability.description', $readabilityImport->getDescription());
50 }
51
52 public function testImport()
53 {
54 $readabilityImport = $this->getReadabilityImport();
55 $readabilityImport->setFilepath(__DIR__.'/../fixtures/readability.json');
56
57 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
58 ->disableOriginalConstructor()
59 ->getMock();
60
61 $entryRepo->expects($this->exactly(2))
62 ->method('findByUrlAndUserId')
63 ->will($this->onConsecutiveCalls(false, true));
64
65 $this->em
66 ->expects($this->any())
67 ->method('getRepository')
68 ->willReturn($entryRepo);
69
70 $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry')
71 ->disableOriginalConstructor()
72 ->getMock();
73
74 $this->contentProxy
75 ->expects($this->exactly(1))
76 ->method('updateEntry')
77 ->willReturn($entry);
78
79 $res = $readabilityImport->import();
80
81 $this->assertTrue($res);
82 $this->assertEquals(['skipped' => 1, 'imported' => 1], $readabilityImport->getSummary());
83 }
84
85 public function testImportAndMarkAllAsRead()
86 {
87 $readabilityImport = $this->getReadabilityImport();
88 $readabilityImport->setFilepath(__DIR__.'/../fixtures/readability-read.json');
89
90 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
91 ->disableOriginalConstructor()
92 ->getMock();
93
94 $entryRepo->expects($this->exactly(2))
95 ->method('findByUrlAndUserId')
96 ->will($this->onConsecutiveCalls(false, false));
97
98 $this->em
99 ->expects($this->any())
100 ->method('getRepository')
101 ->willReturn($entryRepo);
102
103 $this->contentProxy
104 ->expects($this->exactly(2))
105 ->method('updateEntry')
106 ->willReturn(new Entry($this->user));
107
108 // check that every entry persisted are archived
109 $this->em
110 ->expects($this->any())
111 ->method('persist')
112 ->with($this->callback(function ($persistedEntry) {
113 return $persistedEntry->isArchived();
114 }));
115
116 $res = $readabilityImport->setMarkAsRead(true)->import();
117
118 $this->assertTrue($res);
119
120 $this->assertEquals(['skipped' => 0, 'imported' => 2], $readabilityImport->getSummary());
121 }
122
123 public function testImportBadFile()
124 {
125 $readabilityImport = $this->getReadabilityImport();
126 $readabilityImport->setFilepath(__DIR__.'/../fixtures/wallabag-v1.jsonx');
127
128 $res = $readabilityImport->import();
129
130 $this->assertFalse($res);
131
132 $records = $this->logHandler->getRecords();
133 $this->assertContains('ReadabilityImport: unable to read file', $records[0]['message']);
134 $this->assertEquals('ERROR', $records[0]['level_name']);
135 }
136
137 public function testImportUserNotDefined()
138 {
139 $readabilityImport = $this->getReadabilityImport(true);
140 $readabilityImport->setFilepath(__DIR__.'/../fixtures/readability.json');
141
142 $res = $readabilityImport->import();
143
144 $this->assertFalse($res);
145
146 $records = $this->logHandler->getRecords();
147 $this->assertContains('ReadabilityImport: user is not defined', $records[0]['message']);
148 $this->assertEquals('ERROR', $records[0]['level_name']);
149 }
150}
diff --git a/tests/Wallabag/ImportBundle/fixtures/readability-read.json b/tests/Wallabag/ImportBundle/fixtures/readability-read.json
new file mode 100644
index 00000000..c60767dc
--- /dev/null
+++ b/tests/Wallabag/ImportBundle/fixtures/readability-read.json
@@ -0,0 +1,25 @@
1{
2 "bookmarks": [
3 {
4 "article__excerpt": "This is a guest post from Moritz Beller from the Delft University of Technology in The Netherlands. His team produced amazing research on several million Travis CI builds, creating invaluable&hellip;",
5 "favorite": false,
6 "date_archived": "2016-08-02T06:49:30",
7 "article__url": "https://blog.travis-ci.com/2016-07-28-what-we-learned-from-analyzing-2-million-travis-builds/",
8 "date_added": "2016-08-01T05:24:16",
9 "date_favorited": null,
10 "article__title": "Travis",
11 "archive": true
12 },
13 {
14 "article__excerpt": "The GraphQL Type system describes the capabilities of a GraphQL server and is used to determine if a query is valid. The type system also describes the input types of query variables to determine if&hellip;",
15 "favorite": false,
16 "date_archived": "2016-07-19T06:48:31",
17 "article__url": "https://facebook.github.io/graphql/",
18 "date_added": "2016-06-24T17:50:16",
19 "date_favorited": null,
20 "article__title": "GraphQL",
21 "archive": true
22 }
23 ],
24 "recommendations": []
25}
diff --git a/tests/Wallabag/ImportBundle/fixtures/readability.json b/tests/Wallabag/ImportBundle/fixtures/readability.json
new file mode 100644
index 00000000..34379905
--- /dev/null
+++ b/tests/Wallabag/ImportBundle/fixtures/readability.json
@@ -0,0 +1,25 @@
1{
2 "bookmarks": [
3 {
4 "article__excerpt": "When Twitter started it had so much promise to change the way we communicate. But now it has been ruined by the amount of garbage and hate we have to wade through. It&#x2019;s like that polluted&hellip;",
5 "favorite": false,
6 "date_archived": null,
7 "article__url": "https://venngage.com/blog/hashtags-are-worthless/",
8 "date_added": "2016-08-25T12:05:00",
9 "date_favorited": null,
10 "article__title": "We Looked At 167,943 Tweets & Found Out Hashtags Are Worthless",
11 "archive": false
12 },
13 {
14 "article__excerpt": "TL;DR: Re-use your DOM elements and remove the ones that are far away from the viewport. Use placeholders to account for delayed data. Here&#x2019;s a demo and the code for the infinite&hellip;",
15 "favorite": false,
16 "date_archived": "2016-08-26T12:21:54",
17 "article__url": "https://developers.google.com/web/updates/2016/07/infinite-scroller?imm_mid=0e6839&cmp=em-webops-na-na-newsltr_20160805",
18 "date_added": "2016-08-06T05:35:26",
19 "date_favorited": null,
20 "article__title": "Complexities of an infinite scroller | Web Updates",
21 "archive": true
22 }
23 ],
24 "recommendations": []
25}