-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from ibexa/temp_1.3_to_4.5
Merge branch '1.3' of ezsystems/ezplatform-content-forms into 4.5
- Loading branch information
Showing
3 changed files
with
130 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa 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\Tests\ContentForms\Data\Mapper; | ||
|
||
use Ibexa\ContentForms\Data\Mapper\ContentUpdateMapper; | ||
use Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo; | ||
use Ibexa\Contracts\Core\Repository\Values\Content\Field as APIField; | ||
use Ibexa\Contracts\Core\Repository\Values\Content\Language; | ||
use Ibexa\Contracts\Core\Repository\Values\Content\Section; | ||
use Ibexa\Core\Repository\Values\Content\Content; | ||
use Ibexa\Core\Repository\Values\Content\Location as APILocation; | ||
use Ibexa\Core\Repository\Values\Content\VersionInfo; | ||
use Ibexa\Core\Repository\Values\ContentType\ContentType; | ||
use Ibexa\Core\Repository\Values\ContentType\FieldDefinition; | ||
use Ibexa\Core\Repository\Values\ContentType\FieldDefinitionCollection; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class ContentUpdateMapperTest extends TestCase | ||
{ | ||
public function testMapToFormData(): void | ||
{ | ||
$currentFields = [ | ||
new APIField([ | ||
'fieldDefIdentifier' => 'name', | ||
'fieldTypeIdentifier' => 'ezstring', | ||
'languageCode' => 'eng-GB', | ||
'value' => 'Name', | ||
]), | ||
new APIField([ | ||
'fieldDefIdentifier' => 'short_name', | ||
'fieldTypeIdentifier' => 'ezstring', | ||
'languageCode' => 'eng-DE', | ||
'value' => $expectedShortName = 'Nontranslateable short name', | ||
]), | ||
]; | ||
$content = new Content([ | ||
'versionInfo' => new VersionInfo([ | ||
'contentInfo' => new ContentInfo([ | ||
'remoteId' => 'foo', | ||
'mainLanguage' => new Language([ | ||
'languageCode' => 'eng-GB', | ||
]), | ||
'alwaysAvailable' => true, | ||
'sectionId' => 2, | ||
'section' => new Section([ | ||
'id' => 2, | ||
'identifier' => 'foo_section_identifier', | ||
]), | ||
'publishedDate' => new \DateTime('2020-10-30T11:40:09+00:00'), | ||
'modificationDate' => new \DateTime('2020-10-30T11:40:09+00:00'), | ||
'mainLocation' => new APILocation([ | ||
'parentLocationId' => 1, | ||
'hidden' => true, | ||
'sortField' => 9, | ||
'sortOrder' => 0, | ||
'priority' => 1, | ||
]), | ||
]), | ||
]), | ||
'contentType' => $contentType = new ContentType([ | ||
'identifier' => 'folder', | ||
'fieldDefinitions' => new FieldDefinitionCollection([ | ||
new FieldDefinition([ | ||
'identifier' => 'name', | ||
'isTranslatable' => true, | ||
'defaultValue' => '', | ||
]), | ||
new FieldDefinition([ | ||
'identifier' => 'short_name', | ||
'isTranslatable' => false, | ||
'defaultValue' => '', | ||
]), | ||
]), | ||
]), | ||
'internalFields' => [ | ||
new APIField([ | ||
'fieldDefIdentifier' => 'name', | ||
'fieldTypeIdentifier' => 'ezstring', | ||
'languageCode' => 'ger-DE', | ||
'value' => $expectedName = 'GER name', | ||
]), | ||
new APIField([ | ||
'fieldDefIdentifier' => 'short_name', | ||
'fieldTypeIdentifier' => 'ezstring', | ||
'languageCode' => 'ger-DE', | ||
'value' => '', | ||
]), | ||
], | ||
]); | ||
|
||
$data = (new ContentUpdateMapper())->mapToFormData($content, [ | ||
'languageCode' => 'ger-DE', | ||
'contentType' => $contentType, | ||
'currentFields' => $currentFields, | ||
]); | ||
|
||
$fieldsData = $data->fieldsData; | ||
|
||
self::assertSame($expectedName, $fieldsData['name']->value); | ||
self::assertSame($expectedShortName, $fieldsData['short_name']->value); | ||
} | ||
} |