diff --git a/src/Renderer/Renderer.php b/src/Renderer/Renderer.php
index 8bfeef1..54ce0d3 100644
--- a/src/Renderer/Renderer.php
+++ b/src/Renderer/Renderer.php
@@ -6,7 +6,8 @@
use SixtyEightPublishers\AmpClient\Exception\RendererException;
use SixtyEightPublishers\AmpClient\Renderer\Phtml\PhtmlRendererBridge;
-use SixtyEightPublishers\AmpClient\Response\ValueObject\Position;
+use SixtyEightPublishers\AmpClient\Request\ValueObject\Position as RequestPosition;
+use SixtyEightPublishers\AmpClient\Response\ValueObject\Position as ResponsePosition;
use Throwable;
use function get_class;
@@ -32,25 +33,25 @@ public static function create(?RendererBridgeInterface $rendererBridge = null):
);
}
- public function render(Position $position, array $elementAttributes = []): string
+ public function render(ResponsePosition $position, array $elementAttributes = []): string
{
try {
switch ($position->getDisplayType()) {
case null:
return $this->rendererBridge->renderNotFound($position, $elementAttributes);
- case Position::DisplayTypeMultiple:
+ case ResponsePosition::DisplayTypeMultiple:
return $this->rendererBridge->renderMultiple(
$position,
$this->bannersResolver->resolveMultiple($position),
$elementAttributes,
);
- case Position::DisplayTypeRandom:
+ case ResponsePosition::DisplayTypeRandom:
return $this->rendererBridge->renderRandom(
$position,
$this->bannersResolver->resolveRandom($position),
$elementAttributes,
);
- case Position::DisplayTypeSingle:
+ case ResponsePosition::DisplayTypeSingle:
default:
return $this->rendererBridge->renderSingle(
$position,
@@ -70,4 +71,21 @@ public function render(Position $position, array $elementAttributes = []): strin
);
}
}
+
+ public function renderClientSide(RequestPosition $position, array $elementAttributes = []): string
+ {
+ try {
+ return $this->rendererBridge->renderClientSide($position, $elementAttributes);
+ } catch (Throwable $e) {
+ if ($e instanceof RendererException) {
+ throw $e;
+ }
+
+ throw RendererException::rendererBridgeThrownError(
+ get_class($this->rendererBridge),
+ $position->getCode(),
+ $e,
+ );
+ }
+ }
}
diff --git a/src/Renderer/RendererBridgeInterface.php b/src/Renderer/RendererBridgeInterface.php
index 5f12254..5c6288f 100644
--- a/src/Renderer/RendererBridgeInterface.php
+++ b/src/Renderer/RendererBridgeInterface.php
@@ -4,8 +4,9 @@
namespace SixtyEightPublishers\AmpClient\Renderer;
+use SixtyEightPublishers\AmpClient\Request\ValueObject\Position as RequestPosition;
use SixtyEightPublishers\AmpClient\Response\ValueObject\Banner;
-use SixtyEightPublishers\AmpClient\Response\ValueObject\Position;
+use SixtyEightPublishers\AmpClient\Response\ValueObject\Position as ResponsePosition;
interface RendererBridgeInterface
{
@@ -14,21 +15,26 @@ public function overrideTemplates(Templates $templates): self;
/**
* @param array
$elementAttributes
*/
- public function renderNotFound(Position $position, array $elementAttributes = []): string;
+ public function renderNotFound(ResponsePosition $position, array $elementAttributes = []): string;
/**
* @param array $elementAttributes
*/
- public function renderSingle(Position $position, ?Banner $banner, array $elementAttributes = []): string;
+ public function renderSingle(ResponsePosition $position, ?Banner $banner, array $elementAttributes = []): string;
/**
* @param array $elementAttributes
*/
- public function renderRandom(Position $position, ?Banner $banner, array $elementAttributes = []): string;
+ public function renderRandom(ResponsePosition $position, ?Banner $banner, array $elementAttributes = []): string;
/**
* @param array $banners
* @param array $elementAttributes
*/
- public function renderMultiple(Position $position, array $banners, array $elementAttributes = []): string;
+ public function renderMultiple(ResponsePosition $position, array $banners, array $elementAttributes = []): string;
+
+ /**
+ * @param array $elementAttributes
+ */
+ public function renderClientSide(RequestPosition $position, array $elementAttributes = []): string;
}
diff --git a/src/Renderer/RendererInterface.php b/src/Renderer/RendererInterface.php
index b928ef4..d977788 100644
--- a/src/Renderer/RendererInterface.php
+++ b/src/Renderer/RendererInterface.php
@@ -5,7 +5,8 @@
namespace SixtyEightPublishers\AmpClient\Renderer;
use SixtyEightPublishers\AmpClient\Exception\RendererException;
-use SixtyEightPublishers\AmpClient\Response\ValueObject\Position;
+use SixtyEightPublishers\AmpClient\Request\ValueObject\Position as RequestPosition;
+use SixtyEightPublishers\AmpClient\Response\ValueObject\Position as ResponsePosition;
interface RendererInterface
{
@@ -14,5 +15,12 @@ interface RendererInterface
*
* @throws RendererException
*/
- public function render(Position $position, array $elementAttributes = []): string;
+ public function render(ResponsePosition $position, array $elementAttributes = []): string;
+
+ /**
+ * @param array $elementAttributes
+ *
+ * @throws RendererException
+ */
+ public function renderClientSide(RequestPosition $position, array $elementAttributes = []): string;
}
diff --git a/src/Renderer/Templates.php b/src/Renderer/Templates.php
index b40f489..7f350f1 100644
--- a/src/Renderer/Templates.php
+++ b/src/Renderer/Templates.php
@@ -9,17 +9,19 @@
final class Templates
{
- public const TemplateSingle = 'single';
- public const TemplateRandom = 'random';
- public const TemplateMultiple = 'multiple';
- public const TemplateNotFound = 'notFound';
+ public const Single = 'single';
+ public const Random = 'random';
+ public const Multiple = 'multiple';
+ public const NotFound = 'notFound';
+ public const ClientSide = 'clientSide';
/**
* @var array{
* single?: string,
* random?: string,
* multiple?: string,
- * 'notFound'?: string,
+ * notFound?: string,
+ * clientSide?: string,
* }
*/
private array $filesMap;
@@ -30,6 +32,7 @@ final class Templates
* random?: string,
* multiple?: string,
* notFound?: string,
+ * clientSide?: string,
* } $filesMap
*/
public function __construct(array $filesMap)
diff --git a/tests/Bridge/Latte/AmpClientLatteExtensionTest.php b/tests/Bridge/Latte/AmpClientLatteExtensionTest.php
index cf487e0..f5f5e24 100644
--- a/tests/Bridge/Latte/AmpClientLatteExtensionTest.php
+++ b/tests/Bridge/Latte/AmpClientLatteExtensionTest.php
@@ -116,6 +116,70 @@ public function latteTemplatesDataProvider(): array
],
2 => null,
],
+ 'Attributes as array' => [
+ 0 => <<<'LATTE'
+ {banner homepage.top, attributes: ['class' => 'test-class']}
+ LATTE,
+ 1 => [
+ 'homepage.top',
+ [
+ 'attributes' => ['class' => 'test-class'],
+ ],
+ ],
+ 2 => null,
+ ],
+ 'Attributes as variable' => [
+ 0 => <<<'LATTE'
+ {var $attributes = ['class' => 'test-class']}
+ {banner homepage.top, attributes: $attributes}
+ LATTE,
+ 1 => [
+ 'homepage.top',
+ [
+ 'attributes' => ['class' => 'test-class'],
+ ],
+ ],
+ 2 => null,
+ ],
+ 'Mode as string' => [
+ 0 => <<<'LATTE'
+ {banner homepage.top, mode: 'client_side'}
+ LATTE,
+ 1 => [
+ 'homepage.top',
+ [
+ 'mode' => 'client_side',
+ ],
+ ],
+ 2 => null,
+ ],
+ 'Mode as variable' => [
+ 0 => <<<'LATTE'
+ {var $mode = 'client_side'}
+ {banner homepage.top, mode: $mode}
+ LATTE,
+ 1 => [
+ 'homepage.top',
+ [
+ 'mode' => 'client_side',
+ ],
+ ],
+ 2 => null,
+ ],
+ 'Full featured' => [
+ 0 => <<<'LATTE'
+ {banner homepage.top, resources: [product => '123', category => ['123', '456']], attributes: ['class' => 'test-class'], mode: 'client_side'}
+ LATTE,
+ 1 => [
+ 'homepage.top',
+ [
+ 'resources' => ['product' => '123', 'category' => ['123', '456']],
+ 'attributes' => ['class' => 'test-class'],
+ 'mode' => 'client_side',
+ ],
+ ],
+ 2 => null,
+ ],
];
}
diff --git a/tests/Bridge/Latte/RendererProviderTest.php b/tests/Bridge/Latte/RendererProviderTest.php
index b91855b..dcfb660 100644
--- a/tests/Bridge/Latte/RendererProviderTest.php
+++ b/tests/Bridge/Latte/RendererProviderTest.php
@@ -4,6 +4,7 @@
namespace SixtyEightPublishers\AmpClient\Tests\Bridge\Latte;
+use InvalidArgumentException;
use Mockery;
use Psr\Log\LoggerInterface;
use SixtyEightPublishers\AmpClient\AmpClientInterface;
@@ -62,6 +63,41 @@ public function testInvokingDefaultInstanceWithoutResources(): void
Assert::same('', $provider(new stdClass(), 'homepage.top'));
}
+ public function testInvokingDefaultInstanceWithSameModeAsDefault(): void
+ {
+ $client = Mockery::mock(AmpClientInterface::class);
+ $renderer = Mockery::mock(RendererInterface::class);
+ $provider = new RendererProvider($client, $renderer);
+
+ $responsePosition = new ResponsePosition('1234', 'homepage.top', 'Homepage top', 0, ResponsePosition::DisplayTypeSingle, ResponsePosition::BreakpointTypeMin, []);
+ $response = new BannersResponse([
+ 'homepage.top' => $responsePosition,
+ ]);
+
+ $client
+ ->shouldReceive('fetchBanners')
+ ->once()
+ ->with(Mockery::type(BannersRequest::class))
+ ->andReturnUsing(static function (BannersRequest $request) use ($response): BannersResponse {
+ Assert::equal(
+ new BannersRequest([
+ new RequestPosition('homepage.top'),
+ ]),
+ $request,
+ );
+
+ return $response;
+ });
+
+ $renderer
+ ->shouldReceive('render')
+ ->once()
+ ->with($responsePosition, [])
+ ->andReturn('');
+
+ Assert::same('', $provider(new stdClass(), 'homepage.top', ['mode' => 'direct']));
+ }
+
public function testInvokingDefaultInstanceWithAttributes(): void
{
$client = Mockery::mock(AmpClientInterface::class);
@@ -360,6 +396,22 @@ public function testPositionsShouldBeQueuedAndReplacedInStringOutput(): void
$provider->setRenderingMode($renderingMode);
$renderingMode
+ ->shouldReceive('shouldBePositionRenderedClientSide')
+ ->once()
+ ->with(Mockery::type(RequestPosition::class))
+ ->andReturnUsing(static function (RequestPosition $position) use ($requestPosition1): bool {
+ Assert::equal($requestPosition1, $position);
+
+ return false;
+ })
+ ->shouldReceive('shouldBePositionRenderedClientSide')
+ ->once()
+ ->with(Mockery::type(RequestPosition::class))
+ ->andReturnUsing(static function (RequestPosition $position) use ($requestPosition2): bool {
+ Assert::equal($requestPosition2, $position);
+
+ return false;
+ })
->shouldReceive('shouldBePositionQueued')
->once()
->with(Mockery::type(RequestPosition::class), $globals)
@@ -436,6 +488,22 @@ public function testPositionsShouldBeQueuedAndReplacedInArrayOutput(): void
$provider->setRenderingMode($renderingMode);
$renderingMode
+ ->shouldReceive('shouldBePositionRenderedClientSide')
+ ->once()
+ ->with(Mockery::type(RequestPosition::class))
+ ->andReturnUsing(static function (RequestPosition $position) use ($requestPosition1): bool {
+ Assert::equal($requestPosition1, $position);
+
+ return false;
+ })
+ ->shouldReceive('shouldBePositionRenderedClientSide')
+ ->once()
+ ->with(Mockery::type(RequestPosition::class))
+ ->andReturnUsing(static function (RequestPosition $position) use ($requestPosition2): bool {
+ Assert::equal($requestPosition2, $position);
+
+ return false;
+ })
->shouldReceive('shouldBePositionQueued')
->once()
->with(Mockery::type(RequestPosition::class), $globals)
@@ -504,6 +572,94 @@ public function testPositionsShouldBeQueuedAndReplacedInArrayOutput(): void
);
}
+ public function testPositionShouldBeRenderedClientSide(): void
+ {
+ $client = Mockery::mock(AmpClientInterface::class);
+ $renderer = Mockery::mock(RendererInterface::class);
+ $clientSideRenderingMode = Mockery::mock(RenderingModeInterface::class);
+ $requestPosition = new RequestPosition('homepage.top');
+
+ $provider = new RendererProvider($client, $renderer);
+
+ $provider->setRenderingMode($clientSideRenderingMode);
+
+ $clientSideRenderingMode
+ ->shouldReceive('shouldBePositionRenderedClientSide')
+ ->once()
+ ->with(Mockery::type(RequestPosition::class))
+ ->andReturnUsing(static function (RequestPosition $position) use ($requestPosition): bool {
+ Assert::equal($requestPosition, $position);
+
+ return true;
+ });
+
+ $renderer
+ ->shouldReceive('renderClientSide')
+ ->once()
+ ->with(Mockery::type(RequestPosition::class), [])
+ ->andReturnUsing(static function (RequestPosition $position) use ($requestPosition): string {
+ Assert::equal($requestPosition, $position);
+
+ return '';
+ });
+
+ Assert::same('', $provider(new stdClass(), 'homepage.top'));
+ }
+
+ public function testPositionShouldBeRenderedClientSideWithAlternativeMode(): void
+ {
+ $client = Mockery::mock(AmpClientInterface::class);
+ $renderer = Mockery::mock(RendererInterface::class);
+ $clientSideRenderingMode = Mockery::mock(RenderingModeInterface::class);
+ $requestPosition = new RequestPosition('homepage.top');
+
+ $provider = new RendererProvider($client, $renderer);
+
+ $clientSideRenderingMode
+ ->shouldReceive('getName')
+ ->once()
+ ->withNoArgs()
+ ->andReturn('client_side');
+
+ $clientSideRenderingMode
+ ->shouldReceive('shouldBePositionRenderedClientSide')
+ ->once()
+ ->with(Mockery::type(RequestPosition::class))
+ ->andReturnUsing(static function (RequestPosition $position) use ($requestPosition): bool {
+ Assert::equal($requestPosition, $position);
+
+ return true;
+ });
+
+ $renderer
+ ->shouldReceive('renderClientSide')
+ ->once()
+ ->with(Mockery::type(RequestPosition::class), [])
+ ->andReturnUsing(static function (RequestPosition $position) use ($requestPosition): string {
+ Assert::equal($requestPosition, $position);
+
+ return '';
+ });
+
+ $provider->setAlternativeRenderingModes([$clientSideRenderingMode]);
+
+ Assert::same('', $provider(new stdClass(), 'homepage.top', ['mode' => 'client_side']));
+ }
+
+ public function testExceptionShouldBeThrownWhenProviderIsInvokedWithModeThatIsNotRegisteredBetweenAlternativeModes(): void
+ {
+ $client = Mockery::mock(AmpClientInterface::class);
+ $renderer = Mockery::mock(RendererInterface::class);
+
+ $provider = new RendererProvider($client, $renderer);
+
+ Assert::exception(
+ static fn () => $provider(new stdClass(), 'homepage.top', ['mode' => 'test']),
+ InvalidArgumentException::class,
+ 'Invalid value for option "mode". The value "test" is not registered between alternative rendering modes.',
+ );
+ }
+
protected function tearDown(): void
{
Mockery::close();
diff --git a/tests/Bridge/Latte/RenderingMode/ClientSideRenderingModeTest.php b/tests/Bridge/Latte/RenderingMode/ClientSideRenderingModeTest.php
new file mode 100644
index 0000000..70cdff5
--- /dev/null
+++ b/tests/Bridge/Latte/RenderingMode/ClientSideRenderingModeTest.php
@@ -0,0 +1,29 @@
+getName());
+ Assert::false($mode->supportsQueues());
+ Assert::true($mode->shouldBePositionRenderedClientSide($position));
+ Assert::false($mode->shouldBePositionQueued($position, (object) []));
+ }
+}
+
+(new ClientSideRenderingModeTest())->run();
diff --git a/tests/Bridge/Latte/RenderingMode/DirectRenderingModeTest.php b/tests/Bridge/Latte/RenderingMode/DirectRenderingModeTest.php
new file mode 100644
index 0000000..6c4f99f
--- /dev/null
+++ b/tests/Bridge/Latte/RenderingMode/DirectRenderingModeTest.php
@@ -0,0 +1,29 @@
+getName());
+ Assert::false($mode->supportsQueues());
+ Assert::false($mode->shouldBePositionRenderedClientSide($position));
+ Assert::false($mode->shouldBePositionQueued($position, (object) []));
+ }
+}
+
+(new DirectRenderingModeTest())->run();
diff --git a/tests/Bridge/Latte/RenderingMode/QueuedRenderingInPresenterContextModeTest.php b/tests/Bridge/Latte/RenderingMode/QueuedRenderingInPresenterContextModeTest.php
new file mode 100644
index 0000000..c36cdf6
--- /dev/null
+++ b/tests/Bridge/Latte/RenderingMode/QueuedRenderingInPresenterContextModeTest.php
@@ -0,0 +1,34 @@
+getName());
+ Assert::true($mode->supportsQueues());
+ Assert::false($mode->shouldBePositionRenderedClientSide($position));
+
+ Assert::false($mode->shouldBePositionQueued($position, (object) []));
+ Assert::true($mode->shouldBePositionQueued($position, (object) [
+ 'uiPresenter' => new class extends Presenter {},
+ ]));
+ }
+}
+
+(new QueuedRenderingInPresenterContextModeTest())->run();
diff --git a/tests/Bridge/Latte/RenderingMode/QueuedRenderingModeTest.php b/tests/Bridge/Latte/RenderingMode/QueuedRenderingModeTest.php
new file mode 100644
index 0000000..3831ab2
--- /dev/null
+++ b/tests/Bridge/Latte/RenderingMode/QueuedRenderingModeTest.php
@@ -0,0 +1,29 @@
+getName());
+ Assert::true($mode->supportsQueues());
+ Assert::false($mode->shouldBePositionRenderedClientSide($position));
+ Assert::true($mode->shouldBePositionQueued($position, (object) []));
+ }
+}
+
+(new QueuedRenderingModeTest())->run();
diff --git a/tests/Bridge/Nette/DI/AmpClientExtensionTest.php b/tests/Bridge/Nette/DI/AmpClientExtensionTest.php
index 55f6995..8f1a03b 100644
--- a/tests/Bridge/Nette/DI/AmpClientExtensionTest.php
+++ b/tests/Bridge/Nette/DI/AmpClientExtensionTest.php
@@ -137,10 +137,11 @@ public function testContainerWithRendererTemplates(): void
$templates = call_user_func(Closure::bind(static fn (): Templates => $rendererBridge->templates, null, PhtmlRendererBridge::class));
assert($templates instanceof Templates);
- Assert::same(__DIR__ . '/../../../resources/renderer/single/templates/single1.phtml', $templates->getTemplateFile(Templates::TemplateSingle));
- Assert::same(__DIR__ . '/../../../resources/renderer/random/templates/random1.phtml', $templates->getTemplateFile(Templates::TemplateRandom));
- Assert::same(__DIR__ . '/../../../resources/renderer/multiple/templates/multiple1.phtml', $templates->getTemplateFile(Templates::TemplateMultiple));
- Assert::same(__DIR__ . '/../../../resources/renderer/not-found/templates/not-found1.phtml', $templates->getTemplateFile(Templates::TemplateNotFound));
+ Assert::same(__DIR__ . '/../../../resources/renderer/single/templates/single1.phtml', $templates->getTemplateFile(Templates::Single));
+ Assert::same(__DIR__ . '/../../../resources/renderer/random/templates/random1.phtml', $templates->getTemplateFile(Templates::Random));
+ Assert::same(__DIR__ . '/../../../resources/renderer/multiple/templates/multiple1.phtml', $templates->getTemplateFile(Templates::Multiple));
+ Assert::same(__DIR__ . '/../../../resources/renderer/not-found/templates/not-found1.phtml', $templates->getTemplateFile(Templates::NotFound));
+ Assert::same(__DIR__ . '/../../../resources/renderer/client-side/templates/client-side1.phtml', $templates->getTemplateFile(Templates::ClientSide));
}
public function testContainerWithMethodOption(): void
diff --git a/tests/Bridge/Nette/DI/AmpClientLatteExtensionTest.php b/tests/Bridge/Nette/DI/AmpClientLatteExtensionTest.php
index 5bbf2be..123cda2 100644
--- a/tests/Bridge/Nette/DI/AmpClientLatteExtensionTest.php
+++ b/tests/Bridge/Nette/DI/AmpClientLatteExtensionTest.php
@@ -12,6 +12,7 @@
use RuntimeException;
use SixtyEightPublishers\AmpClient\Bridge\Latte\Event\ConfigureClientEventHandlerInterface;
use SixtyEightPublishers\AmpClient\Bridge\Latte\RendererProvider;
+use SixtyEightPublishers\AmpClient\Bridge\Latte\RenderingMode\ClientSideRenderingMode;
use SixtyEightPublishers\AmpClient\Bridge\Latte\RenderingMode\DirectRenderingMode;
use SixtyEightPublishers\AmpClient\Bridge\Latte\RenderingMode\QueuedRenderingInPresenterContextMode;
use SixtyEightPublishers\AmpClient\Bridge\Latte\RenderingMode\QueuedRenderingMode;
@@ -53,9 +54,6 @@ public function testContainerWithMinimalConfiguration(): void
$container,
false,
new DirectRenderingMode(),
- [
- ConfigureClientEventHandlerInterface::class => [],
- ],
);
}
@@ -67,9 +65,6 @@ public function testContainerWithMinimalConfigurationAndApplicationEnabled(): vo
$container,
false,
new DirectRenderingMode(),
- [
- ConfigureClientEventHandlerInterface::class => [],
- ],
);
$this->assertApplicationHandlerAttached($container);
@@ -83,9 +78,6 @@ public function testContainerWithDebugMode(): void
$container,
true,
new DirectRenderingMode(),
- [
- ConfigureClientEventHandlerInterface::class => [],
- ],
);
}
@@ -97,9 +89,6 @@ public function testContainerWithDirectRenderingModeAsString(): void
$container,
false,
new DirectRenderingMode(),
- [
- ConfigureClientEventHandlerInterface::class => [],
- ],
);
}
@@ -111,9 +100,6 @@ public function testContainerWithDirectRenderingModeAsClassname(): void
$container,
false,
new DirectRenderingMode(),
- [
- ConfigureClientEventHandlerInterface::class => [],
- ],
);
}
@@ -125,9 +111,6 @@ public function testContainerWithDirectRenderingModeAsStatement(): void
$container,
false,
new DirectRenderingMode(),
- [
- ConfigureClientEventHandlerInterface::class => [],
- ],
);
}
@@ -139,9 +122,6 @@ public function testContainerWithQueuedRenderingModeAsString(): void
$container,
false,
new QueuedRenderingMode(),
- [
- ConfigureClientEventHandlerInterface::class => [],
- ],
);
}
@@ -153,9 +133,6 @@ public function testContainerWithQueuedRenderingModeAsClassname(): void
$container,
false,
new QueuedRenderingMode(),
- [
- ConfigureClientEventHandlerInterface::class => [],
- ],
);
}
@@ -167,9 +144,6 @@ public function testContainerWithQueuedRenderingModeAsStatement(): void
$container,
false,
new QueuedRenderingMode(),
- [
- ConfigureClientEventHandlerInterface::class => [],
- ],
);
}
@@ -181,9 +155,6 @@ public function testContainerWithQueuedRenderingInPresenterModeModeAsString(): v
$container,
false,
new QueuedRenderingInPresenterContextMode(),
- [
- ConfigureClientEventHandlerInterface::class => [],
- ],
);
}
@@ -195,9 +166,6 @@ public function testContainerWithQueuedRenderingInPresenterModeModeAsClassname()
$container,
false,
new QueuedRenderingInPresenterContextMode(),
- [
- ConfigureClientEventHandlerInterface::class => [],
- ],
);
}
@@ -209,8 +177,54 @@ public function testContainerWithQueuedRenderingInPresenterModeModeAsStatement()
$container,
false,
new QueuedRenderingInPresenterContextMode(),
+ );
+ }
+
+ public function testContainerWithClientSideRenderingInPresenterModeModeAsString(): void
+ {
+ $container = ContainerFactory::create(__DIR__ . '/Config/AmpClientLatteExtension/config.withClientSideRenderingModeAsString.neon', ['latte']);
+
+ $this->assertLatteExtension(
+ $container,
+ false,
+ new ClientSideRenderingMode(),
+ );
+ }
+
+ public function testContainerWithClientSideRenderingInPresenterModeModeAsClassname(): void
+ {
+ $container = ContainerFactory::create(__DIR__ . '/Config/AmpClientLatteExtension/config.withClientSideRenderingModeAsClassname.neon', ['latte']);
+
+ $this->assertLatteExtension(
+ $container,
+ false,
+ new ClientSideRenderingMode(),
+ );
+ }
+
+ public function testContainerWithClientSideRenderingInPresenterModeModeAsStatement(): void
+ {
+ $container = ContainerFactory::create(__DIR__ . '/Config/AmpClientLatteExtension/config.withClientSideRenderingModeAsStatement.neon', ['latte']);
+
+ $this->assertLatteExtension(
+ $container,
+ false,
+ new ClientSideRenderingMode(),
+ );
+ }
+
+ public function testContainerWithAlternativeRenderingModes(): void
+ {
+ $container = ContainerFactory::create(__DIR__ . '/Config/AmpClientLatteExtension/config.withAlternativeRenderingModes.neon', ['latte']);
+
+ $this->assertLatteExtension(
+ $container,
+ false,
+ new DirectRenderingMode(),
[
- ConfigureClientEventHandlerInterface::class => [],
+ ClientSideRenderingMode::Name => new ClientSideRenderingMode(),
+ QueuedRenderingMode::Name => new QueuedRenderingMode(),
+ QueuedRenderingInPresenterContextMode::Name => new QueuedRenderingInPresenterContextMode(),
],
);
}
@@ -223,6 +237,7 @@ public function testContainerWithConfigureClientEventHandler(): void
$container,
false,
new DirectRenderingMode(),
+ [],
[
ConfigureClientEventHandlerInterface::class => [
new ConfigureClientEventHandlerFixture(null),
@@ -231,8 +246,19 @@ public function testContainerWithConfigureClientEventHandler(): void
);
}
- private function assertLatteExtension(Container $container, bool $debugMode, RenderingModeInterface $renderingMode, array $eventHandlers): void
- {
+ private function assertLatteExtension(
+ Container $container,
+ bool $debugMode,
+ RenderingModeInterface $renderingMode,
+ array $alternativeRenderingModes = [],
+ ?array $eventHandlers = null
+ ): void {
+ if (null === $eventHandlers) {
+ $eventHandlers = [
+ ConfigureClientEventHandlerInterface::class => [],
+ ];
+ }
+
$latteFactory = $container->getByType(class_exists(LatteFactory::class) ? LatteFactory::class : ILatteFactory::class);
$latte = $latteFactory->create();
$providers = $latte->getProviders();
@@ -244,9 +270,10 @@ private function assertLatteExtension(Container $container, bool $debugMode, Ren
Assert::type(RendererProvider::class, $provider);
call_user_func(Closure::bind(
- static function () use ($provider, $debugMode, $renderingMode, $eventHandlers): void {
+ static function () use ($provider, $debugMode, $renderingMode, $alternativeRenderingModes, $eventHandlers): void {
Assert::same($debugMode, $provider->debugMode);
Assert::equal($renderingMode, $provider->renderingMode);
+ Assert::equal($alternativeRenderingModes, $provider->alternativeRenderingModes);
Assert::equal($eventHandlers, $provider->eventHandlers);
},
null,
diff --git a/tests/Bridge/Nette/DI/Config/AmpClientExtension/config.withRendererTemplates.neon b/tests/Bridge/Nette/DI/Config/AmpClientExtension/config.withRendererTemplates.neon
index c58b89e..c20d0f6 100644
--- a/tests/Bridge/Nette/DI/Config/AmpClientExtension/config.withRendererTemplates.neon
+++ b/tests/Bridge/Nette/DI/Config/AmpClientExtension/config.withRendererTemplates.neon
@@ -11,3 +11,4 @@ amp_client:
random: %resources%/renderer/random/templates/random1.phtml
multiple: %resources%/renderer/multiple/templates/multiple1.phtml
not_found: %resources%/renderer/not-found/templates/not-found1.phtml
+ client_side: %resources%/renderer/client-side/templates/client-side1.phtml
diff --git a/tests/Bridge/Nette/DI/Config/AmpClientLatteExtension/config.withAlternativeRenderingModes.neon b/tests/Bridge/Nette/DI/Config/AmpClientLatteExtension/config.withAlternativeRenderingModes.neon
new file mode 100644
index 0000000..13d52f5
--- /dev/null
+++ b/tests/Bridge/Nette/DI/Config/AmpClientLatteExtension/config.withAlternativeRenderingModes.neon
@@ -0,0 +1,13 @@
+extensions:
+ amp_client: SixtyEightPublishers\AmpClient\Bridge\Nette\DI\AmpClientExtension
+ amp_client.latte: SixtyEightPublishers\AmpClient\Bridge\Nette\DI\AmpClientLatteExtension
+
+amp_client:
+ url: https://www.example.com
+ channel: test
+
+amp_client.latte:
+ alternative_rendering_modes:
+ - client_side
+ - SixtyEightPublishers\AmpClient\Bridge\Latte\RenderingMode\QueuedRenderingMode
+ - SixtyEightPublishers\AmpClient\Bridge\Latte\RenderingMode\QueuedRenderingInPresenterContextMode()
diff --git a/tests/Bridge/Nette/DI/Config/AmpClientLatteExtension/config.withClientSideRenderingModeAsClassname.neon b/tests/Bridge/Nette/DI/Config/AmpClientLatteExtension/config.withClientSideRenderingModeAsClassname.neon
new file mode 100644
index 0000000..478f947
--- /dev/null
+++ b/tests/Bridge/Nette/DI/Config/AmpClientLatteExtension/config.withClientSideRenderingModeAsClassname.neon
@@ -0,0 +1,10 @@
+extensions:
+ amp_client: SixtyEightPublishers\AmpClient\Bridge\Nette\DI\AmpClientExtension
+ amp_client.latte: SixtyEightPublishers\AmpClient\Bridge\Nette\DI\AmpClientLatteExtension
+
+amp_client:
+ url: https://www.example.com
+ channel: test
+
+amp_client.latte:
+ rendering_mode: SixtyEightPublishers\AmpClient\Bridge\Latte\RenderingMode\ClientSideRenderingMode
diff --git a/tests/Bridge/Nette/DI/Config/AmpClientLatteExtension/config.withClientSideRenderingModeAsStatement.neon b/tests/Bridge/Nette/DI/Config/AmpClientLatteExtension/config.withClientSideRenderingModeAsStatement.neon
new file mode 100644
index 0000000..bd83df6
--- /dev/null
+++ b/tests/Bridge/Nette/DI/Config/AmpClientLatteExtension/config.withClientSideRenderingModeAsStatement.neon
@@ -0,0 +1,10 @@
+extensions:
+ amp_client: SixtyEightPublishers\AmpClient\Bridge\Nette\DI\AmpClientExtension
+ amp_client.latte: SixtyEightPublishers\AmpClient\Bridge\Nette\DI\AmpClientLatteExtension
+
+amp_client:
+ url: https://www.example.com
+ channel: test
+
+amp_client.latte:
+ rendering_mode: SixtyEightPublishers\AmpClient\Bridge\Latte\RenderingMode\ClientSideRenderingMode()
diff --git a/tests/Bridge/Nette/DI/Config/AmpClientLatteExtension/config.withClientSideRenderingModeAsString.neon b/tests/Bridge/Nette/DI/Config/AmpClientLatteExtension/config.withClientSideRenderingModeAsString.neon
new file mode 100644
index 0000000..4d6416c
--- /dev/null
+++ b/tests/Bridge/Nette/DI/Config/AmpClientLatteExtension/config.withClientSideRenderingModeAsString.neon
@@ -0,0 +1,10 @@
+extensions:
+ amp_client: SixtyEightPublishers\AmpClient\Bridge\Nette\DI\AmpClientExtension
+ amp_client.latte: SixtyEightPublishers\AmpClient\Bridge\Nette\DI\AmpClientLatteExtension
+
+amp_client:
+ url: https://www.example.com
+ channel: test
+
+amp_client.latte:
+ rendering_mode: client_side
diff --git a/tests/Renderer/Latte/LatteRendererBridgeTest.php b/tests/Renderer/Latte/LatteRendererBridgeTest.php
index 251524f..8a81229 100644
--- a/tests/Renderer/Latte/LatteRendererBridgeTest.php
+++ b/tests/Renderer/Latte/LatteRendererBridgeTest.php
@@ -8,8 +8,9 @@
use Latte\Engine;
use SixtyEightPublishers\AmpClient\Renderer\Latte\LatteRendererBridge;
use SixtyEightPublishers\AmpClient\Renderer\Templates;
+use SixtyEightPublishers\AmpClient\Request\ValueObject\Position as RequestPosition;
use SixtyEightPublishers\AmpClient\Response\ValueObject\Banner;
-use SixtyEightPublishers\AmpClient\Response\ValueObject\Position;
+use SixtyEightPublishers\AmpClient\Response\ValueObject\Position as ResponsePosition;
use SixtyEightPublishers\AmpClient\Tests\Renderer\AssertHtml;
use Tester\Assert;
use Tester\TestCase;
@@ -23,7 +24,7 @@ public function testTemplatesShouldBeOverridden(): void
{
$renderer = $this->createRendererBridge();
$modifiedRenderer = $renderer->overrideTemplates(new Templates([
- Templates::TemplateSingle => '/path/to/file',
+ Templates::Single => '/path/to/file',
]));
$originalTemplates = call_user_func(Closure::bind(static fn () => $renderer->templates, null, LatteRendererBridge::class));
@@ -37,7 +38,7 @@ public function testTemplatesShouldBeOverridden(): void
* @dataProvider notFoundTemplateDataProvider
*/
public function testNotFoundTemplateRendering(
- Position $position,
+ ResponsePosition $position,
array $elementAttributes,
string $expectationFile
): void {
@@ -50,7 +51,7 @@ public function testNotFoundTemplateRendering(
* @dataProvider singleTemplateDataProvider
*/
public function testSingleTemplateRendering(
- Position $position,
+ ResponsePosition $position,
?Banner $banner,
array $elementAttributes,
string $expectationFile
@@ -64,7 +65,7 @@ public function testSingleTemplateRendering(
* @dataProvider randomTemplateDataProvider
*/
public function testRandomTemplateRendering(
- Position $position,
+ ResponsePosition $position,
?Banner $banner,
array $elementAttributes,
string $expectationFile
@@ -78,7 +79,7 @@ public function testRandomTemplateRendering(
* @dataProvider multipleTemplateDataProvider
* */
public function testMultipleTemplateRendering(
- Position $position,
+ ResponsePosition $position,
array $banners,
array $elementAttributes,
string $expectationFile
@@ -88,6 +89,19 @@ public function testMultipleTemplateRendering(
AssertHtml::assert($expectationFile, $renderer->renderMultiple($position, $banners, $elementAttributes));
}
+ /**
+ * @dataProvider clientSideTemplateDataProvider
+ */
+ public function testClientSideTemplateRendering(
+ RequestPosition $position,
+ array $elementAttributes,
+ string $expectationFile
+ ): void {
+ $renderer = $this->createRendererBridge();
+
+ AssertHtml::assert($expectationFile, $renderer->renderClientSide($position, $elementAttributes));
+ }
+
public function notFoundTemplateDataProvider(): array
{
return require __DIR__ . '/../../resources/renderer/not-found/data-provider.php';
@@ -108,6 +122,11 @@ public function multipleTemplateDataProvider(): array
return require __DIR__ . '/../../resources/renderer/multiple/data-provider.php';
}
+ public function clientSideTemplateDataProvider(): array
+ {
+ return require __DIR__ . '/../../resources/renderer/client-side/data-provider.php';
+ }
+
private function createRendererBridge(): LatteRendererBridge
{
return LatteRendererBridge::fromEngine(new Engine());
diff --git a/tests/Renderer/Phtml/PhtmlRendererBridgeTest.php b/tests/Renderer/Phtml/PhtmlRendererBridgeTest.php
index 593dbfc..2c70a31 100644
--- a/tests/Renderer/Phtml/PhtmlRendererBridgeTest.php
+++ b/tests/Renderer/Phtml/PhtmlRendererBridgeTest.php
@@ -7,8 +7,9 @@
use Closure;
use SixtyEightPublishers\AmpClient\Renderer\Phtml\PhtmlRendererBridge;
use SixtyEightPublishers\AmpClient\Renderer\Templates;
+use SixtyEightPublishers\AmpClient\Request\ValueObject\Position as RequestPosition;
use SixtyEightPublishers\AmpClient\Response\ValueObject\Banner;
-use SixtyEightPublishers\AmpClient\Response\ValueObject\Position;
+use SixtyEightPublishers\AmpClient\Response\ValueObject\Position as ResponsePosition;
use SixtyEightPublishers\AmpClient\Tests\Renderer\AssertHtml;
use Tester\Assert;
use Tester\TestCase;
@@ -22,7 +23,7 @@ public function testTemplatesShouldBeOverridden(): void
{
$renderer = new PhtmlRendererBridge();
$modifiedRenderer = $renderer->overrideTemplates(new Templates([
- Templates::TemplateSingle => '/path/to/file',
+ Templates::Single => '/path/to/file',
]));
$originalTemplates = call_user_func(Closure::bind(static fn () => $renderer->templates, null, PhtmlRendererBridge::class));
@@ -36,7 +37,7 @@ public function testTemplatesShouldBeOverridden(): void
* @dataProvider notFoundTemplateDataProvider
*/
public function testNotFoundTemplateRendering(
- Position $position,
+ ResponsePosition $position,
array $elementAttributes,
string $expectationFile
): void {
@@ -49,7 +50,7 @@ public function testNotFoundTemplateRendering(
* @dataProvider singleTemplateDataProvider
*/
public function testSingleTemplateRendering(
- Position $position,
+ ResponsePosition $position,
?Banner $banner,
array $elementAttributes,
string $expectationFile
@@ -63,7 +64,7 @@ public function testSingleTemplateRendering(
* @dataProvider randomTemplateDataProvider
*/
public function testRandomTemplateRendering(
- Position $position,
+ ResponsePosition $position,
?Banner $banner,
array $elementAttributes,
string $expectationFile
@@ -77,7 +78,7 @@ public function testRandomTemplateRendering(
* @dataProvider multipleTemplateDataProvider
*/
public function testMultipleTemplateRendering(
- Position $position,
+ ResponsePosition $position,
array $banners,
array $elementAttributes,
string $expectationFile
@@ -87,6 +88,19 @@ public function testMultipleTemplateRendering(
AssertHtml::assert($expectationFile, $renderer->renderMultiple($position, $banners, $elementAttributes));
}
+ /**
+ * @dataProvider clientSideTemplateDataProvider
+ */
+ public function testClientSideTemplateRendering(
+ RequestPosition $position,
+ array $elementAttributes,
+ string $expectationFile
+ ): void {
+ $renderer = new PhtmlRendererBridge();
+
+ AssertHtml::assert($expectationFile, $renderer->renderClientSide($position, $elementAttributes));
+ }
+
public function notFoundTemplateDataProvider(): array
{
return require __DIR__ . '/../../resources/renderer/not-found/data-provider.php';
@@ -106,6 +120,11 @@ public function multipleTemplateDataProvider(): array
{
return require __DIR__ . '/../../resources/renderer/multiple/data-provider.php';
}
+
+ public function clientSideTemplateDataProvider(): array
+ {
+ return require __DIR__ . '/../../resources/renderer/client-side/data-provider.php';
+ }
}
(new PhtmlRendererBridgeTest())->run();
diff --git a/tests/Renderer/RendererTest.php b/tests/Renderer/RendererTest.php
index 5ed981c..6bf4e3a 100644
--- a/tests/Renderer/RendererTest.php
+++ b/tests/Renderer/RendererTest.php
@@ -13,8 +13,10 @@
use SixtyEightPublishers\AmpClient\Renderer\Phtml\PhtmlRendererBridge;
use SixtyEightPublishers\AmpClient\Renderer\Renderer;
use SixtyEightPublishers\AmpClient\Renderer\RendererBridgeInterface;
+use SixtyEightPublishers\AmpClient\Request\ValueObject\BannerResource;
+use SixtyEightPublishers\AmpClient\Request\ValueObject\Position as RequestPosition;
use SixtyEightPublishers\AmpClient\Response\ValueObject\Banner;
-use SixtyEightPublishers\AmpClient\Response\ValueObject\Position;
+use SixtyEightPublishers\AmpClient\Response\ValueObject\Position as ResponsePosition;
use Tester\Assert;
use Tester\TestCase;
use function call_user_func;
@@ -44,7 +46,7 @@ public function testNotFoundTemplateShouldBeRendered(): void
$rendererBridge = Mockery::mock(RendererBridgeInterface::class);
$renderer = new Renderer($bannersResolver, $rendererBridge);
- $position = new Position(null, 'homepage.top', null, 0, null, Position::BreakpointTypeMin, []);
+ $position = new ResponsePosition(null, 'homepage.top', null, 0, null, ResponsePosition::BreakpointTypeMin, []);
$rendererBridge
->shouldReceive('renderNotFound')
@@ -62,7 +64,7 @@ public function testSingleTemplateShouldBeRendered(): void
$renderer = new Renderer($bannersResolver, $rendererBridge);
$banner = new Banner('1234', 'Main', 0, null, null, null, []);
- $position = new Position('1234', 'homepage.top', 'Homepage top', 0, Position::DisplayTypeSingle, Position::BreakpointTypeMin, [$banner]);
+ $position = new ResponsePosition('1234', 'homepage.top', 'Homepage top', 0, ResponsePosition::DisplayTypeSingle, ResponsePosition::BreakpointTypeMin, [$banner]);
$bannersResolver
->shouldReceive('resolveSingle')
@@ -86,7 +88,7 @@ public function testRandomTemplateShouldBeRendered(): void
$renderer = new Renderer($bannersResolver, $rendererBridge);
$banner = new Banner('1234', 'Main', 0, null, null, null, []);
- $position = new Position('1234', 'homepage.top', 'Homepage top', 0, Position::DisplayTypeRandom, Position::BreakpointTypeMin, [$banner]);
+ $position = new ResponsePosition('1234', 'homepage.top', 'Homepage top', 0, ResponsePosition::DisplayTypeRandom, ResponsePosition::BreakpointTypeMin, [$banner]);
$bannersResolver
->shouldReceive('resolveRandom')
@@ -113,7 +115,7 @@ public function testMultipleTemplateShouldBeRendered(): void
new Banner('1234', 'Main', 0, null, null, null, []),
new Banner('1235', 'Secondary', 0, null, null, null, []),
];
- $position = new Position('1234', 'homepage.top', 'Homepage top', 0, Position::DisplayTypeMultiple, Position::BreakpointTypeMin, $banners);
+ $position = new ResponsePosition('1234', 'homepage.top', 'Homepage top', 0, ResponsePosition::DisplayTypeMultiple, ResponsePosition::BreakpointTypeMin, $banners);
$bannersResolver
->shouldReceive('resolveMultiple')
@@ -130,13 +132,32 @@ public function testMultipleTemplateShouldBeRendered(): void
Assert::same('multiple', $renderer->render($position));
}
- public function testRendererExceptionShouldBeThrownWhenBridgeThrowsTheException(): void
+ public function testClientSideTemplateShouldBeRendered(): void
{
$bannersResolver = Mockery::mock(BannersResolverInterface::class);
$rendererBridge = Mockery::mock(RendererBridgeInterface::class);
$renderer = new Renderer($bannersResolver, $rendererBridge);
- $position = new Position(null, 'homepage.top', null, 0, null, Position::BreakpointTypeMin, []);
+ $position = new RequestPosition('homepage.top', [
+ new BannerResource('role', 'vip'),
+ ]);
+
+ $rendererBridge
+ ->shouldReceive('renderClientSide')
+ ->once()
+ ->with($position, [])
+ ->andReturn('client-side');
+
+ Assert::same('client-side', $renderer->renderClientSide($position));
+ }
+
+ public function testRendererExceptionShouldBeThrownOnRenderingWhenBridgeThrowsTheException(): void
+ {
+ $bannersResolver = Mockery::mock(BannersResolverInterface::class);
+ $rendererBridge = Mockery::mock(RendererBridgeInterface::class);
+ $renderer = new Renderer($bannersResolver, $rendererBridge);
+
+ $position = new ResponsePosition(null, 'homepage.top', null, 0, null, ResponsePosition::BreakpointTypeMin, []);
$rendererBridge
->shouldReceive('renderNotFound')
@@ -151,13 +172,34 @@ public function testRendererExceptionShouldBeThrownWhenBridgeThrowsTheException(
);
}
- public function testRendererExceptionShouldBeThrownWhenBridgeThrowsAnyException(): void
+ public function testRendererExceptionShouldBeThrownOnClientSideRenderingWhenBridgeThrowsTheException(): void
+ {
+ $bannersResolver = Mockery::mock(BannersResolverInterface::class);
+ $rendererBridge = Mockery::mock(RendererBridgeInterface::class);
+ $renderer = new Renderer($bannersResolver, $rendererBridge);
+
+ $position = new RequestPosition('homepage.top');
+
+ $rendererBridge
+ ->shouldReceive('renderClientSide')
+ ->once()
+ ->with($position, [])
+ ->andThrow(new RendererException('Test exception'));
+
+ Assert::exception(
+ static fn () => $renderer->renderClientSide($position),
+ RendererException::class,
+ 'Test exception',
+ );
+ }
+
+ public function testRendererExceptionShouldBeThrownOnRenderingWhenBridgeThrowsAnyException(): void
{
$bannersResolver = Mockery::mock(BannersResolverInterface::class);
$rendererBridge = Mockery::mock(RendererBridgeInterface::class);
$renderer = new Renderer($bannersResolver, $rendererBridge);
- $position = new Position(null, 'homepage.top', null, 0, null, Position::BreakpointTypeMin, []);
+ $position = new ResponsePosition(null, 'homepage.top', null, 0, null, ResponsePosition::BreakpointTypeMin, []);
$rendererBridge
->shouldReceive('renderNotFound')
@@ -172,6 +214,27 @@ public function testRendererExceptionShouldBeThrownWhenBridgeThrowsAnyException(
);
}
+ public function testRendererExceptionShouldBeThrownOnClientSideRenderingWhenBridgeThrowsAnyException(): void
+ {
+ $bannersResolver = Mockery::mock(BannersResolverInterface::class);
+ $rendererBridge = Mockery::mock(RendererBridgeInterface::class);
+ $renderer = new Renderer($bannersResolver, $rendererBridge);
+
+ $position = new RequestPosition('homepage.top');
+
+ $rendererBridge
+ ->shouldReceive('renderClientSide')
+ ->once()
+ ->with($position, [])
+ ->andThrow(new Exception('Test exception'));
+
+ Assert::exception(
+ static fn () => $renderer->renderClientSide($position),
+ RendererException::class,
+ 'Renderer bridge of type %A% thrown an exception while rendering a position homepage.top: Test exception',
+ );
+ }
+
protected function tearDown(): void
{
Mockery::close();
diff --git a/tests/Renderer/TemplatesTest.php b/tests/Renderer/TemplatesTest.php
index d549e42..ec1c4cb 100644
--- a/tests/Renderer/TemplatesTest.php
+++ b/tests/Renderer/TemplatesTest.php
@@ -17,11 +17,11 @@ final class TemplatesTest extends TestCase
public function testExceptionShouldBeThrownWhenTemplateFileNotFound(): void
{
$templates = new Templates([
- Templates::TemplateSingle => __DIR__ . '/path/to/missing-file.phtml',
+ Templates::Single => __DIR__ . '/path/to/missing-file.phtml',
]);
Assert::exception(
- static fn () => $templates->getTemplateFile(Templates::TemplateSingle),
+ static fn () => $templates->getTemplateFile(Templates::Single),
RendererException::class,
'Template file "%A%/path/to/missing-file.phtml" not found.',
);
@@ -30,11 +30,11 @@ public function testExceptionShouldBeThrownWhenTemplateFileNotFound(): void
public function testExceptionShouldBeThrownWhenTemplateFileNotDefined(): void
{
$templates = new Templates([
- Templates::TemplateSingle => __DIR__ . '/path/to/missing-file.phtml',
+ Templates::Single => __DIR__ . '/path/to/missing-file.phtml',
]);
Assert::exception(
- static fn () => $templates->getTemplateFile(Templates::TemplateMultiple),
+ static fn () => $templates->getTemplateFile(Templates::Multiple),
RendererException::class,
'Template file of type "multiple" not defined.',
);
@@ -44,10 +44,10 @@ public function testTemplateFileShouldBeReturned(): void
{
$filename = realpath(__DIR__ . '/../resources/renderer/not-found/templates/not-found1.phtml');
$templates = new Templates([
- Templates::TemplateNotFound => $filename,
+ Templates::NotFound => $filename,
]);
- Assert::same($filename, $templates->getTemplateFile(Templates::TemplateNotFound));
+ Assert::same($filename, $templates->getTemplateFile(Templates::NotFound));
}
public function testTemplatesShouldBeOverridden(): void
@@ -58,21 +58,21 @@ public function testTemplatesShouldBeOverridden(): void
$notFoundOverridden = realpath(__DIR__ . '/../resources/renderer/not-found/templates/not-found2.phtml');
$templates = new Templates([
- Templates::TemplateNotFound => $notFound,
- Templates::TemplateSingle => $single,
+ Templates::NotFound => $notFound,
+ Templates::Single => $single,
]);
$overriddenTemplates = $templates->override(new Templates([
- Templates::TemplateNotFound => $notFoundOverridden,
+ Templates::NotFound => $notFoundOverridden,
]));
Assert::notSame($templates, $overriddenTemplates);
- Assert::same($notFound, $templates->getTemplateFile(Templates::TemplateNotFound));
- Assert::same($single, $templates->getTemplateFile(Templates::TemplateSingle));
+ Assert::same($notFound, $templates->getTemplateFile(Templates::NotFound));
+ Assert::same($single, $templates->getTemplateFile(Templates::Single));
- Assert::same($notFoundOverridden, $overriddenTemplates->getTemplateFile(Templates::TemplateNotFound));
- Assert::same($single, $overriddenTemplates->getTemplateFile(Templates::TemplateSingle));
+ Assert::same($notFoundOverridden, $overriddenTemplates->getTemplateFile(Templates::NotFound));
+ Assert::same($single, $overriddenTemplates->getTemplateFile(Templates::Single));
}
}
diff --git a/tests/resources/renderer/client-side/data-provider.php b/tests/resources/renderer/client-side/data-provider.php
new file mode 100644
index 0000000..4f792d3
--- /dev/null
+++ b/tests/resources/renderer/client-side/data-provider.php
@@ -0,0 +1,45 @@
+ [
+ new Position('homepage.top'),
+ [],
+ __DIR__ . '/positionOnly.html',
+ ],
+ 'With resources' => [
+ new Position('homepage.top', [
+ new BannerResource('role', 'vip'),
+ new BannerResource('category', [123, 456]),
+ ]),
+ [],
+ __DIR__ . '/withResources.html',
+ ],
+ 'With attributes' => [
+ new Position('homepage.top'),
+ [
+ 'class' => 'custom-class',
+ 'data-custom' => true,
+ 'data-custom2' => false,
+ 'data-custom3' => null,
+ ],
+ __DIR__ . '/withAttributes.html',
+ ],
+ 'With resources and attributes' => [
+ new Position('homepage.top', [
+ new BannerResource('role', 'vip'),
+ new BannerResource('category', [123, 456]),
+ ]),
+ [
+ 'class' => 'custom-class',
+ 'data-custom' => true,
+ 'data-custom2' => false,
+ 'data-custom3' => null,
+ ],
+ __DIR__ . '/withResourcesAndAttributes.html',
+ ],
+];
diff --git a/tests/resources/renderer/client-side/positionOnly.html b/tests/resources/renderer/client-side/positionOnly.html
new file mode 100644
index 0000000..b5a6f0b
--- /dev/null
+++ b/tests/resources/renderer/client-side/positionOnly.html
@@ -0,0 +1 @@
+
diff --git a/tests/resources/renderer/client-side/templates/client-side1.phtml b/tests/resources/renderer/client-side/templates/client-side1.phtml
new file mode 100644
index 0000000..07e3bda
--- /dev/null
+++ b/tests/resources/renderer/client-side/templates/client-side1.phtml
@@ -0,0 +1,10 @@
+
+Client-side position "= Helpers::escapeHtml($position->getCode()) ?>".
diff --git a/tests/resources/renderer/client-side/withAttributes.html b/tests/resources/renderer/client-side/withAttributes.html
new file mode 100644
index 0000000..3febf56
--- /dev/null
+++ b/tests/resources/renderer/client-side/withAttributes.html
@@ -0,0 +1 @@
+
diff --git a/tests/resources/renderer/client-side/withResources.html b/tests/resources/renderer/client-side/withResources.html
new file mode 100644
index 0000000..074d5ad
--- /dev/null
+++ b/tests/resources/renderer/client-side/withResources.html
@@ -0,0 +1 @@
+
diff --git a/tests/resources/renderer/client-side/withResourcesAndAttributes.html b/tests/resources/renderer/client-side/withResourcesAndAttributes.html
new file mode 100644
index 0000000..dfb9490
--- /dev/null
+++ b/tests/resources/renderer/client-side/withResourcesAndAttributes.html
@@ -0,0 +1 @@
+