aboutsummaryrefslogtreecommitdiff
path: root/tests/jsonapi/FileRefsDeleteTest.php
diff options
context:
space:
mode:
authorJan-Hendrik Willms <tleilax+github@gmail.com>2021-07-22 16:07:19 +0200
committerJan-Hendrik Willms <tleilax+github@gmail.com>2021-07-22 16:19:12 +0200
commita3da1483a9e689846179159355badfec8073dbec (patch)
tree770dcca6bdf5f6f2a11b0e7fcbbeda6919a3fc52 /tests/jsonapi/FileRefsDeleteTest.php
current code from svn, revision 62608
Diffstat (limited to 'tests/jsonapi/FileRefsDeleteTest.php')
-rw-r--r--tests/jsonapi/FileRefsDeleteTest.php66
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/jsonapi/FileRefsDeleteTest.php b/tests/jsonapi/FileRefsDeleteTest.php
new file mode 100644
index 0000000..d1813a4
--- /dev/null
+++ b/tests/jsonapi/FileRefsDeleteTest.php
@@ -0,0 +1,66 @@
+<?php
+
+use JsonApi\Routes\Files\FileRefsDelete;
+use JsonApi\Schemas\ContentTermsOfUse;
+use JsonApi\Schemas\FileRef;
+use JsonApi\Errors\RecordNotFoundException;
+
+require_once 'FilesTestHelper.php';
+
+class FileRefsDeleteTest extends \Codeception\Test\Unit
+{
+ use FilesTestHelper;
+
+ /**
+ * @var \UnitTester
+ */
+ protected $tester;
+
+ protected function _before()
+ {
+ \DBManager::getInstance()->setConnection('studip', $this->getModule('\\Helper\\StudipDb')->dbh);
+ }
+
+ protected function _after()
+ {
+ }
+
+ public function testShouldDeleteFileRef()
+ {
+ $credentials = $this->tester->getCredentialsForTestDozent();
+ $courseId = 'a07535cf2f8a72df33c12ddfa4b53dde';
+ $folder = $this->prepareTopFolder($credentials, $courseId);
+ $file = $this->createFileInFolder($credentials, $folder, 'file.txt', 'some description');
+
+ $response = $this->sendDeleteFileRef($credentials, $file->getId());
+ $this->tester->assertSame($response->getStatusCode(), 204);
+ }
+
+ public function testShouldNotDeleteMissingFileRef()
+ {
+ $credentials = $this->tester->getCredentialsForTestDozent();
+ $missingId = 'missing-id';
+
+ $this->tester->expectThrowable(RecordNotFoundException::class, function () use ($credentials, $missingId) {
+ $this->sendDeleteFileRef($credentials, $missingId);
+ });
+ }
+
+ // **** helper functions ****
+ private function sendDeleteFileRef($user, $fileId)
+ {
+ $app = $this->tester->createApp(
+ $user,
+ 'DELETE',
+ '/file-refs/{id}',
+ FileRefsDelete::class
+ );
+
+ $requestBuilder = $this->tester->createRequestBuilder($user);
+ $requestBuilder
+ ->setUri('/file-refs/'.($fileId))
+ ->delete();
+
+ return $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
+ }
+}