From 9f6fcceee9546ffec00bc1d81df7710a0e32cdd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Tue, 6 Dec 2022 08:51:31 +0100 Subject: [PATCH 01/11] IBX-4123: [Backport] Added `/languages` and `/languages/{code}` endpoints (cherry picked from commit 674e612e176bc85556513a716556d643f81d722d) --- src/bundle/Resources/config/routing.yml | 12 ++ src/bundle/Resources/config/services.yml | 4 + .../config/value_object_visitors.yml | 5 + src/lib/Server/Controller/Language.php | 41 ++++++ .../Output/ValueObjectVisitor/Language.php | 13 +- .../ValueObjectVisitor/LanguageList.php | 35 +++++ src/lib/Server/Values/LanguageList.php | 25 ++++ .../Functional/JsonSchema/Language.json | 38 ++++++ .../Functional/JsonSchema/LanguageList.json | 56 ++++++++ tests/bundle/Functional/LanguageTest.php | 64 +++++++++ .../Functional/ResourceAssertionsTrait.php | 123 ++++++++++++++++++ .../bundle/Functional/_snapshot/Language.json | 9 ++ .../bundle/Functional/_snapshot/Language.xml | 6 + .../Functional/_snapshot/LanguageList.json | 21 +++ .../Functional/_snapshot/LanguageList.xml | 13 ++ 15 files changed, 462 insertions(+), 3 deletions(-) create mode 100644 src/lib/Server/Controller/Language.php create mode 100644 src/lib/Server/Output/ValueObjectVisitor/LanguageList.php create mode 100644 src/lib/Server/Values/LanguageList.php create mode 100644 tests/bundle/Functional/JsonSchema/Language.json create mode 100644 tests/bundle/Functional/JsonSchema/LanguageList.json create mode 100644 tests/bundle/Functional/LanguageTest.php create mode 100644 tests/bundle/Functional/ResourceAssertionsTrait.php create mode 100644 tests/bundle/Functional/_snapshot/Language.json create mode 100644 tests/bundle/Functional/_snapshot/Language.xml create mode 100644 tests/bundle/Functional/_snapshot/LanguageList.json create mode 100644 tests/bundle/Functional/_snapshot/LanguageList.xml diff --git a/src/bundle/Resources/config/routing.yml b/src/bundle/Resources/config/routing.yml index ba95b558..2663e920 100644 --- a/src/bundle/Resources/config/routing.yml +++ b/src/bundle/Resources/config/routing.yml @@ -383,6 +383,18 @@ ezpublish_rest_setObjectStatesForContent: contentId: \d+ +# Languages + +ibexa.rest.languages.list: + path: /languages + methods: [GET] + controller: Ibexa\Rest\Server\Controller\Language::listLanguages + +ibexa.rest.languages.view: + path: /languages/{languageCode} + methods: [GET] + controller: Ibexa\Rest\Server\Controller\Language::loadLanguage + # Locations diff --git a/src/bundle/Resources/config/services.yml b/src/bundle/Resources/config/services.yml index 4eede10d..fc814a1d 100644 --- a/src/bundle/Resources/config/services.yml +++ b/src/bundle/Resources/config/services.yml @@ -177,6 +177,10 @@ services: - "@ezpublish.api.service.location" tags: [controller.service_arguments] + Ibexa\Rest\Server\Controller\Language: + autowire: true + tags: [ controller.service_arguments ] + ezpublish_rest.controller.location: class: "%ezpublish_rest.controller.location.class%" parent: ezpublish_rest.controller.base diff --git a/src/bundle/Resources/config/value_object_visitors.yml b/src/bundle/Resources/config/value_object_visitors.yml index 1273d150..4c76b2e0 100644 --- a/src/bundle/Resources/config/value_object_visitors.yml +++ b/src/bundle/Resources/config/value_object_visitors.yml @@ -206,6 +206,11 @@ services: - { name: ezpublish_rest.output.value_object_visitor, type: Symfony\Component\HttpKernel\Exception\HttpException } # Language + Ibexa\Rest\Server\Output\ValueObjectVisitor\LanguageList: + parent: Ibexa\Contracts\Rest\Output\ValueObjectVisitor + tags: + - { name: ibexa.rest.output.value_object.visitor, type: Ibexa\Rest\Server\Values\LanguageList } + ezpublish_rest.output.value_object_visitor.Language: parent: ezpublish_rest.output.value_object_visitor.base class: EzSystems\EzPlatformRest\Server\Output\ValueObjectVisitor\Language diff --git a/src/lib/Server/Controller/Language.php b/src/lib/Server/Controller/Language.php new file mode 100644 index 00000000..9c005c80 --- /dev/null +++ b/src/lib/Server/Controller/Language.php @@ -0,0 +1,41 @@ +languageService = $languageService; + } + + public function listLanguages(): LanguageList + { + $languages = $this->languageService->loadLanguages(); + + if ($languages instanceof Traversable) { + $languages = iterator_to_array($languages); + } + + return new LanguageList($languages); + } + + public function loadLanguage(string $languageCode): ApiLanguage + { + return $this->languageService->loadLanguage($languageCode); + } +} diff --git a/src/lib/Server/Output/ValueObjectVisitor/Language.php b/src/lib/Server/Output/ValueObjectVisitor/Language.php index 8e05eee2..69272aae 100644 --- a/src/lib/Server/Output/ValueObjectVisitor/Language.php +++ b/src/lib/Server/Output/ValueObjectVisitor/Language.php @@ -28,8 +28,15 @@ public function visit(Visitor $visitor, Generator $generator, $data): void private function visitLanguageAttributes(Visitor $visitor, Generator $generator, LanguageValue $language): void { - $generator->valueElement('languageId', $language->id); - $generator->valueElement('languageCode', $language->languageCode); - $generator->valueElement('name', $language->name); + $generator->attribute( + 'href', + $this->router->generate( + 'ibexa.rest.languages.view', + ['languageCode' => $language->getLanguageCode()], + ), + ); + $generator->valueElement('languageId', $language->getId()); + $generator->valueElement('languageCode', $language->getLanguageCode()); + $generator->valueElement('name', $language->getName()); } } diff --git a/src/lib/Server/Output/ValueObjectVisitor/LanguageList.php b/src/lib/Server/Output/ValueObjectVisitor/LanguageList.php new file mode 100644 index 00000000..c9c82d4b --- /dev/null +++ b/src/lib/Server/Output/ValueObjectVisitor/LanguageList.php @@ -0,0 +1,35 @@ +startObjectElement('LanguageList'); + $visitor->setHeader('Content-Type', $generator->getMediaType('LanguageList')); + + $generator->attribute('href', $this->router->generate('ibexa.rest.languages.list')); + + $generator->startList('Language'); + foreach ($data->languages as $language) { + $visitor->visitValueObject($language); + } + $generator->endList('Language'); + + $generator->endObjectElement('LanguageList'); + } +} diff --git a/src/lib/Server/Values/LanguageList.php b/src/lib/Server/Values/LanguageList.php new file mode 100644 index 00000000..b8ff3ac3 --- /dev/null +++ b/src/lib/Server/Values/LanguageList.php @@ -0,0 +1,25 @@ + $languages + */ + public function __construct(array $languages) + { + $this->languages = $languages; + } +} diff --git a/tests/bundle/Functional/JsonSchema/Language.json b/tests/bundle/Functional/JsonSchema/Language.json new file mode 100644 index 00000000..427ed753 --- /dev/null +++ b/tests/bundle/Functional/JsonSchema/Language.json @@ -0,0 +1,38 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties": { + "Language": { + "type": "object", + "properties": { + "_media-type": { + "type": "string" + }, + "_href": { + "type": "string" + }, + "languageId": { + "type": "integer" + }, + "languageCode": { + "type": "string", + "minLength": 1, + "pattern": "^[[:alnum:]_]+" + }, + "name": { + "type": "string" + } + }, + "required": [ + "_media-type", + "_href", + "languageId", + "languageCode", + "name" + ] + } + }, + "required": [ + "Language" + ] +} diff --git a/tests/bundle/Functional/JsonSchema/LanguageList.json b/tests/bundle/Functional/JsonSchema/LanguageList.json new file mode 100644 index 00000000..c26ce25d --- /dev/null +++ b/tests/bundle/Functional/JsonSchema/LanguageList.json @@ -0,0 +1,56 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties": { + "LanguageList": { + "type": "object", + "properties": { + "_media-type": { + "type": "string" + }, + "_href": { + "type": "string" + }, + "Language": { + "type":"array", + "items": { + "properties": { + "_media-type": { + "type": "string" + }, + "_href": { + "type": "string" + }, + "languageId": { + "type": "integer" + }, + "languageCode": { + "type": "string", + "minLength": 1, + "pattern": "^[[:alnum:]_]+" + }, + "name": { + "type": "string" + } + }, + "required": [ + "_media-type", + "_href", + "languageId", + "languageCode", + "name" + ] + } + } + }, + "required": [ + "_media-type", + "_href", + "Language" + ] + } + }, + "required": [ + "LanguageList" + ] +} diff --git a/tests/bundle/Functional/LanguageTest.php b/tests/bundle/Functional/LanguageTest.php new file mode 100644 index 00000000..f56f1e33 --- /dev/null +++ b/tests/bundle/Functional/LanguageTest.php @@ -0,0 +1,64 @@ +createHttpRequest('GET', '/api/ibexa/v2/languages', '', 'LanguageList+json'); + $response = $this->sendHttpRequest($request); + + self::assertHttpResponseCodeEquals($response, 200); + $content = $response->getBody()->getContents(); + self::assertJson($content); + + self::assertJsonResponseIsValid($content, 'LanguageList'); + self::assertResponseMatchesJsonSnapshot($content, self::SNAPSHOT_DIR . '/LanguageList.json'); + } + + public function testLanguageListXml(): void + { + $request = $this->createHttpRequest('GET', '/api/ibexa/v2/languages'); + $response = $this->sendHttpRequest($request); + + self::assertHttpResponseCodeEquals($response, 200); + $content = $response->getBody()->getContents(); + self::assertResponseMatchesXmlSnapshot($content, self::SNAPSHOT_DIR . '/LanguageList.xml'); + } + + public function testLanguageViewJson(): void + { + $request = $this->createHttpRequest('GET', '/api/ibexa/v2/languages/eng-GB', '', 'LanguageList+json'); + $response = $this->sendHttpRequest($request); + + self::assertHttpResponseCodeEquals($response, 200); + $content = $response->getBody()->getContents(); + self::assertJson($content); + + self::assertJsonResponseIsValid($content, 'Language'); + self::assertResponseMatchesJsonSnapshot($content, self::SNAPSHOT_DIR . '/Language.json'); + } + + public function testLanguageViewXml(): void + { + $request = $this->createHttpRequest('GET', '/api/ibexa/v2/languages/eng-GB'); + $response = $this->sendHttpRequest($request); + + self::assertHttpResponseCodeEquals($response, 200); + $content = $response->getBody()->getContents(); + self::assertResponseMatchesXmlSnapshot($content, self::SNAPSHOT_DIR . '/Language.xml'); + } +} diff --git a/tests/bundle/Functional/ResourceAssertionsTrait.php b/tests/bundle/Functional/ResourceAssertionsTrait.php new file mode 100644 index 00000000..8e55183e --- /dev/null +++ b/tests/bundle/Functional/ResourceAssertionsTrait.php @@ -0,0 +1,123 @@ + 'file://' . self::getSchemaFileLocation($resource), + ]; + + $validator->validate($decodedData, $schemaReference); + + self::assertTrue($validator->isValid(), self::convertErrorsToString($validator, $data)); + } + + private static function convertErrorsToString(Validator $validator, string $data): string + { + $errorMessage = ''; + foreach ($validator->getErrors() as $error) { + $errorMessage .= sprintf( + "property: [%s], constraint: %s, error: %s\n", + $error['property'], + $error['constraint'], + $error['message'] + ); + } + + $errorMessage .= "\n\nFor data:\n\n" . $data; + + return $errorMessage; + } + + private static function getSchemaFileLocation(string $resource): string + { + return __DIR__ . '/JsonSchema/' . $resource . '.json'; + } + + private static function checkSnapshotFileExistence(string $file, string $content): void + { + if (file_exists($file)) { + return; + } + + if ($_ENV['IBEXA_REST_GENERATE_SNAPSHOTS'] ?? false) { + file_put_contents($file, rtrim($content, "\n") . "\n"); + + return; + } + + self::fail(sprintf( + 'File %s does not exist. If it\'s a new REST route, add environment variable "%s" to phpunit.xml ' + . '(or environment) set to truthy value to enable snapshot generation.', + $file, + 'IBEXA_REST_GENERATE_SNAPSHOTS', + )); + } + + private static function getDefaultSnapshotFileLocation(?string $type): string + { + $classInfo = new \ReflectionClass(static::class); + $class = substr(static::class, strrpos(static::class, '\\') + 1); + $classFilename = $classInfo->getFileName(); + self::assertNotFalse($classFilename); + + return dirname($classFilename) . '/_snapshot/' . $class . '.' . ($type ?? 'log'); + } +} diff --git a/tests/bundle/Functional/_snapshot/Language.json b/tests/bundle/Functional/_snapshot/Language.json new file mode 100644 index 00000000..e82ba70f --- /dev/null +++ b/tests/bundle/Functional/_snapshot/Language.json @@ -0,0 +1,9 @@ +{ + "Language": { + "_media-type": "application\/vnd.ibexa.api.Language+json", + "_href": "\/api\/ibexa\/v2\/languages\/eng-GB", + "languageId": 2, + "languageCode": "eng-GB", + "name": "English (United Kingdom)" + } +} diff --git a/tests/bundle/Functional/_snapshot/Language.xml b/tests/bundle/Functional/_snapshot/Language.xml new file mode 100644 index 00000000..43519f1c --- /dev/null +++ b/tests/bundle/Functional/_snapshot/Language.xml @@ -0,0 +1,6 @@ + + + 2 + eng-GB + English (United Kingdom) + diff --git a/tests/bundle/Functional/_snapshot/LanguageList.json b/tests/bundle/Functional/_snapshot/LanguageList.json new file mode 100644 index 00000000..b9eb5383 --- /dev/null +++ b/tests/bundle/Functional/_snapshot/LanguageList.json @@ -0,0 +1,21 @@ +{ + "LanguageList": { + "_media-type": "application\/vnd.ibexa.api.LanguageList+json", + "_href": "\/api\/ibexa\/v2\/languages", + "Language": [ + { + "_media-type": "application\/vnd.ibexa.api.Language+json", + "_href": "\/api\/ibexa\/v2\/languages\/eng-GB", + "languageId": 2, + "languageCode": "eng-GB", + "name": "English (United Kingdom)" + }, { + "_href": "/api/ibexa/v2/languages/pol-PL", + "_media-type": "application/vnd.ibexa.api.Language+json", + "languageCode": "pol-PL", + "languageId": 4, + "name": "Polish (polski)" + } + ] + } +} diff --git a/tests/bundle/Functional/_snapshot/LanguageList.xml b/tests/bundle/Functional/_snapshot/LanguageList.xml new file mode 100644 index 00000000..f61cfa72 --- /dev/null +++ b/tests/bundle/Functional/_snapshot/LanguageList.xml @@ -0,0 +1,13 @@ + + + + 2 + eng-GB + English (United Kingdom) + + + 4 + pol-PL + Polish (polski) + + From 0608432cbee3cd36f770cd89019184b6886cc213 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Thu, 9 Nov 2023 13:01:14 +0100 Subject: [PATCH 02/11] IBX-4123: [Backport] Added `/languages` and `/languages/{code}` endpoints (cherry picked from commit 674e612e176bc85556513a716556d643f81d722d) --- composer.json | 3 ++- phpstan-baseline.neon | 2 +- phpunit-integration-rest.xml | 1 + src/lib/Server/Controller/Language.php | 13 +++++++------ .../Output/ValueObjectVisitor/LanguageList.php | 12 ++++++------ src/lib/Server/Values/LanguageList.php | 12 ++++++------ tests/bundle/Functional/LanguageTest.php | 6 +++--- tests/bundle/Functional/ResourceAssertionsTrait.php | 6 +++--- 8 files changed, 29 insertions(+), 26 deletions(-) diff --git a/composer.json b/composer.json index 2160b8bc..042c1a7d 100644 --- a/composer.json +++ b/composer.json @@ -54,7 +54,8 @@ "phpstan/phpstan": "^1.10", "phpstan/phpstan-symfony": "^1.3", "phpstan/phpstan-phpunit": "^1.3", - "phpstan/phpstan-webmozart-assert": "^1.2" + "phpstan/phpstan-webmozart-assert": "^1.2", + "justinrainbow/json-schema": "^5.2" }, "config": { "allow-plugins": { diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 28558b27..bc6797fc 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -437,7 +437,7 @@ parameters: - message: "#^Cannot access offset mixed on EzSystems\\\\EzPlatformRest\\\\Input\\\\Parser\\.$#" - count: 2 + count: 1 path: src/lib/Input/ParsingDispatcher.php - diff --git a/phpunit-integration-rest.xml b/phpunit-integration-rest.xml index 5018514f..6429db1a 100644 --- a/phpunit-integration-rest.xml +++ b/phpunit-integration-rest.xml @@ -11,6 +11,7 @@ + diff --git a/src/lib/Server/Controller/Language.php b/src/lib/Server/Controller/Language.php index 9c005c80..773e9bc5 100644 --- a/src/lib/Server/Controller/Language.php +++ b/src/lib/Server/Controller/Language.php @@ -1,22 +1,23 @@ $languages + * @param array<\eZ\Publish\API\Repository\Values\Content\Language> $languages */ public function __construct(array $languages) { diff --git a/tests/bundle/Functional/LanguageTest.php b/tests/bundle/Functional/LanguageTest.php index f56f1e33..989181ab 100644 --- a/tests/bundle/Functional/LanguageTest.php +++ b/tests/bundle/Functional/LanguageTest.php @@ -1,14 +1,14 @@ Date: Thu, 9 Nov 2023 13:06:44 +0100 Subject: [PATCH 03/11] IBX-4123: [Backport] Added `/languages` and `/languages/{code}` endpoints (cherry picked from commit 674e612e176bc85556513a716556d643f81d722d) --- src/bundle/Resources/config/routing.yml | 7 +++---- src/bundle/Resources/config/services.yml | 2 +- src/bundle/Resources/config/value_object_visitors.yml | 6 +++--- src/lib/Server/Controller/Language.php | 2 +- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/bundle/Resources/config/routing.yml b/src/bundle/Resources/config/routing.yml index 2663e920..a196a5b3 100644 --- a/src/bundle/Resources/config/routing.yml +++ b/src/bundle/Resources/config/routing.yml @@ -384,16 +384,15 @@ ezpublish_rest_setObjectStatesForContent: # Languages - ibexa.rest.languages.list: path: /languages methods: [GET] - controller: Ibexa\Rest\Server\Controller\Language::listLanguages + controller: EzSystems\EzPlatformRest\Server\Controller\Language::listLanguages ibexa.rest.languages.view: path: /languages/{languageCode} methods: [GET] - controller: Ibexa\Rest\Server\Controller\Language::loadLanguage + controller: EzSystems\EzPlatformRest\Server\Controller\Language::loadLanguage # Locations @@ -595,7 +594,7 @@ ezpublish_rest_loadContentTypeFieldDefinition: requirements: contentTypeId: \d+ fieldDefinitionId: \d+ - + ibexa.rest.load_content_type_field_definition_by_identifier: path: /content/types/{contentTypeId}/fieldDefinition/{fieldDefinitionIdentifier} controller: ezpublish_rest.controller.content_type:loadContentTypeFieldDefinitionByIdentifier diff --git a/src/bundle/Resources/config/services.yml b/src/bundle/Resources/config/services.yml index fc814a1d..8f981399 100644 --- a/src/bundle/Resources/config/services.yml +++ b/src/bundle/Resources/config/services.yml @@ -177,7 +177,7 @@ services: - "@ezpublish.api.service.location" tags: [controller.service_arguments] - Ibexa\Rest\Server\Controller\Language: + EzSystems\EzPlatformRest\Server\Controller\Language: autowire: true tags: [ controller.service_arguments ] diff --git a/src/bundle/Resources/config/value_object_visitors.yml b/src/bundle/Resources/config/value_object_visitors.yml index 4c76b2e0..634cbe83 100644 --- a/src/bundle/Resources/config/value_object_visitors.yml +++ b/src/bundle/Resources/config/value_object_visitors.yml @@ -206,10 +206,10 @@ services: - { name: ezpublish_rest.output.value_object_visitor, type: Symfony\Component\HttpKernel\Exception\HttpException } # Language - Ibexa\Rest\Server\Output\ValueObjectVisitor\LanguageList: - parent: Ibexa\Contracts\Rest\Output\ValueObjectVisitor + EzSystems\EzPlatformRest\Server\Output\ValueObjectVisitor\LanguageList: + parent: ezpublish_rest.output.value_object_visitor.base tags: - - { name: ibexa.rest.output.value_object.visitor, type: Ibexa\Rest\Server\Values\LanguageList } + - { name: ibexa.rest.output.value_object.visitor, type: EzSystems\EzPlatformRest\Server\Values\LanguageList } ezpublish_rest.output.value_object_visitor.Language: parent: ezpublish_rest.output.value_object_visitor.base diff --git a/src/lib/Server/Controller/Language.php b/src/lib/Server/Controller/Language.php index 773e9bc5..678213de 100644 --- a/src/lib/Server/Controller/Language.php +++ b/src/lib/Server/Controller/Language.php @@ -6,7 +6,7 @@ */ declare(strict_types=1); -namespace Ibexa\Rest\Server\Controller; +namespace EzSystems\EzPlatformRest\Server\Controller; use eZ\Publish\API\Repository\LanguageService; use eZ\Publish\API\Repository\Values\Content\Language as ApiLanguage; From dc270cc704d3e0f8a3820b39ca9ef65e7713825a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Thu, 9 Nov 2023 13:19:04 +0100 Subject: [PATCH 04/11] IBX-4123: [Backport] Added `/languages` and `/languages/{code}` endpoints (cherry picked from commit 674e612e176bc85556513a716556d643f81d722d) --- src/bundle/Resources/config/value_object_visitors.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bundle/Resources/config/value_object_visitors.yml b/src/bundle/Resources/config/value_object_visitors.yml index 634cbe83..a7d7fcec 100644 --- a/src/bundle/Resources/config/value_object_visitors.yml +++ b/src/bundle/Resources/config/value_object_visitors.yml @@ -209,7 +209,7 @@ services: EzSystems\EzPlatformRest\Server\Output\ValueObjectVisitor\LanguageList: parent: ezpublish_rest.output.value_object_visitor.base tags: - - { name: ibexa.rest.output.value_object.visitor, type: EzSystems\EzPlatformRest\Server\Values\LanguageList } + - { name: ezpublish_rest.output.value_object_visitor, type: EzSystems\EzPlatformRest\Server\Values\LanguageList } ezpublish_rest.output.value_object_visitor.Language: parent: ezpublish_rest.output.value_object_visitor.base From f36a54bb43c9c103e56ecc4fdf757a7582e7d22b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Thu, 9 Nov 2023 13:30:03 +0100 Subject: [PATCH 05/11] IBX-4123: [Backport] Added `/languages` and `/languages/{code}` endpoints (cherry picked from commit 674e612e176bc85556513a716556d643f81d722d) --- tests/bundle/Functional/LanguageTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/bundle/Functional/LanguageTest.php b/tests/bundle/Functional/LanguageTest.php index 989181ab..297edd97 100644 --- a/tests/bundle/Functional/LanguageTest.php +++ b/tests/bundle/Functional/LanguageTest.php @@ -18,7 +18,7 @@ final class LanguageTest extends RESTFunctionalTestCase public function testLanguageListJson(): void { - $request = $this->createHttpRequest('GET', '/api/ibexa/v2/languages', '', 'LanguageList+json'); + $request = $this->createHttpRequest('GET', '/api/ezp/v2/languages', '', 'LanguageList+json'); $response = $this->sendHttpRequest($request); self::assertHttpResponseCodeEquals($response, 200); @@ -31,7 +31,7 @@ public function testLanguageListJson(): void public function testLanguageListXml(): void { - $request = $this->createHttpRequest('GET', '/api/ibexa/v2/languages'); + $request = $this->createHttpRequest('GET', '/api/ezp/v2/languages'); $response = $this->sendHttpRequest($request); self::assertHttpResponseCodeEquals($response, 200); @@ -41,7 +41,7 @@ public function testLanguageListXml(): void public function testLanguageViewJson(): void { - $request = $this->createHttpRequest('GET', '/api/ibexa/v2/languages/eng-GB', '', 'LanguageList+json'); + $request = $this->createHttpRequest('GET', '/api/ezp/v2/languages/eng-GB', '', 'LanguageList+json'); $response = $this->sendHttpRequest($request); self::assertHttpResponseCodeEquals($response, 200); @@ -54,7 +54,7 @@ public function testLanguageViewJson(): void public function testLanguageViewXml(): void { - $request = $this->createHttpRequest('GET', '/api/ibexa/v2/languages/eng-GB'); + $request = $this->createHttpRequest('GET', '/api/ezp/v2/languages/eng-GB'); $response = $this->sendHttpRequest($request); self::assertHttpResponseCodeEquals($response, 200); From 6c69db6e10335820471483428eb444f7e5d2c20b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Thu, 9 Nov 2023 13:55:47 +0100 Subject: [PATCH 06/11] IBX-4123: [Backport] Added `/languages` and `/languages/{code}` endpoints (cherry picked from commit 674e612e176bc85556513a716556d643f81d722d) --- tests/bundle/Functional/_snapshot/Language.json | 2 +- tests/bundle/Functional/_snapshot/Language.xml | 2 +- tests/bundle/Functional/_snapshot/LanguageList.json | 8 ++++---- tests/bundle/Functional/_snapshot/LanguageList.xml | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/bundle/Functional/_snapshot/Language.json b/tests/bundle/Functional/_snapshot/Language.json index e82ba70f..a0865d90 100644 --- a/tests/bundle/Functional/_snapshot/Language.json +++ b/tests/bundle/Functional/_snapshot/Language.json @@ -1,6 +1,6 @@ { "Language": { - "_media-type": "application\/vnd.ibexa.api.Language+json", + "_media-type": "application\/vnd.ez.api.Language+json", "_href": "\/api\/ibexa\/v2\/languages\/eng-GB", "languageId": 2, "languageCode": "eng-GB", diff --git a/tests/bundle/Functional/_snapshot/Language.xml b/tests/bundle/Functional/_snapshot/Language.xml index 43519f1c..9a37d6f4 100644 --- a/tests/bundle/Functional/_snapshot/Language.xml +++ b/tests/bundle/Functional/_snapshot/Language.xml @@ -1,5 +1,5 @@ - + 2 eng-GB English (United Kingdom) diff --git a/tests/bundle/Functional/_snapshot/LanguageList.json b/tests/bundle/Functional/_snapshot/LanguageList.json index b9eb5383..39acb186 100644 --- a/tests/bundle/Functional/_snapshot/LanguageList.json +++ b/tests/bundle/Functional/_snapshot/LanguageList.json @@ -1,17 +1,17 @@ { "LanguageList": { - "_media-type": "application\/vnd.ibexa.api.LanguageList+json", + "_media-type": "application\/vnd.ez.api.LanguageList+json", "_href": "\/api\/ibexa\/v2\/languages", "Language": [ { - "_media-type": "application\/vnd.ibexa.api.Language+json", + "_media-type": "application\/vnd.ez.api.Language+json", "_href": "\/api\/ibexa\/v2\/languages\/eng-GB", "languageId": 2, "languageCode": "eng-GB", "name": "English (United Kingdom)" }, { - "_href": "/api/ibexa/v2/languages/pol-PL", - "_media-type": "application/vnd.ibexa.api.Language+json", + "_href": "/api/ezp/v2/languages/pol-PL", + "_media-type": "application/vnd.ez.api.Language+json", "languageCode": "pol-PL", "languageId": 4, "name": "Polish (polski)" diff --git a/tests/bundle/Functional/_snapshot/LanguageList.xml b/tests/bundle/Functional/_snapshot/LanguageList.xml index f61cfa72..2db81a85 100644 --- a/tests/bundle/Functional/_snapshot/LanguageList.xml +++ b/tests/bundle/Functional/_snapshot/LanguageList.xml @@ -1,11 +1,11 @@ - - + + 2 eng-GB English (United Kingdom) - + 4 pol-PL Polish (polski) From 0acd10f48a35cba0ad872d67cdfc680fc1f2227d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Thu, 9 Nov 2023 13:56:33 +0100 Subject: [PATCH 07/11] IBX-4123: [Backport] Added `/languages` and `/languages/{code}` endpoints (cherry picked from commit 674e612e176bc85556513a716556d643f81d722d) --- tests/bundle/Functional/_snapshot/Language.json | 2 +- tests/bundle/Functional/_snapshot/LanguageList.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/bundle/Functional/_snapshot/Language.json b/tests/bundle/Functional/_snapshot/Language.json index a0865d90..f642f46d 100644 --- a/tests/bundle/Functional/_snapshot/Language.json +++ b/tests/bundle/Functional/_snapshot/Language.json @@ -1,7 +1,7 @@ { "Language": { "_media-type": "application\/vnd.ez.api.Language+json", - "_href": "\/api\/ibexa\/v2\/languages\/eng-GB", + "_href": "\/api\/ezp\/v2\/languages\/eng-GB", "languageId": 2, "languageCode": "eng-GB", "name": "English (United Kingdom)" diff --git a/tests/bundle/Functional/_snapshot/LanguageList.json b/tests/bundle/Functional/_snapshot/LanguageList.json index 39acb186..8e92f2e2 100644 --- a/tests/bundle/Functional/_snapshot/LanguageList.json +++ b/tests/bundle/Functional/_snapshot/LanguageList.json @@ -1,11 +1,11 @@ { "LanguageList": { "_media-type": "application\/vnd.ez.api.LanguageList+json", - "_href": "\/api\/ibexa\/v2\/languages", + "_href": "\/api\/ezp\/v2\/languages", "Language": [ { "_media-type": "application\/vnd.ez.api.Language+json", - "_href": "\/api\/ibexa\/v2\/languages\/eng-GB", + "_href": "\/api\/ezp\/v2\/languages\/eng-GB", "languageId": 2, "languageCode": "eng-GB", "name": "English (United Kingdom)" From 79983afec68442961d14fea178b843f5f12cfc56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Thu, 9 Nov 2023 14:08:52 +0100 Subject: [PATCH 08/11] IBX-4123: [Backport] Added `/languages` and `/languages/{code}` endpoints (cherry picked from commit 674e612e176bc85556513a716556d643f81d722d) --- tests/bundle/Functional/_snapshot/LanguageList.json | 6 ------ tests/bundle/Functional/_snapshot/LanguageList.xml | 5 ----- 2 files changed, 11 deletions(-) diff --git a/tests/bundle/Functional/_snapshot/LanguageList.json b/tests/bundle/Functional/_snapshot/LanguageList.json index 8e92f2e2..926bb2af 100644 --- a/tests/bundle/Functional/_snapshot/LanguageList.json +++ b/tests/bundle/Functional/_snapshot/LanguageList.json @@ -9,12 +9,6 @@ "languageId": 2, "languageCode": "eng-GB", "name": "English (United Kingdom)" - }, { - "_href": "/api/ezp/v2/languages/pol-PL", - "_media-type": "application/vnd.ez.api.Language+json", - "languageCode": "pol-PL", - "languageId": 4, - "name": "Polish (polski)" } ] } diff --git a/tests/bundle/Functional/_snapshot/LanguageList.xml b/tests/bundle/Functional/_snapshot/LanguageList.xml index 2db81a85..d913689d 100644 --- a/tests/bundle/Functional/_snapshot/LanguageList.xml +++ b/tests/bundle/Functional/_snapshot/LanguageList.xml @@ -5,9 +5,4 @@ eng-GB English (United Kingdom) - - 4 - pol-PL - Polish (polski) - From a48f66fa55ca5d95fa09336e295c9e7356fb36e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Wed, 22 Nov 2023 15:21:14 +0100 Subject: [PATCH 09/11] Switched to new Ibexa namespace for new classes --- src/bundle/Resources/config/services.yml | 2 +- src/bundle/Resources/config/value_object_visitors.yml | 4 ++-- src/lib/Server/Controller/Language.php | 4 ++-- src/lib/Server/Output/ValueObjectVisitor/LanguageList.php | 4 ++-- src/lib/Server/Values/LanguageList.php | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/bundle/Resources/config/services.yml b/src/bundle/Resources/config/services.yml index 8f981399..c2d5d8fd 100644 --- a/src/bundle/Resources/config/services.yml +++ b/src/bundle/Resources/config/services.yml @@ -177,7 +177,7 @@ services: - "@ezpublish.api.service.location" tags: [controller.service_arguments] - EzSystems\EzPlatformRest\Server\Controller\Language: + Ibexa\Bundle\Rest\Server\Controller\Language: autowire: true tags: [ controller.service_arguments ] diff --git a/src/bundle/Resources/config/value_object_visitors.yml b/src/bundle/Resources/config/value_object_visitors.yml index a7d7fcec..c5b3e683 100644 --- a/src/bundle/Resources/config/value_object_visitors.yml +++ b/src/bundle/Resources/config/value_object_visitors.yml @@ -206,10 +206,10 @@ services: - { name: ezpublish_rest.output.value_object_visitor, type: Symfony\Component\HttpKernel\Exception\HttpException } # Language - EzSystems\EzPlatformRest\Server\Output\ValueObjectVisitor\LanguageList: + Ibexa\Rest\Server\Output\ValueObjectVisitor\LanguageList: parent: ezpublish_rest.output.value_object_visitor.base tags: - - { name: ezpublish_rest.output.value_object_visitor, type: EzSystems\EzPlatformRest\Server\Values\LanguageList } + - { name: ezpublish_rest.output.value_object_visitor, type: Ibexa\Rest\Server\Values\LanguageList } ezpublish_rest.output.value_object_visitor.Language: parent: ezpublish_rest.output.value_object_visitor.base diff --git a/src/lib/Server/Controller/Language.php b/src/lib/Server/Controller/Language.php index 678213de..cf170da8 100644 --- a/src/lib/Server/Controller/Language.php +++ b/src/lib/Server/Controller/Language.php @@ -6,12 +6,12 @@ */ declare(strict_types=1); -namespace EzSystems\EzPlatformRest\Server\Controller; +namespace Ibexa\Bundle\Rest\Server\Controller; use eZ\Publish\API\Repository\LanguageService; use eZ\Publish\API\Repository\Values\Content\Language as ApiLanguage; use EzSystems\EzPlatformRest\Server\Controller as RestController; -use EzSystems\EzPlatformRest\Server\Values\LanguageList; +use Ibexa\Rest\Server\Values\LanguageList; use Traversable; final class Language extends RestController diff --git a/src/lib/Server/Output/ValueObjectVisitor/LanguageList.php b/src/lib/Server/Output/ValueObjectVisitor/LanguageList.php index 6c853f06..893153e2 100644 --- a/src/lib/Server/Output/ValueObjectVisitor/LanguageList.php +++ b/src/lib/Server/Output/ValueObjectVisitor/LanguageList.php @@ -6,7 +6,7 @@ */ declare(strict_types=1); -namespace EzSystems\EzPlatformRest\Server\Output\ValueObjectVisitor; +namespace Ibexa\Rest\Server\Output\ValueObjectVisitor; use EzSystems\EzPlatformRest\Output\Generator; use EzSystems\EzPlatformRest\Output\ValueObjectVisitor; @@ -15,7 +15,7 @@ final class LanguageList extends ValueObjectVisitor { /** - * @param \EzSystems\EzPlatformRest\Server\Values\LanguageList $data + * @param \Ibexa\Rest\Server\Values\LanguageList $data */ public function visit(Visitor $visitor, Generator $generator, $data): void { diff --git a/src/lib/Server/Values/LanguageList.php b/src/lib/Server/Values/LanguageList.php index 1d990fad..8b794d91 100644 --- a/src/lib/Server/Values/LanguageList.php +++ b/src/lib/Server/Values/LanguageList.php @@ -6,7 +6,7 @@ */ declare(strict_types=1); -namespace EzSystems\EzPlatformRest\Server\Values; +namespace Ibexa\Rest\Server\Values; use EzSystems\EzPlatformRest\Value as RestValue; From caa2eb747d0d61b9f07a97b35b37ac47a8e1cc76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Wed, 22 Nov 2023 15:23:08 +0100 Subject: [PATCH 10/11] Switched to new Ibexa namespace for new classes --- src/bundle/Resources/config/routing.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bundle/Resources/config/routing.yml b/src/bundle/Resources/config/routing.yml index a196a5b3..a0b255ac 100644 --- a/src/bundle/Resources/config/routing.yml +++ b/src/bundle/Resources/config/routing.yml @@ -387,12 +387,12 @@ ezpublish_rest_setObjectStatesForContent: ibexa.rest.languages.list: path: /languages methods: [GET] - controller: EzSystems\EzPlatformRest\Server\Controller\Language::listLanguages + controller: Ibexa\Bundle\Rest\Server\Controller\Language::listLanguages ibexa.rest.languages.view: path: /languages/{languageCode} methods: [GET] - controller: EzSystems\EzPlatformRest\Server\Controller\Language::loadLanguage + controller: Ibexa\Bundle\Rest\Server\Controller\Language::loadLanguage # Locations From ee4fe519de2816924be588c380737ed0408a5889 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Wed, 22 Nov 2023 15:32:51 +0100 Subject: [PATCH 11/11] Switched to new Ibexa namespace for new classes --- src/bundle/Resources/config/routing.yml | 4 ++-- src/bundle/Resources/config/services.yml | 2 +- src/lib/Server/Controller/Language.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/bundle/Resources/config/routing.yml b/src/bundle/Resources/config/routing.yml index a0b255ac..a83d3bcf 100644 --- a/src/bundle/Resources/config/routing.yml +++ b/src/bundle/Resources/config/routing.yml @@ -387,12 +387,12 @@ ezpublish_rest_setObjectStatesForContent: ibexa.rest.languages.list: path: /languages methods: [GET] - controller: Ibexa\Bundle\Rest\Server\Controller\Language::listLanguages + controller: Ibexa\Rest\Server\Controller\Language::listLanguages ibexa.rest.languages.view: path: /languages/{languageCode} methods: [GET] - controller: Ibexa\Bundle\Rest\Server\Controller\Language::loadLanguage + controller: Ibexa\Rest\Server\Controller\Language::loadLanguage # Locations diff --git a/src/bundle/Resources/config/services.yml b/src/bundle/Resources/config/services.yml index c2d5d8fd..fc814a1d 100644 --- a/src/bundle/Resources/config/services.yml +++ b/src/bundle/Resources/config/services.yml @@ -177,7 +177,7 @@ services: - "@ezpublish.api.service.location" tags: [controller.service_arguments] - Ibexa\Bundle\Rest\Server\Controller\Language: + Ibexa\Rest\Server\Controller\Language: autowire: true tags: [ controller.service_arguments ] diff --git a/src/lib/Server/Controller/Language.php b/src/lib/Server/Controller/Language.php index cf170da8..e7786bc4 100644 --- a/src/lib/Server/Controller/Language.php +++ b/src/lib/Server/Controller/Language.php @@ -6,7 +6,7 @@ */ declare(strict_types=1); -namespace Ibexa\Bundle\Rest\Server\Controller; +namespace Ibexa\Rest\Server\Controller; use eZ\Publish\API\Repository\LanguageService; use eZ\Publish\API\Repository\Values\Content\Language as ApiLanguage;