Commit dd60265a authored by Karamel's avatar Karamel
Browse files

Delete resource route and test.

parent 14f2df25
......@@ -21,3 +21,14 @@ $app->POST('/api/resource', function($request, $response, $args) {
$res = \Pasteque\Server\Model\Resource::fromStruct($tab, $ptApp->getDao());
return $response->withApiResult(APICaller::run($ptApp, 'resource', 'write', $res));
});
$app->DELETE('/api/resource/{label}', function($request, $response, $args) {
$ptApp = $this->get('settings')['ptApp'];
$label = $args['label'];
if ($label != 'Printer.Ticket.Logo' && $label != 'Printer.Ticket.Header'
&& $label != 'Printer.Ticket.Footer' && $label != 'MobilePrinter.Ticket.Logo'
&& $label != 'MobilePrinter.Ticket.Header' && $label != 'MobilePrinter.Ticket.Footer') {
return $response->withStatus(400, 'Cannot delete this resource');
}
return $response->withApiResult(APICaller::run($ptApp, 'resource', 'delete', $label));
});
......@@ -95,4 +95,19 @@ class HttpResourceTest extends TestCase
$this->assertNotNull($dbRes);
$this->assertEquals('Updated content', $dbRes->getContent());
}
public function testDelete() {
$res = new Resource();
$res->setLabel('Printer.Ticket.Header');
$res->setType(Resource::TYPE_TEXT);
$res->setContent('Text content');
$this->dao->write($res);
$this->dao->commit();
curl_setopt($this->curl, CURLOPT_URL, apiUrl('api/resource/Printer.Ticket.Header'));
curl_setopt($this->curl, CURLOPT_CUSTOMREQUEST, 'DELETE');
$resp = curl_exec($this->curl);
$this->assertEquals(200, curl_getinfo($this->curl, CURLINFO_HTTP_CODE));
$dbRes = $this->dao->readSnapshot(Resource::class, 'Printer.Ticket.Header');
$this->assertNull($dbRes);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment