]>
Commit | Line | Data |
---|---|---|
a1a10770 JB |
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 | ||
13470c35 JB |
22 | public function testImportReadabilityWithRabbitEnabled() |
23 | { | |
24 | $this->logInAs('admin'); | |
25 | $client = $this->getClient(); | |
26 | ||
b3437d58 | 27 | $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 1); |
13470c35 JB |
28 | |
29 | $crawler = $client->request('GET', '/import/readability'); | |
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 | ||
b3437d58 JB |
35 | $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 0); |
36 | } | |
37 | ||
38 | public function testImportReadabilityWithRedisEnabled() | |
39 | { | |
40 | $this->logInAs('admin'); | |
41 | $client = $this->getClient(); | |
42 | ||
43 | $client->getContainer()->get('craue_config')->set('import_with_redis', 1); | |
44 | ||
45 | $crawler = $client->request('GET', '/import/readability'); | |
46 | ||
47 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
48 | $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); | |
49 | $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); | |
50 | ||
51 | $client->getContainer()->get('craue_config')->set('import_with_redis', 0); | |
13470c35 JB |
52 | } |
53 | ||
015c7a83 JB |
54 | public function testImportReadabilityBadFile() |
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 | $data = [ | |
63 | 'upload_import_file[file]' => '', | |
64 | ]; | |
65 | ||
66 | $client->submit($form, $data); | |
67 | ||
68 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
69 | } | |
70 | ||
a1a10770 JB |
71 | public function testImportReadabilityWithFile() |
72 | { | |
73 | $this->logInAs('admin'); | |
74 | $client = $this->getClient(); | |
75 | ||
76 | $crawler = $client->request('GET', '/import/readability'); | |
77 | $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); | |
78 | ||
79 | $file = new UploadedFile(__DIR__.'/../fixtures/readability.json', 'readability.json'); | |
80 | ||
81 | $data = [ | |
82 | 'upload_import_file[file]' => $file, | |
83 | ]; | |
84 | ||
85 | $client->submit($form, $data); | |
86 | ||
87 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
88 | ||
89 | $crawler = $client->followRedirect(); | |
90 | ||
91 | $content = $client->getContainer() | |
92 | ->get('doctrine.orm.entity_manager') | |
93 | ->getRepository('WallabagCoreBundle:Entry') | |
94 | ->findByUrlAndUserId( | |
95 | 'https://venngage.com/blog/hashtags-are-worthless/', | |
96 | $this->getLoggedInUserId() | |
97 | ); | |
98 | ||
99 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | |
100 | $this->assertContains('flashes.import.notice.summary', $body[0]); | |
6d65c0a8 JB |
101 | |
102 | $this->assertNotEmpty($content->getMimetype()); | |
103 | $this->assertNotEmpty($content->getPreviewPicture()); | |
104 | $this->assertNotEmpty($content->getLanguage()); | |
105 | $this->assertEquals(0, count($content->getTags())); | |
106 | $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt()); | |
107 | $this->assertEquals('2016-08-25', $content->getCreatedAt()->format('Y-m-d')); | |
a1a10770 JB |
108 | } |
109 | ||
110 | public function testImportReadabilityWithFileAndMarkAllAsRead() | |
111 | { | |
112 | $this->logInAs('admin'); | |
113 | $client = $this->getClient(); | |
114 | ||
115 | $crawler = $client->request('GET', '/import/readability'); | |
116 | $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); | |
117 | ||
118 | $file = new UploadedFile(__DIR__.'/../fixtures/readability-read.json', 'readability-read.json'); | |
119 | ||
120 | $data = [ | |
121 | 'upload_import_file[file]' => $file, | |
122 | 'upload_import_file[mark_as_read]' => 1, | |
123 | ]; | |
124 | ||
125 | $client->submit($form, $data); | |
126 | ||
127 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
128 | ||
129 | $crawler = $client->followRedirect(); | |
130 | ||
131 | $content1 = $client->getContainer() | |
132 | ->get('doctrine.orm.entity_manager') | |
133 | ->getRepository('WallabagCoreBundle:Entry') | |
134 | ->findByUrlAndUserId( | |
135 | 'https://blog.travis-ci.com/2016-07-28-what-we-learned-from-analyzing-2-million-travis-builds/', | |
136 | $this->getLoggedInUserId() | |
137 | ); | |
138 | ||
139 | $this->assertTrue($content1->isArchived()); | |
140 | ||
141 | $content2 = $client->getContainer() | |
142 | ->get('doctrine.orm.entity_manager') | |
143 | ->getRepository('WallabagCoreBundle:Entry') | |
144 | ->findByUrlAndUserId( | |
145 | 'https://facebook.github.io/graphql/', | |
146 | $this->getLoggedInUserId() | |
147 | ); | |
148 | ||
149 | $this->assertTrue($content2->isArchived()); | |
150 | ||
151 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | |
152 | $this->assertContains('flashes.import.notice.summary', $body[0]); | |
153 | } | |
154 | ||
155 | public function testImportReadabilityWithEmptyFile() | |
156 | { | |
157 | $this->logInAs('admin'); | |
158 | $client = $this->getClient(); | |
159 | ||
160 | $crawler = $client->request('GET', '/import/readability'); | |
161 | $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); | |
162 | ||
163 | $file = new UploadedFile(__DIR__.'/../fixtures/test.txt', 'test.txt'); | |
164 | ||
165 | $data = [ | |
166 | 'upload_import_file[file]' => $file, | |
167 | ]; | |
168 | ||
169 | $client->submit($form, $data); | |
170 | ||
171 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
172 | ||
173 | $crawler = $client->followRedirect(); | |
174 | ||
175 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | |
176 | $this->assertContains('flashes.import.notice.failed', $body[0]); | |
177 | } | |
178 | } |