aboutsummaryrefslogtreecommitdiff
path: root/tests/jsonapi
diff options
context:
space:
mode:
authorMarcus Eibrink-Lunzenauer <lunzenauer@elan-ev.de>2021-08-20 06:11:05 +0000
committerMarcus Eibrink-Lunzenauer <lunzenauer@elan-ev.de>2021-08-20 06:11:05 +0000
commit9b6bd7e747bd5ed44d169a8e1baee0e519d209d6 (patch)
tree104c177e3c0d40d7471d7c081d61dec15cb1bab9 /tests/jsonapi
parent8edcc69d26d73736b1bab92df28a00cd97ab8cf3 (diff)
Update der JSONAPI-Bibliotheken, fixes #80
Diffstat (limited to 'tests/jsonapi')
-rw-r--r--tests/jsonapi/BlubberCommentsUpdateTest.php10
-rw-r--r--tests/jsonapi/BlubberThreadsCreateTest.php12
-rw-r--r--tests/jsonapi/BlubberThreadsIndexTest.php17
-rw-r--r--tests/jsonapi/FileRefsCreateTest.php130
-rw-r--r--tests/jsonapi/FileRefsDeleteTest.php5
-rw-r--r--tests/jsonapi/FileRefsShowTest.php5
-rw-r--r--tests/jsonapi/ForumCategoriesCreateTest.php29
-rw-r--r--tests/jsonapi/ForumCategoriesIndexTest.php27
-rw-r--r--tests/jsonapi/ForumCategoriesShowTest.php24
-rw-r--r--tests/jsonapi/ForumCategoriesUpdateTest.php28
-rw-r--r--tests/jsonapi/ForumCategoryDeleteTest.php26
-rw-r--r--tests/jsonapi/ForumEntriesCreateTest.php75
-rw-r--r--tests/jsonapi/ForumEntriesDeleteTest.php24
-rw-r--r--tests/jsonapi/ForumEntriesShowTest.php91
-rw-r--r--tests/jsonapi/ForumEntriesUpdateTest.php29
-rw-r--r--tests/jsonapi/MessagesShowTest.php7
-rw-r--r--tests/jsonapi/NewsCreateTest.php130
-rw-r--r--tests/jsonapi/NewsShowTest.php19
-rw-r--r--tests/jsonapi/UserEventsIcalTest.php2
-rw-r--r--tests/jsonapi/UserScheduleShowTest.php1
-rw-r--r--tests/jsonapi/_bootstrap.php1
21 files changed, 290 insertions, 402 deletions
diff --git a/tests/jsonapi/BlubberCommentsUpdateTest.php b/tests/jsonapi/BlubberCommentsUpdateTest.php
index 7ee569d..d9f4a1e 100644
--- a/tests/jsonapi/BlubberCommentsUpdateTest.php
+++ b/tests/jsonapi/BlubberCommentsUpdateTest.php
@@ -50,13 +50,9 @@ class BlubberCommentsUpdateTest extends \Codeception\Test\Unit
$comment = $this->createBlubberComment($credentialsAutor, $thread, 'Autolykos knows him.');
$this->tester->assertEquals($num + 1, \BlubberComment::countBySQL('1'));
- $this->tester->expectThrowable(\JsonApi\Errors\AuthorizationFailedException::class, function () use (
- $credentialsDozent,
- $comment
- ) {
- $content = 'Who knows Erginos?';
- $this->updateBlubberCommentJSONAPI($credentialsDozent, $comment, $content);
- });
+ $content = 'Who knows Erginos?';
+ $response = $this->updateBlubberCommentJSONAPI($credentialsDozent, $comment, $content);
+ $this->tester->assertSame(403, $response->getStatusCode());
}
public function testUpdateOtherCommentSuccess()
diff --git a/tests/jsonapi/BlubberThreadsCreateTest.php b/tests/jsonapi/BlubberThreadsCreateTest.php
index 9bcbf41..4b275d5 100644
--- a/tests/jsonapi/BlubberThreadsCreateTest.php
+++ b/tests/jsonapi/BlubberThreadsCreateTest.php
@@ -69,14 +69,14 @@ class BlubberThreadsCreateTest extends \Codeception\Test\Unit
// given
$credentials = $this->tester->getCredentialsForTestAutor();
- $this->expectException(JsonApi\Errors\BadRequestException::class);
- $this->createThread($credentials, 'course');
+ $response = $this->createThread($credentials, 'course');
+ $this->tester->assertSame(400, $response->getStatusCode());
- $this->expectException(JsonApi\Errors\BadRequestException::class);
- $this->createThread($credentials, 'institute');
+ $response = $this->createThread($credentials, 'institute');
+ $this->tester->assertSame(400, $response->getStatusCode());
- $this->expectException(JsonApi\Errors\BadRequestException::class);
- $this->createThread($credentials, 'public');
+ $response = $this->createThread($credentials, 'public');
+ $this->tester->assertSame(400, $response->getStatusCode());
}
diff --git a/tests/jsonapi/BlubberThreadsIndexTest.php b/tests/jsonapi/BlubberThreadsIndexTest.php
index 304f6b1..ea665ab 100644
--- a/tests/jsonapi/BlubberThreadsIndexTest.php
+++ b/tests/jsonapi/BlubberThreadsIndexTest.php
@@ -118,10 +118,9 @@ class BlubberThreadsIndexTest extends \Codeception\Test\Unit
// given
$credentials = $this->tester->getCredentialsForTestAutor();
- $this->tester->expectThrowable(RecordNotFoundException::class, function () use ($credentials) {
- $courseId = 'missing';
- $this->fetchCourseThreads($credentials, $courseId);
- });
+ $courseId = 'missing';
+ $response = $this->fetchCourseThreads($credentials, $courseId);
+ $this->tester->assertSame(404, $response->getStatusCode());
}
public function testIndexAllThreadsOfAnInstitute()
@@ -151,10 +150,9 @@ class BlubberThreadsIndexTest extends \Codeception\Test\Unit
// given
$credentials = $this->tester->getCredentialsForTestAutor();
- $this->tester->expectThrowable(RecordNotFoundException::class, function () use ($credentials) {
- $instituteId = 'missing';
- $this->fetchInstituteThreads($credentials, $instituteId);
- });
+ $instituteId = 'missing';
+ $response = $this->fetchInstituteThreads($credentials, $instituteId);
+ $this->tester->assertSame(404, $response->getStatusCode());
}
public function testIndexAllThreadsWithSinceFilter()
@@ -265,7 +263,8 @@ class BlubberThreadsIndexTest extends \Codeception\Test\Unit
);
}
- private function fetchCourseThreads(array $credentials, string $courseId, array $filters = [])
+ private function fetchCourseThreads
+ (array $credentials, string $courseId, array $filters = [])
{
$requestBuilder = $this->tester
->createRequestBuilder($credentials)
diff --git a/tests/jsonapi/FileRefsCreateTest.php b/tests/jsonapi/FileRefsCreateTest.php
index 1e3c5b5..d58e181 100644
--- a/tests/jsonapi/FileRefsCreateTest.php
+++ b/tests/jsonapi/FileRefsCreateTest.php
@@ -1,10 +1,10 @@
-<?php
-
+><?php
use JsonApi\Errors\RecordNotFoundException;
use JsonApi\Errors\UnprocessableEntityException;
-use JsonApi\Routes\Files\FileRefsCreate;
+use JsonApi\Routes\Files\NegotiateFileRefsCreate as FileRefsCreate;
use JsonApi\Schemas\ContentTermsOfUse;
use JsonApi\Schemas\FileRef;
+use Slim\Psr7\Factory\ServerRequestFactory;
require_once 'FilesTestHelper.php';
@@ -36,13 +36,7 @@ class FileRefsCreateTest extends \Codeception\Test\Unit
$name = 'filename.jpg';
$description = 'a description';
- $response = $this->sendCreateFileRefInFolder(
- $credentials,
- $folder,
- $name,
- $description,
- $license
- );
+ $response = $this->sendCreateFileRefInFolder($credentials, $folder, $name, $description, $license);
$this->assertFileRefCreated($response, $name, $description, $license);
}
@@ -56,18 +50,8 @@ class FileRefsCreateTest extends \Codeception\Test\Unit
$name = 'filename.jpg';
$description = 'a description';
- $this->tester->expectThrowable(
- RecordNotFoundException::class,
- function () use ($credentials, $missingFolder, $name, $description, $license) {
- $this->sendCreateFileRefInFolder(
- $credentials,
- $missingFolder,
- $name,
- $description,
- $license
- );
- }
- );
+ $response = $this->sendCreateFileRefInFolder($credentials, $missingFolder, $name, $description, $license);
+ $this->tester->assertSame(404, $response->getStatusCode());
}
public function testShouldFailOnEmptyName()
@@ -80,18 +64,8 @@ class FileRefsCreateTest extends \Codeception\Test\Unit
$name = '';
$description = 'a description';
- $this->tester->expectThrowable(
- UnprocessableEntityException::class,
- function () use ($credentials, $folder, $name, $description, $license) {
- $this->sendCreateFileRefInFolder(
- $credentials,
- $folder,
- $name,
- $description,
- $license
- );
- }
- );
+ $response = $this->sendCreateFileRefInFolder($credentials, $folder, $name, $description, $license);
+ $this->tester->assertSame(422, $response->getStatusCode());
}
public function testShouldFailOnMissingLicense()
@@ -103,18 +77,8 @@ class FileRefsCreateTest extends \Codeception\Test\Unit
$name = 'a-real-filename.gif';
$description = 'a description';
- $this->tester->expectThrowable(
- UnprocessableEntityException::class,
- function () use ($credentials, $folder, $name, $description) {
- $this->sendCreateFileRefInFolder(
- $credentials,
- $folder,
- $name,
- $description,
- null
- );
- }
- );
+ $response = $this->sendCreateFileRefInFolder($credentials, $folder, $name, $description, null);
+ $this->tester->assertSame(422, $response->getStatusCode());
}
public function testShouldCreateLinkIfSameUser()
@@ -133,8 +97,8 @@ class FileRefsCreateTest extends \Codeception\Test\Unit
$credentials,
$folder,
$file,
- $name = "another-name.jpg",
- $description = "another description",
+ $name = 'another-name.jpg',
+ $description = 'another description',
$license
);
@@ -162,8 +126,8 @@ class FileRefsCreateTest extends \Codeception\Test\Unit
$credentialsAutor,
$folder,
$file,
- $name = "another-name.jpg",
- $description = "another description",
+ $name = 'another-name.jpg',
+ $description = 'another description',
$license
);
@@ -174,20 +138,47 @@ class FileRefsCreateTest extends \Codeception\Test\Unit
$this->assertFileRefCreated($response, $name, $description, $license);
}
+ public function testShouldCreateFileRefByUpload()
+ {
+ $credentials = $this->tester->getCredentialsForTestDozent();
+ $courseId = 'a07535cf2f8a72df33c12ddfa4b53dde';
+ $folder = $this->prepareTopFolder($credentials, $courseId);
+ $license = $this->getSampleLicense();
+
+ $name = 'tiny.gif';
+ $filename = __DIR__ . '/' . $name;
+ $description = 'a description';
+ $content = base64_decode('R0lGODlhAQABAIABAP///wAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==');
+ if (!file_exists($filename)) {
+ file_put_contents($filename, $content);
+ }
+ $this->tester->assertTrue(file_exists($filename));
+ $file = new \Slim\Psr7\UploadedFile($this->fileToStreamInterface($filename), $name);
+
+ $app = $this->tester->createApp($credentials, 'POST', '/folders/{id}/file-refs', FileRefsCreate::class);
+
+ $factory = new ServerRequestFactory();
+ $serverParams = [
+ 'PHP_AUTH_USER' => $credentials['username'],
+ 'PHP_AUTH_PW' => $credentials['password'],
+ ];
+ $request = $factory->createServerRequest('POST', '/folders/' . $folder->id . '/file-refs', $serverParams);
+ $request = $request->withUploadedFiles([$file])->withHeader('Content-Type', 'multipart/form-data');
+
+ $response = $this->tester->sendMockRequest($app, $request);
+ $this->tester->assertSame(201, $response->getStatusCode());
+ $this->tester->assertArrayHasKey('Location', $response->getHeaders());
+ }
+
// **** helper functions ****
private function sendCreateFileRefInFolder($user, $folder, $name, $description, $license)
{
- $app = $this->tester->createApp(
- $user,
- 'POST',
- '/folders/{id}/file-refs',
- FileRefsCreate::class
- );
+ $app = $this->tester->createApp($user, 'POST', '/folders/{id}/file-refs', FileRefsCreate::class);
$requestBuilder = $this->tester->createRequestBuilder($user);
$requestBuilder
->setJsonApiBody($this->prepareValidFileRefBody($name, $description, $license))
- ->setUri('/folders/'.($folder->id).'/file-refs')
+ ->setUri('/folders/' . $folder->id . '/file-refs')
->create();
return $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
@@ -195,24 +186,12 @@ class FileRefsCreateTest extends \Codeception\Test\Unit
private function sendCopyFileInFolder($credentials, $folder, $file, $name, $description, $license)
{
- $app = $this->tester->createApp(
- $credentials,
- 'POST',
- '/folders/{id}/file-refs',
- FileRefsCreate::class
- );
+ $app = $this->tester->createApp($credentials, 'POST', '/folders/{id}/file-refs', FileRefsCreate::class);
$requestBuilder = $this->tester->createRequestBuilder($credentials);
$requestBuilder
- ->setJsonApiBody(
- $this->prepareValidFileRefBody(
- $name,
- $description,
- $license,
- $file
- )
- )
- ->setUri('/folders/'.($folder->id).'/file-refs')
+ ->setJsonApiBody($this->prepareValidFileRefBody($name, $description, $license, $file))
+ ->setUri('/folders/' . $folder->id . '/file-refs')
->create();
return $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
@@ -235,4 +214,11 @@ class FileRefsCreateTest extends \Codeception\Test\Unit
$resourceLink = $resource->relationship('terms-of-use')->firstResourceLink();
$this->tester->assertSame($license->id, $resourceLink['id']);
}
+
+ private function fileToStreamInterface(string $filename)
+ {
+ $factory = new \Slim\Psr7\Factory\StreamFactory();
+
+ return $factory->createStreamFromFile($filename);
+ }
}
diff --git a/tests/jsonapi/FileRefsDeleteTest.php b/tests/jsonapi/FileRefsDeleteTest.php
index d1813a4..8b30e0d 100644
--- a/tests/jsonapi/FileRefsDeleteTest.php
+++ b/tests/jsonapi/FileRefsDeleteTest.php
@@ -41,9 +41,8 @@ class FileRefsDeleteTest extends \Codeception\Test\Unit
$credentials = $this->tester->getCredentialsForTestDozent();
$missingId = 'missing-id';
- $this->tester->expectThrowable(RecordNotFoundException::class, function () use ($credentials, $missingId) {
- $this->sendDeleteFileRef($credentials, $missingId);
- });
+ $response = $this->sendDeleteFileRef($credentials, $missingId);
+ $this->tester->assertSame(404, $response->getStatusCode());
}
// **** helper functions ****
diff --git a/tests/jsonapi/FileRefsShowTest.php b/tests/jsonapi/FileRefsShowTest.php
index 10dc035..6fcca0a 100644
--- a/tests/jsonapi/FileRefsShowTest.php
+++ b/tests/jsonapi/FileRefsShowTest.php
@@ -45,9 +45,8 @@ class FileRefsShowTest extends \Codeception\Test\Unit
{
$credentials = $this->tester->getCredentialsForTestDozent();
- $this->tester->expectThrowable(RecordNotFoundException::class, function () use ($credentials) {
- $this->sendShowFileRef($credentials, 'missing-id');
- });
+ $response = $this->sendShowFileRef($credentials, 'missing-id');
+ $this->tester->assertSame(404, $response->getStatusCode());
}
// **** helper functions ****
diff --git a/tests/jsonapi/ForumCategoriesCreateTest.php b/tests/jsonapi/ForumCategoriesCreateTest.php
index c9a12fb..4fd96d4 100644
--- a/tests/jsonapi/ForumCategoriesCreateTest.php
+++ b/tests/jsonapi/ForumCategoriesCreateTest.php
@@ -48,25 +48,20 @@ class ForumCategoriesCreateTest extends \Codeception\Test\Unit
public function testShouldNotCreateCategory()
{
- $this->tester->expectThrowable(RecordNotFoundException::class, function () {
- $credentials = $this->tester->getCredentialsForTestAutor();
- $cat = $this->createCategory($credentials);
- $course_id = 'badCourse';
- $cat_document = $this->buildValidResourceCategory();
- $app = $this->tester->createApp($credentials, 'POST', '/courses/{id}/forum-categories', ForumCategoriesCreate::class);
+ $credentials = $this->tester->getCredentialsForTestAutor();
+ $cat = $this->createCategory($credentials);
+ $course_id = 'badCourse';
+ $cat_document = $this->buildValidResourceCategory();
+ $app = $this->tester->createApp($credentials, 'POST', '/courses/{id}/forum-categories', ForumCategoriesCreate::class);
- $requestBuilder = $this->tester->createRequestBuilder($credentials);
- $requestBuilder
- ->setUri('/courses/'.$course_id.'/forum-categories')
- ->create()
- ->setJsonApiBody($cat_document);
+ $requestBuilder = $this->tester->createRequestBuilder($credentials);
+ $requestBuilder
+ ->setUri('/courses/'.$course_id.'/forum-categories')
+ ->create()
+ ->setJsonApiBody($cat_document);
- $response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
+ $response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
- $this->tester->assertTrue($response->isSuccessfulDocument([201]));
- $document = $response->document();
- $resourceObject = $document->primaryResource();
- $this->tester->assertSame($cat->entry_name, $resourceObject->attribute('title'));
- });
+ $this->tester->assertSame(404, $response->getStatusCode());
}
}
diff --git a/tests/jsonapi/ForumCategoriesIndexTest.php b/tests/jsonapi/ForumCategoriesIndexTest.php
index 5ef4096..01ba294 100644
--- a/tests/jsonapi/ForumCategoriesIndexTest.php
+++ b/tests/jsonapi/ForumCategoriesIndexTest.php
@@ -39,29 +39,22 @@ class ForumCategoriesIndexTest extends \Codeception\Test\Unit
$response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
$this->tester->assertTrue($response->isSuccessfulDocument([200]));
- $document = $response->document();
- $resourceObject = $document->primaryResource();
}
public function testShouldNotShowCategory()
{
- $this->tester->expectThrowable(RecordNotFoundException::class, function () {
- $credentials = $this->tester->getCredentialsForTestDozent();
- $course_id = 'a07535cf2f8a72df33c12ddfa4b53dde';
- $cat = $this->createCategory($credentials);
-
- $app = $this->tester->createApp($credentials, 'get', '/course/{id}/forum-categories', ForumCategoriesIndex::class);
+ $credentials = $this->tester->getCredentialsForTestDozent();
+ $course_id = 'a07535cf2f8a72df33c12ddfa4b53dde';
+ $cat = $this->createCategory($credentials);
- $requestBuilder = $this->tester->createRequestBuilder($credentials);
- $requestBuilder
- ->setUri('/course/badID/forum-categories')
- ->fetch();
+ $app = $this->tester->createApp($credentials, 'get', '/course/{id}/forum-categories', ForumCategoriesIndex::class);
- $response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
+ $requestBuilder = $this->tester->createRequestBuilder($credentials);
+ $requestBuilder
+ ->setUri('/course/badID/forum-categories')
+ ->fetch();
- $this->tester->assertTrue($response->isSuccessfulDocument([200]));
- $document = $response->document();
- $resourceObject = $document->primaryResource();
- });
+ $response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
+ $this->tester->assertSame(404, $response->getStatusCode());
}
}
diff --git a/tests/jsonapi/ForumCategoriesShowTest.php b/tests/jsonapi/ForumCategoriesShowTest.php
index 710a7b1..4e8df26 100644
--- a/tests/jsonapi/ForumCategoriesShowTest.php
+++ b/tests/jsonapi/ForumCategoriesShowTest.php
@@ -47,24 +47,16 @@ class ForumCategoriesShowTest extends \Codeception\Test\Unit
public function testShouldNotShowCategories()
{
- $this->tester->expectThrowable(RecordNotFoundException::class, function () {
- $credentials = $this->tester->getCredentialsForTestDozent();
+ $credentials = $this->tester->getCredentialsForTestDozent();
- $app = $this->tester->createApp($credentials, 'get', '/forum-categories/{id}', ForumCategoriesShow::class);
-
- $requestBuilder = $this->tester->createRequestBuilder($credentials);
- $requestBuilder
- ->setUri('/forum-categories/'.'badId')
- ->fetch();
-
- $response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
+ $app = $this->tester->createApp($credentials, 'get', '/forum-categories/{id}', ForumCategoriesShow::class);
- $this->tester->assertTrue($response->isSuccessfulDocument([200]));
- $document = $response->document();
- $resourceObject = $document->primaryResource();
+ $requestBuilder = $this->tester->createRequestBuilder($credentials);
+ $requestBuilder
+ ->setUri('/forum-categories/'.'badId')
+ ->fetch();
- $this->tester->assertSame($cat->entry_name, $resourceObject->attribute('title'));
- $this->tester->assertSame((int) $cat->pos, $resourceObject->attribute('position'));
- });
+ $response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
+ $this->tester->assertSame(404, $response->getStatusCode());
}
}
diff --git a/tests/jsonapi/ForumCategoriesUpdateTest.php b/tests/jsonapi/ForumCategoriesUpdateTest.php
index cbcc766..f2015cb 100644
--- a/tests/jsonapi/ForumCategoriesUpdateTest.php
+++ b/tests/jsonapi/ForumCategoriesUpdateTest.php
@@ -47,24 +47,18 @@ class ForumCategoriesUpdateTest extends \Codeception\Test\Unit
public function testShouldNotUpdateCategory()
{
- $this->tester->expectThrowable(RecordNotFoundException::class, function () {
- $credentials = $this->tester->getCredentialsForTestAutor();
- $cat = $this->createCategory($credentials);
- $cat_document = $this->buildValidResourceCategoryUpdate();
- $app = $this->tester->createApp($credentials, 'PATCH', '/forum-categories/{id}', ForumCategoriesUpdate::class);
-
- $requestBuilder = $this->tester->createRequestBuilder($credentials);
- $requestBuilder
- ->setUri('/forum-categories/badId')
- ->update()
- ->setJsonApiBody($cat_document);
+ $credentials = $this->tester->getCredentialsForTestAutor();
+ $cat = $this->createCategory($credentials);
+ $cat_document = $this->buildValidResourceCategoryUpdate();
+ $app = $this->tester->createApp($credentials, 'PATCH', '/forum-categories/{id}', ForumCategoriesUpdate::class);
- $response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
+ $requestBuilder = $this->tester->createRequestBuilder($credentials);
+ $requestBuilder
+ ->setUri('/forum-categories/badId')
+ ->update()
+ ->setJsonApiBody($cat_document);
- $this->tester->assertTrue($response->isSuccessfulDocument([200]));
- $document = $response->document();
- $resourceObject = $document->primaryResource();
- $this->tester->assertNotEquals($cat->entry_name, $resourceObject->attribute('title'));
- });
+ $response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
+ $this->tester->assertSame(404, $response->getStatusCode());
}
}
diff --git a/tests/jsonapi/ForumCategoryDeleteTest.php b/tests/jsonapi/ForumCategoryDeleteTest.php
index 2805f53..8d144f2 100644
--- a/tests/jsonapi/ForumCategoryDeleteTest.php
+++ b/tests/jsonapi/ForumCategoryDeleteTest.php
@@ -44,19 +44,17 @@ class ForumCategoryDeleteTest extends \Codeception\Test\Unit
public function testShouldNotDeleteEntry()
{
- $this->tester->expectThrowable(RecordNotFoundException::class, function () {
- $credentials = $this->tester->getCredentialsForTestDozent();
- $cat = $this->createCategory($credentials);
- $entry = $this->createEntry($credentials, $cat->id);
- $app = $this->tester->createApp($credentials, 'delete', '/forum-categories/{id}', ForumCategoriesDelete::class);
-
- $requestBuilder = $this->tester->createRequestBuilder($credentials);
- $requestBuilder
- ->setUri('/forum-categories/badId')
- ->delete();
-
- $response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
- $this->tester->assertIsEmpty(ForumCat::find($cat->id));
- });
+ $credentials = $this->tester->getCredentialsForTestDozent();
+ $cat = $this->createCategory($credentials);
+ $entry = $this->createEntry($credentials, $cat->id);
+ $app = $this->tester->createApp($credentials, 'delete', '/forum-categories/{id}', ForumCategoriesDelete::class);
+
+ $requestBuilder = $this->tester->createRequestBuilder($credentials);
+ $requestBuilder
+ ->setUri('/forum-categories/badId')
+ ->delete();
+
+ $response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
+ $this->tester->assertSame(404, $response->getStatusCode());
}
}
diff --git a/tests/jsonapi/ForumEntriesCreateTest.php b/tests/jsonapi/ForumEntriesCreateTest.php
index 6f374a3..04d119e 100644
--- a/tests/jsonapi/ForumEntriesCreateTest.php
+++ b/tests/jsonapi/ForumEntriesCreateTest.php
@@ -52,27 +52,21 @@ class ForumEntriesCreateTest extends \Codeception\Test\Unit
public function testShouldNotCreateEntryForCategory()
{
- $this->tester->expectThrowable(RecordNotFoundException::class, function () {
- $credentials = $this->tester->getCredentialsForTestDozent();
- $cat = $this->createCategory($credentials);
- $content = 'some content to test';
- $title = 'entry-test-title';
- $entry_json = $this->buildValidResourceEntry($content, $title);
- $app = $this->tester->createApp($credentials, 'post', '/forum-categories/{id}/entries', ForumCategoryEntriesCreate::class);
-
- $requestBuilder = $this->tester->createRequestBuilder($credentials);
- $requestBuilder
- ->setUri('/forum-categories/'.'badId'.'/entries')
- ->create()
- ->setJsonApiBody($entry_json);
-
- $response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
- $this->tester->assertTrue($response->isSuccessfulDocument([201]));
- $document = $response->document();
- $resourceObject = $document->primaryResource();
- $this->tester->assertNotNull($resourceObject->attribute('title'));
- $this->tester->assertNotNull($resourceObject->attribute('content'));
- });
+ $credentials = $this->tester->getCredentialsForTestDozent();
+ $cat = $this->createCategory($credentials);
+ $content = 'some content to test';
+ $title = 'entry-test-title';
+ $entry_json = $this->buildValidResourceEntry($content, $title);
+ $app = $this->tester->createApp($credentials, 'post', '/forum-categories/{id}/entries', ForumCategoryEntriesCreate::class);
+
+ $requestBuilder = $this->tester->createRequestBuilder($credentials);
+ $requestBuilder
+ ->setUri('/forum-categories/'.'badId'.'/entries')
+ ->create()
+ ->setJsonApiBody($entry_json);
+
+ $response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
+ $this->tester->assertSame(404, $response->getStatusCode());
}
public function testShouldCreateEntryForEntry()
@@ -101,28 +95,21 @@ class ForumEntriesCreateTest extends \Codeception\Test\Unit
public function testShouldNotCreateEntryForEntry()
{
- $this->tester->expectThrowable(RecordNotFoundException::class, function () {
- $credentials = $this->tester->getCredentialsForTestDozent();
- $cat = $this->createCategory($credentials);
- $entry = $this->createEntry($credentials, $cat->id);
- $content = 'some new content to test';
- $title = 'entry-test-title new';
- $entry_json = $this->buildValidResourceEntry($content, $title);
- $app = $this->tester->createApp($credentials, 'post', '/forum-entries/{id}/entries', ForumEntryEntriesCreate::class);
-
- $requestBuilder = $this->tester->createRequestBuilder($credentials);
- $requestBuilder
- ->setUri('/forum-entries/'.'badID'.'/entries')
- ->create()
- ->setJsonApiBody($entry_json);
-
- $response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
-
- $this->tester->assertTrue($response->isSuccessfulDocument([201]));
- $document = $response->document();
- $resourceObject = $document->primaryResource();
- $this->tester->assertNotNull($resourceObject->attribute('title'));
- $this->tester->assertNotNull($resourceObject->attribute('content'));
- });
+ $credentials = $this->tester->getCredentialsForTestDozent();
+ $cat = $this->createCategory($credentials);
+ $entry = $this->createEntry($credentials, $cat->id);
+ $content = 'some new content to test';
+ $title = 'entry-test-title new';
+ $entry_json = $this->buildValidResourceEntry($content, $title);
+ $app = $this->tester->createApp($credentials, 'post', '/forum-entries/{id}/entries', ForumEntryEntriesCreate::class);
+
+ $requestBuilder = $this->tester->createRequestBuilder($credentials);
+ $requestBuilder
+ ->setUri('/forum-entries/'.'badID'.'/entries')
+ ->create()
+ ->setJsonApiBody($entry_json);
+
+ $response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
+ $this->tester->assertSame(404, $response->getStatusCode());
}
}
diff --git a/tests/jsonapi/ForumEntriesDeleteTest.php b/tests/jsonapi/ForumEntriesDeleteTest.php
index 5af0b89..60ae3a6 100644
--- a/tests/jsonapi/ForumEntriesDeleteTest.php
+++ b/tests/jsonapi/ForumEntriesDeleteTest.php
@@ -46,20 +46,18 @@ class ForumEntriesDeleteTest extends \Codeception\Test\Unit
public function testShouldNotDeleteEntry()
{
- $this->tester->expectThrowable(RecordNotFoundException::class, function () {
- $credentials = $this->tester->getCredentialsForTestDozent();
- $cat = $this->createCategory($credentials);
- $entry = $this->createEntry($credentials, $cat->id);
- $app = $this->tester->createApp($credentials, 'delete', '/forum-entries/{id}', ForumEntriesDelete::class);
+ $credentials = $this->tester->getCredentialsForTestDozent();
+ $cat = $this->createCategory($credentials);
+ $entry = $this->createEntry($credentials, $cat->id);
+ $app = $this->tester->createApp($credentials, 'delete', '/forum-entries/{id}', ForumEntriesDelete::class);
- $requestBuilder = $this->tester->createRequestBuilder($credentials);
- $requestBuilder
- ->setUri('/forum-entries/badId')
- ->delete()
- ->setJsonApiBody($entry_json);
+ $requestBuilder = $this->tester->createRequestBuilder($credentials);
+ $requestBuilder
+ ->setUri('/forum-entries/badId')
+ ->delete()
+ ->setJsonApiBody($entry_json);
- $response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
- $this->tester->assertIsEmpty(ForumEntry::find($entry->id));
- });
+ $response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
+ $this->tester->assertSame(404, $response->getStatusCode());
}
}
diff --git a/tests/jsonapi/ForumEntriesShowTest.php b/tests/jsonapi/ForumEntriesShowTest.php
index 45f9e6a..2443fa6 100644
--- a/tests/jsonapi/ForumEntriesShowTest.php
+++ b/tests/jsonapi/ForumEntriesShowTest.php
@@ -61,42 +61,35 @@ class ForumEntriesShowTest extends \Codeception\Test\Unit
public function testShouldNotShowEntry()
{
- $this->tester->expectThrowable(RecordNotFoundException::class, function () {
- $credentials = $this->tester->getCredentialsForRoot();
- $app = $this->tester->createApp($credentials, 'get', '/forum-entries/{id}', ForumEntriesShow::class);
-
- $requestBuilder = $this->tester->createRequestBuilder($credentials);
- $requestBuilder
- ->setUri('/forum-entries/'.'badEntry')
- ->fetch();
+ $credentials = $this->tester->getCredentialsForRoot();
+ $app = $this->tester->createApp($credentials, 'get', '/forum-entries/{id}', ForumEntriesShow::class);
- $response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
+ $requestBuilder = $this->tester->createRequestBuilder($credentials);
+ $requestBuilder
+ ->setUri('/forum-entries/'.'badEntry')
+ ->fetch();
- $this->tester->assertTrue($response->isSuccessfulDocument([200]));
- });
+ $response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
+ $this->tester->assertSame(404, $response->getStatusCode());
}
public function testShouldNotShowEntriesForCategory()
{
- $this->tester->expectThrowable(RecordNotFoundException::class, function () {
- $credentials = $this->tester->getCredentialsForRoot();
- $cat = $this->createCategory($credentials);
- $this->createEntry($credentials, $cat->id);
- $this->createEntry($credentials, $cat->id);
- $this->createEntry($credentials, $cat->id);
-
- $app = $this->tester->createApp($credentials, 'get', '/forum-categories/{id}/entries', ForumCategoryEntriesIndex::class);
-
- $requestBuilder = $this->tester->createRequestBuilder($credentials);
- $requestBuilder
- ->setUri('/forum-categories/badID/entries')
- ->fetch();
-
- $response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
- $document = $response->document();
- $resourceObject = $document->primaryResource();
- $this->tester->assertNotNull($resourceObject);
- });
+ $credentials = $this->tester->getCredentialsForRoot();
+ $cat = $this->createCategory($credentials);
+ $this->createEntry($credentials, $cat->id);
+ $this->createEntry($credentials, $cat->id);
+ $this->createEntry($credentials, $cat->id);
+
+ $app = $this->tester->createApp($credentials, 'get', '/forum-categories/{id}/entries', ForumCategoryEntriesIndex::class);
+
+ $requestBuilder = $this->tester->createRequestBuilder($credentials);
+ $requestBuilder
+ ->setUri('/forum-categories/badID/entries')
+ ->fetch();
+
+ $response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
+ $this->tester->assertSame(404, $response->getStatusCode());
}
public function testShouldShowEntriesForCategory()
@@ -116,7 +109,7 @@ class ForumEntriesShowTest extends \Codeception\Test\Unit
$response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
$document = $response->document();
- $resourceObject = $document->primaryResource();
+ $resourceObject = $document->primaryResources();
$this->tester->assertNotNull($resourceObject);
}
@@ -137,30 +130,26 @@ class ForumEntriesShowTest extends \Codeception\Test\Unit
$response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
$document = $response->document();
- $resourceObject = $document->primaryResource();
+ $resourceObject = $document->primaryResources();
$this->tester->assertNotNull($resourceObject);
}
public function testShouldNotShowEntriesForEntry()
{
- $this->tester->expectThrowable(RecordNotFoundException::class, function () {
- $credentials = $this->tester->getCredentialsForRoot();
- $cat = $this->createCategory($credentials);
- $targetEntry = $this->createEntry($credentials, $cat->id);
- $this->createEntry($credentials, $targetEntry->id);
- $this->createEntry($credentials, $targetEntry->id);
- $this->createEntry($credentials, $targetEntry->id);
- $app = $this->tester->createApp($credentials, 'get', '/forum-entries/{id}/entries', ForumEntryEntriesIndex::class);
-
- $requestBuilder = $this->tester->createRequestBuilder($credentials);
- $requestBuilder
- ->setUri('/forum-entries/badTopic/entries')
- ->fetch();
-
- $response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
- $document = $response->document();
- $resourceObject = $document->primaryResource();
- $this->tester->assertNotNull($resourceObject);
- });
+ $credentials = $this->tester->getCredentialsForRoot();
+ $cat = $this->createCategory($credentials);
+ $targetEntry = $this->createEntry($credentials, $cat->id);
+ $this->createEntry($credentials, $targetEntry->id);
+ $this->createEntry($credentials, $targetEntry->id);
+ $this->createEntry($credentials, $targetEntry->id);
+ $app = $this->tester->createApp($credentials, 'get', '/forum-entries/{id}/entries', ForumEntryEntriesIndex::class);
+
+ $requestBuilder = $this->tester->createRequestBuilder($credentials);
+ $requestBuilder
+ ->setUri('/forum-entries/badTopic/entries')
+ ->fetch();
+
+ $response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
+ $this->tester->assertSame(404, $response->getStatusCode());
}
}
diff --git a/tests/jsonapi/ForumEntriesUpdateTest.php b/tests/jsonapi/ForumEntriesUpdateTest.php
index 91f2c54..db08917 100644
--- a/tests/jsonapi/ForumEntriesUpdateTest.php
+++ b/tests/jsonapi/ForumEntriesUpdateTest.php
@@ -48,24 +48,19 @@ class ForumEntriesUpdateTest extends \Codeception\Test\Unit
public function testShouldNotUpdateEntry()
{
- $this->tester->expectThrowable(RecordNotFoundException::class, function () {
- $credentials = $this->tester->getCredentialsForTestDozent();
- $cat = $this->createCategory($credentials);
- $entry = $this->createEntry($credentials, $cat->id);
- $entry_json = $this->buildValidResourceEntryUpdate();
- $app = $this->tester->createApp($credentials, 'PATCH', '/forum-entries/{id}', ForumEntriesUpdate::class);
+ $credentials = $this->tester->getCredentialsForTestDozent();
+ $cat = $this->createCategory($credentials);
+ $entry = $this->createEntry($credentials, $cat->id);
+ $entry_json = $this->buildValidResourceEntryUpdate();
+ $app = $this->tester->createApp($credentials, 'PATCH', '/forum-entries/{id}', ForumEntriesUpdate::class);
- $requestBuilder = $this->tester->createRequestBuilder($credentials);
- $requestBuilder
- ->setUri('/forum-entries/badId')
- ->update()
- ->setJsonApiBody($entry_json);
+ $requestBuilder = $this->tester->createRequestBuilder($credentials);
+ $requestBuilder
+ ->setUri('/forum-entries/badId')
+ ->update()
+ ->setJsonApiBody($entry_json);
- $response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
- $this->tester->assertTrue($response->isSuccessfulDocument([200]));
- $document = $response->document();
- $resourceObject = $document->primaryResource();
- $this->tester->assertNotEquals($entry->name, $resourceObject->attribute('title'));
- });
+ $response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
+ $this->tester->assertSame(404, $response->getStatusCode());
}
}
diff --git a/tests/jsonapi/MessagesShowTest.php b/tests/jsonapi/MessagesShowTest.php
index 9bf5464..b9563dc 100644
--- a/tests/jsonapi/MessagesShowTest.php
+++ b/tests/jsonapi/MessagesShowTest.php
@@ -23,10 +23,9 @@ class MessagesShowTest extends \Codeception\Test\Unit
// tests
public function testMessageNotFound()
{
- $this->tester->expectThrowable(RecordNotFoundException::class, function () {
- $credentials = $this->tester->getCredentialsForTestAutor();
- $response = $this->fetchMessage($credentials, new \Message(md5('eurydamas')));
- });
+ $credentials = $this->tester->getCredentialsForTestAutor();
+ $response = $this->fetchMessage($credentials, new \Message(md5('eurydamas')));
+ $this->tester->assertSame(404, $response->getStatusCode());
}
public function testShowMessage()
diff --git a/tests/jsonapi/NewsCreateTest.php b/tests/jsonapi/NewsCreateTest.php
index 199cea5..eaf9dfd 100644
--- a/tests/jsonapi/NewsCreateTest.php
+++ b/tests/jsonapi/NewsCreateTest.php
@@ -1,16 +1,12 @@
<?php
require_once 'NewsTestHelper.php';
-use JsonApi\Models\C;
+use JsonApi\Routes\News\CommentCreate;
use JsonApi\Routes\News\CourseNewsCreate;
-use JsonApi\Routes\News\UserNewsCreate;
+use JsonApi\Routes\News\NewsUpdate;
use JsonApi\Routes\News\StudipNewsCreate;
-use JsonApi\Routes\News\CommentCreate;
-use JsonApi\Routes\News\NewsUpdate;
-use JsonApi\Errors\AuthorizationFailedException;
-use JsonApi\Errors\RecordNotFoundException;
-use JsonApi\Routes\News\CommentsDelete;
+use JsonApi\Routes\News\UserNewsCreate;
class NewsCreateTest extends \Codeception\Test\Unit
{
@@ -53,49 +49,43 @@ class NewsCreateTest extends \Codeception\Test\Unit
$this->tester->assertNotNull($resourceObject->attribute('content'));
$newsId = $news->id;
}
+
public function testShouldNotStudipNewsCreate()
{
+ $credentials = $this->tester->getCredentialsForTestDozent();
+ $title = 'A public testing title';
+ $content = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit';
+ $entry_json = $this->buildValidResourceEntry($content, $title);
+ $app = $this->tester->createApp($credentials, 'post', '/news', StudipNewsCreate::class);
+
+ $requestBuilder = $this->tester->createRequestBuilder($credentials);
+ $requestBuilder
+ ->setUri('/news')
+ ->create()
+ ->setJsonApiBody($entry_json);
- $this->tester->expectThrowable(AuthorizationFailedException::class, function () {
- $credentials = $this->tester->getCredentialsForTestDozent();
- $title = 'A public testing title';
- $content = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit';
- $entry_json = $this->buildValidResourceEntry($content, $title);
- $app = $this->tester->createApp($credentials, 'post', '/news', StudipNewsCreate::class);
-
- $requestBuilder = $this->tester->createRequestBuilder($credentials);
- $requestBuilder
- ->setUri('/news')
- ->create()
- ->setJsonApiBody($entry_json);
-
- $response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
- $this->tester->assertTrue($response->isSuccessfulDocument([201]));
- $document = $response->document();
- $resourceObject = $document->primaryResource();
- $this->tester->assertNotNull($resourceObject->attribute('title'));
- $this->tester->assertNotNull($resourceObject->attribute('content'));
- $newsId = $news->id;
-
- });
+ $response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
+ $this->tester->assertFalse($response->isSuccessfulDocument());
+ $this->tester->assertSame(403, $response->getStatusCode());
}
- public function testShouldNewsUpdate() {
+
+ public function testShouldNewsUpdate()
+ {
$title = 'A course testing title';
$credentials = $this->tester->getCredentialsForTestDozent();
$content = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit';
$news = $this->createNews($credentials, $title, $content);
-
+
$changedContent = 'Lorem ipsum dolor sit amet';
$entry_json = $this->buildValidUpdateEntry($changedContent);
$app = $this->tester->createApp($credentials, 'patch', '/news/{id}', NewsUpdate::class);
-
+
$requestBuilder = $this->tester->createRequestBuilder($credentials);
$requestBuilder
->setUri('/news/'.$news->id)
->update()
->setJsonApiBody($entry_json);
-
-
+
$response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
$this->tester->assertTrue($response->isSuccessfulDocument());
@@ -128,10 +118,9 @@ class NewsCreateTest extends \Codeception\Test\Unit
$this->tester->assertNotNull($resourceObject->attribute('content'));
$newsId = $news->id;
}
+
public function testShouldNotCourseNewsCreate()
{
- $this->tester->expectThrowable(AuthorizationFailedException::class, function () {
-
$credentials = $this->tester->getCredentialsForTestAutor();
$courseId = 'a07535cf2f8a72df33c12ddfa4b53dde';
$title = 'A course testing title';
@@ -147,15 +136,9 @@ class NewsCreateTest extends \Codeception\Test\Unit
$response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
- $this->tester->assertTrue($response->isSuccessfulDocument([201]));
- $document = $response->document();
- $resourceObject = $document->primaryResource();
- $this->tester->assertNotNull($resourceObject->attribute('title'));
- $this->tester->assertNotNull($resourceObject->attribute('content'));
- $newsId = $news->id;
-
- });
+ $this->tester->assertSame(403, $response->getStatusCode());
}
+
public function testShouldUserNewsCreate()
{
$credentials = $this->tester->getCredentialsForTestAutor();
@@ -172,7 +155,6 @@ class NewsCreateTest extends \Codeception\Test\Unit
->setJsonApiBody($entry_json);
$response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
-
$this->tester->assertTrue($response->isSuccessfulDocument([201]));
$document = $response->document();
$resourceObject = $document->primaryResource();
@@ -180,10 +162,9 @@ class NewsCreateTest extends \Codeception\Test\Unit
$this->tester->assertNotNull($resourceObject->attribute('content'));
$newsId = $news->id;
}
+
public function testShouldNotUserNewsCreate()
{
- $this->tester->expectThrowable(AuthorizationFailedException::class, function () {
-
$credentials = $this->tester->getCredentialsForTestAutor();
$otherUser = $this->tester->getCredentialsForTestDozent();
$userId = $otherUser['id'];
@@ -199,16 +180,9 @@ class NewsCreateTest extends \Codeception\Test\Unit
->setJsonApiBody($entry_json);
$response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
-
- $this->tester->assertTrue($response->isSuccessfulDocument([201]));
- $document = $response->document();
- $resourceObject = $document->primaryResource();
- $this->tester->assertNotNull($resourceObject->attribute('title'));
- $this->tester->assertNotNull($resourceObject->attribute('content'));
- $newsId = $news->id;
-
- });
+ $this->assertSame(403, $response->getStatusCode());
}
+
public function testShouldCommentCreate()
{
$title = 'A course testing title';
@@ -227,37 +201,29 @@ class NewsCreateTest extends \Codeception\Test\Unit
$response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
- $this->tester->assertTrue($response->isSuccessfulDocument([201]));
+ $this->tester->assertTrue($response->isSuccessfulDocument());
$document = $response->document();
$resourceObject = $document->primaryResource();
$this->tester->assertNotNull($resourceObject->attribute('content'));
}
+
public function testShouldNotCommentCreate()
{
- //missing title
- $this->tester->expectThrowable(RecordNotFoundException::class, function () {
- $title = 'A course testing title';
- $credentials = $this->tester->getCredentialsForTestDozent();
- $content = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit';
- $news = $this->createNews($credentials, $title, $content);
- $comment = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit';
- $entry_json = $this->buildValidCommentEntry($comment);
-
- $app = $this->tester->createApp($credentials, 'post', '/news/{id}/comments', CommentCreate::class);
- $requestBuilder = $this->tester->createRequestBuilder($credentials);
- $requestBuilder
- ->setUri('/news/badId/comments')
- ->create()
- ->setJsonApiBody($entry_json);
-
- $response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
-
- $this->tester->assertTrue($response->isSuccessfulDocument([201]));
- $document = $response->document();
- $resourceObject = $document->primaryResource();
- $this->tester->assertNotNull($resourceObject->attribute('content'));
- });
- }
-
+ $title = 'A course testing title';
+ $credentials = $this->tester->getCredentialsForTestDozent();
+ $content = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit';
+ $news = $this->createNews($credentials, $title, $content);
+ $comment = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit';
+ $entry_json = $this->buildValidCommentEntry($comment);
+ $app = $this->tester->createApp($credentials, 'post', '/news/{id}/comments', CommentCreate::class);
+ $requestBuilder = $this->tester->createRequestBuilder($credentials);
+ $requestBuilder
+ ->setUri('/news/badId/comments')
+ ->create()
+ ->setJsonApiBody($entry_json);
+
+ $response = $this->tester->sendMockRequest($app, $requestBuilder->getRequest());
+ $this->tester->assertFalse($response->isSuccessfulDocument());
+ }
}
diff --git a/tests/jsonapi/NewsShowTest.php b/tests/jsonapi/NewsShowTest.php
index 79df86d..6a90657 100644
--- a/tests/jsonapi/NewsShowTest.php
+++ b/tests/jsonapi/NewsShowTest.php
@@ -35,7 +35,7 @@ class NewsShowTest extends \Codeception\Test\Unit
$news = $this->createNews($credentials, $title, $content, $range_id);
$newsId = $news->id;
$app = $this->tester->createApp($credentials, 'get', '/studip/news', GlobalNewsShow::class);
-
+
$response = $this->tester->sendMockRequest(
$app,
$this->tester->createRequestBuilder($credentials)
@@ -47,11 +47,12 @@ class NewsShowTest extends \Codeception\Test\Unit
$this->tester->assertSame(200, $response->getStatusCode());
$this->tester->assertTrue($response->isSuccessfulDocument([200]));
$document = $response->document();
- $resourceObject = $document->primaryResource();
+ $resourceObjects = $document->primaryResources();
+ $resourceObject = current($resourceObjects);
$this->tester->assertNotNull($resourceObject->attribute('title'));
$this->tester->assertNotNull($resourceObject->attribute('content'));
$this->tester->assertNotNull($document->isSingleResourceDocument());
- $this->tester->assertSame($newsId, $document->primaryResource()->id());
+ $this->tester->assertSame($newsId, $resourceObject->id());
$this->tester->storeJsonMd('show_news', $response);
}
@@ -64,7 +65,7 @@ class NewsShowTest extends \Codeception\Test\Unit
$news = $this->createNews($credentials, $title, $content, $course_id);
$newsId = $news->id;
$app = $this->tester->createApp($credentials, 'get', '/courses/{id}/news', ByCourseIndex::class);
-
+
$response = $this->tester->sendMockRequest(
$app,
$this->tester->createRequestBuilder($credentials)
@@ -74,10 +75,11 @@ class NewsShowTest extends \Codeception\Test\Unit
);
$this->tester->assertTrue($response->isSuccessfulDocument());
$document = $response->document();
- $resourceObject = $document->primaryResource();
+ $resourceObjects = $document->primaryResources();
+ $resourceObject = current($resourceObjects);
$this->tester->assertNotNull($resourceObject->attribute('title'));
$this->tester->assertNotNull($resourceObject->attribute('content'));
-
+
}
public function testShouldShowNewsByCurrentUser()
@@ -92,8 +94,7 @@ class NewsShowTest extends \Codeception\Test\Unit
$this->tester->assertSame(200, $response->getStatusCode());
$this->tester->assertTrue($response->isSuccessfulDocument([200]));
$document = $response->document();
- $this->tester->assertNotNull($document->primaryResource());
- $this->tester->assertSame($newsId, $document->primaryResource()->id());
+ $this->tester->assertNotEmpty($document->primaryResources());
}
public function testShouldNotShowNewsByCurrentUser()
@@ -107,7 +108,7 @@ class NewsShowTest extends \Codeception\Test\Unit
$this->tester->assertSame(200, $response->getStatusCode());
$this->tester->assertTrue($response->isSuccessfulDocument([200]));
$document = $response->document();
- $this->tester->assertNull($document->primaryResource());
+ $this->tester->assertEmpty($document->primaryResources());
}
private function getNoNewsByUser($credentials)
diff --git a/tests/jsonapi/UserEventsIcalTest.php b/tests/jsonapi/UserEventsIcalTest.php
index bf3d2ba..3d0a78a 100644
--- a/tests/jsonapi/UserEventsIcalTest.php
+++ b/tests/jsonapi/UserEventsIcalTest.php
@@ -39,7 +39,7 @@ class UserEventsIcalTest extends \Codeception\Test\Unit
$requestBuilder = $this->tester->createRequestBuilder($credentials);
$requestBuilder->setUri('/users/'.$credentials['id'].'/events.ics')->fetch();
- $response = $app($requestBuilder->getRequest(), new \Slim\Http\Response());
+ $response = $app->handle($requestBuilder->getRequest());
$this->tester->assertEquals(200, $response->getStatusCode());
$this->tester->assertStringContainsString('BEGIN:VEVENT', (string) $response->getBody());
diff --git a/tests/jsonapi/UserScheduleShowTest.php b/tests/jsonapi/UserScheduleShowTest.php
index f505977..fc7529f 100644
--- a/tests/jsonapi/UserScheduleShowTest.php
+++ b/tests/jsonapi/UserScheduleShowTest.php
@@ -38,6 +38,7 @@ class UserScheduleShowTest extends \Codeception\Test\Unit
$scheduleId = \DBManager::get()->lastInsertId();
$app = $this->tester->createApp($credentials, 'get', '/users/{id}/schedule', UserScheduleShow::class, 'get-schedule');
+ $app->get('/xxx', function () {})->setName('get-semester');
$requestBuilder = $this->tester->createRequestBuilder($credentials);
$requestBuilder->setUri('/users/'.$credentials['id'].'/schedule')->fetch();
diff --git a/tests/jsonapi/_bootstrap.php b/tests/jsonapi/_bootstrap.php
index b4481af..d9c5adc 100644
--- a/tests/jsonapi/_bootstrap.php
+++ b/tests/jsonapi/_bootstrap.php
@@ -55,6 +55,7 @@ StudipAutoloader::addAutoloadPath($GLOBALS['STUDIP_BASE_PATH'].'/lib/calendar/li
StudipAutoloader::addAutoloadPath($GLOBALS['STUDIP_BASE_PATH'].'/lib/filesystem');
StudipAutoloader::addAutoloadPath($GLOBALS['STUDIP_BASE_PATH'].'/lib/migrations');
StudipAutoloader::addAutoloadPath($GLOBALS['STUDIP_BASE_PATH'].'/lib/modules');
+StudipAutoloader::addAutoloadPath($GLOBALS['STUDIP_BASE_PATH'].'/lib/navigation');
StudipAutoloader::addAutoloadPath($GLOBALS['STUDIP_BASE_PATH'].'/lib/phplib');
StudipAutoloader::addAutoloadPath($GLOBALS['STUDIP_BASE_PATH'].'/lib/raumzeit');
StudipAutoloader::addAutoloadPath($GLOBALS['STUDIP_BASE_PATH'].'/lib/resources');