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:
Kevin Decherf 2019-02-17 15:25:21 +01:00
parent b1992b340e
commit 4e0ed3368d

View file

@ -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');