|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * @copyright Copyright (C) Ibexa AS. All rights reserved. |
| 5 | + * @license For full copyright and license information view LICENSE file distributed with this source code. |
| 6 | + */ |
| 7 | +declare(strict_types=1); |
| 8 | + |
| 9 | +namespace Ibexa\Tests\Core\Repository\Mapper; |
| 10 | + |
| 11 | +use eZ\Publish\API\Repository\Values\Content\ContentInfo; |
| 12 | +use eZ\Publish\API\Repository\Values\Content\Field; |
| 13 | +use eZ\Publish\API\Repository\Values\Content\VersionInfo as APIVersionInfo; |
| 14 | +use eZ\Publish\Core\FieldType\FieldTypeRegistry; |
| 15 | +use eZ\Publish\Core\FieldType\TextLine; |
| 16 | +use eZ\Publish\Core\Persistence\Cache\ContentLanguageHandler; |
| 17 | +use eZ\Publish\Core\Repository\Mapper\ContentMapper; |
| 18 | +use eZ\Publish\Core\Repository\Values\Content\Content; |
| 19 | +use eZ\Publish\Core\Repository\Values\Content\VersionInfo; |
| 20 | +use eZ\Publish\Core\Repository\Values\ContentType\ContentType; |
| 21 | +use eZ\Publish\Core\Repository\Values\ContentType\FieldDefinition; |
| 22 | +use eZ\Publish\Core\Repository\Values\ContentType\FieldDefinitionCollection; |
| 23 | +use PHPUnit\Framework\TestCase; |
| 24 | + |
| 25 | +final class ContentMapperTest extends TestCase |
| 26 | +{ |
| 27 | + /** @var \eZ\Publish\Core\Persistence\Legacy\Content\Language\Handler|\PHPUnit\Framework\MockObject\MockObject */ |
| 28 | + private $contentLanguageHandler; |
| 29 | + |
| 30 | + /** @var \eZ\Publish\Core\FieldType\FieldTypeRegistry|\PHPUnit\Framework\MockObject\MockObject */ |
| 31 | + private $fieldTypeRegistry; |
| 32 | + |
| 33 | + /** @var \eZ\Publish\Core\Repository\Mapper\ContentMapper */ |
| 34 | + private $contentMapper; |
| 35 | + |
| 36 | + protected function setUp(): void |
| 37 | + { |
| 38 | + $this->contentLanguageHandler = $this->createMock(ContentLanguageHandler::class); |
| 39 | + $this->fieldTypeRegistry = $this->createMock(FieldTypeRegistry::class); |
| 40 | + |
| 41 | + $this->contentMapper = new ContentMapper( |
| 42 | + $this->contentLanguageHandler, |
| 43 | + $this->fieldTypeRegistry |
| 44 | + ); |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * @covers \eZ\Publish\Core\Repository\ContentService::updateContent |
| 49 | + * |
| 50 | + * @throws \eZ\Publish\Core\Base\Exceptions\ContentValidationException |
| 51 | + */ |
| 52 | + public function testUpdateContentGetsProperFieldsToUpdate(): void |
| 53 | + { |
| 54 | + $updatedField = new Field( |
| 55 | + [ |
| 56 | + 'id' => 1234, |
| 57 | + 'value' => new TextLine\Value('updated one'), |
| 58 | + 'languageCode' => 'fre-FR', |
| 59 | + 'fieldDefIdentifier' => 'name', |
| 60 | + 'fieldTypeIdentifier' => 'ezstring', |
| 61 | + ] |
| 62 | + ); |
| 63 | + $updatedField2 = new Field( |
| 64 | + [ |
| 65 | + 'id' => 1235, |
| 66 | + 'value' => new TextLine\Value('two'), |
| 67 | + 'languageCode' => 'fre-FR', |
| 68 | + 'fieldDefIdentifier' => 'name', |
| 69 | + 'fieldTypeIdentifier' => 'ezstring', |
| 70 | + ] |
| 71 | + ); |
| 72 | + $updatedFields = [$updatedField, $updatedField2]; |
| 73 | + |
| 74 | + $versionInfo = new VersionInfo( |
| 75 | + [ |
| 76 | + 'contentInfo' => new ContentInfo(['id' => 422, 'mainLanguageCode' => 'eng-GB']), |
| 77 | + 'versionNo' => 7, |
| 78 | + 'status' => APIVersionInfo::STATUS_DRAFT, |
| 79 | + ] |
| 80 | + ); |
| 81 | + |
| 82 | + $content = new Content( |
| 83 | + [ |
| 84 | + 'versionInfo' => $versionInfo, |
| 85 | + 'internalFields' => [ |
| 86 | + new Field( |
| 87 | + [ |
| 88 | + 'value' => new TextLine\Value('one'), |
| 89 | + 'languageCode' => 'eng-GB', |
| 90 | + 'fieldDefIdentifier' => 'name', |
| 91 | + 'fieldTypeIdentifier' => 'ezstring', |
| 92 | + ] |
| 93 | + ), |
| 94 | + $updatedField2, |
| 95 | + ], |
| 96 | + 'contentType' => new ContentType([ |
| 97 | + 'fieldDefinitions' => new FieldDefinitionCollection([ |
| 98 | + new FieldDefinition([ |
| 99 | + 'identifier' => 'name', |
| 100 | + 'fieldTypeIdentifier' => 'ezstring', |
| 101 | + ]), |
| 102 | + ]), |
| 103 | + ]), |
| 104 | + ] |
| 105 | + ); |
| 106 | + |
| 107 | + $this->fieldTypeRegistry |
| 108 | + ->expects(self::any()) |
| 109 | + ->method('getFieldType') |
| 110 | + ->willReturn(new TextLine\Type()); |
| 111 | + |
| 112 | + $fieldForUpdate = $this->contentMapper->getFieldsForUpdate($updatedFields, $content); |
| 113 | + |
| 114 | + self::assertSame([$updatedField], $fieldForUpdate); |
| 115 | + } |
| 116 | +} |
0 commit comments