-
Notifications
You must be signed in to change notification settings - Fork 17
IBX-3035 [Twig] Allowed passing parameters to ibexa render function
#674
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 4.6
Are you sure you want to change the base?
Changes from all commits
b8e7872
1c020fb
59bd8e6
edc5bf4
5695842
c73648c
d1b51a5
5490ae1
1a8644a
5e212bb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,70 @@ | ||||||
| <?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\Core\MVC\Symfony\Templating; | ||||||
|
|
||||||
| use Ibexa\Contracts\Core\MVC\Templating\RenderStrategy; | ||||||
| use Ibexa\Core\MVC\Symfony\Templating\RenderOptions; | ||||||
| use PHPUnit\Framework\TestCase; | ||||||
| use Symfony\Component\HttpFoundation\Response; | ||||||
| use Symfony\Component\HttpKernel\Controller\ControllerReference; | ||||||
|
|
||||||
| trait ForwardParamOptionsToFragmentRendererTrait | ||||||
| { | ||||||
| /** | ||||||
| * @param \Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface|\PHPUnit\Framework\MockObject\MockObject $fragmentRendererMock | ||||||
| * @param \Ibexa\Contracts\Core\Repository\Values\ValueObject|\PHPUnit\Framework\MockObject\MockObject $valueObjectMock | ||||||
| * @param class-string<RenderStrategy> $renderStrategyClass | ||||||
| */ | ||||||
| public function forwardParamOptionsToFragmentRenderer( | ||||||
| object $fragmentRendererMock, | ||||||
| object $valueObjectMock, | ||||||
| string $renderStrategyClass | ||||||
| ): void { | ||||||
| $params = [ | ||||||
| 'param1' => 'value1', | ||||||
| 'param2' => 'value2', | ||||||
| ]; | ||||||
|
|
||||||
| $fragmentRendererMock | ||||||
| ->method('getName') | ||||||
| ->willReturn('fragment_render_mock'); | ||||||
| $fragmentRendererMock->expects(self::once()) | ||||||
| ->method('render') | ||||||
| ->with( | ||||||
| self::callback(static function ($controllerReference) use ($params) { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| if (!$controllerReference instanceof ControllerReference) { | ||||||
| return false; | ||||||
| } | ||||||
|
|
||||||
| return $controllerReference->attributes['params'] === $params; | ||||||
| }), | ||||||
| self::anything(), | ||||||
| ) | ||||||
| ->willReturn(new Response('fragment_render_mock_rendered')); | ||||||
|
|
||||||
| $renderContentStrategy = self::createRenderStrategy( | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||
| $renderStrategyClass, | ||||||
| [ | ||||||
| $fragmentRendererMock, | ||||||
| ], | ||||||
| ); | ||||||
|
|
||||||
| /** @var \Ibexa\Contracts\Core\Repository\Values\ValueObject&\PHPUnit\Framework\MockObject\MockObject $valueObjectMock */ | ||||||
| TestCase::assertTrue($renderContentStrategy->supports($valueObjectMock)); | ||||||
|
|
||||||
| TestCase::assertSame( | ||||||
| 'fragment_render_mock_rendered', | ||||||
| $renderContentStrategy->render($valueObjectMock, new RenderOptions([ | ||||||
| 'method' => 'fragment_render_mock', | ||||||
| 'viewType' => 'awesome', | ||||||
| 'params' => $params, | ||||||
| ])) | ||||||
| ); | ||||||
| } | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -21,6 +21,8 @@ | |||||
|
|
||||||
| class RenderContentStrategyTest extends BaseRenderStrategyTest | ||||||
| { | ||||||
| use ForwardParamOptionsToFragmentRendererTrait; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it necessarily needs to be a Trait? Why not putting related code into |
||||||
|
|
||||||
| public function testUnsupportedValueObject(): void | ||||||
| { | ||||||
| $renderContentStrategy = $this->createRenderStrategy( | ||||||
|
|
@@ -32,7 +34,7 @@ public function testUnsupportedValueObject(): void | |||||
|
|
||||||
| $valueObject = new class() extends ValueObject { | ||||||
| }; | ||||||
| $this->assertFalse($renderContentStrategy->supports($valueObject)); | ||||||
| self::assertFalse($renderContentStrategy->supports($valueObject)); | ||||||
|
|
||||||
| $this->expectException(InvalidArgumentException::class); | ||||||
| $renderContentStrategy->render($valueObject, new RenderOptions()); | ||||||
|
|
@@ -49,9 +51,9 @@ public function testDefaultFragmentRenderer(): void | |||||
| ); | ||||||
|
|
||||||
| $contentMock = $this->createMock(Content::class); | ||||||
| $this->assertTrue($renderContentStrategy->supports($contentMock)); | ||||||
| self::assertTrue($renderContentStrategy->supports($contentMock)); | ||||||
|
|
||||||
| $this->assertSame( | ||||||
| self::assertSame( | ||||||
| 'inline_rendered', | ||||||
| $renderContentStrategy->render($contentMock, new RenderOptions()) | ||||||
| ); | ||||||
|
|
@@ -65,7 +67,7 @@ public function testUnknownFragmentRenderer(): void | |||||
| ); | ||||||
|
|
||||||
| $contentMock = $this->createMock(Content::class); | ||||||
| $this->assertTrue($renderContentStrategy->supports($contentMock)); | ||||||
| self::assertTrue($renderContentStrategy->supports($contentMock)); | ||||||
|
|
||||||
| $this->expectException(InvalidArgumentException::class); | ||||||
| $renderContentStrategy->render($contentMock, new RenderOptions()); | ||||||
|
|
@@ -83,16 +85,25 @@ public function testMultipleFragmentRenderers(): void | |||||
| ); | ||||||
|
|
||||||
| $contentMock = $this->createMock(Content::class); | ||||||
| $this->assertTrue($renderContentStrategy->supports($contentMock)); | ||||||
| self::assertTrue($renderContentStrategy->supports($contentMock)); | ||||||
|
|
||||||
| $this->assertSame( | ||||||
| self::assertSame( | ||||||
| 'method_b_rendered', | ||||||
| $renderContentStrategy->render($contentMock, new RenderOptions([ | ||||||
| 'method' => 'method_b', | ||||||
| ])) | ||||||
| ); | ||||||
| } | ||||||
|
|
||||||
| public function testForwardParamOptionsToFragmentRenderer(): void | ||||||
| { | ||||||
| $this->forwardParamOptionsToFragmentRenderer( | ||||||
| $this->createMock(FragmentRendererInterface::class), | ||||||
| $this->createMock(Content::class), | ||||||
| RenderContentStrategy::class, | ||||||
| ); | ||||||
| } | ||||||
|
|
||||||
| public function testDuplicatedFragmentRenderers(): void | ||||||
| { | ||||||
| $renderContentStrategy = $this->createRenderStrategy( | ||||||
|
|
@@ -127,19 +138,19 @@ public function testExpectedMethodRenderArgumentsFormat(): void | |||||
| ->method('getName') | ||||||
| ->willReturn('method_b'); | ||||||
|
|
||||||
| $controllerReferenceCallback = $this->callback(function (ControllerReference $controllerReference) { | ||||||
| $this->assertInstanceOf(ControllerReference::class, $controllerReference); | ||||||
| $this->assertEquals('ibexa_content::viewAction', $controllerReference->controller); | ||||||
| $this->assertSame([ | ||||||
| $controllerReferenceCallback = $this->callback(static function (ControllerReference $controllerReference) { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| self::assertEquals('ibexa_content::viewAction', $controllerReference->controller); | ||||||
| self::assertSame([ | ||||||
| 'contentId' => 123, | ||||||
| 'viewType' => 'awesome', | ||||||
| 'params' => [], | ||||||
| ], $controllerReference->attributes); | ||||||
|
|
||||||
| return true; | ||||||
| }); | ||||||
|
|
||||||
| $requestCallback = $this->callback(function (Request $request) use ($siteAccess, $content): bool { | ||||||
| $this->assertSame('TEST/1.0', $request->headers->get('Surrogate-Capability')); | ||||||
| $requestCallback = $this->callback(static function (Request $request): bool { | ||||||
| self::assertSame('TEST/1.0', $request->headers->get('Surrogate-Capability')); | ||||||
|
|
||||||
| return true; | ||||||
| }); | ||||||
|
|
@@ -162,7 +173,7 @@ public function testExpectedMethodRenderArgumentsFormat(): void | |||||
| $request | ||||||
| ); | ||||||
|
|
||||||
| $this->assertSame('some_rendered_content', $renderContentStrategy->render( | ||||||
| self::assertSame('some_rendered_content', $renderContentStrategy->render( | ||||||
| $content, | ||||||
| new RenderOptions([ | ||||||
| 'method' => 'method_b', | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.