From 44b47e81f5fec688d6ee8adad97de45f49575564 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Tue, 21 Feb 2023 13:32:10 +0100 Subject: [PATCH] Refactored --- tests/bundle/Functional/ViewTest.php | 48 +++++++++++++++++----------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/tests/bundle/Functional/ViewTest.php b/tests/bundle/Functional/ViewTest.php index 6326079f..2d73b448 100644 --- a/tests/bundle/Functional/ViewTest.php +++ b/tests/bundle/Functional/ViewTest.php @@ -10,6 +10,18 @@ class ViewTest extends TestCase { use ResourceAssertionsTrait; + private const VIEW_ENDPOINT_ACCEPT_TYPE = 'View+json'; + private const VIEW_ENDPOINT_URL = '/api/ibexa/v2/views'; + + private const FORMAT_XML = 'xml'; + private const FORMAT_JSON = 'json'; + + private const OPERATOR_EQUALITY = 'eq'; + private const OPERATOR_IN = 'in'; + + private const CRITERION_LOCATION_DEPTH = 'LocationDepth'; + private const CRITERION_IS_MAIN_LOCATION = 'IsMainLocation'; + /** * Covers POST /views. */ @@ -38,9 +50,9 @@ public function testViewRequestWithOrStatement(): void XML; $request = $this->createHttpRequest( 'POST', - '/api/ibexa/v2/views', + self::VIEW_ENDPOINT_URL, 'ViewInput+xml', - 'View+json', + self::VIEW_ENDPOINT_ACCEPT_TYPE, $body ); $response = $this->sendHttpRequest($request); @@ -58,9 +70,9 @@ public function testCriterions(string $body, string $type): void { $request = $this->createHttpRequest( 'POST', - '/api/ibexa/v2/views', + self::VIEW_ENDPOINT_URL, "ViewInput+$type", - 'View+json', + self::VIEW_ENDPOINT_ACCEPT_TYPE, $body ); $response = $this->sendHttpRequest($request); @@ -82,34 +94,34 @@ public function provideForViewTest(): iterable strtoupper($format), ); - yield $template('LocationDepth', 'eq', 'xml') => [ + yield $template(self::CRITERION_LOCATION_DEPTH, self::OPERATOR_EQUALITY, self::FORMAT_XML) => [ file_get_contents(__DIR__ . '/_input/search/LocationDepth.eq.xml'), - 'xml', + self::FORMAT_XML, ]; - yield $template('LocationDepth', 'eq', 'json') => [ + yield $template(self::CRITERION_LOCATION_DEPTH, self::OPERATOR_EQUALITY, self::FORMAT_JSON) => [ file_get_contents(__DIR__ . '/_input/search/LocationDepth.eq.json'), - 'json', + self::FORMAT_JSON, ]; - yield $template('LocationDepth', 'in', 'xml') => [ + yield $template(self::CRITERION_LOCATION_DEPTH, self::OPERATOR_IN, self::FORMAT_XML) => [ file_get_contents(__DIR__ . '/_input/search/LocationDepth.in.xml'), - 'xml', + self::FORMAT_XML, ]; - yield $template('LocationDepth', 'in', 'json') => [ + yield $template(self::CRITERION_LOCATION_DEPTH, self::OPERATOR_IN, self::FORMAT_JSON) => [ file_get_contents(__DIR__ . '/_input/search/LocationDepth.in.json'), - 'json', + self::FORMAT_JSON, ]; - yield $template('IsMainLocation', 'eq', 'xml') => [ + yield $template(self::CRITERION_IS_MAIN_LOCATION, self::OPERATOR_EQUALITY, self::FORMAT_XML) => [ file_get_contents(__DIR__ . '/_input/search/IsMainLocation.xml'), - 'xml', + self::FORMAT_XML, ]; - yield $template('IsMainLocation', 'eq', 'json') => [ + yield $template(self::CRITERION_IS_MAIN_LOCATION, self::OPERATOR_EQUALITY, self::FORMAT_JSON) => [ file_get_contents(__DIR__ . '/_input/search/IsMainLocation.json'), - 'json', + self::FORMAT_JSON, ]; } @@ -144,9 +156,9 @@ public function testViewRequestWithAndStatement(): void XML; $request = $this->createHttpRequest( 'POST', - '/api/ibexa/v2/views', + self::VIEW_ENDPOINT_URL, 'ViewInput+xml', - 'View+json', + self::VIEW_ENDPOINT_ACCEPT_TYPE, $body ); $response = $this->sendHttpRequest($request);