Skip to content

Commit 1bf2fda

Browse files
committed
Merged branch '4.6' into main
# Conflicts: # phpstan-baseline.neon # tests/bundle/Core/Fragment/DirectFragmentRendererTest.php # tests/lib/MVC/Symfony/Templating/BaseRenderStrategyTestCase.php # tests/lib/MVC/Symfony/Templating/RenderContentStrategyTest.php
2 parents db093b3 + 2bb8931 commit 1bf2fda

File tree

7 files changed

+82
-37
lines changed

7 files changed

+82
-37
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22122,12 +22122,6 @@ parameters:
2212222122
count: 1
2212322123
path: tests/bundle/Core/Fragment/DirectFragmentRendererTest.php
2212422124

22125-
-
22126-
message: '#^Call to static method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Symfony\\\\Component\\\\HttpFoundation\\\\Response'' and Symfony\\Component\\HttpFoundation\\Response will always evaluate to true\.$#'
22127-
identifier: staticMethod.alreadyNarrowedType
22128-
count: 4
22129-
path: tests/bundle/Core/Fragment/DirectFragmentRendererTest.php
22130-
2213122125
-
2213222126
message: '#^Method Ibexa\\Tests\\Bundle\\Core\\Fragment\\FragmentListenerFactoryTest\:\:buildFragmentListenerProvider\(\) has no return type specified\.$#'
2213322127
identifier: missingType.return
@@ -45240,24 +45234,6 @@ parameters:
4524045234
count: 1
4524145235
path: tests/lib/MVC/Symfony/Templating/GlobalHelperTest.php
4524245236

45243-
-
45244-
message: '#^Anonymous function has an unused use \$content\.$#'
45245-
identifier: closure.unusedUse
45246-
count: 1
45247-
path: tests/lib/MVC/Symfony/Templating/RenderContentStrategyTest.php
45248-
45249-
-
45250-
message: '#^Anonymous function has an unused use \$siteAccess\.$#'
45251-
identifier: closure.unusedUse
45252-
count: 1
45253-
path: tests/lib/MVC/Symfony/Templating/RenderContentStrategyTest.php
45254-
45255-
-
45256-
message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Symfony\\\\Component\\\\HttpKernel\\\\Controller\\\\ControllerReference'' and Symfony\\Component\\HttpKernel\\Controller\\ControllerReference will always evaluate to true\.$#'
45257-
identifier: method.alreadyNarrowedType
45258-
count: 1
45259-
path: tests/lib/MVC/Symfony/Templating/RenderContentStrategyTest.php
45260-
4526145237
-
4526245238
message: '#^Anonymous function has an unused use \$content\.$#'
4526345239
identifier: closure.unusedUse

src/lib/MVC/Symfony/Templating/RenderContentStrategy.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
final class RenderContentStrategy extends BaseRenderStrategy implements RenderStrategy
2020
{
21-
private const DEFAULT_VIEW_TYPE = 'embed';
21+
private const string DEFAULT_VIEW_TYPE = 'embed';
2222

2323
public function supports(ValueObject $valueObject): bool
2424
{
@@ -41,6 +41,7 @@ public function render(ValueObject $valueObject, RenderOptions $options): string
4141
$controllerReference = new ControllerReference('ibexa_content::viewAction', [
4242
'contentId' => $content->id,
4343
'viewType' => $options->get('viewType', self::DEFAULT_VIEW_TYPE),
44+
'params' => $options->get('params', []),
4445
]);
4546

4647
$renderer = $this->getFragmentRenderer($options->get('method', $this->defaultRenderer));

src/lib/MVC/Symfony/Templating/RenderLocationStrategy.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
final class RenderLocationStrategy extends BaseRenderStrategy implements RenderStrategy
1919
{
20-
private const DEFAULT_VIEW_TYPE = 'embed';
20+
private const string DEFAULT_VIEW_TYPE = 'embed';
2121

2222
public function supports(ValueObject $valueObject): bool
2323
{
@@ -42,6 +42,7 @@ public function render(ValueObject $valueObject, RenderOptions $options): string
4242
'contentId' => $content->id,
4343
'locationId' => $location->id,
4444
'viewType' => $options->get('viewType', self::DEFAULT_VIEW_TYPE),
45+
'params' => $options->get('params', []),
4546
]);
4647

4748
$renderer = $this->getFragmentRenderer($options->get('method', $this->defaultRenderer));

tests/bundle/Core/Fragment/DirectFragmentRendererTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ public function testSubRequestBuilding(): void
6666
$directFragmentRenderer = $this->getDirectFragmentRenderer($controllerResolver);
6767
$response = $directFragmentRenderer->render($controllerReference, $request);
6868

69-
self::assertInstanceOf(Response::class, $response);
7069
self::assertSame('rendered_response', $response->getContent());
7170
}
7271

@@ -83,7 +82,6 @@ public function testControllerResponse(): void
8382
$directFragmentRenderer = $this->getDirectFragmentRenderer($controllerResolver);
8483
$response = $directFragmentRenderer->render('', new Request(), []);
8584

86-
self::assertInstanceOf(Response::class, $response);
8785
self::assertSame('response_body', $response->getContent());
8886
}
8987

@@ -114,7 +112,6 @@ public function testControllerViewResponse(): void
114112
);
115113
$response = $directFragmentRenderer->render('', new Request(), []);
116114

117-
self::assertInstanceOf(Response::class, $response);
118115
self::assertSame('rendered_template_identifier', $response->getContent());
119116
}
120117

@@ -131,7 +128,6 @@ public function testControllerStringResponse(): void
131128
$directFragmentRenderer = $this->getDirectFragmentRenderer($controllerResolver);
132129
$response = $directFragmentRenderer->render('', new Request(), []);
133130

134-
self::assertInstanceOf(Response::class, $response);
135131
self::assertSame('some_prerendered_response', $response->getContent());
136132
}
137133

tests/lib/MVC/Symfony/Templating/BaseRenderStrategyTestCase.php

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,19 @@
88

99
namespace Ibexa\Tests\Core\MVC\Symfony\Templating;
1010

11+
use Ibexa\Contracts\Core\MVC\Templating\BaseRenderStrategy;
1112
use Ibexa\Contracts\Core\MVC\Templating\RenderStrategy;
1213
use Ibexa\Contracts\Core\Repository\Values\Content\Content as APIContent;
1314
use Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo;
1415
use Ibexa\Contracts\Core\Repository\Values\Content\Location as APILocation;
16+
use Ibexa\Contracts\Core\Repository\Values\ValueObject;
1517
use Ibexa\Core\MVC\Symfony\SiteAccess;
18+
use Ibexa\Core\MVC\Symfony\Templating\RenderOptions;
1619
use Ibexa\Core\Repository\Values\Content\Content;
1720
use Ibexa\Core\Repository\Values\Content\Location;
1821
use Ibexa\Core\Repository\Values\Content\VersionInfo;
1922
use Ibexa\Tests\Core\Search\TestCase;
23+
use PHPUnit\Framework\MockObject\MockObject;
2024
use Symfony\Component\HttpFoundation\Request;
2125
use Symfony\Component\HttpFoundation\RequestStack;
2226
use Symfony\Component\HttpFoundation\Response;
@@ -66,7 +70,7 @@ public function getName(): string
6670
}
6771

6872
/**
69-
* @param array<string, mixed> $options
73+
* @phpstan-param array<string, mixed> $options
7074
*/
7175
public function render(
7276
string|ControllerReference $uri,
@@ -97,4 +101,52 @@ public function createContent(int $id): APIContent
97101
]),
98102
]);
99103
}
104+
105+
/**
106+
* @phpstan-param class-string<BaseRenderStrategy> $renderStrategyClass
107+
*/
108+
public function forwardParamOptionsToFragmentRenderer(
109+
FragmentRendererInterface & MockObject $fragmentRendererMock,
110+
ValueObject & MockObject $valueObjectMock,
111+
string $renderStrategyClass
112+
): void {
113+
$params = [
114+
'param1' => 'value1',
115+
'param2' => 'value2',
116+
];
117+
118+
$fragmentRendererMock
119+
->method('getName')
120+
->willReturn('fragment_render_mock');
121+
$fragmentRendererMock->expects(self::once())
122+
->method('render')
123+
->with(
124+
self::callback(static function ($controllerReference) use ($params): bool {
125+
if (!$controllerReference instanceof ControllerReference) {
126+
return false;
127+
}
128+
129+
return $controllerReference->attributes['params'] === $params;
130+
}),
131+
)
132+
->willReturn(new Response('fragment_render_mock_rendered'));
133+
134+
$renderContentStrategy = $this->createRenderStrategy(
135+
$renderStrategyClass,
136+
[
137+
$fragmentRendererMock,
138+
],
139+
);
140+
141+
self::assertTrue($renderContentStrategy->supports($valueObjectMock));
142+
143+
self::assertSame(
144+
'fragment_render_mock_rendered',
145+
$renderContentStrategy->render($valueObjectMock, new RenderOptions([
146+
'method' => 'fragment_render_mock',
147+
'viewType' => 'awesome',
148+
'params' => $params,
149+
]))
150+
);
151+
}
100152
}

tests/lib/MVC/Symfony/Templating/RenderContentStrategyTest.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,15 @@ public function testMultipleFragmentRenderers(): void
9393
);
9494
}
9595

96+
public function testForwardParamOptionsToFragmentRenderer(): void
97+
{
98+
$this->forwardParamOptionsToFragmentRenderer(
99+
$this->createMock(FragmentRendererInterface::class),
100+
$this->createMock(Content::class),
101+
RenderContentStrategy::class,
102+
);
103+
}
104+
96105
public function testDuplicatedFragmentRenderers(): void
97106
{
98107
$renderContentStrategy = $this->createRenderStrategy(
@@ -127,19 +136,19 @@ public function testExpectedMethodRenderArgumentsFormat(): void
127136
->method('getName')
128137
->willReturn('method_b');
129138

130-
$controllerReferenceCallback = self::callback(function (ControllerReference $controllerReference): bool {
131-
$this->assertInstanceOf(ControllerReference::class, $controllerReference);
132-
$this->assertEquals('ibexa_content::viewAction', $controllerReference->controller);
133-
$this->assertSame([
139+
$controllerReferenceCallback = self::callback(static function (ControllerReference $controllerReference): bool {
140+
self::assertEquals('ibexa_content::viewAction', $controllerReference->controller);
141+
self::assertSame([
134142
'contentId' => 123,
135143
'viewType' => 'awesome',
144+
'params' => [],
136145
], $controllerReference->attributes);
137146

138147
return true;
139148
});
140149

141-
$requestCallback = self::callback(function (Request $request) use ($siteAccess, $content): bool {
142-
$this->assertSame('TEST/1.0', $request->headers->get('Surrogate-Capability'));
150+
$requestCallback = self::callback(static function (Request $request): bool {
151+
self::assertSame('TEST/1.0', $request->headers->get('Surrogate-Capability'));
143152

144153
return true;
145154
});

tests/lib/MVC/Symfony/Templating/RenderLocationStrategyTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,15 @@ public function testMultipleFragmentRenderers(): void
9393
);
9494
}
9595

96+
public function testForwardParamOptionsToFragmentRenderer(): void
97+
{
98+
$this->forwardParamOptionsToFragmentRenderer(
99+
$this->createMock(FragmentRendererInterface::class),
100+
$this->createMock(Location::class),
101+
RenderLocationStrategy::class,
102+
);
103+
}
104+
96105
public function testExpectedMethodRenderRequestFormat(): void
97106
{
98107
$request = new Request();
@@ -114,6 +123,7 @@ public function testExpectedMethodRenderRequestFormat(): void
114123
'contentId' => 234,
115124
'locationId' => 345,
116125
'viewType' => 'awesome',
126+
'params' => [],
117127
], $controllerReference->attributes);
118128

119129
return true;

0 commit comments

Comments
 (0)