Skip to content

Commit

Permalink
EZP-29764: As a Developer I want to update single Content Type transl…
Browse files Browse the repository at this point in the history
…ation (#2484)

* Created integration test for updating CT with single new translation

* EZP-29764: As a Developer I want to update single Content Type translation

* EZP-29764: Replace UpdateStruct with Type object for update content type method

* EZP-29764: Handling for content type field definitions

* EZP-29764: Handling translation for new field definition

* EZP-29764: Handling translation for new field definition

* EZP-29764: Code review fixes

* Add missing language_mask attribute to select query

* Fix failing tests

* EZP-29764: bc breaks update
  • Loading branch information
ViniTou authored and Łukasz Serwatka committed Dec 14, 2018
1 parent a2bf3c6 commit 7011525
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 0 deletions.
104 changes: 104 additions & 0 deletions Repository/Tests/ContentTypeServiceTest.php
Expand Up @@ -1333,6 +1333,46 @@ public function testUpdateContentTypeDraftStructValues($data)
}
}

/**
* @covers \eZ\Publish\API\Repository\ContentTypeService::updateContentTypeDraft
*
* @throws \eZ\Publish\API\Repository\Exceptions\ForbiddenException
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
*/
public function testUpdateContentTypeDraftWithNewTranslation()
{
$repository = $this->getRepository();
$contentTypeService = $repository->getContentTypeService();

$contentTypeDraft = $this->createContentTypeDraft();
$contentTypeService->publishContentTypeDraft($contentTypeDraft);

$contentType = $contentTypeService->loadContentType($contentTypeDraft->id);
// sanity check
self::assertEquals(
['eng-US', 'ger-DE'],
array_keys($contentType->getNames())
);

$contentTypeDraft = $contentTypeService->createContentTypeDraft($contentType);
$updateStruct = $contentTypeService->newContentTypeUpdateStruct();
$updateStruct->names = [
'eng-GB' => 'BrE blog post',
];
$contentTypeService->updateContentTypeDraft($contentTypeDraft, $updateStruct);
$contentTypeService->publishContentTypeDraft($contentTypeDraft);

self::assertEquals(
[
'eng-US' => 'Blog post',
'ger-DE' => 'Blog-Eintrag',
'eng-GB' => 'BrE blog post',
],
$contentTypeService->loadContentType($contentType->id)->getNames()
);
}

/**
* Test for the updateContentTypeDraft() method.
*
Expand Down Expand Up @@ -2143,6 +2183,70 @@ public function testUpdateFieldDefinition()
);
}

/**
* @covers \eZ\Publish\API\Repository\ContentTypeService::updateFieldDefinition
*/
public function testUpdateFieldDefinitionWithNewTranslation()
{
$repository = $this->getRepository();
$contentTypeService = $repository->getContentTypeService();

/* BEGIN: Use Case */
$contentTypeDraft = $this->createContentTypeDraft();

$bodyField = $contentTypeDraft->getFieldDefinition('body');

self::assertEquals(
['eng-US', 'ger-DE'],
array_keys($bodyField->getNames())
);

$bodyUpdateStruct = $contentTypeService->newFieldDefinitionUpdateStruct();
$bodyUpdateStruct->identifier = 'blog-body';
$bodyUpdateStruct->names = [
'eng-GB' => 'New blog post body',
];
$bodyUpdateStruct->descriptions = [
'eng-GB' => null,
];
$bodyUpdateStruct->fieldGroup = 'updated-blog-content';
$bodyUpdateStruct->position = 3;
$bodyUpdateStruct->isTranslatable = false;
$bodyUpdateStruct->isRequired = false;
$bodyUpdateStruct->isInfoCollector = true;
$bodyUpdateStruct->validatorConfiguration = [];
$bodyUpdateStruct->fieldSettings = [
'textRows' => 60,
];
$bodyUpdateStruct->isSearchable = false;

$contentTypeService->updateFieldDefinition(
$contentTypeDraft,
$bodyField,
$bodyUpdateStruct
);
/* END: Use Case */

$contentType = $contentTypeService->loadContentTypeDraft($contentTypeDraft->id);

self::assertEquals(
[
'eng-GB' => 'New blog post body',
'eng-US' => 'Body',
'ger-DE' => 'Textkörper',
],
$contentType->getFieldDefinition('blog-body')->getNames()
);
self::assertEquals(
[
'eng-GB' => null,
'eng-US' => 'Body of the blog post',
'ger-DE' => 'Textkörper des Blog-Eintrages',
],
$contentType->getFieldDefinition('blog-body')->getDescriptions()
);
}

/**
* Test for the updateFieldDefinition() method.
*
Expand Down
8 changes: 8 additions & 0 deletions Repository/Values/ContentType/ContentType.php
Expand Up @@ -30,6 +30,7 @@
* @property-read bool $isContainer This flag hints to UIs if type may have children or not.
* @property-read string $mainLanguageCode the main language of the content type names and description used for fallback.
* @property-read bool $defaultAlwaysAvailable if an instance of a content type is created the always available flag is set by default this this value.
* @property-read string[] $languageCodes array of language codes used by content type translations.
*
* @property-read int $defaultSortField Specifies which property the child locations should be sorted on by default when created. Valid values are found at {@link Location::SORT_FIELD_*}
* @property-read int $defaultSortOrder Specifies whether the sort order should be ascending or descending by default when created. Valid values are {@link Location::SORT_ORDER_*}
Expand Down Expand Up @@ -163,6 +164,13 @@ abstract class ContentType extends ValueObject implements MultiLanguageName, Mul
*/
protected $defaultSortOrder;

/**
* List of language codes used by translations.
*
* @var string[]
*/
protected $languageCodes;

/**
* This method returns the content type groups this content type is assigned to.
*
Expand Down

0 comments on commit 7011525

Please sign in to comment.