Skip to content

Commit

Permalink
Merge branch '7.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
andrerom committed Dec 11, 2018
2 parents b6087af + a0c71cd commit e4e2cfc
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 31 deletions.
10 changes: 6 additions & 4 deletions Repository/LocationService.php
Expand Up @@ -44,11 +44,12 @@ public function copySubtree(Location $subtree, Location $targetParentLocation);
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException If the specified location is not found
*
* @param mixed $locationId
* @param string[]|null $prioritizedLanguages Used as prioritized language code on translated properties of returned object.
* @param string[]|null $prioritizedLanguages Filter on and use as prioritized language code on translated properties of returned object.
* @param bool|null $useAlwaysAvailable Respect always available flag on content when filtering on $prioritizedLanguages.
*
* @return \eZ\Publish\API\Repository\Values\Content\Location
*/
public function loadLocation($locationId, array $prioritizedLanguages = null);
public function loadLocation($locationId, array $prioritizedLanguages = null, bool $useAlwaysAvailable = null);

/**
* Loads a location object from its $remoteId.
Expand All @@ -57,11 +58,12 @@ public function loadLocation($locationId, array $prioritizedLanguages = null);
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException If the specified location is not found
*
* @param string $remoteId
* @param string[]|null $prioritizedLanguages Used as prioritized language code on translated properties of returned object.
* @param string[]|null $prioritizedLanguages Filter on and use as prioritized language code on translated properties of returned object.
* @param bool|null $useAlwaysAvailable Respect always available flag on content when filtering on $prioritizedLanguages.
*
* @return \eZ\Publish\API\Repository\Values\Content\Location
*/
public function loadLocationByRemoteId($remoteId, array $prioritizedLanguages = null);
public function loadLocationByRemoteId($remoteId, array $prioritizedLanguages = null, bool $useAlwaysAvailable = null);

/**
* Loads the locations for the given content object.
Expand Down
24 changes: 23 additions & 1 deletion Repository/Tests/BaseTest.php
Expand Up @@ -11,7 +11,7 @@
use Doctrine\DBAL\Connection;
use eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException;
use eZ\Publish\API\Repository\Tests\PHPUnitConstraint\ValidationErrorOccurs as PHPUnitConstraintValidationErrorOccurs;
use eZ\Publish\API\Repository\Values\Content\Location;
use eZ\Publish\API\Repository\Values\Content\Language;
use EzSystems\EzPlatformSolrSearchEngine\Tests\SetupFactory\LegacySetupFactory as LegacySolrSetupFactory;
use PHPUnit\Framework\TestCase;
use eZ\Publish\API\Repository\Repository;
Expand Down Expand Up @@ -717,4 +717,26 @@ protected function createFolder(array $names, $parentLocationId)

return $contentService->publishVersion($contentDraft->versionInfo);
}

/**
* Add new Language to the Repository.
*
* @param string $languageCode
* @param string $name
* @param bool $enabled
*
* @return \eZ\Publish\API\Repository\Values\Content\Language
*/
protected function createLanguage(string $languageCode, string $name, bool $enabled = true): Language
{
$repository = $this->getRepository(false);

$languageService = $repository->getContentLanguageService();
$languageStruct = $languageService->newLanguageCreateStruct();
$languageStruct->name = $name;
$languageStruct->languageCode = $languageCode;
$languageStruct->enabled = $enabled;

return $languageService->createLanguage($languageStruct);
}
}
20 changes: 0 additions & 20 deletions Repository/Tests/LanguageServiceTest.php
Expand Up @@ -548,26 +548,6 @@ public function testGetDefaultLanguageCode()
);
}

/**
* Helper method that creates a new language test fixture in the
* API implementation under test.
*
* @return \eZ\Publish\API\Repository\Values\Content\Language
*/
private function createLanguage()
{
$repository = $this->getRepository();

$languageService = $repository->getContentLanguageService();
$languageCreate = $languageService->newLanguageCreateStruct();

$languageCreate->enabled = false;
$languageCreate->name = 'English';
$languageCreate->languageCode = 'eng-US';

return $languageService->createLanguage($languageCreate);
}

/**
* Test for the createLanguage() method.
*
Expand Down
26 changes: 20 additions & 6 deletions Repository/Tests/LocationServiceTest.php
Expand Up @@ -478,11 +478,7 @@ public function testLoadLocationPrioritizedLanguagesFallback()
$repository = $this->getRepository();

// Add a language
$languageService = $repository->getContentLanguageService();
$languageStruct = $languageService->newLanguageCreateStruct();
$languageStruct->name = 'Norsk';
$languageStruct->languageCode = 'nor-NO';
$languageService->createLanguage($languageStruct);
$this->createLanguage('nor-NO', 'Norsk');

$locationService = $repository->getLocationService();
$contentService = $repository->getContentService();
Expand All @@ -495,7 +491,7 @@ public function testLoadLocationPrioritizedLanguagesFallback()
$draft = $contentService->updateContent($draft->getVersionInfo(), $struct);
$contentService->publishVersion($draft->getVersionInfo());

// Load with prioritc language (fallback will be the old one)
// Load with priority language (fallback will be the old one)
$location = $locationService->loadLocation(5, ['nor-NO']);

$this->assertInstanceOf(
Expand All @@ -513,6 +509,24 @@ public function testLoadLocationPrioritizedLanguagesFallback()
$this->assertEquals($content->getVersionInfo()->getName('eng-US'), 'Users');
}

/**
* Test that accessing lazy-loaded Content without a translation in the specific
* not available language throws NotFoundException.
*/
public function testLoadLocationThrowsNotFoundExceptionForNotAvailableContent(): void
{
$repository = $this->getRepository();

$locationService = $repository->getLocationService();

$this->createLanguage('pol-PL', 'Polski');

$this->expectException(NotFoundException::class);

// Note: relying on existing database fixtures to make test case more readable
$locationService->loadLocation(60, ['pol-PL']);
}

/**
* Test for the loadLocation() method.
*
Expand Down

0 comments on commit e4e2cfc

Please sign in to comment.