]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | ||
3 | namespace Wallabag\CoreBundle\Tests\Controller; | |
4 | ||
5 | use Wallabag\CoreBundle\Tests\WallabagCoreTestCase; | |
6 | ||
7 | class EntryControllerTest extends WallabagCoreTestCase | |
8 | { | |
9 | public $url = 'http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html'; | |
10 | ||
11 | public function testLogin() | |
12 | { | |
13 | $client = $this->getClient(); | |
14 | ||
15 | $client->request('GET', '/new'); | |
16 | ||
17 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
18 | $this->assertContains('login', $client->getResponse()->headers->get('location')); | |
19 | } | |
20 | ||
21 | public function testGetNew() | |
22 | { | |
23 | $this->logInAs('admin'); | |
24 | $client = $this->getClient(); | |
25 | ||
26 | $crawler = $client->request('GET', '/new'); | |
27 | ||
28 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
29 | ||
30 | $this->assertCount(1, $crawler->filter('input[type=url]')); | |
31 | $this->assertCount(1, $crawler->filter('button[type=submit]')); | |
32 | } | |
33 | ||
34 | public function testPostNewEmpty() | |
35 | { | |
36 | $this->logInAs('admin'); | |
37 | $client = $this->getClient(); | |
38 | ||
39 | $crawler = $client->request('GET', '/new'); | |
40 | ||
41 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
42 | ||
43 | $form = $crawler->filter('button[type=submit]')->form(); | |
44 | ||
45 | $crawler = $client->submit($form); | |
46 | ||
47 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
48 | $this->assertCount(1, $alert = $crawler->filter('form ul li')->extract(array('_text'))); | |
49 | $this->assertEquals('This value should not be blank.', $alert[0]); | |
50 | } | |
51 | ||
52 | public function testPostNewOk() | |
53 | { | |
54 | $this->logInAs('admin'); | |
55 | $client = $this->getClient(); | |
56 | ||
57 | $crawler = $client->request('GET', '/new'); | |
58 | ||
59 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
60 | ||
61 | $form = $crawler->filter('button[type=submit]')->form(); | |
62 | ||
63 | $data = array( | |
64 | 'entry[url]' => $this->url, | |
65 | ); | |
66 | ||
67 | $client->submit($form, $data); | |
68 | ||
69 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
70 | ||
71 | $crawler = $client->followRedirect(); | |
72 | ||
73 | $this->assertGreaterThan(1, $alert = $crawler->filter('h2 a')->extract(array('_text'))); | |
74 | $this->assertContains('Google', $alert[0]); | |
75 | } | |
76 | ||
77 | public function testArchive() | |
78 | { | |
79 | $this->logInAs('admin'); | |
80 | $client = $this->getClient(); | |
81 | ||
82 | $client->request('GET', '/archive/list'); | |
83 | ||
84 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
85 | } | |
86 | ||
87 | public function testStarred() | |
88 | { | |
89 | $this->logInAs('admin'); | |
90 | $client = $this->getClient(); | |
91 | ||
92 | $client->request('GET', '/starred/list'); | |
93 | ||
94 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
95 | } | |
96 | ||
97 | public function testView() | |
98 | { | |
99 | $this->logInAs('admin'); | |
100 | $client = $this->getClient(); | |
101 | ||
102 | $content = $client->getContainer() | |
103 | ->get('doctrine.orm.entity_manager') | |
104 | ->getRepository('WallabagCoreBundle:Entry') | |
105 | ->findOneByUrl($this->url); | |
106 | ||
107 | $client->request('GET', '/view/'.$content->getId()); | |
108 | ||
109 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
110 | $this->assertContains($content->getTitle(), $client->getResponse()->getContent()); | |
111 | } | |
112 | ||
113 | public function testEdit() | |
114 | { | |
115 | $this->logInAs('admin'); | |
116 | $client = $this->getClient(); | |
117 | ||
118 | $content = $client->getContainer() | |
119 | ->get('doctrine.orm.entity_manager') | |
120 | ->getRepository('WallabagCoreBundle:Entry') | |
121 | ->findOneByUrl($this->url); | |
122 | ||
123 | $crawler = $client->request('GET', '/edit/'.$content->getId()); | |
124 | ||
125 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
126 | ||
127 | $this->assertCount(1, $crawler->filter('input[id=entry_title]')); | |
128 | $this->assertCount(1, $crawler->filter('button[id=entry_save]')); | |
129 | } | |
130 | ||
131 | public function testEditUpdate() | |
132 | { | |
133 | $this->logInAs('admin'); | |
134 | $client = $this->getClient(); | |
135 | ||
136 | $content = $client->getContainer() | |
137 | ->get('doctrine.orm.entity_manager') | |
138 | ->getRepository('WallabagCoreBundle:Entry') | |
139 | ->findOneByUrl($this->url); | |
140 | ||
141 | $crawler = $client->request('GET', '/edit/'.$content->getId()); | |
142 | ||
143 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
144 | ||
145 | $form = $crawler->filter('button[type=submit]')->form(); | |
146 | ||
147 | $data = array( | |
148 | 'entry[title]' => 'My updated title hehe :)', | |
149 | ); | |
150 | ||
151 | $client->submit($form, $data); | |
152 | ||
153 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
154 | ||
155 | $crawler = $client->followRedirect(); | |
156 | ||
157 | $this->assertGreaterThan(1, $alert = $crawler->filter('div[id=article] h1')->extract(array('_text'))); | |
158 | $this->assertContains('My updated title hehe :)', $alert[0]); | |
159 | } | |
160 | ||
161 | public function testToggleArchive() | |
162 | { | |
163 | $this->logInAs('admin'); | |
164 | $client = $this->getClient(); | |
165 | ||
166 | $content = $client->getContainer() | |
167 | ->get('doctrine.orm.entity_manager') | |
168 | ->getRepository('WallabagCoreBundle:Entry') | |
169 | ->findOneByUrl($this->url); | |
170 | ||
171 | $client->request('GET', '/archive/'.$content->getId()); | |
172 | ||
173 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
174 | ||
175 | $res = $client->getContainer() | |
176 | ->get('doctrine.orm.entity_manager') | |
177 | ->getRepository('WallabagCoreBundle:Entry') | |
178 | ->find($content->getId()); | |
179 | ||
180 | $this->assertEquals($res->isArchived(), true); | |
181 | } | |
182 | ||
183 | public function testToggleStar() | |
184 | { | |
185 | $this->logInAs('admin'); | |
186 | $client = $this->getClient(); | |
187 | ||
188 | $content = $client->getContainer() | |
189 | ->get('doctrine.orm.entity_manager') | |
190 | ->getRepository('WallabagCoreBundle:Entry') | |
191 | ->findOneByUrl($this->url); | |
192 | ||
193 | $client->request('GET', '/star/'.$content->getId()); | |
194 | ||
195 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
196 | ||
197 | $res = $client->getContainer() | |
198 | ->get('doctrine.orm.entity_manager') | |
199 | ->getRepository('WallabagCoreBundle:Entry') | |
200 | ->findOneById($content->getId()); | |
201 | ||
202 | $this->assertEquals($res->isStarred(), true); | |
203 | } | |
204 | ||
205 | public function testDelete() | |
206 | { | |
207 | $this->logInAs('admin'); | |
208 | $client = $this->getClient(); | |
209 | ||
210 | $content = $client->getContainer() | |
211 | ->get('doctrine.orm.entity_manager') | |
212 | ->getRepository('WallabagCoreBundle:Entry') | |
213 | ->findOneByUrl($this->url); | |
214 | ||
215 | $client->request('GET', '/delete/'.$content->getId()); | |
216 | ||
217 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
218 | ||
219 | $client->request('GET', '/delete/'.$content->getId()); | |
220 | ||
221 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | |
222 | } | |
223 | ||
224 | public function testViewOtherUserEntry() | |
225 | { | |
226 | $this->logInAs('admin'); | |
227 | $client = $this->getClient(); | |
228 | ||
229 | $content = $client->getContainer() | |
230 | ->get('doctrine.orm.entity_manager') | |
231 | ->getRepository('WallabagCoreBundle:Entry') | |
232 | ->findOneByUsernameAndNotArchived('bob'); | |
233 | ||
234 | $client->request('GET', '/view/'.$content->getId()); | |
235 | ||
236 | $this->assertEquals(403, $client->getResponse()->getStatusCode()); | |
237 | } | |
238 | ||
239 | public function testFilterOnReadingTime() | |
240 | { | |
241 | $this->logInAs('admin'); | |
242 | $client = $this->getClient(); | |
243 | ||
244 | $crawler = $client->request('GET', '/unread/list'); | |
245 | ||
246 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
247 | ||
248 | $data = array( | |
249 | 'entry_filter[readingTime][right_number]' => 11, | |
250 | 'entry_filter[readingTime][left_number]' => 11, | |
251 | ); | |
252 | ||
253 | $crawler = $client->submit($form, $data); | |
254 | ||
255 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
256 | } | |
257 | ||
258 | public function testFilterOnCreationDate() | |
259 | { | |
260 | $this->logInAs('admin'); | |
261 | $client = $this->getClient(); | |
262 | ||
263 | $crawler = $client->request('GET', '/unread/list'); | |
264 | ||
265 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
266 | ||
267 | $data = array( | |
268 | 'entry_filter[createdAt][left_date]' => date('d/m/Y'), | |
269 | 'entry_filter[createdAt][right_date]' => date('d/m/Y', strtotime('+1 day')), | |
270 | ); | |
271 | ||
272 | $crawler = $client->submit($form, $data); | |
273 | ||
274 | $this->assertCount(5, $crawler->filter('div[class=entry]')); | |
275 | ||
276 | $data = array( | |
277 | 'entry_filter[createdAt][left_date]' => date('d/m/Y'), | |
278 | 'entry_filter[createdAt][right_date]' => date('d/m/Y'), | |
279 | ); | |
280 | ||
281 | $crawler = $client->submit($form, $data); | |
282 | ||
283 | $this->assertCount(5, $crawler->filter('div[class=entry]')); | |
284 | ||
285 | $data = array( | |
286 | 'entry_filter[createdAt][left_date]' => '01/01/1970', | |
287 | 'entry_filter[createdAt][right_date]' => '01/01/1970', | |
288 | ); | |
289 | ||
290 | $crawler = $client->submit($form, $data); | |
291 | ||
292 | $this->assertCount(0, $crawler->filter('div[class=entry]')); | |
293 | } | |
294 | ||
295 | public function testPaginationWithFilter() | |
296 | { | |
297 | $this->logInAs('admin'); | |
298 | $client = $this->getClient(); | |
299 | $crawler = $client->request('GET', '/config'); | |
300 | ||
301 | $form = $crawler->filter('button[id=config_save]')->form(); | |
302 | ||
303 | $data = array( | |
304 | 'config[items_per_page]' => '1', | |
305 | ); | |
306 | ||
307 | $client->submit($form, $data); | |
308 | ||
309 | $parameters = '?entry_filter%5BreadingTime%5D%5Bleft_number%5D=&entry_filter%5BreadingTime%5D%5Bright_number%5D='; | |
310 | ||
311 | $crawler = $client->request('GET', 'unread/list'.$parameters); | |
312 | ||
313 | $this->assertContains($parameters, $client->getResponse()->getContent()); | |
314 | ||
315 | // reset pagination | |
316 | $crawler = $client->request('GET', '/config'); | |
317 | $form = $crawler->filter('button[id=config_save]')->form(); | |
318 | $data = array( | |
319 | 'config[items_per_page]' => '12', | |
320 | ); | |
321 | $client->submit($form, $data); | |
322 | } | |
323 | ||
324 | public function testFilterOnDomainName() | |
325 | { | |
326 | $this->logInAs('admin'); | |
327 | $client = $this->getClient(); | |
328 | ||
329 | $crawler = $client->request('GET', '/unread/list'); | |
330 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
331 | $data = array( | |
332 | 'entry_filter[domainName]' => 'domain', | |
333 | ); | |
334 | ||
335 | $crawler = $client->submit($form, $data); | |
336 | $this->assertCount(5, $crawler->filter('div[class=entry]')); | |
337 | ||
338 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
339 | $data = array( | |
340 | 'entry_filter[domainName]' => 'wallabag', | |
341 | ); | |
342 | ||
343 | $crawler = $client->submit($form, $data); | |
344 | $this->assertCount(0, $crawler->filter('div[class=entry]')); | |
345 | } | |
346 | ||
347 | public function testFilterOnStatus() | |
348 | { | |
349 | $this->logInAs('admin'); | |
350 | $client = $this->getClient(); | |
351 | ||
352 | $crawler = $client->request('GET', '/unread/list'); | |
353 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
354 | $form['entry_filter[isArchived]']->tick(); | |
355 | $form['entry_filter[isStarred]']->untick(); | |
356 | ||
357 | $crawler = $client->submit($form); | |
358 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
359 | ||
360 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
361 | $form['entry_filter[isArchived]']->untick(); | |
362 | $form['entry_filter[isStarred]']->tick(); | |
363 | ||
364 | $crawler = $client->submit($form); | |
365 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
366 | } | |
367 | ||
368 | public function testPreviewPictureFilter() | |
369 | { | |
370 | $this->logInAs('admin'); | |
371 | $client = $this->getClient(); | |
372 | ||
373 | $crawler = $client->request('GET', '/unread/list'); | |
374 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
375 | $form['entry_filter[previewPicture]']->tick(); | |
376 | ||
377 | $crawler = $client->submit($form); | |
378 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
379 | } | |
380 | ||
381 | public function testFilterOnLanguage() | |
382 | { | |
383 | $this->logInAs('admin'); | |
384 | $client = $this->getClient(); | |
385 | ||
386 | $crawler = $client->request('GET', '/unread/list'); | |
387 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
388 | $data = array( | |
389 | 'entry_filter[language]' => 'fr', | |
390 | ); | |
391 | ||
392 | $crawler = $client->submit($form, $data); | |
393 | $this->assertCount(2, $crawler->filter('div[class=entry]')); | |
394 | ||
395 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
396 | $data = array( | |
397 | 'entry_filter[language]' => 'en', | |
398 | ); | |
399 | ||
400 | $crawler = $client->submit($form, $data); | |
401 | $this->assertCount(2, $crawler->filter('div[class=entry]')); | |
402 | } | |
403 | } |