Skip to content

Commit d0dec35

Browse files
committed
Merged branch '4.4'
2 parents 538d058 + 982342d commit d0dec35

File tree

3 files changed

+118
-3
lines changed

3 files changed

+118
-3
lines changed

src/contracts/Repository/Values/Content/Field.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class Field extends ValueObject
4747
/**
4848
* the language code.
4949
*
50-
* @var string
50+
* @var string|null
5151
*/
5252
protected $languageCode;
5353

@@ -76,7 +76,7 @@ public function getValue()
7676
return $this->value;
7777
}
7878

79-
public function getLanguageCode(): string
79+
public function getLanguageCode(): ?string
8080
{
8181
return $this->languageCode;
8282
}

src/lib/Repository/Mapper/ContentMapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ public function getFieldsForUpdate(array $updatedFields, Content $content): arra
300300

301301
$fieldType = $this->fieldTypeRegistry->getFieldType($fieldDefinition->fieldTypeIdentifier);
302302

303-
$field = $content->getField($updatedField->fieldDefIdentifier);
303+
$field = $content->getField($updatedField->fieldDefIdentifier, $updatedField->getLanguageCode());
304304
$updatedFieldValue = $this->getFieldValueForUpdate(
305305
$updatedField,
306306
$field,
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
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 Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo;
12+
use Ibexa\Contracts\Core\Repository\Values\Content\Field;
13+
use Ibexa\Contracts\Core\Repository\Values\Content\VersionInfo as APIVersionInfo;
14+
use Ibexa\Core\FieldType\FieldTypeRegistry;
15+
use Ibexa\Core\FieldType\TextLine;
16+
use Ibexa\Core\Persistence\Legacy\Content\Language\Handler;
17+
use Ibexa\Core\Repository\Mapper\ContentMapper;
18+
use Ibexa\Core\Repository\Values\Content\Content;
19+
use Ibexa\Core\Repository\Values\Content\VersionInfo;
20+
use Ibexa\Core\Repository\Values\ContentType\ContentType;
21+
use Ibexa\Core\Repository\Values\ContentType\FieldDefinition;
22+
use Ibexa\Core\Repository\Values\ContentType\FieldDefinitionCollection;
23+
use PHPUnit\Framework\TestCase;
24+
25+
final class ContentMapperTest extends TestCase
26+
{
27+
/** @var \Ibexa\Core\Persistence\Legacy\Content\Language\Handler&\PHPUnit\Framework\MockObject\MockObject */
28+
private Handler $contentLanguageHandler;
29+
30+
/** @var \Ibexa\Core\FieldType\FieldTypeRegistry&\PHPUnit\Framework\MockObject\MockObject */
31+
private FieldTypeRegistry $fieldTypeRegistry;
32+
33+
private ContentMapper $contentMapper;
34+
35+
protected function setUp(): void
36+
{
37+
$this->contentLanguageHandler = $this->createMock(Handler::class);
38+
$this->fieldTypeRegistry = $this->createMock(FieldTypeRegistry::class);
39+
40+
$this->contentMapper = new ContentMapper(
41+
$this->contentLanguageHandler,
42+
$this->fieldTypeRegistry
43+
);
44+
}
45+
46+
/**
47+
* @covers \Ibexa\Core\Repository\ContentService::updateContent
48+
*
49+
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\ContentValidationException
50+
*/
51+
public function testUpdateContentGetsProperFieldsToUpdate(): void
52+
{
53+
$updatedField = new Field(
54+
[
55+
'id' => 1234,
56+
'value' => new TextLine\Value('updated one'),
57+
'languageCode' => 'fre-FR',
58+
'fieldDefIdentifier' => 'name',
59+
'fieldTypeIdentifier' => 'ezstring',
60+
]
61+
);
62+
$updatedField2 = new Field(
63+
[
64+
'id' => 1235,
65+
'value' => new TextLine\Value('two'),
66+
'languageCode' => 'fre-FR',
67+
'fieldDefIdentifier' => 'name',
68+
'fieldTypeIdentifier' => 'ezstring',
69+
]
70+
);
71+
$updatedFields = [$updatedField, $updatedField2];
72+
73+
$versionInfo = new VersionInfo(
74+
[
75+
'contentInfo' => new ContentInfo(['id' => 422, 'mainLanguageCode' => 'eng-GB']),
76+
'versionNo' => 7,
77+
'status' => APIVersionInfo::STATUS_DRAFT,
78+
]
79+
);
80+
81+
$content = new Content(
82+
[
83+
'versionInfo' => $versionInfo,
84+
'internalFields' => [
85+
new Field(
86+
[
87+
'value' => new TextLine\Value('one'),
88+
'languageCode' => 'eng-GB',
89+
'fieldDefIdentifier' => 'name',
90+
'fieldTypeIdentifier' => 'ezstring',
91+
]
92+
),
93+
$updatedField2,
94+
],
95+
'contentType' => new ContentType([
96+
'fieldDefinitions' => new FieldDefinitionCollection([
97+
new FieldDefinition([
98+
'identifier' => 'name',
99+
'fieldTypeIdentifier' => 'ezstring',
100+
]),
101+
]),
102+
]),
103+
]
104+
);
105+
106+
$this->fieldTypeRegistry
107+
->expects(self::any())
108+
->method('getFieldType')
109+
->willReturn(new TextLine\Type());
110+
111+
$fieldForUpdate = $this->contentMapper->getFieldsForUpdate($updatedFields, $content);
112+
113+
self::assertSame([$updatedField], $fieldForUpdate);
114+
}
115+
}

0 commit comments

Comments
 (0)