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