-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IBX-4123: [Backport] Added
/languages
and /languages/{code}
endpo…
…ints
- Loading branch information
Showing
18 changed files
with
456 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\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 Ibexa\Rest\Server\Values\LanguageList; | ||
use Traversable; | ||
|
||
final class Language extends RestController | ||
{ | ||
/** @var \eZ\Publish\API\Repository\LanguageService */ | ||
private $languageService; | ||
|
||
public function __construct(LanguageService $languageService) | ||
{ | ||
$this->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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\Rest\Server\Output\ValueObjectVisitor; | ||
|
||
use EzSystems\EzPlatformRest\Output\Generator; | ||
use EzSystems\EzPlatformRest\Output\ValueObjectVisitor; | ||
use EzSystems\EzPlatformRest\Output\Visitor; | ||
|
||
final class LanguageList extends ValueObjectVisitor | ||
{ | ||
/** | ||
* @param \Ibexa\Rest\Server\Values\LanguageList $data | ||
*/ | ||
public function visit(Visitor $visitor, Generator $generator, $data): void | ||
{ | ||
$generator->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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\Rest\Server\Values; | ||
|
||
use EzSystems\EzPlatformRest\Value as RestValue; | ||
|
||
final class LanguageList extends RestValue | ||
{ | ||
/** @var \eZ\Publish\API\Repository\Values\Content\Language[] */ | ||
public $languages; | ||
|
||
/** | ||
* @param array<\eZ\Publish\API\Repository\Values\Content\Language> $languages | ||
*/ | ||
public function __construct(array $languages) | ||
{ | ||
$this->languages = $languages; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace EzSystems\EzPlatformRestBundle\Tests\Functional; | ||
|
||
use EzSystems\EzPlatformRestBundle\Tests\Functional\TestCase as RESTFunctionalTestCase; | ||
|
||
final class LanguageTest extends RESTFunctionalTestCase | ||
{ | ||
use ResourceAssertionsTrait; | ||
|
||
private const SNAPSHOT_DIR = __DIR__ . '/_snapshot'; | ||
|
||
public function testLanguageListJson(): void | ||
{ | ||
$request = $this->createHttpRequest('GET', '/api/ezp/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/ezp/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/ezp/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/ezp/v2/languages/eng-GB'); | ||
$response = $this->sendHttpRequest($request); | ||
|
||
self::assertHttpResponseCodeEquals($response, 200); | ||
$content = $response->getBody()->getContents(); | ||
self::assertResponseMatchesXmlSnapshot($content, self::SNAPSHOT_DIR . '/Language.xml'); | ||
} | ||
} |
Oops, something went wrong.