Skip to content

Commit

Permalink
Refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
Steveb-p committed Feb 21, 2023
1 parent 3388ef2 commit 44b47e8
Showing 1 changed file with 30 additions and 18 deletions.
48 changes: 30 additions & 18 deletions tests/bundle/Functional/ViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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,
];
}

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 44b47e8

Please sign in to comment.