diff options
author | Jeremy Benoist <j0k3r@users.noreply.github.com> | 2016-09-01 14:18:48 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-09-01 14:18:48 +0200 |
commit | bd8c13e8b028bba7e8222c7e3f410e4444c794c5 (patch) | |
tree | f8fc8c534433e1fa1bb4e72cbf0eff0fde69d1ac /tests/Wallabag/ImportBundle/Controller | |
parent | cdd3010b478c9ca818dd6d22d03c81ef4a5ab208 (diff) | |
parent | dc9d76b4906c34a79fbfa6255814f267082033d5 (diff) | |
download | wallabag-bd8c13e8b028bba7e8222c7e3f410e4444c794c5.tar.gz wallabag-bd8c13e8b028bba7e8222c7e3f410e4444c794c5.tar.zst wallabag-bd8c13e8b028bba7e8222c7e3f410e4444c794c5.zip |
Merge pull request #2255 from wallabag/readability
Add Readability import
Diffstat (limited to 'tests/Wallabag/ImportBundle/Controller')
-rw-r--r-- | tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php | 2 | ||||
-rw-r--r-- | tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php | 122 |
2 files changed, 123 insertions, 1 deletions
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 | |||
3 | namespace Tests\Wallabag\ImportBundle\Controller; | ||
4 | |||
5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | ||
6 | use Symfony\Component\HttpFoundation\File\UploadedFile; | ||
7 | |||
8 | class 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 | } | ||