diff options
Diffstat (limited to 'tests/Wallabag')
-rw-r--r-- | tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php | 149 | ||||
-rw-r--r-- | tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php (renamed from tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php) | 96 | ||||
-rw-r--r-- | tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php | 2 | ||||
-rw-r--r-- | tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php | 1 | ||||
-rw-r--r-- | tests/Wallabag/ImportBundle/Import/ChromeImportTest.php | 233 | ||||
-rw-r--r-- | tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php | 233 |
6 files changed, 679 insertions, 35 deletions
diff --git a/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php new file mode 100644 index 00000000..448e559f --- /dev/null +++ b/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php | |||
@@ -0,0 +1,149 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Tests\Wallabag\ImportBundle\Controller; | ||
4 | |||
5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | ||
6 | use Symfony\Component\HttpFoundation\File\UploadedFile; | ||
7 | |||
8 | class ChromeControllerTest extends WallabagCoreTestCase | ||
9 | { | ||
10 | public function testImportChrome() | ||
11 | { | ||
12 | $this->logInAs('admin'); | ||
13 | $client = $this->getClient(); | ||
14 | |||
15 | $crawler = $client->request('GET', '/import/chrome'); | ||
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 testImportChromeWithRabbitEnabled() | ||
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/chrome'); | ||
30 | |||
31 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
32 | $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); | ||
33 | $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); | ||
34 | |||
35 | $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 0); | ||
36 | } | ||
37 | |||
38 | public function testImportChromeBadFile() | ||
39 | { | ||
40 | $this->logInAs('admin'); | ||
41 | $client = $this->getClient(); | ||
42 | |||
43 | $crawler = $client->request('GET', '/import/chrome'); | ||
44 | $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); | ||
45 | |||
46 | $data = [ | ||
47 | 'upload_import_file[file]' => '', | ||
48 | ]; | ||
49 | |||
50 | $client->submit($form, $data); | ||
51 | |||
52 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
53 | } | ||
54 | |||
55 | public function testImportChromeWithRedisEnabled() | ||
56 | { | ||
57 | $this->logInAs('admin'); | ||
58 | $client = $this->getClient(); | ||
59 | $client->getContainer()->get('craue_config')->set('import_with_redis', 1); | ||
60 | |||
61 | $crawler = $client->request('GET', '/import/chrome'); | ||
62 | |||
63 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
64 | $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); | ||
65 | $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); | ||
66 | |||
67 | $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); | ||
68 | |||
69 | $file = new UploadedFile(__DIR__.'/../fixtures/chrome-bookmarks', 'Bookmarks'); | ||
70 | |||
71 | $data = [ | ||
72 | 'upload_import_file[file]' => $file, | ||
73 | ]; | ||
74 | |||
75 | $client->submit($form, $data); | ||
76 | |||
77 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
78 | |||
79 | $crawler = $client->followRedirect(); | ||
80 | |||
81 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | ||
82 | $this->assertContains('flashes.import.notice.summary', $body[0]); | ||
83 | |||
84 | $this->assertNotEmpty($client->getContainer()->get('wallabag_core.redis.client')->lpop('wallabag.import.chrome')); | ||
85 | |||
86 | $client->getContainer()->get('craue_config')->set('import_with_redis', 0); | ||
87 | } | ||
88 | |||
89 | public function testImportWallabagWithChromeFile() | ||
90 | { | ||
91 | $this->logInAs('admin'); | ||
92 | $client = $this->getClient(); | ||
93 | |||
94 | $crawler = $client->request('GET', '/import/chrome'); | ||
95 | $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); | ||
96 | |||
97 | $file = new UploadedFile(__DIR__.'/../fixtures/chrome-bookmarks', 'Bookmarks'); | ||
98 | |||
99 | $data = [ | ||
100 | 'upload_import_file[file]' => $file, | ||
101 | ]; | ||
102 | |||
103 | $client->submit($form, $data); | ||
104 | |||
105 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
106 | |||
107 | $crawler = $client->followRedirect(); | ||
108 | |||
109 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | ||
110 | $this->assertContains('flashes.import.notice.summary', $body[0]); | ||
111 | |||
112 | $content = $client->getContainer() | ||
113 | ->get('doctrine.orm.entity_manager') | ||
114 | ->getRepository('WallabagCoreBundle:Entry') | ||
115 | ->findByUrlAndUserId( | ||
116 | 'http://www.usinenouvelle.com/article/la-multiplication-des-chefs-de-projet-est-une-catastrophe-manageriale-majeure-affirme-le-sociologue-francois-dupuy.N307730', | ||
117 | $this->getLoggedInUserId() | ||
118 | ); | ||
119 | |||
120 | $this->assertEmpty($content->getMimetype()); | ||
121 | $this->assertNotEmpty($content->getPreviewPicture()); | ||
122 | $this->assertNotEmpty($content->getLanguage()); | ||
123 | $this->assertEquals(0, count($content->getTags())); | ||
124 | } | ||
125 | |||
126 | public function testImportWallabagWithEmptyFile() | ||
127 | { | ||
128 | $this->logInAs('admin'); | ||
129 | $client = $this->getClient(); | ||
130 | |||
131 | $crawler = $client->request('GET', '/import/chrome'); | ||
132 | $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); | ||
133 | |||
134 | $file = new UploadedFile(__DIR__.'/../fixtures/test.txt', 'test.txt'); | ||
135 | |||
136 | $data = [ | ||
137 | 'upload_import_file[file]' => $file, | ||
138 | ]; | ||
139 | |||
140 | $client->submit($form, $data); | ||
141 | |||
142 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
143 | |||
144 | $crawler = $client->followRedirect(); | ||
145 | |||
146 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | ||
147 | $this->assertContains('flashes.import.notice.failed', $body[0]); | ||
148 | } | ||
149 | } | ||
diff --git a/tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php b/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php index b686fcd9..2de0aa09 100644 --- a/tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php | |||
@@ -5,26 +5,65 @@ namespace Tests\Wallabag\ImportBundle\Controller; | |||
5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | 5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; |
6 | use Symfony\Component\HttpFoundation\File\UploadedFile; | 6 | use Symfony\Component\HttpFoundation\File\UploadedFile; |
7 | 7 | ||
8 | class BrowserControllerTest extends WallabagCoreTestCase | 8 | class FirefoxControllerTest extends WallabagCoreTestCase |
9 | { | 9 | { |
10 | public function testImportWallabag() | 10 | public function testImportFirefox() |
11 | { | 11 | { |
12 | $this->logInAs('admin'); | 12 | $this->logInAs('admin'); |
13 | $client = $this->getClient(); | 13 | $client = $this->getClient(); |
14 | 14 | ||
15 | $crawler = $client->request('GET', '/import/browser'); | 15 | $crawler = $client->request('GET', '/import/firefox'); |
16 | 16 | ||
17 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 17 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); |
18 | $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); | 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()); | 19 | $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); |
20 | } | 20 | } |
21 | 21 | ||
22 | public function testImportWallabagWithFirefoxFile() | 22 | public function testImportFirefoxWithRabbitEnabled() |
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/firefox'); | ||
30 | |||
31 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
32 | $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); | ||
33 | $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); | ||
34 | |||
35 | $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 0); | ||
36 | } | ||
37 | |||
38 | public function testImportFirefoxBadFile() | ||
23 | { | 39 | { |
24 | $this->logInAs('admin'); | 40 | $this->logInAs('admin'); |
25 | $client = $this->getClient(); | 41 | $client = $this->getClient(); |
26 | 42 | ||
27 | $crawler = $client->request('GET', '/import/browser'); | 43 | $crawler = $client->request('GET', '/import/firefox'); |
44 | $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); | ||
45 | |||
46 | $data = [ | ||
47 | 'upload_import_file[file]' => '', | ||
48 | ]; | ||
49 | |||
50 | $client->submit($form, $data); | ||
51 | |||
52 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
53 | } | ||
54 | |||
55 | public function testImportFirefoxWithRedisEnabled() | ||
56 | { | ||
57 | $this->logInAs('admin'); | ||
58 | $client = $this->getClient(); | ||
59 | $client->getContainer()->get('craue_config')->set('import_with_redis', 1); | ||
60 | |||
61 | $crawler = $client->request('GET', '/import/firefox'); | ||
62 | |||
63 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
64 | $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); | ||
65 | $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); | ||
66 | |||
28 | $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); | 67 | $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); |
29 | 68 | ||
30 | $file = new UploadedFile(__DIR__.'/../fixtures/firefox-bookmarks.json', 'Bookmarks'); | 69 | $file = new UploadedFile(__DIR__.'/../fixtures/firefox-bookmarks.json', 'Bookmarks'); |
@@ -42,41 +81,20 @@ class BrowserControllerTest extends WallabagCoreTestCase | |||
42 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | 81 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); |
43 | $this->assertContains('flashes.import.notice.summary', $body[0]); | 82 | $this->assertContains('flashes.import.notice.summary', $body[0]); |
44 | 83 | ||
45 | $content = $client->getContainer() | 84 | $this->assertNotEmpty($client->getContainer()->get('wallabag_core.redis.client')->lpop('wallabag.import.firefox')); |
46 | ->get('doctrine.orm.entity_manager') | ||
47 | ->getRepository('WallabagCoreBundle:Entry') | ||
48 | ->findByUrlAndUserId( | ||
49 | 'http://lexpansion.lexpress.fr/high-tech/orange-offre-un-meilleur-reseau-mobile-que-bouygues-et-sfr-free-derriere_1811554.html', | ||
50 | $this->getLoggedInUserId() | ||
51 | ); | ||
52 | |||
53 | $this->assertNotEmpty($content->getMimetype()); | ||
54 | $this->assertNotEmpty($content->getPreviewPicture()); | ||
55 | $this->assertNotEmpty($content->getLanguage()); | ||
56 | $this->assertEquals(0, count($content->getTags())); | ||
57 | |||
58 | $content = $client->getContainer() | ||
59 | ->get('doctrine.orm.entity_manager') | ||
60 | ->getRepository('WallabagCoreBundle:Entry') | ||
61 | ->findByUrlAndUserId( | ||
62 | 'http://stackoverflow.com/questions/15017163/parser-for-exported-bookmarks-html-file-of-google-chrome-and-mozilla-in-java', | ||
63 | $this->getLoggedInUserId() | ||
64 | ); | ||
65 | 85 | ||
66 | $this->assertNotEmpty($content->getMimetype()); | 86 | $client->getContainer()->get('craue_config')->set('import_with_redis', 0); |
67 | $this->assertNotEmpty($content->getPreviewPicture()); | ||
68 | $this->assertEmpty($content->getLanguage()); | ||
69 | } | 87 | } |
70 | 88 | ||
71 | public function testImportWallabagWithChromeFile() | 89 | public function testImportWallabagWithFirefoxFile() |
72 | { | 90 | { |
73 | $this->logInAs('admin'); | 91 | $this->logInAs('admin'); |
74 | $client = $this->getClient(); | 92 | $client = $this->getClient(); |
75 | 93 | ||
76 | $crawler = $client->request('GET', '/import/browser'); | 94 | $crawler = $client->request('GET', '/import/firefox'); |
77 | $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); | 95 | $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); |
78 | 96 | ||
79 | $file = new UploadedFile(__DIR__.'/../fixtures/chrome-bookmarks', 'Bookmarks'); | 97 | $file = new UploadedFile(__DIR__.'/../fixtures/firefox-bookmarks.json', 'Bookmarks'); |
80 | 98 | ||
81 | $data = [ | 99 | $data = [ |
82 | 'upload_import_file[file]' => $file, | 100 | 'upload_import_file[file]' => $file, |
@@ -95,7 +113,7 @@ class BrowserControllerTest extends WallabagCoreTestCase | |||
95 | ->get('doctrine.orm.entity_manager') | 113 | ->get('doctrine.orm.entity_manager') |
96 | ->getRepository('WallabagCoreBundle:Entry') | 114 | ->getRepository('WallabagCoreBundle:Entry') |
97 | ->findByUrlAndUserId( | 115 | ->findByUrlAndUserId( |
98 | 'http://www.usinenouvelle.com/article/la-multiplication-des-chefs-de-projet-est-une-catastrophe-manageriale-majeure-affirme-le-sociologue-francois-dupuy.N307730', | 116 | 'http://lexpansion.lexpress.fr/high-tech/orange-offre-un-meilleur-reseau-mobile-que-bouygues-et-sfr-free-derriere_1811554.html', |
99 | $this->getLoggedInUserId() | 117 | $this->getLoggedInUserId() |
100 | ); | 118 | ); |
101 | 119 | ||
@@ -103,6 +121,18 @@ class BrowserControllerTest extends WallabagCoreTestCase | |||
103 | $this->assertNotEmpty($content->getPreviewPicture()); | 121 | $this->assertNotEmpty($content->getPreviewPicture()); |
104 | $this->assertNotEmpty($content->getLanguage()); | 122 | $this->assertNotEmpty($content->getLanguage()); |
105 | $this->assertEquals(0, count($content->getTags())); | 123 | $this->assertEquals(0, count($content->getTags())); |
124 | |||
125 | $content = $client->getContainer() | ||
126 | ->get('doctrine.orm.entity_manager') | ||
127 | ->getRepository('WallabagCoreBundle:Entry') | ||
128 | ->findByUrlAndUserId( | ||
129 | 'http://stackoverflow.com/questions/15017163/parser-for-exported-bookmarks-html-file-of-google-chrome-and-mozilla-in-java', | ||
130 | $this->getLoggedInUserId() | ||
131 | ); | ||
132 | |||
133 | $this->assertNotEmpty($content->getMimetype()); | ||
134 | $this->assertNotEmpty($content->getPreviewPicture()); | ||
135 | $this->assertEmpty($content->getLanguage()); | ||
106 | } | 136 | } |
107 | 137 | ||
108 | public function testImportWallabagWithEmptyFile() | 138 | public function testImportWallabagWithEmptyFile() |
@@ -110,7 +140,7 @@ class BrowserControllerTest extends WallabagCoreTestCase | |||
110 | $this->logInAs('admin'); | 140 | $this->logInAs('admin'); |
111 | $client = $this->getClient(); | 141 | $client = $this->getClient(); |
112 | 142 | ||
113 | $crawler = $client->request('GET', '/import/browser'); | 143 | $crawler = $client->request('GET', '/import/firefox'); |
114 | $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); | 144 | $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); |
115 | 145 | ||
116 | $file = new UploadedFile(__DIR__.'/../fixtures/test.txt', 'test.txt'); | 146 | $file = new UploadedFile(__DIR__.'/../fixtures/test.txt', 'test.txt'); |
diff --git a/tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php index 23a7c877..b6783a56 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(5, $crawler->filter('blockquote')->count()); | 27 | $this->assertEquals(6, $crawler->filter('blockquote')->count()); |
28 | } | 28 | } |
29 | } | 29 | } |
diff --git a/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php index 87ecb9d3..916dd297 100644 --- a/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php | |||
@@ -57,7 +57,6 @@ class ReadabilityControllerTest extends WallabagCoreTestCase | |||
57 | $this->checkRedis(); | 57 | $this->checkRedis(); |
58 | $this->logInAs('admin'); | 58 | $this->logInAs('admin'); |
59 | $client = $this->getClient(); | 59 | $client = $this->getClient(); |
60 | |||
61 | $client->getContainer()->get('craue_config')->set('import_with_redis', 1); | 60 | $client->getContainer()->get('craue_config')->set('import_with_redis', 1); |
62 | 61 | ||
63 | $crawler = $client->request('GET', '/import/readability'); | 62 | $crawler = $client->request('GET', '/import/readability'); |
diff --git a/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php b/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php new file mode 100644 index 00000000..f781a4d2 --- /dev/null +++ b/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php | |||
@@ -0,0 +1,233 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Tests\Wallabag\ImportBundle\Import; | ||
4 | |||
5 | use Wallabag\ImportBundle\Import\ChromeImport; | ||
6 | use Wallabag\UserBundle\Entity\User; | ||
7 | use Wallabag\CoreBundle\Entity\Entry; | ||
8 | use Wallabag\ImportBundle\Redis\Producer; | ||
9 | use Monolog\Logger; | ||
10 | use Monolog\Handler\TestHandler; | ||
11 | use Simpleue\Queue\RedisQueue; | ||
12 | use M6Web\Component\RedisMock\RedisMockFactory; | ||
13 | |||
14 | class ChromeImportTest extends \PHPUnit_Framework_TestCase | ||
15 | { | ||
16 | protected $user; | ||
17 | protected $em; | ||
18 | protected $logHandler; | ||
19 | protected $contentProxy; | ||
20 | |||
21 | private function getChromeImport($unsetUser = false) | ||
22 | { | ||
23 | $this->user = new User(); | ||
24 | |||
25 | $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') | ||
26 | ->disableOriginalConstructor() | ||
27 | ->getMock(); | ||
28 | |||
29 | $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') | ||
30 | ->disableOriginalConstructor() | ||
31 | ->getMock(); | ||
32 | |||
33 | $wallabag = new ChromeImport($this->em, $this->contentProxy); | ||
34 | |||
35 | $this->logHandler = new TestHandler(); | ||
36 | $logger = new Logger('test', [$this->logHandler]); | ||
37 | $wallabag->setLogger($logger); | ||
38 | |||
39 | if (false === $unsetUser) { | ||
40 | $wallabag->setUser($this->user); | ||
41 | } | ||
42 | |||
43 | return $wallabag; | ||
44 | } | ||
45 | |||
46 | public function testInit() | ||
47 | { | ||
48 | $chromeImport = $this->getChromeImport(); | ||
49 | |||
50 | $this->assertEquals('Chrome', $chromeImport->getName()); | ||
51 | $this->assertNotEmpty($chromeImport->getUrl()); | ||
52 | $this->assertEquals('import.chrome.description', $chromeImport->getDescription()); | ||
53 | } | ||
54 | |||
55 | public function testImport() | ||
56 | { | ||
57 | $chromeImport = $this->getChromeImport(); | ||
58 | $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks'); | ||
59 | |||
60 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') | ||
61 | ->disableOriginalConstructor() | ||
62 | ->getMock(); | ||
63 | |||
64 | $entryRepo->expects($this->exactly(4)) | ||
65 | ->method('findByUrlAndUserId') | ||
66 | ->willReturn(false); | ||
67 | |||
68 | $this->em | ||
69 | ->expects($this->any()) | ||
70 | ->method('getRepository') | ||
71 | ->willReturn($entryRepo); | ||
72 | |||
73 | $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry') | ||
74 | ->disableOriginalConstructor() | ||
75 | ->getMock(); | ||
76 | |||
77 | $this->contentProxy | ||
78 | ->expects($this->exactly(4)) | ||
79 | ->method('updateEntry') | ||
80 | ->willReturn($entry); | ||
81 | |||
82 | $res = $chromeImport->import(); | ||
83 | |||
84 | $this->assertTrue($res); | ||
85 | $this->assertEquals(['skipped' => 0, 'imported' => 4, 'queued' => 0], $chromeImport->getSummary()); | ||
86 | } | ||
87 | |||
88 | public function testImportAndMarkAllAsRead() | ||
89 | { | ||
90 | $chromeImport = $this->getChromeImport(); | ||
91 | $chromeImport->setFilepath(__DIR__.'/../fixtures/readability-read.json'); | ||
92 | |||
93 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') | ||
94 | ->disableOriginalConstructor() | ||
95 | ->getMock(); | ||
96 | |||
97 | $entryRepo->expects($this->exactly(2)) | ||
98 | ->method('findByUrlAndUserId') | ||
99 | ->will($this->onConsecutiveCalls(false, true)); | ||
100 | |||
101 | $this->em | ||
102 | ->expects($this->any()) | ||
103 | ->method('getRepository') | ||
104 | ->willReturn($entryRepo); | ||
105 | |||
106 | $this->contentProxy | ||
107 | ->expects($this->exactly(1)) | ||
108 | ->method('updateEntry') | ||
109 | ->willReturn(new Entry($this->user)); | ||
110 | |||
111 | // check that every entry persisted are archived | ||
112 | $this->em | ||
113 | ->expects($this->any()) | ||
114 | ->method('persist') | ||
115 | ->with($this->callback(function ($persistedEntry) { | ||
116 | return $persistedEntry->isArchived(); | ||
117 | })); | ||
118 | |||
119 | $res = $chromeImport->setMarkAsRead(true)->import(); | ||
120 | |||
121 | $this->assertTrue($res); | ||
122 | |||
123 | $this->assertEquals(['skipped' => 1, 'imported' => 1, 'queued' => 0], $chromeImport->getSummary()); | ||
124 | } | ||
125 | |||
126 | public function testImportWithRabbit() | ||
127 | { | ||
128 | $chromeImport = $this->getChromeImport(); | ||
129 | $chromeImport->setFilepath(__DIR__.'/../fixtures/readability.json'); | ||
130 | |||
131 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') | ||
132 | ->disableOriginalConstructor() | ||
133 | ->getMock(); | ||
134 | |||
135 | $entryRepo->expects($this->never()) | ||
136 | ->method('findByUrlAndUserId'); | ||
137 | |||
138 | $this->em | ||
139 | ->expects($this->never()) | ||
140 | ->method('getRepository'); | ||
141 | |||
142 | $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry') | ||
143 | ->disableOriginalConstructor() | ||
144 | ->getMock(); | ||
145 | |||
146 | $this->contentProxy | ||
147 | ->expects($this->never()) | ||
148 | ->method('updateEntry'); | ||
149 | |||
150 | $producer = $this->getMockBuilder('OldSound\RabbitMqBundle\RabbitMq\Producer') | ||
151 | ->disableOriginalConstructor() | ||
152 | ->getMock(); | ||
153 | |||
154 | $producer | ||
155 | ->expects($this->exactly(4)) | ||
156 | ->method('publish'); | ||
157 | |||
158 | $chromeImport->setProducer($producer); | ||
159 | |||
160 | $res = $readabilityImport->setMarkAsRead(true)->import(); | ||
161 | |||
162 | $this->assertTrue($res); | ||
163 | $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $chromeImport->getSummary()); | ||
164 | } | ||
165 | |||
166 | public function testImportWithRedis() | ||
167 | { | ||
168 | $chromeImport = $this->getReadabilityImport(); | ||
169 | $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks'); | ||
170 | |||
171 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') | ||
172 | ->disableOriginalConstructor() | ||
173 | ->getMock(); | ||
174 | |||
175 | $entryRepo->expects($this->never()) | ||
176 | ->method('findByUrlAndUserId'); | ||
177 | |||
178 | $this->em | ||
179 | ->expects($this->never()) | ||
180 | ->method('getRepository'); | ||
181 | |||
182 | $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry') | ||
183 | ->disableOriginalConstructor() | ||
184 | ->getMock(); | ||
185 | |||
186 | $this->contentProxy | ||
187 | ->expects($this->never()) | ||
188 | ->method('updateEntry'); | ||
189 | |||
190 | $factory = new RedisMockFactory(); | ||
191 | $redisMock = $factory->getAdapter('Predis\Client', true); | ||
192 | |||
193 | $queue = new RedisQueue($redisMock, 'chrome'); | ||
194 | $producer = new Producer($queue); | ||
195 | |||
196 | $chromeImport->setProducer($producer); | ||
197 | |||
198 | $res = $chromeImport->setMarkAsRead(true)->import(); | ||
199 | |||
200 | $this->assertTrue($res); | ||
201 | $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $chromeImport->getSummary()); | ||
202 | |||
203 | $this->assertNotEmpty($redisMock->lpop('chrome')); | ||
204 | } | ||
205 | |||
206 | public function testImportBadFile() | ||
207 | { | ||
208 | $chromeImport = $this->getChromeImport(); | ||
209 | $chromeImport->setFilepath(__DIR__.'/../fixtures/wallabag-v1.jsonx'); | ||
210 | |||
211 | $res = $chromeImport->import(); | ||
212 | |||
213 | $this->assertFalse($res); | ||
214 | |||
215 | $records = $this->logHandler->getRecords(); | ||
216 | $this->assertContains('ChromeImport: unable to read file', $records[0]['message']); | ||
217 | $this->assertEquals('ERROR', $records[0]['level_name']); | ||
218 | } | ||
219 | |||
220 | public function testImportUserNotDefined() | ||
221 | { | ||
222 | $chromeImport = $this->getChromeImport(true); | ||
223 | $chromeImport->setFilepath(__DIR__.'/../fixtures/readability.json'); | ||
224 | |||
225 | $res = $chromeImport->import(); | ||
226 | |||
227 | $this->assertFalse($res); | ||
228 | |||
229 | $records = $this->logHandler->getRecords(); | ||
230 | $this->assertContains('ChromeImport: user is not defined', $records[0]['message']); | ||
231 | $this->assertEquals('ERROR', $records[0]['level_name']); | ||
232 | } | ||
233 | } | ||
diff --git a/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php b/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php new file mode 100644 index 00000000..0b4a28b4 --- /dev/null +++ b/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php | |||
@@ -0,0 +1,233 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Tests\Wallabag\ImportBundle\Import; | ||
4 | |||
5 | use Wallabag\ImportBundle\Import\FirefoxImport; | ||
6 | use Wallabag\UserBundle\Entity\User; | ||
7 | use Wallabag\CoreBundle\Entity\Entry; | ||
8 | use Wallabag\ImportBundle\Redis\Producer; | ||
9 | use Monolog\Logger; | ||
10 | use Monolog\Handler\TestHandler; | ||
11 | use Simpleue\Queue\RedisQueue; | ||
12 | use M6Web\Component\RedisMock\RedisMockFactory; | ||
13 | |||
14 | class FirefoxImportTest extends \PHPUnit_Framework_TestCase | ||
15 | { | ||
16 | protected $user; | ||
17 | protected $em; | ||
18 | protected $logHandler; | ||
19 | protected $contentProxy; | ||
20 | |||
21 | private function getFirefoxImport($unsetUser = false) | ||
22 | { | ||
23 | $this->user = new User(); | ||
24 | |||
25 | $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') | ||
26 | ->disableOriginalConstructor() | ||
27 | ->getMock(); | ||
28 | |||
29 | $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') | ||
30 | ->disableOriginalConstructor() | ||
31 | ->getMock(); | ||
32 | |||
33 | $wallabag = new FirefoxImport($this->em, $this->contentProxy); | ||
34 | |||
35 | $this->logHandler = new TestHandler(); | ||
36 | $logger = new Logger('test', [$this->logHandler]); | ||
37 | $wallabag->setLogger($logger); | ||
38 | |||
39 | if (false === $unsetUser) { | ||
40 | $wallabag->setUser($this->user); | ||
41 | } | ||
42 | |||
43 | return $wallabag; | ||
44 | } | ||
45 | |||
46 | public function testInit() | ||
47 | { | ||
48 | $firefoxImport = $this->getFirefoxImport(); | ||
49 | |||
50 | $this->assertEquals('Firefox', $firefoxImport->getName()); | ||
51 | $this->assertNotEmpty($firefoxImport->getUrl()); | ||
52 | $this->assertEquals('import.firefox.description', $firefoxImport->getDescription()); | ||
53 | } | ||
54 | |||
55 | public function testImport() | ||
56 | { | ||
57 | $firefoxImport = $this->getFirefoxImport(); | ||
58 | $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json'); | ||
59 | |||
60 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') | ||
61 | ->disableOriginalConstructor() | ||
62 | ->getMock(); | ||
63 | |||
64 | $entryRepo->expects($this->exactly(4)) | ||
65 | ->method('findByUrlAndUserId') | ||
66 | ->willReturn(false); | ||
67 | |||
68 | $this->em | ||
69 | ->expects($this->any()) | ||
70 | ->method('getRepository') | ||
71 | ->willReturn($entryRepo); | ||
72 | |||
73 | $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry') | ||
74 | ->disableOriginalConstructor() | ||
75 | ->getMock(); | ||
76 | |||
77 | $this->contentProxy | ||
78 | ->expects($this->exactly(4)) | ||
79 | ->method('updateEntry') | ||
80 | ->willReturn($entry); | ||
81 | |||
82 | $res = $firefoxImport->import(); | ||
83 | |||
84 | $this->assertTrue($res); | ||
85 | $this->assertEquals(['skipped' => 0, 'imported' => 4, 'queued' => 0], $firefoxImport->getSummary()); | ||
86 | } | ||
87 | |||
88 | public function testImportAndMarkAllAsRead() | ||
89 | { | ||
90 | $firefoxImport = $this->getFirefoxImport(); | ||
91 | $firefoxImport->setFilepath(__DIR__.'/../fixtures/readability-read.json'); | ||
92 | |||
93 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') | ||
94 | ->disableOriginalConstructor() | ||
95 | ->getMock(); | ||
96 | |||
97 | $entryRepo->expects($this->exactly(2)) | ||
98 | ->method('findByUrlAndUserId') | ||
99 | ->will($this->onConsecutiveCalls(false, true)); | ||
100 | |||
101 | $this->em | ||
102 | ->expects($this->any()) | ||
103 | ->method('getRepository') | ||
104 | ->willReturn($entryRepo); | ||
105 | |||
106 | $this->contentProxy | ||
107 | ->expects($this->exactly(1)) | ||
108 | ->method('updateEntry') | ||
109 | ->willReturn(new Entry($this->user)); | ||
110 | |||
111 | // check that every entry persisted are archived | ||
112 | $this->em | ||
113 | ->expects($this->any()) | ||
114 | ->method('persist') | ||
115 | ->with($this->callback(function ($persistedEntry) { | ||
116 | return $persistedEntry->isArchived(); | ||
117 | })); | ||
118 | |||
119 | $res = $firefoxImport->setMarkAsRead(true)->import(); | ||
120 | |||
121 | $this->assertTrue($res); | ||
122 | |||
123 | $this->assertEquals(['skipped' => 1, 'imported' => 1, 'queued' => 0], $firefoxImport->getSummary()); | ||
124 | } | ||
125 | |||
126 | public function testImportWithRabbit() | ||
127 | { | ||
128 | $firefoxImport = $this->getFirefoxImport(); | ||
129 | $firefoxImport->setFilepath(__DIR__.'/../fixtures/readability.json'); | ||
130 | |||
131 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') | ||
132 | ->disableOriginalConstructor() | ||
133 | ->getMock(); | ||
134 | |||
135 | $entryRepo->expects($this->never()) | ||
136 | ->method('findByUrlAndUserId'); | ||
137 | |||
138 | $this->em | ||
139 | ->expects($this->never()) | ||
140 | ->method('getRepository'); | ||
141 | |||
142 | $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry') | ||
143 | ->disableOriginalConstructor() | ||
144 | ->getMock(); | ||
145 | |||
146 | $this->contentProxy | ||
147 | ->expects($this->never()) | ||
148 | ->method('updateEntry'); | ||
149 | |||
150 | $producer = $this->getMockBuilder('OldSound\RabbitMqBundle\RabbitMq\Producer') | ||
151 | ->disableOriginalConstructor() | ||
152 | ->getMock(); | ||
153 | |||
154 | $producer | ||
155 | ->expects($this->exactly(4)) | ||
156 | ->method('publish'); | ||
157 | |||
158 | $firefoxImport->setProducer($producer); | ||
159 | |||
160 | $res = $readabilityImport->setMarkAsRead(true)->import(); | ||
161 | |||
162 | $this->assertTrue($res); | ||
163 | $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $firefoxImport->getSummary()); | ||
164 | } | ||
165 | |||
166 | public function testImportWithRedis() | ||
167 | { | ||
168 | $firefoxImport = $this->getReadabilityImport(); | ||
169 | $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json'); | ||
170 | |||
171 | $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') | ||
172 | ->disableOriginalConstructor() | ||
173 | ->getMock(); | ||
174 | |||
175 | $entryRepo->expects($this->never()) | ||
176 | ->method('findByUrlAndUserId'); | ||
177 | |||
178 | $this->em | ||
179 | ->expects($this->never()) | ||
180 | ->method('getRepository'); | ||
181 | |||
182 | $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry') | ||
183 | ->disableOriginalConstructor() | ||
184 | ->getMock(); | ||
185 | |||
186 | $this->contentProxy | ||
187 | ->expects($this->never()) | ||
188 | ->method('updateEntry'); | ||
189 | |||
190 | $factory = new RedisMockFactory(); | ||
191 | $redisMock = $factory->getAdapter('Predis\Client', true); | ||
192 | |||
193 | $queue = new RedisQueue($redisMock, 'firefox'); | ||
194 | $producer = new Producer($queue); | ||
195 | |||
196 | $firefoxImport->setProducer($producer); | ||
197 | |||
198 | $res = $firefoxImport->setMarkAsRead(true)->import(); | ||
199 | |||
200 | $this->assertTrue($res); | ||
201 | $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $firefoxImport->getSummary()); | ||
202 | |||
203 | $this->assertNotEmpty($redisMock->lpop('firefox')); | ||
204 | } | ||
205 | |||
206 | public function testImportBadFile() | ||
207 | { | ||
208 | $firefoxImport = $this->getFirefoxImport(); | ||
209 | $firefoxImport->setFilepath(__DIR__.'/../fixtures/wallabag-v1.jsonx'); | ||
210 | |||
211 | $res = $firefoxImport->import(); | ||
212 | |||
213 | $this->assertFalse($res); | ||
214 | |||
215 | $records = $this->logHandler->getRecords(); | ||
216 | $this->assertContains('FirefoxImport: unable to read file', $records[0]['message']); | ||
217 | $this->assertEquals('ERROR', $records[0]['level_name']); | ||
218 | } | ||
219 | |||
220 | public function testImportUserNotDefined() | ||
221 | { | ||
222 | $firefoxImport = $this->getFirefoxImport(true); | ||
223 | $firefoxImport->setFilepath(__DIR__.'/../fixtures/readability.json'); | ||
224 | |||
225 | $res = $firefoxImport->import(); | ||
226 | |||
227 | $this->assertFalse($res); | ||
228 | |||
229 | $records = $this->logHandler->getRecords(); | ||
230 | $this->assertContains('FirefoxImport: user is not defined', $records[0]['message']); | ||
231 | $this->assertEquals('ERROR', $records[0]['level_name']); | ||
232 | } | ||
233 | } | ||