diff options
author | Jeremy Benoist <jeremy.benoist@gmail.com> | 2016-09-01 09:57:02 +0200 |
---|---|---|
committer | Jeremy Benoist <jeremy.benoist@gmail.com> | 2016-09-01 13:39:41 +0200 |
commit | a1a107705948c724aca7326f8550c336a25a6364 (patch) | |
tree | a34b02008987f8b05b31bf6b8c4d0e19b6ddf029 /tests/Wallabag/ImportBundle/Controller | |
parent | ca2a43ae7dc48d76fffe7d40976fb8c902a73dc7 (diff) | |
download | wallabag-a1a107705948c724aca7326f8550c336a25a6364.tar.gz wallabag-a1a107705948c724aca7326f8550c336a25a6364.tar.zst wallabag-a1a107705948c724aca7326f8550c336a25a6364.zip |
Add tests on ReadabilityImport
Diffstat (limited to 'tests/Wallabag/ImportBundle/Controller')
-rw-r--r-- | tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php | 122 |
1 files changed, 122 insertions, 0 deletions
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 | } | ||