Skip to content

Commit f233721

Browse files
committed
Merge branch '4.6'
2 parents 68c6492 + 7728d69 commit f233721

9 files changed

Lines changed: 319 additions & 1218 deletions

File tree

phpstan-baseline.neon

Lines changed: 0 additions & 490 deletions
Large diffs are not rendered by default.

phpunit.functional.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
bootstrap="vendor/autoload.php"
55
beStrictAboutTestsThatDoNotTestAnything="false"
66
colors="true"
7+
failOnWarning="true"
78
>
89
<php>
910
<env name="EZP_TEST_REST_HOST" value="localhost"/>

phpunit.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
bootstrap="vendor/autoload.php"
55
beStrictAboutTestsThatDoNotTestAnything="false"
66
colors="true"
7+
failOnWarning="true"
78
>
89
<testsuites>
910
<testsuite name="Ibexa REST Bundle">

src/contracts/Input/Parser.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ abstract class Parser
1414
/**
1515
* Parse input structure.
1616
*
17-
* @param array $data
18-
* @param \Ibexa\Contracts\Rest\Input\ParsingDispatcher $parsingDispatcher
17+
* @param array<mixed> $data
1918
*
2019
* @return \Ibexa\Contracts\Core\Repository\Values\ValueObject|object
2120
*/
Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
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\Rest\Server\Output\ValueObjectVisitor;
10+
11+
use DateTime;
12+
use DOMDocument;
13+
use Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo;
14+
use Ibexa\Contracts\Core\Repository\Values\Content\Location;
15+
use Ibexa\Core\Repository\Values\ContentType\ContentType;
16+
use Ibexa\Tests\Rest\Output\ValueObjectVisitorBaseTest;
17+
18+
abstract class BaseContentValueObjectVisitorTestCase extends ValueObjectVisitorBaseTest
19+
{
20+
abstract public function testVisitWithoutEmbeddedVersion(): DOMDocument;
21+
22+
abstract protected function getXPathFirstElementName(): string;
23+
24+
protected function getContentInfoStub(): ContentInfo
25+
{
26+
return new ContentInfo(
27+
[
28+
'id' => 22,
29+
'name' => 'Sindelfingen',
30+
'sectionId' => 23,
31+
'currentVersionNo' => 5,
32+
'published' => true,
33+
'ownerId' => 24,
34+
'modificationDate' => new DateTime('2012-09-05 15:27 Europe/Berlin'),
35+
'publishedDate' => new DateTime('2012-09-05 15:27 Europe/Berlin'),
36+
'alwaysAvailable' => true,
37+
'status' => ContentInfo::STATUS_PUBLISHED,
38+
'remoteId' => 'abc123',
39+
'mainLanguageCode' => 'eng-US',
40+
'mainLocationId' => 25,
41+
'contentTypeId' => 26,
42+
'contentType' => new ContentType(['id' => 26]),
43+
'isHidden' => true,
44+
]
45+
);
46+
}
47+
48+
/**
49+
* @depends testVisitWithoutEmbeddedVersion
50+
*/
51+
public function testNameCorrect(DOMDocument $dom): void
52+
{
53+
$this->assertXPath($dom, sprintf('/%s/name[text()="Sindelfingen"]', $this->getXPathFirstElementName()));
54+
}
55+
56+
/**
57+
* @depends testVisitWithoutEmbeddedVersion
58+
*/
59+
public function testVersionsHrefCorrect(DOMDocument $dom): void
60+
{
61+
$this->assertXPath($dom, sprintf('/%s/Versions[@href="/content/objects/22/versions"]', $this->getXPathFirstElementName()));
62+
}
63+
64+
/**
65+
* @depends testVisitWithoutEmbeddedVersion
66+
*/
67+
public function testVersionsMediaTypeCorrect(DOMDocument $dom): void
68+
{
69+
$this->assertXPath($dom, sprintf('/%s/Versions[@media-type="application/vnd.ibexa.api.VersionList+xml"]', $this->getXPathFirstElementName()));
70+
}
71+
72+
/**
73+
* @depends testVisitWithoutEmbeddedVersion
74+
*/
75+
public function testSectionHrefCorrect(DOMDocument $dom): void
76+
{
77+
$this->assertXPath($dom, sprintf('/%s/Section[@href="/content/sections/23"]', $this->getXPathFirstElementName()));
78+
}
79+
80+
/**
81+
* @depends testVisitWithoutEmbeddedVersion
82+
*/
83+
public function testSectionMediaTypeCorrect(DOMDocument $dom): void
84+
{
85+
$this->assertXPath($dom, sprintf('/%s/Section[@media-type="application/vnd.ibexa.api.Section+xml"]', $this->getXPathFirstElementName()));
86+
}
87+
88+
/**
89+
* @depends testVisitWithoutEmbeddedVersion
90+
*/
91+
public function testMainLocationHrefCorrect(DOMDocument $dom): void
92+
{
93+
$this->assertXPath($dom, sprintf('/%s/MainLocation[@href="/content/locations/1/2/23"]', $this->getXPathFirstElementName()));
94+
}
95+
96+
/**
97+
* @depends testVisitWithoutEmbeddedVersion
98+
*/
99+
public function testMainLocationMediaTypeCorrect(DOMDocument $dom): void
100+
{
101+
$this->assertXPath($dom, sprintf('/%s/MainLocation[@media-type="application/vnd.ibexa.api.Location+xml"]', $this->getXPathFirstElementName()));
102+
}
103+
104+
/**
105+
* @depends testVisitWithoutEmbeddedVersion
106+
*/
107+
public function testLocationsHrefCorrect(DOMDocument $dom): void
108+
{
109+
$this->assertXPath($dom, sprintf('/%s/Locations[@href="/content/objects/22/locations"]', $this->getXPathFirstElementName()));
110+
}
111+
112+
/**
113+
* @depends testVisitWithoutEmbeddedVersion
114+
*/
115+
public function testLocationsMediaTypeCorrect(DOMDocument $dom): void
116+
{
117+
$this->assertXPath($dom, sprintf('/%s/Locations[@media-type="application/vnd.ibexa.api.LocationList+xml"]', $this->getXPathFirstElementName()));
118+
}
119+
120+
/**
121+
* @depends testVisitWithoutEmbeddedVersion
122+
*/
123+
public function testOwnerHrefCorrect(DOMDocument $dom): void
124+
{
125+
$this->assertXPath($dom, sprintf('/%s/Owner[@href="/user/users/24"]', $this->getXPathFirstElementName()));
126+
}
127+
128+
/**
129+
* @depends testVisitWithoutEmbeddedVersion
130+
*/
131+
public function testOwnerMediaTypeCorrect(DOMDocument $dom): void
132+
{
133+
$this->assertXPath($dom, sprintf('/%s/Owner[@media-type="application/vnd.ibexa.api.User+xml"]', $this->getXPathFirstElementName()));
134+
}
135+
136+
/**
137+
* @depends testVisitWithoutEmbeddedVersion
138+
*/
139+
public function testLastModificationDateCorrect(DOMDocument $dom): void
140+
{
141+
$this->assertXPath($dom, sprintf('/%s/lastModificationDate[text()="2012-09-05T15:27:00+02:00"]', $this->getXPathFirstElementName()));
142+
}
143+
144+
/**
145+
* @depends testVisitWithoutEmbeddedVersion
146+
*/
147+
public function testMainLanguageCodeCorrect(DOMDocument $dom): void
148+
{
149+
$this->assertXPath($dom, sprintf('/%s/mainLanguageCode[text()="eng-US"]', $this->getXPathFirstElementName()));
150+
}
151+
152+
/**
153+
* @depends testVisitWithoutEmbeddedVersion
154+
*/
155+
public function testAlwaysAvailableCorrect(DOMDocument $dom): void
156+
{
157+
$this->assertXPath($dom, sprintf('/%s/alwaysAvailable[text()="true"]', $this->getXPathFirstElementName()));
158+
}
159+
160+
protected function addContentRouteExpectations(ContentInfo $contentInfo, Location $location): void
161+
{
162+
$contentId = $contentInfo->getId();
163+
$contentTypeId = $contentInfo->getContentType()->id;
164+
$sectionId = $contentInfo->getSectionId();
165+
166+
$this->addRouteExpectation(
167+
'ibexa.rest.load_content_type',
168+
['contentTypeId' => $contentTypeId],
169+
"/content/types/$contentTypeId"
170+
);
171+
$this->addRouteExpectation(
172+
'ibexa.rest.load_content_versions',
173+
['contentId' => $contentId],
174+
"/content/objects/$contentId/versions"
175+
);
176+
$this->addRouteExpectation(
177+
'ibexa.rest.load_section',
178+
['sectionId' => $sectionId],
179+
"/content/sections/$sectionId"
180+
);
181+
$locationPath = trim($location->getPathString(), '/');
182+
$this->addRouteExpectation(
183+
'ibexa.rest.load_location',
184+
['locationPath' => $locationPath],
185+
"/content/locations/$locationPath"
186+
);
187+
$this->addRouteExpectation(
188+
'ibexa.rest.load_locations_for_content',
189+
['contentId' => $contentId],
190+
"/content/objects/$contentId/locations"
191+
);
192+
}
193+
}

tests/lib/Server/Output/ValueObjectVisitor/FieldTest.php

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88

99
namespace Ibexa\Tests\Rest\Server\Output\ValueObjectVisitor;
1010

11+
use Ibexa\Contracts\Core\Repository\FieldType;
12+
use Ibexa\Contracts\Core\Repository\FieldTypeService;
1113
use Ibexa\Contracts\Core\Repository\Values\Content\Field as ApiField;
12-
use Ibexa\Contracts\Rest\Output\Generator;
14+
use Ibexa\Rest\FieldTypeProcessorRegistry;
1315
use Ibexa\Rest\Output\FieldTypeSerializer;
1416
use Ibexa\Rest\Server\Output\ValueObjectVisitor\Field;
1517
use Ibexa\Tests\Rest\Output\ValueObjectVisitorBaseTest;
@@ -19,14 +21,18 @@
1921
*/
2022
final class FieldTest extends ValueObjectVisitorBaseTest
2123
{
22-
/** @var \Ibexa\Rest\Output\FieldTypeSerializer&\PHPUnit\Framework\MockObject\MockObject */
23-
private FieldTypeSerializer $fieldTypeSerializer;
24+
/** @var \Ibexa\Contracts\Core\Repository\FieldTypeService&\PHPUnit\Framework\MockObject\MockObject */
25+
private FieldTypeService $fieldTypeService;
26+
27+
/** @var \Ibexa\Rest\FieldTypeProcessorRegistry&\PHPUnit\Framework\MockObject\MockObject */
28+
private FieldTypeProcessorRegistry $fieldTypeProcessorRegistry;
2429

2530
protected function setUp(): void
2631
{
2732
parent::setUp();
2833

29-
$this->fieldTypeSerializer = $this->createMock(FieldTypeSerializer::class);
34+
$this->fieldTypeService = $this->createMock(FieldTypeService::class);
35+
$this->fieldTypeProcessorRegistry = $this->createMock(FieldTypeProcessorRegistry::class);
3036
}
3137

3238
public function testVisit(): void
@@ -41,15 +47,11 @@ public function testVisit(): void
4147
'fieldDefIdentifier' => 'foo',
4248
'value' => 'foo',
4349
'languageCode' => 'eng-GB',
44-
'fieldTypeIdentifier' => 'ezfoo',
50+
'fieldTypeIdentifier' => 'foo_field_type',
4551
]
4652
);
4753

48-
$this->mockFieldTypeSerializerSerializeContentFieldValue(
49-
$generator,
50-
$field,
51-
'<value>foo</value>'
52-
);
54+
$this->mockSerializingFieldValue($field);
5355

5456
$visitor->visit(
5557
$this->getVisitorMock(),
@@ -67,25 +69,24 @@ public function testVisit(): void
6769
$this->assertContainsTag('fieldTypeIdentifier', $result);
6870
}
6971

70-
private function mockFieldTypeSerializerSerializeContentFieldValue(
71-
Generator $generator,
72-
ApiField $field,
73-
string $value
74-
): void {
75-
$this->fieldTypeSerializer
76-
->method('serializeContentFieldValue')
77-
->with(
78-
$generator,
79-
$field
80-
)
81-
->willReturn($value);
72+
private function mockSerializingFieldValue(ApiField $field): void
73+
{
74+
$fieldTypeMock = $this->createMock(FieldType::class);
75+
$fieldTypeIdentifier = $field->getFieldTypeIdentifier();
76+
77+
$fieldTypeMock->method('getFieldTypeIdentifier')->willReturn($fieldTypeIdentifier);
78+
$fieldTypeMock->method('toHash')->with('foo')->willReturn(['value' => 'foo']);
79+
80+
$this->fieldTypeProcessorRegistry->method('hasProcessor')->with($fieldTypeIdentifier)->willReturn(false);
81+
82+
$this->fieldTypeService->method('getFieldType')->with($fieldTypeIdentifier)->willReturn($fieldTypeMock);
8283
}
8384

8485
private function assertContainsTag(
8586
string $tag,
8687
string $result
8788
): void {
88-
$this->assertXMLTag(
89+
self::assertXMLTag(
8990
[
9091
'tag' => $tag,
9192
],
@@ -96,6 +97,11 @@ private function assertContainsTag(
9697

9798
protected function internalGetVisitor(): Field
9899
{
99-
return new Field($this->fieldTypeSerializer);
100+
return new Field(
101+
new FieldTypeSerializer(
102+
$this->fieldTypeService,
103+
$this->fieldTypeProcessorRegistry
104+
)
105+
);
100106
}
101107
}

0 commit comments

Comments
 (0)