aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/ApiBundle
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Wallabag/ApiBundle')
-rw-r--r--tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php68
1 files changed, 55 insertions, 13 deletions
diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
index 2a1d2e15..46b5f460 100644
--- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
+++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
@@ -400,29 +400,71 @@ class EntryRestControllerTest extends WallabagApiTestCase
400 400
401 public function testDeleteEntry() 401 public function testDeleteEntry()
402 { 402 {
403 $entry = $this->client->getContainer() 403 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
404 ->get('doctrine.orm.entity_manager') 404 $entry = new Entry($em->getReference(User::class, 1));
405 ->getRepository('WallabagCoreBundle:Entry') 405 $entry->setUrl('http://0.0.0.0/test-delete-entry');
406 ->findOneByUser(1, ['id' => 'asc']); 406 $entry->setTitle('Test delete entry');
407 $em->persist($entry);
408 $em->flush();
407 409
408 if (!$entry) { 410 $em->clear();
409 $this->markTestSkipped('No content found in db.');
410 }
411 411
412 $this->client->request('DELETE', '/api/entries/' . $entry->getId() . '.json'); 412 $e = [
413 'title' => $entry->getTitle(),
414 'url' => $entry->getUrl(),
415 'id' => $entry->getId(),
416 ];
417
418 $this->client->request('DELETE', '/api/entries/' . $e['id'] . '.json');
413 419
414 $this->assertSame(200, $this->client->getResponse()->getStatusCode()); 420 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
415 421
416 $content = json_decode($this->client->getResponse()->getContent(), true); 422 $content = json_decode($this->client->getResponse()->getContent(), true);
417 423
418 $this->assertSame($entry->getTitle(), $content['title']); 424 $this->assertSame($e['title'], $content['title']);
419 $this->assertSame($entry->getUrl(), $content['url']); 425 $this->assertSame($e['url'], $content['url']);
420 $this->assertSame($entry->getId(), $content['id']); 426 $this->assertSame($e['id'], $content['id']);
421 427
422 // We'll try to delete this entry again 428 // We'll try to delete this entry again
423 $this->client->request('DELETE', '/api/entries/' . $entry->getId() . '.json'); 429 $client = $this->createAuthorizedClient();
430 $client->request('DELETE', '/api/entries/' . $e['id'] . '.json');
431
432 $this->assertSame(404, $client->getResponse()->getStatusCode());
433 }
424 434
425 $this->assertSame(404, $this->client->getResponse()->getStatusCode()); 435 public function testDeleteEntryExpectId()
436 {
437 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
438 $entry = new Entry($em->getReference(User::class, 1));
439 $entry->setUrl('http://0.0.0.0/test-delete-entry-id');
440 $em->persist($entry);
441 $em->flush();
442
443 $em->clear();
444
445 $id = $entry->getId();
446
447 $this->client->request('DELETE', '/api/entries/' . $id . '.json?expect=id');
448
449 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
450
451 $content = json_decode($this->client->getResponse()->getContent(), true);
452
453 $this->assertSame($id, $content['id']);
454 $this->assertArrayNotHasKey('url', $content);
455
456 // We'll try to delete this entry again
457 $client = $this->createAuthorizedClient();
458 $client->request('DELETE', '/api/entries/' . $id . '.json');
459
460 $this->assertSame(404, $client->getResponse()->getStatusCode());
461 }
462
463 public function testDeleteEntryExpectBadRequest()
464 {
465 $this->client->request('DELETE', '/api/entries/1.json?expect=badrequest');
466
467 $this->assertSame(400, $this->client->getResponse()->getStatusCode());
426 } 468 }
427 469
428 public function testPostEntry() 470 public function testPostEntry()