diff options
| author | Jan-Hendrik Willms <tleilax+studip@gmail.com> | 2024-05-21 11:41:55 +0000 |
|---|---|---|
| committer | David Siegfried <david.siegfried@uni-vechta.de> | 2024-05-21 11:41:55 +0000 |
| commit | c21817bfe8bd8695f612e47c2a1d8de03148fb88 (patch) | |
| tree | 791a588cd0c276f117e1bf8f70a4b56d9c83013f /tests/jsonapi/ConsultationHelper.php | |
| parent | 98ee46ee0cb82934ff111a72d5cb7a93b68219d8 (diff) | |
implement jsonapi for clipboard and clipboard items and replace old clipboards route with new ones, fixes #4198
Closes #4198
Merge request studip/studip!3029
Diffstat (limited to 'tests/jsonapi/ConsultationHelper.php')
| -rw-r--r-- | tests/jsonapi/ConsultationHelper.php | 108 |
1 files changed, 2 insertions, 106 deletions
diff --git a/tests/jsonapi/ConsultationHelper.php b/tests/jsonapi/ConsultationHelper.php index 673174e..f84820b 100644 --- a/tests/jsonapi/ConsultationHelper.php +++ b/tests/jsonapi/ConsultationHelper.php @@ -1,19 +1,9 @@ <?php -use WoohooLabs\Yang\JsonApi\Response\JsonApiResponse; -use WoohooLabs\Yang\JsonApi\Schema\Document; -use WoohooLabs\Yang\JsonApi\Schema\Resource\ResourceObject; +require_once __DIR__ . '/JSONAPIHelperTrait.php'; trait ConsultationHelper { - /** - * @var \UnitTester - */ - protected $tester; - - protected function _before() - { - \DBManager::getInstance()->setConnection('studip', $this->getModule('\\Helper\\StudipDb')->dbh); - } + use JSONAPIHelperTrait; protected static $BLOCK_DATA = [ 'room' => 'Testraum', @@ -88,23 +78,6 @@ trait ConsultationHelper return $block->slots->first(); } - protected function withStudipEnv(array $credentials, callable $fn) - { - // Create global template factory if neccessary - $has_template_factory = isset($GLOBALS['template_factory']); - if (!$has_template_factory) { - $GLOBALS['template_factory'] = new Flexi\Factory($GLOBALS['STUDIP_BASE_PATH'] . '/templates'); - } - - $result = $this->tester->withPHPLib($credentials, $fn); - - if (!$has_template_factory) { - unset($GLOBALS['template_factory']); - } - - return $result; - } - protected function createBookingForSlot(array $credentials, ConsultationSlot $slot, User $user): ConsultationBooking { return $this->withStudipEnv( @@ -122,81 +95,4 @@ trait ConsultationHelper } ); } - - protected function sendMockRequest(string $route, string $handler, array $credentials, array $variables = [], array $options = []): JsonApiResponse - { - $options = array_merge([ - 'method' => 'GET', - 'considered_successful' => [200], - 'json_body' => null, - ], $options); - - $app = $this->tester->createApp( - $credentials, - strtolower($options['method']), - $route, - $handler - ); - - $evaluated_route = preg_replace_callback( - '/\{(.+?)(:[^}]+)?}/', - function ($match) use ($variables) { - $key = $match[1]; - if (!isset($variables[$key])) { - throw new Exception("No variable '{$key}' defined"); - } - return $variables[$key]; - }, - $route - ); - - $requestBuilder = $this->tester->createRequestBuilder($credentials); - $requestBuilder->setUri($evaluated_route)->setMethod(strtoupper($options['method'])); - - if (isset($options['json_body'])) { - $requestBuilder->setJsonApiBody($options['json_body']); - - } - - /** @var JsonApiResponse $response */ - $response = $this->withStudipEnv($credentials, function () use ($app, $requestBuilder) { - return $this->tester->sendMockRequest($app, $requestBuilder->getRequest()); - }); - - if ($options['considered_successful']) { - $this->assertTrue( - $response->isSuccessful($options['considered_successful']), - 'Actual status code is ' . $response->getStatusCode() - ); - } - - return $response; - } - - protected function getSingleResourceDocument(JsonApiResponse $response): Document - { - $this->assertTrue($response->hasDocument()); - - $document = $response->document(); - $this->assertTrue($document->isSingleResourceDocument()); - - return $document; - } - - protected function getResourceCollectionDocument(JsonApiResponse $response): Document - { - $this->assertTrue($response->hasDocument()); - - $document = $response->document(); - $this->assertTrue($document->isResourceCollectionDocument()); - - return $document; - } - - protected function assertHasRelations(ResourceObject $resource, ...$relations) - { - foreach ($relations as $relation) { - $this->assertTrue($resource->hasRelationship($relation)); - } - } } |
