aboutsummaryrefslogtreecommitdiff
path: root/tests/jsonapi/FileRefsContentHeadTest.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/FileRefsContentHeadTest.php
current code from svn, revision 62608
Diffstat (limited to 'tests/jsonapi/FileRefsContentHeadTest.php')
-rw-r--r--tests/jsonapi/FileRefsContentHeadTest.php75
1 files changed, 75 insertions, 0 deletions
diff --git a/tests/jsonapi/FileRefsContentHeadTest.php b/tests/jsonapi/FileRefsContentHeadTest.php
new file mode 100644
index 0000000..c850984
--- /dev/null
+++ b/tests/jsonapi/FileRefsContentHeadTest.php
@@ -0,0 +1,75 @@
+<?php
+
+use JsonApi\Errors\RecordNotFoundException;
+use JsonApi\Errors\UnprocessableEntityException;
+use JsonApi\Routes\Files\FileRefsContentHead;
+use JsonApi\Schemas\ContentTermsOfUse;
+use JsonApi\Schemas\FileRef;
+
+require_once 'FilesTestHelper.php';
+
+class FileRefsContentHeadTest 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 testShouldGetHead()
+ {
+ $credentials = $this->tester->getCredentialsForTestDozent();
+ $courseId = 'a07535cf2f8a72df33c12ddfa4b53dde';
+ $folder = $this->prepareTopFolder($credentials, $courseId);
+ $file = $this->createFileInFolder($credentials, $folder, 'file.txt', 'some description');
+
+ $this->assertNotNull(\FileRef::find($file->getFileRef()->id));
+
+ $response = $this->getHeadResponse($credentials, $file);
+
+ $this->tester->assertSame($response->getStatusCode(), 200);
+ $this->tester->assertArrayHasKey('ETag', $headers = $response->getHeaders());
+ $this->tester->assertNotEmpty($headers['ETag']);
+ $this->tester->assertIsString(current($headers['ETag']));
+ }
+
+ public function testShouldNotGetHeadOnMissingFile()
+ {
+ $credentials = $this->tester->getCredentialsForTestDozent();
+ $missingId = 'missing-id';
+ $this->assertNull(\FileRef::find($missingId));
+
+ $response = $this->getHeadResponse($credentials, $missingId);
+
+ $this->tester->assertSame($response->getStatusCode(), 404);
+ }
+
+
+ // **** helper functions ****
+ private function getHeadResponse($user, $fileOrId)
+ {
+ $app = $this->tester->createApp(
+ $user,
+ 'HEAD',
+ '/file-refs/{id}/content',
+ FileRefsContentHead::class
+ );
+
+ $requestBuilder = $this->tester->createRequestBuilder($user);
+ $requestBuilder
+ ->setUri('/file-refs/'.(is_object($fileOrId) ? $fileOrId->getFileRef()->id : $fileOrId).'/content')
+ ->setMethod('HEAD');
+
+ return $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
+ }
+}