Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Pasteque
pasteque-server
Commits
dd60265a
Commit
dd60265a
authored
Aug 18, 2019
by
Karamel
Browse files
Delete resource route and test.
parent
14f2df25
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/http/routes/resource.php
View file @
dd60265a
...
...
@@ -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
));
});
tests/http/HttpResourceTest.php
View file @
dd60265a
...
...
@@ -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
);
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment