diff options
author | Jérémy Benoist <j0k3r@users.noreply.github.com> | 2019-02-25 10:56:07 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-25 10:56:07 +0100 |
commit | 4de99d1ab161fc378e0f7cc121c60396f86bc577 (patch) | |
tree | 7495caff11c8183fb1aeed9abebf38c6a4a2207f /tests/Wallabag | |
parent | b1992b340e21b6846a1ec2ae6ddd7217f3b24fb5 (diff) | |
parent | 12a97c352275d81e9252ca4179de51180403eb6f (diff) | |
download | wallabag-4de99d1ab161fc378e0f7cc121c60396f86bc577.tar.gz wallabag-4de99d1ab161fc378e0f7cc121c60396f86bc577.tar.zst wallabag-4de99d1ab161fc378e0f7cc121c60396f86bc577.zip |
Merge pull request #3887 from wallabag/issue-3711
Add support of expect parameter to change return object when deleting entry
Diffstat (limited to 'tests/Wallabag')
-rw-r--r-- | tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php | 68 |
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() |