mirror of
https://github.com/wallabag/wallabag.git
synced 2024-11-26 11:01:04 +00:00
tests: create entry for testDeleteEntry, fix missing id
When using the entity manager to retrieve an already stored entry, the id disapears from $entry after the first delete call. This leads to testing a nonexistent endpoint (api/entries/.json) during the second delete call. This change now creates an entry specifically for the test. Signed-off-by: Kevin Decherf <kevin@kdecherf.com>
This commit is contained in:
parent
b1992b340e
commit
4e0ed3368d
1 changed files with 29 additions and 7 deletions
|
@ -400,13 +400,35 @@ class EntryRestControllerTest extends WallabagApiTestCase
|
|||
|
||||
public function testDeleteEntry()
|
||||
{
|
||||
$entry = $this->client->getContainer()
|
||||
->get('doctrine.orm.entity_manager')
|
||||
->getRepository('WallabagCoreBundle:Entry')
|
||||
->findOneByUser(1, ['id' => 'asc']);
|
||||
$em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
|
||||
$entry = new Entry($em->getReference(User::class, 1));
|
||||
$entry->setUrl('http://0.0.0.0/test-delete-entry');
|
||||
$entry->setTitle('Test delete entry');
|
||||
$em->persist($entry);
|
||||
$em->flush();
|
||||
|
||||
if (!$entry) {
|
||||
$this->markTestSkipped('No content found in db.');
|
||||
$em->clear();
|
||||
|
||||
$e = [
|
||||
'title' => $entry->getTitle(),
|
||||
'url' => $entry->getUrl(),
|
||||
'id' => $entry->getId(),
|
||||
];
|
||||
|
||||
$this->client->request('DELETE', '/api/entries/' . $e['id'] . '.json');
|
||||
|
||||
$this->assertSame(200, $this->client->getResponse()->getStatusCode());
|
||||
|
||||
$content = json_decode($this->client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertSame($e['title'], $content['title']);
|
||||
$this->assertSame($e['url'], $content['url']);
|
||||
$this->assertSame($e['id'], $content['id']);
|
||||
|
||||
// We'll try to delete this entry again
|
||||
$this->client->request('DELETE', '/api/entries/' . $e['id'] . '.json');
|
||||
|
||||
$this->assertSame(404, $this->client->getResponse()->getStatusCode());
|
||||
}
|
||||
|
||||
$this->client->request('DELETE', '/api/entries/' . $entry->getId() . '.json');
|
||||
|
|
Loading…
Reference in a new issue