aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php')
-rw-r--r--tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php592
1 files changed, 454 insertions, 138 deletions
diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
index 0a65f9ce..2dc08be2 100644
--- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
+++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
@@ -3,8 +3,10 @@
3namespace Tests\Wallabag\ApiBundle\Controller; 3namespace Tests\Wallabag\ApiBundle\Controller;
4 4
5use Tests\Wallabag\ApiBundle\WallabagApiTestCase; 5use Tests\Wallabag\ApiBundle\WallabagApiTestCase;
6use Wallabag\CoreBundle\Entity\Entry;
6use Wallabag\CoreBundle\Entity\Tag; 7use Wallabag\CoreBundle\Entity\Tag;
7use Wallabag\CoreBundle\Helper\ContentProxy; 8use Wallabag\CoreBundle\Helper\ContentProxy;
9use Wallabag\UserBundle\Entity\User;
8 10
9class EntryRestControllerTest extends WallabagApiTestCase 11class EntryRestControllerTest extends WallabagApiTestCase
10{ 12{
@@ -19,19 +21,19 @@ class EntryRestControllerTest extends WallabagApiTestCase
19 $this->markTestSkipped('No content found in db.'); 21 $this->markTestSkipped('No content found in db.');
20 } 22 }
21 23
22 $this->client->request('GET', '/api/entries/'.$entry->getId().'.json'); 24 $this->client->request('GET', '/api/entries/' . $entry->getId() . '.json');
23 $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); 25 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
24 26
25 $content = json_decode($this->client->getResponse()->getContent(), true); 27 $content = json_decode($this->client->getResponse()->getContent(), true);
26 28
27 $this->assertEquals($entry->getTitle(), $content['title']); 29 $this->assertSame($entry->getTitle(), $content['title']);
28 $this->assertEquals($entry->getUrl(), $content['url']); 30 $this->assertSame($entry->getUrl(), $content['url']);
29 $this->assertCount(count($entry->getTags()), $content['tags']); 31 $this->assertCount(count($entry->getTags()), $content['tags']);
30 $this->assertEquals($entry->getUserName(), $content['user_name']); 32 $this->assertSame($entry->getUserName(), $content['user_name']);
31 $this->assertEquals($entry->getUserEmail(), $content['user_email']); 33 $this->assertSame($entry->getUserEmail(), $content['user_email']);
32 $this->assertEquals($entry->getUserId(), $content['user_id']); 34 $this->assertSame($entry->getUserId(), $content['user_id']);
33 35
34 $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); 36 $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type'));
35 } 37 }
36 38
37 public function testExportEntry() 39 public function testExportEntry()
@@ -45,39 +47,39 @@ class EntryRestControllerTest extends WallabagApiTestCase
45 $this->markTestSkipped('No content found in db.'); 47 $this->markTestSkipped('No content found in db.');
46 } 48 }
47 49
48 $this->client->request('GET', '/api/entries/'.$entry->getId().'/export.epub'); 50 $this->client->request('GET', '/api/entries/' . $entry->getId() . '/export.epub');
49 $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); 51 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
50 52
51 // epub format got the content type in the content 53 // epub format got the content type in the content
52 $this->assertContains('application/epub', $this->client->getResponse()->getContent()); 54 $this->assertContains('application/epub', $this->client->getResponse()->getContent());
53 $this->assertEquals('application/epub+zip', $this->client->getResponse()->headers->get('Content-Type')); 55 $this->assertSame('application/epub+zip', $this->client->getResponse()->headers->get('Content-Type'));
54 56
55 // re-auth client for mobi 57 // re-auth client for mobi
56 $client = $this->createAuthorizedClient(); 58 $client = $this->createAuthorizedClient();
57 $client->request('GET', '/api/entries/'.$entry->getId().'/export.mobi'); 59 $client->request('GET', '/api/entries/' . $entry->getId() . '/export.mobi');
58 $this->assertEquals(200, $client->getResponse()->getStatusCode()); 60 $this->assertSame(200, $client->getResponse()->getStatusCode());
59 61
60 $this->assertEquals('application/x-mobipocket-ebook', $client->getResponse()->headers->get('Content-Type')); 62 $this->assertSame('application/x-mobipocket-ebook', $client->getResponse()->headers->get('Content-Type'));
61 63
62 // re-auth client for pdf 64 // re-auth client for pdf
63 $client = $this->createAuthorizedClient(); 65 $client = $this->createAuthorizedClient();
64 $client->request('GET', '/api/entries/'.$entry->getId().'/export.pdf'); 66 $client->request('GET', '/api/entries/' . $entry->getId() . '/export.pdf');
65 $this->assertEquals(200, $client->getResponse()->getStatusCode()); 67 $this->assertSame(200, $client->getResponse()->getStatusCode());
66 68
67 $this->assertContains('PDF-', $client->getResponse()->getContent()); 69 $this->assertContains('PDF-', $client->getResponse()->getContent());
68 $this->assertEquals('application/pdf', $client->getResponse()->headers->get('Content-Type')); 70 $this->assertSame('application/pdf', $client->getResponse()->headers->get('Content-Type'));
69 71
70 // re-auth client for pdf 72 // re-auth client for pdf
71 $client = $this->createAuthorizedClient(); 73 $client = $this->createAuthorizedClient();
72 $client->request('GET', '/api/entries/'.$entry->getId().'/export.txt'); 74 $client->request('GET', '/api/entries/' . $entry->getId() . '/export.txt');
73 $this->assertEquals(200, $client->getResponse()->getStatusCode()); 75 $this->assertSame(200, $client->getResponse()->getStatusCode());
74 76
75 $this->assertContains('text/plain', $client->getResponse()->headers->get('Content-Type')); 77 $this->assertContains('text/plain', $client->getResponse()->headers->get('Content-Type'));
76 78
77 // re-auth client for pdf 79 // re-auth client for pdf
78 $client = $this->createAuthorizedClient(); 80 $client = $this->createAuthorizedClient();
79 $client->request('GET', '/api/entries/'.$entry->getId().'/export.csv'); 81 $client->request('GET', '/api/entries/' . $entry->getId() . '/export.csv');
80 $this->assertEquals(200, $client->getResponse()->getStatusCode()); 82 $this->assertSame(200, $client->getResponse()->getStatusCode());
81 83
82 $this->assertContains('application/csv', $client->getResponse()->headers->get('Content-Type')); 84 $this->assertContains('application/csv', $client->getResponse()->headers->get('Content-Type'));
83 } 85 }
@@ -93,26 +95,26 @@ class EntryRestControllerTest extends WallabagApiTestCase
93 $this->markTestSkipped('No content found in db.'); 95 $this->markTestSkipped('No content found in db.');
94 } 96 }
95 97
96 $this->client->request('GET', '/api/entries/'.$entry->getId().'.json'); 98 $this->client->request('GET', '/api/entries/' . $entry->getId() . '.json');
97 99
98 $this->assertEquals(403, $this->client->getResponse()->getStatusCode()); 100 $this->assertSame(403, $this->client->getResponse()->getStatusCode());
99 } 101 }
100 102
101 public function testGetEntries() 103 public function testGetEntries()
102 { 104 {
103 $this->client->request('GET', '/api/entries'); 105 $this->client->request('GET', '/api/entries');
104 106
105 $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); 107 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
106 108
107 $content = json_decode($this->client->getResponse()->getContent(), true); 109 $content = json_decode($this->client->getResponse()->getContent(), true);
108 110
109 $this->assertGreaterThanOrEqual(1, count($content)); 111 $this->assertGreaterThanOrEqual(1, count($content));
110 $this->assertNotEmpty($content['_embedded']['items']); 112 $this->assertNotEmpty($content['_embedded']['items']);
111 $this->assertGreaterThanOrEqual(1, $content['total']); 113 $this->assertGreaterThanOrEqual(1, $content['total']);
112 $this->assertEquals(1, $content['page']); 114 $this->assertSame(1, $content['page']);
113 $this->assertGreaterThanOrEqual(1, $content['pages']); 115 $this->assertGreaterThanOrEqual(1, $content['pages']);
114 116
115 $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); 117 $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type'));
116 } 118 }
117 119
118 public function testGetEntriesWithFullOptions() 120 public function testGetEntriesWithFullOptions()
@@ -126,17 +128,18 @@ class EntryRestControllerTest extends WallabagApiTestCase
126 'perPage' => 2, 128 'perPage' => 2,
127 'tags' => 'foo', 129 'tags' => 'foo',
128 'since' => 1443274283, 130 'since' => 1443274283,
131 'public' => 0,
129 ]); 132 ]);
130 133
131 $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); 134 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
132 135
133 $content = json_decode($this->client->getResponse()->getContent(), true); 136 $content = json_decode($this->client->getResponse()->getContent(), true);
134 137
135 $this->assertGreaterThanOrEqual(1, count($content)); 138 $this->assertGreaterThanOrEqual(1, count($content));
136 $this->assertArrayHasKey('items', $content['_embedded']); 139 $this->assertArrayHasKey('items', $content['_embedded']);
137 $this->assertGreaterThanOrEqual(0, $content['total']); 140 $this->assertGreaterThanOrEqual(0, $content['total']);
138 $this->assertEquals(1, $content['page']); 141 $this->assertSame(1, $content['page']);
139 $this->assertEquals(2, $content['limit']); 142 $this->assertSame(2, $content['limit']);
140 $this->assertGreaterThanOrEqual(1, $content['pages']); 143 $this->assertGreaterThanOrEqual(1, $content['pages']);
141 144
142 $this->assertArrayHasKey('_links', $content); 145 $this->assertArrayHasKey('_links', $content);
@@ -152,9 +155,56 @@ class EntryRestControllerTest extends WallabagApiTestCase
152 $this->assertContains('order=asc', $content['_links'][$link]['href']); 155 $this->assertContains('order=asc', $content['_links'][$link]['href']);
153 $this->assertContains('tags=foo', $content['_links'][$link]['href']); 156 $this->assertContains('tags=foo', $content['_links'][$link]['href']);
154 $this->assertContains('since=1443274283', $content['_links'][$link]['href']); 157 $this->assertContains('since=1443274283', $content['_links'][$link]['href']);
158 $this->assertContains('public=0', $content['_links'][$link]['href']);
155 } 159 }
156 160
157 $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); 161 $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type'));
162 }
163
164 public function testGetEntriesPublicOnly()
165 {
166 $entry = $this->client->getContainer()
167 ->get('doctrine.orm.entity_manager')
168 ->getRepository('WallabagCoreBundle:Entry')
169 ->findOneByUser(1);
170
171 if (!$entry) {
172 $this->markTestSkipped('No content found in db.');
173 }
174
175 // generate at least one public entry
176 $entry->generateUid();
177
178 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
179 $em->persist($entry);
180 $em->flush();
181
182 $this->client->request('GET', '/api/entries', [
183 'public' => 1,
184 ]);
185
186 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
187
188 $content = json_decode($this->client->getResponse()->getContent(), true);
189
190 $this->assertGreaterThanOrEqual(1, count($content));
191 $this->assertArrayHasKey('items', $content['_embedded']);
192 $this->assertGreaterThanOrEqual(1, $content['total']);
193 $this->assertSame(1, $content['page']);
194 $this->assertSame(30, $content['limit']);
195 $this->assertGreaterThanOrEqual(1, $content['pages']);
196
197 $this->assertArrayHasKey('_links', $content);
198 $this->assertArrayHasKey('self', $content['_links']);
199 $this->assertArrayHasKey('first', $content['_links']);
200 $this->assertArrayHasKey('last', $content['_links']);
201
202 foreach (['self', 'first', 'last'] as $link) {
203 $this->assertArrayHasKey('href', $content['_links'][$link]);
204 $this->assertContains('public=1', $content['_links'][$link]['href']);
205 }
206
207 $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type'));
158 } 208 }
159 209
160 public function testGetEntriesOnPageTwo() 210 public function testGetEntriesOnPageTwo()
@@ -164,27 +214,27 @@ class EntryRestControllerTest extends WallabagApiTestCase
164 'perPage' => 2, 214 'perPage' => 2,
165 ]); 215 ]);
166 216
167 $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); 217 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
168 218
169 $content = json_decode($this->client->getResponse()->getContent(), true); 219 $content = json_decode($this->client->getResponse()->getContent(), true);
170 220
171 $this->assertGreaterThanOrEqual(0, $content['total']); 221 $this->assertGreaterThanOrEqual(0, $content['total']);
172 $this->assertEquals(2, $content['page']); 222 $this->assertSame(2, $content['page']);
173 $this->assertEquals(2, $content['limit']); 223 $this->assertSame(2, $content['limit']);
174 } 224 }
175 225
176 public function testGetStarredEntries() 226 public function testGetStarredEntries()
177 { 227 {
178 $this->client->request('GET', '/api/entries', ['starred' => 1, 'sort' => 'updated']); 228 $this->client->request('GET', '/api/entries', ['starred' => 1, 'sort' => 'updated']);
179 229
180 $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); 230 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
181 231
182 $content = json_decode($this->client->getResponse()->getContent(), true); 232 $content = json_decode($this->client->getResponse()->getContent(), true);
183 233
184 $this->assertGreaterThanOrEqual(1, count($content)); 234 $this->assertGreaterThanOrEqual(1, count($content));
185 $this->assertNotEmpty($content['_embedded']['items']); 235 $this->assertNotEmpty($content['_embedded']['items']);
186 $this->assertGreaterThanOrEqual(1, $content['total']); 236 $this->assertGreaterThanOrEqual(1, $content['total']);
187 $this->assertEquals(1, $content['page']); 237 $this->assertSame(1, $content['page']);
188 $this->assertGreaterThanOrEqual(1, $content['pages']); 238 $this->assertGreaterThanOrEqual(1, $content['pages']);
189 239
190 $this->assertArrayHasKey('_links', $content); 240 $this->assertArrayHasKey('_links', $content);
@@ -198,21 +248,21 @@ class EntryRestControllerTest extends WallabagApiTestCase
198 $this->assertContains('sort=updated', $content['_links'][$link]['href']); 248 $this->assertContains('sort=updated', $content['_links'][$link]['href']);
199 } 249 }
200 250
201 $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); 251 $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type'));
202 } 252 }
203 253
204 public function testGetArchiveEntries() 254 public function testGetArchiveEntries()
205 { 255 {
206 $this->client->request('GET', '/api/entries', ['archive' => 1]); 256 $this->client->request('GET', '/api/entries', ['archive' => 1]);
207 257
208 $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); 258 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
209 259
210 $content = json_decode($this->client->getResponse()->getContent(), true); 260 $content = json_decode($this->client->getResponse()->getContent(), true);
211 261
212 $this->assertGreaterThanOrEqual(1, count($content)); 262 $this->assertGreaterThanOrEqual(1, count($content));
213 $this->assertNotEmpty($content['_embedded']['items']); 263 $this->assertNotEmpty($content['_embedded']['items']);
214 $this->assertGreaterThanOrEqual(1, $content['total']); 264 $this->assertGreaterThanOrEqual(1, $content['total']);
215 $this->assertEquals(1, $content['page']); 265 $this->assertSame(1, $content['page']);
216 $this->assertGreaterThanOrEqual(1, $content['pages']); 266 $this->assertGreaterThanOrEqual(1, $content['pages']);
217 267
218 $this->assertArrayHasKey('_links', $content); 268 $this->assertArrayHasKey('_links', $content);
@@ -225,21 +275,21 @@ class EntryRestControllerTest extends WallabagApiTestCase
225 $this->assertContains('archive=1', $content['_links'][$link]['href']); 275 $this->assertContains('archive=1', $content['_links'][$link]['href']);
226 } 276 }
227 277
228 $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); 278 $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type'));
229 } 279 }
230 280
231 public function testGetTaggedEntries() 281 public function testGetTaggedEntries()
232 { 282 {
233 $this->client->request('GET', '/api/entries', ['tags' => 'foo,bar']); 283 $this->client->request('GET', '/api/entries', ['tags' => 'foo,bar']);
234 284
235 $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); 285 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
236 286
237 $content = json_decode($this->client->getResponse()->getContent(), true); 287 $content = json_decode($this->client->getResponse()->getContent(), true);
238 288
239 $this->assertGreaterThanOrEqual(1, count($content)); 289 $this->assertGreaterThanOrEqual(1, count($content));
240 $this->assertNotEmpty($content['_embedded']['items']); 290 $this->assertNotEmpty($content['_embedded']['items']);
241 $this->assertGreaterThanOrEqual(1, $content['total']); 291 $this->assertGreaterThanOrEqual(1, $content['total']);
242 $this->assertEquals(1, $content['page']); 292 $this->assertSame(1, $content['page']);
243 $this->assertGreaterThanOrEqual(1, $content['pages']); 293 $this->assertGreaterThanOrEqual(1, $content['pages']);
244 294
245 $this->assertArrayHasKey('_links', $content); 295 $this->assertArrayHasKey('_links', $content);
@@ -249,24 +299,24 @@ class EntryRestControllerTest extends WallabagApiTestCase
249 299
250 foreach (['self', 'first', 'last'] as $link) { 300 foreach (['self', 'first', 'last'] as $link) {
251 $this->assertArrayHasKey('href', $content['_links'][$link]); 301 $this->assertArrayHasKey('href', $content['_links'][$link]);
252 $this->assertContains('tags='.urlencode('foo,bar'), $content['_links'][$link]['href']); 302 $this->assertContains('tags=' . urlencode('foo,bar'), $content['_links'][$link]['href']);
253 } 303 }
254 304
255 $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); 305 $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type'));
256 } 306 }
257 307
258 public function testGetDatedEntries() 308 public function testGetDatedEntries()
259 { 309 {
260 $this->client->request('GET', '/api/entries', ['since' => 1443274283]); 310 $this->client->request('GET', '/api/entries', ['since' => 1443274283]);
261 311
262 $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); 312 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
263 313
264 $content = json_decode($this->client->getResponse()->getContent(), true); 314 $content = json_decode($this->client->getResponse()->getContent(), true);
265 315
266 $this->assertGreaterThanOrEqual(1, count($content)); 316 $this->assertGreaterThanOrEqual(1, count($content));
267 $this->assertNotEmpty($content['_embedded']['items']); 317 $this->assertNotEmpty($content['_embedded']['items']);
268 $this->assertGreaterThanOrEqual(1, $content['total']); 318 $this->assertGreaterThanOrEqual(1, $content['total']);
269 $this->assertEquals(1, $content['page']); 319 $this->assertSame(1, $content['page']);
270 $this->assertGreaterThanOrEqual(1, $content['pages']); 320 $this->assertGreaterThanOrEqual(1, $content['pages']);
271 321
272 $this->assertArrayHasKey('_links', $content); 322 $this->assertArrayHasKey('_links', $content);
@@ -279,7 +329,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
279 $this->assertContains('since=1443274283', $content['_links'][$link]['href']); 329 $this->assertContains('since=1443274283', $content['_links'][$link]['href']);
280 } 330 }
281 331
282 $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); 332 $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type'));
283 } 333 }
284 334
285 public function testGetDatedSupEntries() 335 public function testGetDatedSupEntries()
@@ -287,15 +337,15 @@ class EntryRestControllerTest extends WallabagApiTestCase
287 $future = new \DateTime(date('Y-m-d H:i:s')); 337 $future = new \DateTime(date('Y-m-d H:i:s'));
288 $this->client->request('GET', '/api/entries', ['since' => $future->getTimestamp() + 1000]); 338 $this->client->request('GET', '/api/entries', ['since' => $future->getTimestamp() + 1000]);
289 339
290 $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); 340 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
291 341
292 $content = json_decode($this->client->getResponse()->getContent(), true); 342 $content = json_decode($this->client->getResponse()->getContent(), true);
293 343
294 $this->assertGreaterThanOrEqual(1, count($content)); 344 $this->assertGreaterThanOrEqual(1, count($content));
295 $this->assertEmpty($content['_embedded']['items']); 345 $this->assertEmpty($content['_embedded']['items']);
296 $this->assertEquals(0, $content['total']); 346 $this->assertSame(0, $content['total']);
297 $this->assertEquals(1, $content['page']); 347 $this->assertSame(1, $content['page']);
298 $this->assertEquals(1, $content['pages']); 348 $this->assertSame(1, $content['pages']);
299 349
300 $this->assertArrayHasKey('_links', $content); 350 $this->assertArrayHasKey('_links', $content);
301 $this->assertArrayHasKey('self', $content['_links']); 351 $this->assertArrayHasKey('self', $content['_links']);
@@ -304,10 +354,10 @@ class EntryRestControllerTest extends WallabagApiTestCase
304 354
305 foreach (['self', 'first', 'last'] as $link) { 355 foreach (['self', 'first', 'last'] as $link) {
306 $this->assertArrayHasKey('href', $content['_links'][$link]); 356 $this->assertArrayHasKey('href', $content['_links'][$link]);
307 $this->assertContains('since='.($future->getTimestamp() + 1000), $content['_links'][$link]['href']); 357 $this->assertContains('since=' . ($future->getTimestamp() + 1000), $content['_links'][$link]['href']);
308 } 358 }
309 359
310 $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); 360 $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type'));
311 } 361 }
312 362
313 public function testDeleteEntry() 363 public function testDeleteEntry()
@@ -315,25 +365,25 @@ class EntryRestControllerTest extends WallabagApiTestCase
315 $entry = $this->client->getContainer() 365 $entry = $this->client->getContainer()
316 ->get('doctrine.orm.entity_manager') 366 ->get('doctrine.orm.entity_manager')
317 ->getRepository('WallabagCoreBundle:Entry') 367 ->getRepository('WallabagCoreBundle:Entry')
318 ->findOneByUser(1); 368 ->findOneByUser(1, ['id' => 'asc']);
319 369
320 if (!$entry) { 370 if (!$entry) {
321 $this->markTestSkipped('No content found in db.'); 371 $this->markTestSkipped('No content found in db.');
322 } 372 }
323 373
324 $this->client->request('DELETE', '/api/entries/'.$entry->getId().'.json'); 374 $this->client->request('DELETE', '/api/entries/' . $entry->getId() . '.json');
325 375
326 $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); 376 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
327 377
328 $content = json_decode($this->client->getResponse()->getContent(), true); 378 $content = json_decode($this->client->getResponse()->getContent(), true);
329 379
330 $this->assertEquals($entry->getTitle(), $content['title']); 380 $this->assertSame($entry->getTitle(), $content['title']);
331 $this->assertEquals($entry->getUrl(), $content['url']); 381 $this->assertSame($entry->getUrl(), $content['url']);
332 382
333 // We'll try to delete this entry again 383 // We'll try to delete this entry again
334 $this->client->request('DELETE', '/api/entries/'.$entry->getId().'.json'); 384 $this->client->request('DELETE', '/api/entries/' . $entry->getId() . '.json');
335 385
336 $this->assertEquals(404, $this->client->getResponse()->getStatusCode()); 386 $this->assertSame(404, $this->client->getResponse()->getStatusCode());
337 } 387 }
338 388
339 public function testPostEntry() 389 public function testPostEntry()
@@ -342,38 +392,60 @@ class EntryRestControllerTest extends WallabagApiTestCase
342 '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', 392 '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',
343 'tags' => 'google', 393 'tags' => 'google',
344 'title' => 'New title for my article', 394 'title' => 'New title for my article',
395 'content' => 'my content',
396 'language' => 'de',
397 'published_at' => '2016-09-08T11:55:58+0200',
398 'authors' => 'bob,helen',
399 'public' => 1,
345 ]); 400 ]);
346 401
347 $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); 402 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
348 403
349 $content = json_decode($this->client->getResponse()->getContent(), true); 404 $content = json_decode($this->client->getResponse()->getContent(), true);
350 405
351 $this->assertGreaterThan(0, $content['id']); 406 $this->assertGreaterThan(0, $content['id']);
352 $this->assertEquals('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', $content['url']); 407 $this->assertSame('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', $content['url']);
353 $this->assertEquals(false, $content['is_archived']); 408 $this->assertSame(0, $content['is_archived']);
354 $this->assertEquals(false, $content['is_starred']); 409 $this->assertSame(0, $content['is_starred']);
355 $this->assertEquals('New title for my article', $content['title']); 410 $this->assertSame('New title for my article', $content['title']);
356 $this->assertEquals(1, $content['user_id']); 411 $this->assertSame(1, $content['user_id']);
357 $this->assertCount(1, $content['tags']); 412 $this->assertCount(2, $content['tags']);
413 $this->assertSame('my content', $content['content']);
414 $this->assertSame('de', $content['language']);
415 $this->assertSame('2016-09-08T11:55:58+0200', $content['published_at']);
416 $this->assertCount(2, $content['published_by']);
417 $this->assertContains('bob', $content['published_by']);
418 $this->assertContains('helen', $content['published_by']);
419 $this->assertTrue($content['is_public'], 'A public link has been generated for that entry');
358 } 420 }
359 421
360 public function testPostSameEntry() 422 public function testPostSameEntry()
361 { 423 {
424 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
425 $entry = new Entry($em->getReference(User::class, 1));
426 $entry->setUrl('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');
427 $entry->setArchived(true);
428 $entry->addTag((new Tag())->setLabel('google'));
429 $entry->addTag((new Tag())->setLabel('apple'));
430 $em->persist($entry);
431 $em->flush();
432 $em->clear();
433
362 $this->client->request('POST', '/api/entries.json', [ 434 $this->client->request('POST', '/api/entries.json', [
363 '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', 435 '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',
364 'archive' => '1', 436 'archive' => '1',
365 'tags' => 'google, apple', 437 'tags' => 'google, apple',
366 ]); 438 ]);
367 439
368 $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); 440 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
369 441
370 $content = json_decode($this->client->getResponse()->getContent(), true); 442 $content = json_decode($this->client->getResponse()->getContent(), true);
371 443
372 $this->assertGreaterThan(0, $content['id']); 444 $this->assertGreaterThan(0, $content['id']);
373 $this->assertEquals('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', $content['url']); 445 $this->assertSame('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', $content['url']);
374 $this->assertEquals(true, $content['is_archived']); 446 $this->assertSame(1, $content['is_archived']);
375 $this->assertEquals(false, $content['is_starred']); 447 $this->assertSame(0, $content['is_starred']);
376 $this->assertCount(2, $content['tags']); 448 $this->assertCount(3, $content['tags']);
377 } 449 }
378 450
379 public function testPostEntryWhenFetchContentFails() 451 public function testPostEntryWhenFetchContentFails()
@@ -394,10 +466,10 @@ class EntryRestControllerTest extends WallabagApiTestCase
394 'url' => 'http://www.example.com/', 466 'url' => 'http://www.example.com/',
395 ]); 467 ]);
396 468
397 $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); 469 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
398 $content = json_decode($this->client->getResponse()->getContent(), true); 470 $content = json_decode($this->client->getResponse()->getContent(), true);
399 $this->assertGreaterThan(0, $content['id']); 471 $this->assertGreaterThan(0, $content['id']);
400 $this->assertEquals('http://www.example.com/', $content['url']); 472 $this->assertSame('http://www.example.com/', $content['url']);
401 } finally { 473 } finally {
402 // Remove the created entry to avoid side effects on other tests 474 // Remove the created entry to avoid side effects on other tests
403 if (isset($content['id'])) { 475 if (isset($content['id'])) {
@@ -417,15 +489,15 @@ class EntryRestControllerTest extends WallabagApiTestCase
417 'starred' => '1', 489 'starred' => '1',
418 ]); 490 ]);
419 491
420 $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); 492 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
421 493
422 $content = json_decode($this->client->getResponse()->getContent(), true); 494 $content = json_decode($this->client->getResponse()->getContent(), true);
423 495
424 $this->assertGreaterThan(0, $content['id']); 496 $this->assertGreaterThan(0, $content['id']);
425 $this->assertEquals('http://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html', $content['url']); 497 $this->assertSame('http://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html', $content['url']);
426 $this->assertEquals(true, $content['is_archived']); 498 $this->assertSame(1, $content['is_archived']);
427 $this->assertEquals(true, $content['is_starred']); 499 $this->assertSame(1, $content['is_starred']);
428 $this->assertEquals(1, $content['user_id']); 500 $this->assertSame(1, $content['user_id']);
429 } 501 }
430 502
431 public function testPostArchivedAndStarredEntryWithoutQuotes() 503 public function testPostArchivedAndStarredEntryWithoutQuotes()
@@ -436,14 +508,14 @@ class EntryRestControllerTest extends WallabagApiTestCase
436 'starred' => 1, 508 'starred' => 1,
437 ]); 509 ]);
438 510
439 $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); 511 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
440 512
441 $content = json_decode($this->client->getResponse()->getContent(), true); 513 $content = json_decode($this->client->getResponse()->getContent(), true);
442 514
443 $this->assertGreaterThan(0, $content['id']); 515 $this->assertGreaterThan(0, $content['id']);
444 $this->assertEquals('http://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html', $content['url']); 516 $this->assertSame('http://www.lemonde.fr/idees/article/2016/02/08/preserver-la-liberte-d-expression-sur-les-reseaux-sociaux_4861503_3232.html', $content['url']);
445 $this->assertEquals(false, $content['is_archived']); 517 $this->assertSame(0, $content['is_archived']);
446 $this->assertEquals(true, $content['is_starred']); 518 $this->assertSame(1, $content['is_starred']);
447 } 519 }
448 520
449 public function testPatchEntry() 521 public function testPatchEntry()
@@ -457,25 +529,35 @@ class EntryRestControllerTest extends WallabagApiTestCase
457 $this->markTestSkipped('No content found in db.'); 529 $this->markTestSkipped('No content found in db.');
458 } 530 }
459 531
460 // hydrate the tags relations 532 $this->client->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [
461 $nbTags = count($entry->getTags());
462
463 $this->client->request('PATCH', '/api/entries/'.$entry->getId().'.json', [
464 'title' => 'New awesome title', 533 'title' => 'New awesome title',
465 'tags' => 'new tag '.uniqid(), 534 'tags' => 'new tag ' . uniqid(),
466 'starred' => '1', 535 'starred' => '1',
467 'archive' => '0', 536 'archive' => '0',
537 'language' => 'de_AT',
538 'preview_picture' => 'http://preview.io/picture.jpg',
539 'authors' => 'bob,sponge',
540 'content' => 'awesome',
541 'public' => 0,
542 'published_at' => 1488833381,
468 ]); 543 ]);
469 544
470 $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); 545 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
471 546
472 $content = json_decode($this->client->getResponse()->getContent(), true); 547 $content = json_decode($this->client->getResponse()->getContent(), true);
473 548
474 $this->assertEquals($entry->getId(), $content['id']); 549 $this->assertSame($entry->getId(), $content['id']);
475 $this->assertEquals($entry->getUrl(), $content['url']); 550 $this->assertSame($entry->getUrl(), $content['url']);
476 $this->assertEquals('New awesome title', $content['title']); 551 $this->assertSame('New awesome title', $content['title']);
477 $this->assertGreaterThan($nbTags, count($content['tags'])); 552 $this->assertGreaterThanOrEqual(1, count($content['tags']), 'We force only one tag');
478 $this->assertEquals(1, $content['user_id']); 553 $this->assertSame(1, $content['user_id']);
554 $this->assertSame('de_AT', $content['language']);
555 $this->assertSame('http://preview.io/picture.jpg', $content['preview_picture']);
556 $this->assertContains('sponge', $content['published_by']);
557 $this->assertContains('bob', $content['published_by']);
558 $this->assertSame('awesome', $content['content']);
559 $this->assertFalse($content['is_public'], 'Entry is no more shared');
560 $this->assertContains('2017-03-06', $content['published_at']);
479 } 561 }
480 562
481 public function testPatchEntryWithoutQuotes() 563 public function testPatchEntryWithoutQuotes()
@@ -489,24 +571,27 @@ class EntryRestControllerTest extends WallabagApiTestCase
489 $this->markTestSkipped('No content found in db.'); 571 $this->markTestSkipped('No content found in db.');
490 } 572 }
491 573
492 // hydrate the tags relations 574 $previousContent = $entry->getContent();
493 $nbTags = count($entry->getTags()); 575 $previousLanguage = $entry->getLanguage();
494 576
495 $this->client->request('PATCH', '/api/entries/'.$entry->getId().'.json', [ 577 $this->client->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [
496 'title' => 'New awesome title', 578 'title' => 'New awesome title',
497 'tags' => 'new tag '.uniqid(), 579 'tags' => 'new tag ' . uniqid(),
498 'starred' => 1, 580 'starred' => 1,
499 'archive' => 0, 581 'archive' => 0,
582 'authors' => ['bob', 'sponge'],
500 ]); 583 ]);
501 584
502 $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); 585 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
503 586
504 $content = json_decode($this->client->getResponse()->getContent(), true); 587 $content = json_decode($this->client->getResponse()->getContent(), true);
505 588
506 $this->assertEquals($entry->getId(), $content['id']); 589 $this->assertSame($entry->getId(), $content['id']);
507 $this->assertEquals($entry->getUrl(), $content['url']); 590 $this->assertSame($entry->getUrl(), $content['url']);
508 $this->assertEquals('New awesome title', $content['title']); 591 $this->assertGreaterThanOrEqual(1, count($content['tags']), 'We force only one tag');
509 $this->assertGreaterThan($nbTags, count($content['tags'])); 592 $this->assertEmpty($content['published_by'], 'Authors were not saved because of an array instead of a string');
593 $this->assertSame($previousContent, $content['content'], 'Ensure content has not moved');
594 $this->assertSame($previousLanguage, $content['language'], 'Ensure language has not moved');
510 } 595 }
511 596
512 public function testGetTagsEntry() 597 public function testGetTagsEntry()
@@ -527,9 +612,9 @@ class EntryRestControllerTest extends WallabagApiTestCase
527 $tags[] = ['id' => $tag->getId(), 'label' => $tag->getLabel(), 'slug' => $tag->getSlug()]; 612 $tags[] = ['id' => $tag->getId(), 'label' => $tag->getLabel(), 'slug' => $tag->getSlug()];
528 } 613 }
529 614
530 $this->client->request('GET', '/api/entries/'.$entry->getId().'/tags'); 615 $this->client->request('GET', '/api/entries/' . $entry->getId() . '/tags');
531 616
532 $this->assertEquals(json_encode($tags, JSON_HEX_QUOT), $this->client->getResponse()->getContent()); 617 $this->assertSame(json_encode($tags, JSON_HEX_QUOT), $this->client->getResponse()->getContent());
533 } 618 }
534 619
535 public function testPostTagsOnEntry() 620 public function testPostTagsOnEntry()
@@ -547,14 +632,14 @@ class EntryRestControllerTest extends WallabagApiTestCase
547 632
548 $newTags = 'tag1,tag2,tag3'; 633 $newTags = 'tag1,tag2,tag3';
549 634
550 $this->client->request('POST', '/api/entries/'.$entry->getId().'/tags', ['tags' => $newTags]); 635 $this->client->request('POST', '/api/entries/' . $entry->getId() . '/tags', ['tags' => $newTags]);
551 636
552 $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); 637 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
553 638
554 $content = json_decode($this->client->getResponse()->getContent(), true); 639 $content = json_decode($this->client->getResponse()->getContent(), true);
555 640
556 $this->assertArrayHasKey('tags', $content); 641 $this->assertArrayHasKey('tags', $content);
557 $this->assertEquals($nbTags + 3, count($content['tags'])); 642 $this->assertSame($nbTags + 3, count($content['tags']));
558 643
559 $entryDB = $this->client->getContainer() 644 $entryDB = $this->client->getContainer()
560 ->get('doctrine.orm.entity_manager') 645 ->get('doctrine.orm.entity_manager')
@@ -587,14 +672,14 @@ class EntryRestControllerTest extends WallabagApiTestCase
587 $nbTags = count($entry->getTags()); 672 $nbTags = count($entry->getTags());
588 $tag = $entry->getTags()[0]; 673 $tag = $entry->getTags()[0];
589 674
590 $this->client->request('DELETE', '/api/entries/'.$entry->getId().'/tags/'.$tag->getId().'.json'); 675 $this->client->request('DELETE', '/api/entries/' . $entry->getId() . '/tags/' . $tag->getId() . '.json');
591 676
592 $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); 677 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
593 678
594 $content = json_decode($this->client->getResponse()->getContent(), true); 679 $content = json_decode($this->client->getResponse()->getContent(), true);
595 680
596 $this->assertArrayHasKey('tags', $content); 681 $this->assertArrayHasKey('tags', $content);
597 $this->assertEquals($nbTags - 1, count($content['tags'])); 682 $this->assertSame($nbTags - 1, count($content['tags']));
598 } 683 }
599 684
600 public function testSaveIsArchivedAfterPost() 685 public function testSaveIsArchivedAfterPost()
@@ -612,11 +697,11 @@ class EntryRestControllerTest extends WallabagApiTestCase
612 'url' => $entry->getUrl(), 697 'url' => $entry->getUrl(),
613 ]); 698 ]);
614 699
615 $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); 700 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
616 701
617 $content = json_decode($this->client->getResponse()->getContent(), true); 702 $content = json_decode($this->client->getResponse()->getContent(), true);
618 703
619 $this->assertEquals(true, $content['is_archived']); 704 $this->assertSame(1, $content['is_archived']);
620 } 705 }
621 706
622 public function testSaveIsStarredAfterPost() 707 public function testSaveIsStarredAfterPost()
@@ -634,11 +719,11 @@ class EntryRestControllerTest extends WallabagApiTestCase
634 'url' => $entry->getUrl(), 719 'url' => $entry->getUrl(),
635 ]); 720 ]);
636 721
637 $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); 722 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
638 723
639 $content = json_decode($this->client->getResponse()->getContent(), true); 724 $content = json_decode($this->client->getResponse()->getContent(), true);
640 725
641 $this->assertEquals(true, $content['is_starred']); 726 $this->assertSame(1, $content['is_starred']);
642 } 727 }
643 728
644 public function testSaveIsArchivedAfterPatch() 729 public function testSaveIsArchivedAfterPatch()
@@ -652,15 +737,18 @@ class EntryRestControllerTest extends WallabagApiTestCase
652 $this->markTestSkipped('No content found in db.'); 737 $this->markTestSkipped('No content found in db.');
653 } 738 }
654 739
655 $this->client->request('PATCH', '/api/entries/'.$entry->getId().'.json', [ 740 $previousTitle = $entry->getTitle();
656 'title' => $entry->getTitle().'++', 741
742 $this->client->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [
743 'title' => $entry->getTitle() . '++',
657 ]); 744 ]);
658 745
659 $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); 746 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
660 747
661 $content = json_decode($this->client->getResponse()->getContent(), true); 748 $content = json_decode($this->client->getResponse()->getContent(), true);
662 749
663 $this->assertEquals(true, $content['is_archived']); 750 $this->assertSame(1, $content['is_archived']);
751 $this->assertSame($previousTitle . '++', $content['title']);
664 } 752 }
665 753
666 public function testSaveIsStarredAfterPatch() 754 public function testSaveIsStarredAfterPatch()
@@ -673,60 +761,93 @@ class EntryRestControllerTest extends WallabagApiTestCase
673 if (!$entry) { 761 if (!$entry) {
674 $this->markTestSkipped('No content found in db.'); 762 $this->markTestSkipped('No content found in db.');
675 } 763 }
676 $this->client->request('PATCH', '/api/entries/'.$entry->getId().'.json', [ 764 $this->client->request('PATCH', '/api/entries/' . $entry->getId() . '.json', [
677 'title' => $entry->getTitle().'++', 765 'title' => $entry->getTitle() . '++',
678 ]); 766 ]);
679 767
680 $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); 768 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
681 769
682 $content = json_decode($this->client->getResponse()->getContent(), true); 770 $content = json_decode($this->client->getResponse()->getContent(), true);
683 771
684 $this->assertEquals(true, $content['is_starred']); 772 $this->assertSame(1, $content['is_starred']);
773 }
774
775 public function dataForEntriesExistWithUrl()
776 {
777 return [
778 'with_id' => [
779 'url' => '/api/entries/exists?url=http://0.0.0.0/entry2&return_id=1',
780 'expectedValue' => 2,
781 ],
782 'without_id' => [
783 'url' => '/api/entries/exists?url=http://0.0.0.0/entry2',
784 'expectedValue' => true,
785 ],
786 ];
685 } 787 }
686 788
687 public function testGetEntriesExists() 789 /**
790 * @dataProvider dataForEntriesExistWithUrl
791 */
792 public function testGetEntriesExists($url, $expectedValue)
688 { 793 {
689 $this->client->request('GET', '/api/entries/exists?url=http://0.0.0.0/entry2'); 794 $this->client->request('GET', $url);
690 795
691 $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); 796 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
692 797
693 $content = json_decode($this->client->getResponse()->getContent(), true); 798 $content = json_decode($this->client->getResponse()->getContent(), true);
694 799
695 $this->assertEquals(true, $content['exists']); 800 $this->assertSame($expectedValue, $content['exists']);
696 } 801 }
697 802
698 public function testGetEntriesExistsWithManyUrls() 803 public function testGetEntriesExistsWithManyUrls()
699 { 804 {
700 $url1 = 'http://0.0.0.0/entry2'; 805 $url1 = 'http://0.0.0.0/entry2';
701 $url2 = 'http://0.0.0.0/entry10'; 806 $url2 = 'http://0.0.0.0/entry10';
702 $this->client->request('GET', '/api/entries/exists?urls[]='.$url1.'&urls[]='.$url2); 807 $this->client->request('GET', '/api/entries/exists?urls[]=' . $url1 . '&urls[]=' . $url2 . '&return_id=1');
703 808
704 $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); 809 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
705 810
706 $content = json_decode($this->client->getResponse()->getContent(), true); 811 $content = json_decode($this->client->getResponse()->getContent(), true);
707 812
708 $this->assertArrayHasKey($url1, $content); 813 $this->assertArrayHasKey($url1, $content);
709 $this->assertArrayHasKey($url2, $content); 814 $this->assertArrayHasKey($url2, $content);
710 $this->assertEquals(true, $content[$url1]); 815 $this->assertSame(2, $content[$url1]);
711 $this->assertEquals(false, $content[$url2]); 816 $this->assertNull($content[$url2]);
817 }
818
819 public function testGetEntriesExistsWithManyUrlsReturnBool()
820 {
821 $url1 = 'http://0.0.0.0/entry2';
822 $url2 = 'http://0.0.0.0/entry10';
823 $this->client->request('GET', '/api/entries/exists?urls[]=' . $url1 . '&urls[]=' . $url2);
824
825 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
826
827 $content = json_decode($this->client->getResponse()->getContent(), true);
828
829 $this->assertArrayHasKey($url1, $content);
830 $this->assertArrayHasKey($url2, $content);
831 $this->assertTrue($content[$url1]);
832 $this->assertFalse($content[$url2]);
712 } 833 }
713 834
714 public function testGetEntriesExistsWhichDoesNotExists() 835 public function testGetEntriesExistsWhichDoesNotExists()
715 { 836 {
716 $this->client->request('GET', '/api/entries/exists?url=http://google.com/entry2'); 837 $this->client->request('GET', '/api/entries/exists?url=http://google.com/entry2');
717 838
718 $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); 839 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
719 840
720 $content = json_decode($this->client->getResponse()->getContent(), true); 841 $content = json_decode($this->client->getResponse()->getContent(), true);
721 842
722 $this->assertEquals(false, $content['exists']); 843 $this->assertSame(false, $content['exists']);
723 } 844 }
724 845
725 public function testGetEntriesExistsWithNoUrl() 846 public function testGetEntriesExistsWithNoUrl()
726 { 847 {
727 $this->client->request('GET', '/api/entries/exists?url='); 848 $this->client->request('GET', '/api/entries/exists?url=');
728 849
729 $this->assertEquals(403, $this->client->getResponse()->getStatusCode()); 850 $this->assertSame(403, $this->client->getResponse()->getStatusCode());
730 } 851 }
731 852
732 public function testReloadEntryErrorWhileFetching() 853 public function testReloadEntryErrorWhileFetching()
@@ -739,8 +860,8 @@ class EntryRestControllerTest extends WallabagApiTestCase
739 $this->markTestSkipped('No content found in db.'); 860 $this->markTestSkipped('No content found in db.');
740 } 861 }
741 862
742 $this->client->request('PATCH', '/api/entries/'.$entry->getId().'/reload.json'); 863 $this->client->request('PATCH', '/api/entries/' . $entry->getId() . '/reload.json');
743 $this->assertEquals(304, $this->client->getResponse()->getStatusCode()); 864 $this->assertSame(304, $this->client->getResponse()->getStatusCode());
744 } 865 }
745 866
746 public function testReloadEntry() 867 public function testReloadEntry()
@@ -755,13 +876,208 @@ class EntryRestControllerTest extends WallabagApiTestCase
755 876
756 $this->setUp(); 877 $this->setUp();
757 878
758 $this->client->request('PATCH', '/api/entries/'.$json['id'].'/reload.json'); 879 $this->client->request('PATCH', '/api/entries/' . $json['id'] . '/reload.json');
759 $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); 880 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
760 881
761 $content = json_decode($this->client->getResponse()->getContent(), true); 882 $content = json_decode($this->client->getResponse()->getContent(), true);
762 883
763 $this->assertNotEmpty($content['title']); 884 $this->assertNotEmpty($content['title']);
764 885
765 $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); 886 $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type'));
887 }
888
889 public function testPostEntriesTagsListAction()
890 {
891 $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager')
892 ->getRepository('WallabagCoreBundle:Entry')
893 ->findByUrlAndUserId('http://0.0.0.0/entry4', 1);
894
895 $tags = $entry->getTags();
896
897 $this->assertCount(2, $tags);
898
899 $list = [
900 [
901 'url' => 'http://0.0.0.0/entry4',
902 'tags' => 'new tag 1, new tag 2',
903 ],
904 ];
905
906 $this->client->request('POST', '/api/entries/tags/lists?list=' . json_encode($list));
907
908 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
909
910 $content = json_decode($this->client->getResponse()->getContent(), true);
911
912 $this->assertInternalType('int', $content[0]['entry']);
913 $this->assertSame('http://0.0.0.0/entry4', $content[0]['url']);
914
915 $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager')
916 ->getRepository('WallabagCoreBundle:Entry')
917 ->findByUrlAndUserId('http://0.0.0.0/entry4', 1);
918
919 $tags = $entry->getTags();
920 $this->assertCount(4, $tags);
921 }
922
923 public function testPostEntriesTagsListActionNoList()
924 {
925 $this->client->request('POST', '/api/entries/tags/lists?list=' . json_encode([]));
926
927 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
928
929 $content = json_decode($this->client->getResponse()->getContent(), true);
930
931 $this->assertEmpty($content);
932 }
933
934 public function testDeleteEntriesTagsListAction()
935 {
936 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
937 $entry = new Entry($em->getReference(User::class, 1));
938 $entry->setUrl('http://0.0.0.0/test-entry');
939 $entry->addTag((new Tag())->setLabel('foo-tag'));
940 $entry->addTag((new Tag())->setLabel('bar-tag'));
941 $em->persist($entry);
942 $em->flush();
943
944 $em->clear();
945
946 $list = [
947 [
948 'url' => 'http://0.0.0.0/test-entry',
949 'tags' => 'foo-tag, bar-tag',
950 ],
951 ];
952
953 $this->client->request('DELETE', '/api/entries/tags/list?list=' . json_encode($list));
954 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
955
956 $entry = $em->getRepository('WallabagCoreBundle:Entry')->find($entry->getId());
957 $this->assertCount(0, $entry->getTags());
958 }
959
960 public function testDeleteEntriesTagsListActionNoList()
961 {
962 $this->client->request('DELETE', '/api/entries/tags/list?list=' . json_encode([]));
963
964 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
965
966 $content = json_decode($this->client->getResponse()->getContent(), true);
967
968 $this->assertEmpty($content);
969 }
970
971 public function testPostEntriesListAction()
972 {
973 $list = [
974 'http://www.lemonde.fr/musiques/article/2017/04/23/loin-de-la-politique-le-printemps-de-bourges-retombe-en-enfance_5115862_1654986.html',
975 'http://0.0.0.0/entry2',
976 ];
977
978 $this->client->request('POST', '/api/entries/lists?urls=' . json_encode($list));
979
980 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
981
982 $content = json_decode($this->client->getResponse()->getContent(), true);
983
984 $this->assertInternalType('int', $content[0]['entry']);
985 $this->assertSame('http://www.lemonde.fr/musiques/article/2017/04/23/loin-de-la-politique-le-printemps-de-bourges-retombe-en-enfance_5115862_1654986.html', $content[0]['url']);
986
987 $this->assertInternalType('int', $content[1]['entry']);
988 $this->assertSame('http://0.0.0.0/entry2', $content[1]['url']);
989 }
990
991 public function testPostEntriesListActionWithNoUrls()
992 {
993 $this->client->request('POST', '/api/entries/lists?urls=' . json_encode([]));
994
995 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
996
997 $content = json_decode($this->client->getResponse()->getContent(), true);
998
999 $this->assertEmpty($content);
1000 }
1001
1002 public function testDeleteEntriesListAction()
1003 {
1004 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
1005 $em->persist((new Entry($em->getReference(User::class, 1)))->setUrl('http://0.0.0.0/test-entry1'));
1006
1007 $em->flush();
1008 $em->clear();
1009 $list = [
1010 'http://0.0.0.0/test-entry1',
1011 'http://0.0.0.0/test-entry-not-exist',
1012 ];
1013
1014 $this->client->request('DELETE', '/api/entries/list?urls=' . json_encode($list));
1015
1016 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
1017
1018 $content = json_decode($this->client->getResponse()->getContent(), true);
1019
1020 $this->assertTrue($content[0]['entry']);
1021 $this->assertSame('http://0.0.0.0/test-entry1', $content[0]['url']);
1022
1023 $this->assertFalse($content[1]['entry']);
1024 $this->assertSame('http://0.0.0.0/test-entry-not-exist', $content[1]['url']);
1025 }
1026
1027 public function testDeleteEntriesListActionWithNoUrls()
1028 {
1029 $this->client->request('DELETE', '/api/entries/list?urls=' . json_encode([]));
1030
1031 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
1032
1033 $content = json_decode($this->client->getResponse()->getContent(), true);
1034
1035 $this->assertEmpty($content);
1036 }
1037
1038 public function testLimitBulkAction()
1039 {
1040 $list = [
1041 'http://0.0.0.0/entry1',
1042 'http://0.0.0.0/entry1',
1043 'http://0.0.0.0/entry1',
1044 'http://0.0.0.0/entry1',
1045 'http://0.0.0.0/entry1',
1046 'http://0.0.0.0/entry1',
1047 'http://0.0.0.0/entry1',
1048 'http://0.0.0.0/entry1',
1049 'http://0.0.0.0/entry1',
1050 'http://0.0.0.0/entry1',
1051 'http://0.0.0.0/entry1',
1052 ];
1053
1054 $this->client->request('POST', '/api/entries/lists?urls=' . json_encode($list));
1055
1056 $this->assertSame(400, $this->client->getResponse()->getStatusCode());
1057 $this->assertContains('API limit reached', $this->client->getResponse()->getContent());
1058 }
1059
1060 public function testRePostEntryAndReUsePublishedAt()
1061 {
1062 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
1063 $entry = new Entry($em->getReference(User::class, 1));
1064 $entry->setTitle('Antoine de Caunes : « Je veux avoir le droit de tâtonner »');
1065 $entry->setContent('hihi');
1066 $entry->setUrl('http://www.lemonde.fr/m-perso/article/2017/06/25/antoine-de-caunes-je-veux-avoir-le-droit-de-tatonner_5150728_4497916.html');
1067 $entry->setPublishedAt(new \DateTime('2017-06-26T07:46:02+0200'));
1068 $em->persist($entry);
1069 $em->flush();
1070 $em->clear();
1071
1072 $this->client->request('POST', '/api/entries.json', [
1073 'url' => 'http://www.lemonde.fr/m-perso/article/2017/06/25/antoine-de-caunes-je-veux-avoir-le-droit-de-tatonner_5150728_4497916.html',
1074 ]);
1075
1076 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
1077
1078 $content = json_decode($this->client->getResponse()->getContent(), true);
1079
1080 $this->assertGreaterThan(0, $content['id']);
1081 $this->assertSame('http://www.lemonde.fr/m-perso/article/2017/06/25/antoine-de-caunes-je-veux-avoir-le-droit-de-tatonner_5150728_4497916.html', $content['url']);
766 } 1082 }
767} 1083}