Skip to content
Permalink
Browse files

EZP-30006: As a Developer I possibility to load several languages at …

…once (#2524)

Introduces API to load several languages at once (specifically by id or locale), exposes more specific methods on languageMask handler and in SPI to make language handling more efficient.
  • Loading branch information...
andrerom committed Feb 19, 2019
1 parent 7a8b5f7 commit c53d48d70dfbad2e547a0c33af097d7fb93a24bf
Showing with 65 additions and 12 deletions.
  1. +22 −0 Repository/LanguageService.php
  2. +43 −12 Repository/Tests/LanguageServiceTest.php
@@ -91,6 +91,28 @@ public function loadLanguages();
*/
public function loadLanguageById($languageId);
/**
* Bulk-load Languages by language codes.
*
* Note: it does not throw exceptions on load, just ignores erroneous Languages.
*
* @param string[] $languageCodes
*
* @return \eZ\Publish\API\Repository\Values\Content\Language[] list of Languages with language-code as keys
*/
public function loadLanguageListByCode(array $languageCodes): iterable;
/**
* Bulk-load Languages by ids.
*
* Note: it does not throw exceptions on load, just ignores erroneous Languages.
*
* @param int[] $languageIds
*
* @return \eZ\Publish\API\Repository\Values\Content\Language[] list of Languages with id as keys
*/
public function loadLanguageListById(array $languageIds): iterable;
/**
* Deletes a language from content repository.
*
@@ -152,13 +152,13 @@ public function testCreateLanguageThrowsInvalidArgumentException()
* Test for the loadLanguageById() method.
*
* @covers \eZ\Publish\API\Repository\LanguageService::loadLanguageById
* @depends eZ\Publish\API\Repository\Tests\LanguageServiceTest::testCreateLanguage
* @covers \eZ\Publish\API\Repository\LanguageService::loadLanguageListById
* @depends testCreateLanguage
*/
public function testLoadLanguageById()
{
$repository = $this->getRepository();
/* BEGIN: Use Case */
$languageService = $repository->getContentLanguageService();
$languageCreate = $languageService->newLanguageCreateStruct();
@@ -169,20 +169,25 @@ public function testLoadLanguageById()
$languageId = $languageService->createLanguage($languageCreate)->id;
$language = $languageService->loadLanguageById($languageId);
/* END: Use Case */
$this->assertInstanceOf(
Language::class,
$language
);
$languages = $languageService->loadLanguageListById([$languageId]);
$this->assertInternalType('iterable', $languages);
$this->assertCount(1, $languages);
$this->assertInstanceOf(Language::class, $languages[$languageId]);
}
/**
* Test for the loadLanguageById() method.
*
* @covers \eZ\Publish\API\Repository\LanguageService::loadLanguageById
* @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException
* @depends eZ\Publish\API\Repository\Tests\LanguageServiceTest::testLoadLanguageById
* @covers \eZ\Publish\API\Repository\LanguageService::loadLanguageListById
* @depends testLoadLanguageById
*/
public function testLoadLanguageByIdThrowsNotFoundException()
{
@@ -192,7 +197,13 @@ public function testLoadLanguageByIdThrowsNotFoundException()
/* BEGIN: Use Case */
$languageService = $repository->getContentLanguageService();
// This call should fail with a "NotFoundException"
$languages = $languageService->loadLanguageListById([$nonExistentLanguageId]);
$this->assertInternalType('iterable', $languages);
$this->assertCount(0, $languages);
$this->expectException(NotFoundException::class);
$languageService->loadLanguageById($nonExistentLanguageId);
/* END: Use Case */
}
@@ -322,7 +333,8 @@ public function testDisableLanguage()
* Test for the loadLanguage() method.
*
* @covers \eZ\Publish\API\Repository\LanguageService::loadLanguage
* @depends eZ\Publish\API\Repository\Tests\LanguageServiceTest::testCreateLanguage
* @covers \eZ\Publish\API\Repository\LanguageService::loadLanguageListByCode
* @depends testCreateLanguage
*/
public function testLoadLanguage()
{
@@ -351,25 +363,44 @@ public function testLoadLanguage()
],
$language
);
$languages = $languageService->loadLanguageListByCode(['eng-NZ']);
$this->assertInternalType('iterable', $languages);
$this->assertCount(1, $languages);
$this->assertPropertiesCorrect(
[
'id' => $languageId,
'languageCode' => 'eng-NZ',
'name' => 'English',
'enabled' => true,
],
$languages['eng-NZ']
);
}
/**
* Test for the loadLanguage() method.
*
* @covers \eZ\Publish\API\Repository\LanguageService::loadLanguage
* @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException
* @depends eZ\Publish\API\Repository\Tests\LanguageServiceTest::testLoadLanguage
* @covers \eZ\Publish\API\Repository\LanguageService::loadLanguageListByCode
* @depends testLoadLanguage
*/
public function testLoadLanguageThrowsNotFoundException()
{
$repository = $this->getRepository();
/* BEGIN: Use Case */
$languageService = $repository->getContentLanguageService();
// This call should fail with an exception
$languages = $languageService->loadLanguageListById(['fre-FR']);
$this->assertInternalType('iterable', $languages);
$this->assertCount(0, $languages);
$this->expectException(NotFoundException::class);
$languageService->loadLanguage('fre-FR');
/* END: Use Case */
}
/**

0 comments on commit c53d48d

Please sign in to comment.
You can’t perform that action at this time.