Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EZP-31053: Prioritized languages should be respected by Content::getContentType #2833

Merged
merged 1 commit into from
Oct 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ public function testLoadContentThrowsUnauthorizedException()
* Test for the loadContent() method.
*
* @see \eZ\Publish\API\Repository\ContentService::loadContent($contentId, $languages)
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentWithSecondParameter
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentWithPrioritizedLanguages
*/
public function testLoadContentThrowsUnauthorizedExceptionWithSecondParameter()
{
Expand Down
26 changes: 22 additions & 4 deletions eZ/Publish/API/Repository/Tests/ContentServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2687,7 +2687,7 @@ public function testLoadContentByContentInfoThrowsNotFoundExceptionWithVersionNu
* @see \eZ\Publish\API\Repository\ContentService::loadContent($contentId, $languages)
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft
*/
public function testLoadContentWithSecondParameter()
public function testLoadContentWithPrioritizedLanguages()
{
$draft = $this->createMultipleLanguageDraftVersion1();

Expand All @@ -2696,23 +2696,41 @@ public function testLoadContentWithSecondParameter()

$this->assertLocaleFieldsEquals($draftLocalized->getFields(), self::ENG_GB);

return $draft;
return $draftLocalized;
}

/**
* Test for the loadContent() method using undefined translation.
*
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentWithSecondParameter
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentWithPrioritizedLanguages
*
* @param \eZ\Publish\API\Repository\Values\Content\Content $contentDraft
*/
public function testLoadContentWithSecondParameterThrowsNotFoundException(Content $contentDraft)
public function testLoadContentWithPrioritizedLanguagesThrowsNotFoundException(Content $contentDraft)
{
$this->expectException(NotFoundException::class);

$this->contentService->loadContent($contentDraft->id, [self::GER_DE], null, false);
}

/**
* Test for the loadContent() method.
*
* @see \eZ\Publish\API\Repository\ContentService::loadContent
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentWithPrioritizedLanguages
*/
public function testLoadContentPassTroughPrioritizedLanguagesToContentType(Content $content): void
{
$contentTypeService = $this->getRepository()->getContentTypeService();

$contentType = $contentTypeService->loadContentType(
$content->contentInfo->contentTypeId,
[self::ENG_GB]
);

$this->assertEquals($contentType, $content->getContentType());
}

/**
* Test for the loadContent() method.
*
Expand Down
9 changes: 7 additions & 2 deletions eZ/Publish/Core/Repository/ContentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -382,12 +382,17 @@ public function internalLoadContent($id, array $languages = null, $versionNo = n
);
}

if ($languages === null) {
$languages = [];
}

return $this->domainMapper->buildContentDomainObject(
$spiContent,
$this->repository->getContentTypeService()->loadContentType(
$spiContent->versionInfo->contentInfo->contentTypeId
$spiContent->versionInfo->contentInfo->contentTypeId,
$languages
),
$languages ?? [],
$languages,
$alwaysAvailableLanguageCode
);
}
Expand Down