diff --git a/CHANGELOG.md b/CHANGELOG.md index 95285eb..4905182 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added -- Added integration of the new AMP API field `mode`. +- Added integration of the new AMP API fields `mode` and `dimensions`. - Added possibility to render embed banners. - Added new rendering mode `embed` (`EmbedRenderingMode`) for the Latte bridge. diff --git a/src/Renderer/AmpBannerExternalAttribute.php b/src/Renderer/AmpBannerExternalAttribute.php index eb4573a..548832c 100644 --- a/src/Renderer/AmpBannerExternalAttribute.php +++ b/src/Renderer/AmpBannerExternalAttribute.php @@ -43,6 +43,10 @@ public function __toString(): string 'rotationSeconds' => $this->position->getRotationSeconds(), 'displayType' => $this->position->getDisplayType(), 'breakpointType' => $this->position->getBreakpointType(), + 'dimensions' => [ + 'width' => $this->position->getDimensions()->getWidth(), + 'height' => $this->position->getDimensions()->getHeight(), + ], ], 'state' => [ 'value' => $this->state, diff --git a/src/Renderer/Latte/Templates/contents.fragment.latte b/src/Renderer/Latte/Templates/contents.fragment.latte index 7122925..a849788 100644 --- a/src/Renderer/Latte/Templates/contents.fragment.latte +++ b/src/Renderer/Latte/Templates/contents.fragment.latte @@ -20,7 +20,12 @@ src="{$content->getSrc()}" sizes="{$content->getSizes()}" alt="{$content->getAlt()}" - n:attr="title => '' !== $content->getTitle() ? $content->getTitle() : null, loading => $options['loading'] ?? null"> + n:attr=" + width => null !== $position->getDimensions()->getWidth() ? $position->getDimensions()->getWidth() : null, + height => null !== $position->getDimensions()->getHeight() ? $position->getDimensions()->getHeight() : null, + title => '' !== $content->getTitle() ? $content->getTitle() : null, + loading => $options['loading'] ?? null + "> {elseif $content instanceof SixtyEightPublishers\AmpClient\Response\ValueObject\HtmlContent} diff --git a/src/Renderer/Phtml/Templates/contents.fragment.phtml b/src/Renderer/Phtml/Templates/contents.fragment.phtml index 98168c7..ff87cd6 100644 --- a/src/Renderer/Phtml/Templates/contents.fragment.phtml +++ b/src/Renderer/Phtml/Templates/contents.fragment.phtml @@ -14,7 +14,7 @@ use SixtyEightPublishers\AmpClient\Renderer\BreakpointStyle\BreakpointStyle; /** @var ?Banner $banner */ /** @var array $options */ ?> -getContents() as $index => $content) : ?> +getContents() as $content) : ?> getDimensions()->getWidth()) : ?>width="getDimensions()->getWidth()) ?>" + getDimensions()->getHeight()) : ?>height="getDimensions()->getHeight()) ?>" getTitle()) : ?>title="getTitle()) ?>" loading=""> diff --git a/src/Response/Hydrator/BannersResponseHydratorHandler.php b/src/Response/Hydrator/BannersResponseHydratorHandler.php index eea5a50..ae3cda1 100644 --- a/src/Response/Hydrator/BannersResponseHydratorHandler.php +++ b/src/Response/Hydrator/BannersResponseHydratorHandler.php @@ -7,6 +7,7 @@ use SixtyEightPublishers\AmpClient\Response\BannersResponse; use SixtyEightPublishers\AmpClient\Response\ValueObject\Banner; use SixtyEightPublishers\AmpClient\Response\ValueObject\ContentInterface; +use SixtyEightPublishers\AmpClient\Response\ValueObject\Dimensions; use SixtyEightPublishers\AmpClient\Response\ValueObject\HtmlContent; use SixtyEightPublishers\AmpClient\Response\ValueObject\ImageContent; use SixtyEightPublishers\AmpClient\Response\ValueObject\Position; @@ -46,6 +47,11 @@ * contents: array, * } * + * @phpstan-type DimensionsData = array{ + * width: int|null, + * height: int|null, + * } + * * @phpstan-type PositionData = array{ * position_id?: string|null, * position_name?: string|null, @@ -53,6 +59,7 @@ * display_type: string|null, * breakpoint_type: string, * mode?: string, + * dimensions?: DimensionsData, * banners: array, * } * @@ -85,6 +92,7 @@ public function hydrate($responseBody): BannersResponse $positionData['display_type'] ?? null, $positionData['breakpoint_type'], $positionData['mode'] ?? Position::ModeManaged, + $this->hydrateDimensions($positionData['dimensions'] ?? null), $this->hydrateBanners($positionData['banners']), ); } @@ -161,4 +169,19 @@ private function hydrateContents(array $contentsData): array return $contents; } + + /** + * @param DimensionsData|null $dimensions + */ + private function hydrateDimensions(?array $dimensions): Dimensions + { + if (null === $dimensions) { + return new Dimensions(null, null); + } + + return new Dimensions( + $dimensions['width'] ?? null, + $dimensions['height'] ?? null, + ); + } } diff --git a/src/Response/ValueObject/Dimensions.php b/src/Response/ValueObject/Dimensions.php new file mode 100644 index 0000000..6f0426a --- /dev/null +++ b/src/Response/ValueObject/Dimensions.php @@ -0,0 +1,30 @@ +width = $width; + $this->height = $height; + } + + public function getWidth(): ?int + { + return $this->width; + } + + public function getHeight(): ?int + { + return $this->height; + } +} diff --git a/src/Response/ValueObject/Position.php b/src/Response/ValueObject/Position.php index 52c1d77..5fd7dd7 100644 --- a/src/Response/ValueObject/Position.php +++ b/src/Response/ValueObject/Position.php @@ -30,6 +30,8 @@ final class Position private string $mode; + private Dimensions $dimensions; + /** @var array */ private array $banners; @@ -44,6 +46,7 @@ public function __construct( ?string $displayType, string $breakpointType, string $mode, + Dimensions $dimensions, array $banners ) { $this->id = $id; @@ -53,6 +56,7 @@ public function __construct( $this->displayType = $displayType; $this->breakpointType = $breakpointType; $this->mode = $mode; + $this->dimensions = $dimensions; $this->banners = $banners; } @@ -91,6 +95,11 @@ public function getMode(): string return $this->mode; } + public function getDimensions(): Dimensions + { + return $this->dimensions; + } + /** * @return array */ diff --git a/tests/Bridge/Latte/RendererProviderTest.php b/tests/Bridge/Latte/RendererProviderTest.php index 9bdcab4..91ec645 100644 --- a/tests/Bridge/Latte/RendererProviderTest.php +++ b/tests/Bridge/Latte/RendererProviderTest.php @@ -20,6 +20,7 @@ use SixtyEightPublishers\AmpClient\Request\ValueObject\BannerResource; use SixtyEightPublishers\AmpClient\Request\ValueObject\Position as RequestPosition; use SixtyEightPublishers\AmpClient\Response\BannersResponse; +use SixtyEightPublishers\AmpClient\Response\ValueObject\Dimensions; use SixtyEightPublishers\AmpClient\Response\ValueObject\Position as ResponsePosition; use SixtyEightPublishers\AmpClient\Tests\Bridge\Latte\Event\ConfigureClientEventHandlerFixture; use SixtyEightPublishers\AmpClient\Tests\Exception\AmpExceptionFixture; @@ -37,7 +38,17 @@ public function testInvokingDefaultInstanceWithoutResources(): void $renderer = Mockery::mock(RendererInterface::class); $provider = new RendererProvider($client, $renderer); - $responsePosition = new ResponsePosition('1234', 'homepage.top', 'Homepage top', 0, ResponsePosition::DisplayTypeSingle, ResponsePosition::BreakpointTypeMin, ResponsePosition::ModeManaged, []); + $responsePosition = new ResponsePosition( + '1234', + 'homepage.top', + 'Homepage top', + 0, + ResponsePosition::DisplayTypeSingle, + ResponsePosition::BreakpointTypeMin, + ResponsePosition::ModeManaged, + new Dimensions(null, null), + [], + ); $response = new BannersResponse([ 'homepage.top' => $responsePosition, ]); @@ -72,7 +83,17 @@ public function testInvokingDefaultInstanceWithSameModeAsDefault(): void $renderer = Mockery::mock(RendererInterface::class); $provider = new RendererProvider($client, $renderer); - $responsePosition = new ResponsePosition('1234', 'homepage.top', 'Homepage top', 0, ResponsePosition::DisplayTypeSingle, ResponsePosition::BreakpointTypeMin, ResponsePosition::ModeManaged, []); + $responsePosition = new ResponsePosition( + '1234', + 'homepage.top', + 'Homepage top', + 0, + ResponsePosition::DisplayTypeSingle, + ResponsePosition::BreakpointTypeMin, + ResponsePosition::ModeManaged, + new Dimensions(null, null), + [], + ); $response = new BannersResponse([ 'homepage.top' => $responsePosition, ]); @@ -107,7 +128,17 @@ public function testInvokingDefaultInstanceWithAttributes(): void $renderer = Mockery::mock(RendererInterface::class); $provider = new RendererProvider($client, $renderer); - $responsePosition = new ResponsePosition('1234', 'homepage.top', 'Homepage top', 0, ResponsePosition::DisplayTypeSingle, ResponsePosition::BreakpointTypeMin, ResponsePosition::ModeManaged, []); + $responsePosition = new ResponsePosition( + '1234', + 'homepage.top', + 'Homepage top', + 0, + ResponsePosition::DisplayTypeSingle, + ResponsePosition::BreakpointTypeMin, + ResponsePosition::ModeManaged, + new Dimensions(null, null), + [], + ); $response = new BannersResponse([ 'homepage.top' => $responsePosition, ]); @@ -142,7 +173,17 @@ public function testInvokingDefaultInstanceWithOptions(): void $renderer = Mockery::mock(RendererInterface::class); $provider = new RendererProvider($client, $renderer); - $responsePosition = new ResponsePosition('1234', 'homepage.top', 'Homepage top', 0, ResponsePosition::DisplayTypeSingle, ResponsePosition::BreakpointTypeMin, ResponsePosition::ModeManaged, []); + $responsePosition = new ResponsePosition( + '1234', + 'homepage.top', + 'Homepage top', + 0, + ResponsePosition::DisplayTypeSingle, + ResponsePosition::BreakpointTypeMin, + ResponsePosition::ModeManaged, + new Dimensions(null, null), + [], + ); $response = new BannersResponse([ 'homepage.top' => $responsePosition, ]); @@ -177,7 +218,17 @@ public function testInvokingDefaultInstanceWithResources(): void $renderer = Mockery::mock(RendererInterface::class); $provider = new RendererProvider($client, $renderer); - $responsePosition = new ResponsePosition('1234', 'homepage.top', 'Homepage top', 0, ResponsePosition::DisplayTypeSingle, ResponsePosition::BreakpointTypeMin, ResponsePosition::ModeManaged, []); + $responsePosition = new ResponsePosition( + '1234', + 'homepage.top', + 'Homepage top', + 0, + ResponsePosition::DisplayTypeSingle, + ResponsePosition::BreakpointTypeMin, + ResponsePosition::ModeManaged, + new Dimensions(null, null), + [], + ); $response = new BannersResponse([ 'homepage.top' => $responsePosition, ]); @@ -228,7 +279,17 @@ public function testInvokingDefaultInstanceWithPositionInEmbedMode(): void $provider = new RendererProvider($client, $renderer); $positionMode = ResponsePosition::ModeEmbed; - $responsePosition = new ResponsePosition('1234', 'homepage.top', 'Homepage top', 0, ResponsePosition::DisplayTypeSingle, ResponsePosition::BreakpointTypeMin, $positionMode, []); + $responsePosition = new ResponsePosition( + '1234', + 'homepage.top', + 'Homepage top', + 0, + ResponsePosition::DisplayTypeSingle, + ResponsePosition::BreakpointTypeMin, + $positionMode, + new Dimensions(null, null), + [], + ); $response = new BannersResponse([ 'homepage.top' => $responsePosition, ]); @@ -264,7 +325,17 @@ public function testClientConfigurationEventsShouldBeInvokedBeforeFirstFetch(): $renderer = Mockery::mock(RendererInterface::class); $provider = new RendererProvider($client, $renderer); - $responsePosition = new ResponsePosition('1234', 'homepage.top', 'Homepage top', 0, ResponsePosition::DisplayTypeSingle, ResponsePosition::BreakpointTypeMin, ResponsePosition::ModeManaged, []); + $responsePosition = new ResponsePosition( + '1234', + 'homepage.top', + 'Homepage top', + 0, + ResponsePosition::DisplayTypeSingle, + ResponsePosition::BreakpointTypeMin, + ResponsePosition::ModeManaged, + new Dimensions(null, null), + [], + ); $handler = new ConfigureClientEventHandlerFixture(static function (ConfigureClientEvent $event) use ($client, $modifiedClient) { Assert::same($client, $event->getClient()); @@ -374,7 +445,17 @@ public function testExceptionShouldBeThrownWhenRendererThrowsExceptionInDebugMod $provider->setDebugMode(true); - $responsePosition = new ResponsePosition('1234', 'homepage.top', 'Homepage top', 0, ResponsePosition::DisplayTypeSingle, ResponsePosition::BreakpointTypeMin, ResponsePosition::ModeManaged, []); + $responsePosition = new ResponsePosition( + '1234', + 'homepage.top', + 'Homepage top', + 0, + ResponsePosition::DisplayTypeSingle, + ResponsePosition::BreakpointTypeMin, + ResponsePosition::ModeManaged, + new Dimensions(null, null), + [], + ); $client ->shouldReceive('fetchBanners') @@ -403,7 +484,17 @@ public function testEmptyStringShouldBeReturnedWhenRendererThrowsExceptionInNonD $renderer = Mockery::mock(RendererInterface::class); $provider = new RendererProvider($client, $renderer); - $responsePosition = new ResponsePosition('1234', 'homepage.top', 'Homepage top', 0, ResponsePosition::DisplayTypeSingle, ResponsePosition::BreakpointTypeMin, ResponsePosition::ModeManaged, []); + $responsePosition = new ResponsePosition( + '1234', + 'homepage.top', + 'Homepage top', + 0, + ResponsePosition::DisplayTypeSingle, + ResponsePosition::BreakpointTypeMin, + ResponsePosition::ModeManaged, + new Dimensions(null, null), + [], + ); $client ->shouldReceive('fetchBanners') @@ -430,7 +521,17 @@ public function testExceptionShouldBeLoggedWhenRendererThrowsExceptionInNonDebug $exception = new RendererException('Test renderer exception'); $provider = new RendererProvider($client, $renderer, $logger); - $responsePosition = new ResponsePosition('1234', 'homepage.top', 'Homepage top', 0, ResponsePosition::DisplayTypeSingle, ResponsePosition::BreakpointTypeMin, ResponsePosition::ModeManaged, []); + $responsePosition = new ResponsePosition( + '1234', + 'homepage.top', + 'Homepage top', + 0, + ResponsePosition::DisplayTypeSingle, + ResponsePosition::BreakpointTypeMin, + ResponsePosition::ModeManaged, + new Dimensions(null, null), + [], + ); $client ->shouldReceive('fetchBanners') @@ -507,8 +608,28 @@ public function testPositionsShouldBeQueuedAndReplacedInStringOutput(): void Assert::same('', $provider($globals, 'homepage.bottom', ['resources' => ['resource' => ['a']]])); Assert::true($provider->isAnythingQueued()); - $responsePosition1 = new ResponsePosition('1234', 'homepage.top', 'Homepage top', 0, ResponsePosition::DisplayTypeSingle, ResponsePosition::BreakpointTypeMin, ResponsePosition::ModeManaged, []); - $responsePosition2 = new ResponsePosition('1235', 'homepage.bottom', 'Homepage bottom', 0, ResponsePosition::DisplayTypeSingle, ResponsePosition::BreakpointTypeMin, ResponsePosition::ModeManaged, []); + $responsePosition1 = new ResponsePosition( + '1234', + 'homepage.top', + 'Homepage top', + 0, + ResponsePosition::DisplayTypeSingle, + ResponsePosition::BreakpointTypeMin, + ResponsePosition::ModeManaged, + new Dimensions(null, null), + [], + ); + $responsePosition2 = new ResponsePosition( + '1235', + 'homepage.bottom', + 'Homepage bottom', + 0, + ResponsePosition::DisplayTypeSingle, + ResponsePosition::BreakpointTypeMin, + ResponsePosition::ModeManaged, + new Dimensions(null, null), + [], + ); $response = new BannersResponse([ 'homepage.top' => $responsePosition1, 'homepage.bottom' => $responsePosition2, @@ -599,8 +720,28 @@ public function testPositionsShouldBeQueuedAndReplacedInArrayOutput(): void Assert::same('', $provider($globals, 'homepage.bottom', ['resources' => ['resource' => ['a']]])); Assert::true($provider->isAnythingQueued()); - $responsePosition1 = new ResponsePosition('1234', 'homepage.top', 'Homepage top', 0, ResponsePosition::DisplayTypeSingle, ResponsePosition::BreakpointTypeMin, ResponsePosition::ModeManaged, []); - $responsePosition2 = new ResponsePosition('1235', 'homepage.bottom', 'Homepage bottom', 0, ResponsePosition::DisplayTypeSingle, ResponsePosition::BreakpointTypeMin, ResponsePosition::ModeManaged, []); + $responsePosition1 = new ResponsePosition( + '1234', + 'homepage.top', + 'Homepage top', + 0, + ResponsePosition::DisplayTypeSingle, + ResponsePosition::BreakpointTypeMin, + ResponsePosition::ModeManaged, + new Dimensions(null, null), + [], + ); + $responsePosition2 = new ResponsePosition( + '1235', + 'homepage.bottom', + 'Homepage bottom', + 0, + ResponsePosition::DisplayTypeSingle, + ResponsePosition::BreakpointTypeMin, + ResponsePosition::ModeManaged, + new Dimensions(null, null), + [], + ); $response = new BannersResponse([ 'homepage.top' => $responsePosition1, 'homepage.bottom' => $responsePosition2, @@ -681,7 +822,17 @@ public function testEmbedPositionReturnedFromApiShouldBeQueuedAndReplacedInStrin Assert::same('', $provider($globals, 'homepage.bottom', ['resources' => ['resource' => ['a']]])); Assert::true($provider->isAnythingQueued()); - $responsePosition1 = new ResponsePosition('1234', 'homepage.top', 'Homepage top', 0, ResponsePosition::DisplayTypeSingle, ResponsePosition::BreakpointTypeMin, ResponsePosition::ModeEmbed, []); + $responsePosition1 = new ResponsePosition( + '1234', + 'homepage.top', + 'Homepage top', + 0, + ResponsePosition::DisplayTypeSingle, + ResponsePosition::BreakpointTypeMin, + ResponsePosition::ModeEmbed, + new Dimensions(null, null), + [], + ); $response = new BannersResponse([ 'homepage.bottom' => $responsePosition1, ]); diff --git a/tests/Renderer/BannersResolverTest.php b/tests/Renderer/BannersResolverTest.php index 6575a57..3f26f7d 100644 --- a/tests/Renderer/BannersResolverTest.php +++ b/tests/Renderer/BannersResolverTest.php @@ -6,6 +6,7 @@ use SixtyEightPublishers\AmpClient\Renderer\BannersResolver; use SixtyEightPublishers\AmpClient\Response\ValueObject\Banner; +use SixtyEightPublishers\AmpClient\Response\ValueObject\Dimensions; use SixtyEightPublishers\AmpClient\Response\ValueObject\Position; use Tester\Assert; use Tester\TestCase; @@ -16,7 +17,17 @@ final class BannersResolverTest extends TestCase { public function testNullShouldBeReturnedWhenResolvingSinglePositionWithoutBanners(): void { - $position = new Position('1234', 'homepage.top', 'Homepage top', 0, Position::DisplayTypeSingle, Position::BreakpointTypeMin, Position::ModeManaged, []); + $position = new Position( + '1234', + 'homepage.top', + 'Homepage top', + 0, + Position::DisplayTypeSingle, + Position::BreakpointTypeMin, + Position::ModeManaged, + new Dimensions(null, null), + [], + ); $resolver = new BannersResolver(); Assert::null($resolver->resolveSingle($position)); @@ -28,7 +39,17 @@ public function testFirstBannerWithHighestScoreShouldBeReturnedWhenResolvingSing $banner2 = new Banner('2', '2', 2, null, null, null, []); $banner3 = new Banner('3', '3', 1, null, null, null, []); $banner4 = new Banner('4', '4', 2, null, null, null, []); - $position = new Position('1234', 'homepage.top', 'Homepage top', 0, Position::DisplayTypeSingle, Position::BreakpointTypeMin, Position::ModeManaged, [$banner1, $banner2, $banner3, $banner4]); + $position = new Position( + '1234', + 'homepage.top', + 'Homepage top', + 0, + Position::DisplayTypeSingle, + Position::BreakpointTypeMin, + Position::ModeManaged, + new Dimensions(null, null), + [$banner1, $banner2, $banner3, $banner4], + ); $resolver = new BannersResolver(); Assert::same($banner2, $resolver->resolveSingle($position)); @@ -36,7 +57,17 @@ public function testFirstBannerWithHighestScoreShouldBeReturnedWhenResolvingSing public function testEmptyArrayShouldBeReturnedWhenResolvingMultiplePositionWithoutBanners(): void { - $position = new Position('1234', 'homepage.top', 'Homepage top', 0, Position::DisplayTypeMultiple, Position::BreakpointTypeMin, Position::ModeManaged, []); + $position = new Position( + '1234', + 'homepage.top', + 'Homepage top', + 0, + Position::DisplayTypeMultiple, + Position::BreakpointTypeMin, + Position::ModeManaged, + new Dimensions(null, null), + [], + ); $resolver = new BannersResolver(); Assert::same([], $resolver->resolveMultiple($position)); @@ -48,7 +79,17 @@ public function testSortedBannersShouldBeReturnedWhenResolvingMultiplePosition() $banner2 = new Banner('2', '2', 2, null, null, null, []); $banner3 = new Banner('3', '3', 1, null, null, null, []); $banner4 = new Banner('4', '4', 2, null, null, null, []); - $position = new Position('1234', 'homepage.top', 'Homepage top', 0, Position::DisplayTypeMultiple, Position::BreakpointTypeMin, Position::ModeManaged, [$banner1, $banner2, $banner3, $banner4]); + $position = new Position( + '1234', + 'homepage.top', + 'Homepage top', + 0, + Position::DisplayTypeMultiple, + Position::BreakpointTypeMin, + Position::ModeManaged, + new Dimensions(null, null), + [$banner1, $banner2, $banner3, $banner4], + ); $resolver = new BannersResolver(); Assert::same([ @@ -61,7 +102,17 @@ public function testSortedBannersShouldBeReturnedWhenResolvingMultiplePosition() public function testNullShouldBeReturnedWhenResolvingRandomPositionWithoutBanners(): void { - $position = new Position('1234', 'homepage.top', 'Homepage top', 0, Position::DisplayTypeRandom, Position::BreakpointTypeMin, Position::ModeManaged, []); + $position = new Position( + '1234', + 'homepage.top', + 'Homepage top', + 0, + Position::DisplayTypeRandom, + Position::BreakpointTypeMin, + Position::ModeManaged, + new Dimensions(null, null), + [], + ); $resolver = new BannersResolver(); Assert::null($resolver->resolveRandom($position)); @@ -73,7 +124,17 @@ public function testRandomBannerShouldBeReturnedWhenResolvingRandomPosition(): v $banner2 = new Banner('2', '2', 3, null, null, null, []); $banner3 = new Banner('3', '3', 2, null, null, null, []); $banner4 = new Banner('4', '4', 3, null, null, null, []); - $position = new Position('1234', 'homepage.top', 'Homepage top', 0, Position::DisplayTypeRandom, Position::BreakpointTypeMin, Position::ModeManaged, [$banner1, $banner2, $banner3, $banner4]); + $position = new Position( + '1234', + 'homepage.top', + 'Homepage top', + 0, + Position::DisplayTypeRandom, + Position::BreakpointTypeMin, + Position::ModeManaged, + new Dimensions(null, null), + [$banner1, $banner2, $banner3, $banner4], + ); $resolver = new BannersResolver(); Assert::type(Banner::class, $resolver->resolveRandom($position)); # @todo: Mock mt_rand() ? diff --git a/tests/Renderer/BreakpointStyle/BreakpointStyleTest.php b/tests/Renderer/BreakpointStyle/BreakpointStyleTest.php index 43f126e..e430c0a 100644 --- a/tests/Renderer/BreakpointStyle/BreakpointStyleTest.php +++ b/tests/Renderer/BreakpointStyle/BreakpointStyleTest.php @@ -6,6 +6,7 @@ use SixtyEightPublishers\AmpClient\Renderer\BreakpointStyle\BreakpointStyle; use SixtyEightPublishers\AmpClient\Response\ValueObject\Banner; +use SixtyEightPublishers\AmpClient\Response\ValueObject\Dimensions; use SixtyEightPublishers\AmpClient\Response\ValueObject\HtmlContent; use SixtyEightPublishers\AmpClient\Response\ValueObject\Position; use SixtyEightPublishers\AmpClient\Response\ValueObject\Position as ResponsePosition; @@ -132,6 +133,7 @@ private function createBreakpointStyle(string $breakpointType, array $contents): Position::DisplayTypeSingle, $breakpointType, ResponsePosition::ModeManaged, + new Dimensions(null, null), [$banner], ); diff --git a/tests/Renderer/RendererTest.php b/tests/Renderer/RendererTest.php index a24f725..33a092d 100644 --- a/tests/Renderer/RendererTest.php +++ b/tests/Renderer/RendererTest.php @@ -18,6 +18,7 @@ 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\Dimensions; use SixtyEightPublishers\AmpClient\Response\ValueObject\Position as ResponsePosition; use Tester\Assert; use Tester\TestCase; @@ -48,7 +49,17 @@ public function testNotFoundTemplateShouldBeRendered(): void $rendererBridge = Mockery::mock(RendererBridgeInterface::class); $renderer = new Renderer($bannersResolver, $rendererBridge); - $position = new ResponsePosition(null, 'homepage.top', null, 0, null, ResponsePosition::BreakpointTypeMin, ResponsePosition::ModeManaged, []); + $position = new ResponsePosition( + null, + 'homepage.top', + null, + 0, + null, + ResponsePosition::BreakpointTypeMin, + ResponsePosition::ModeManaged, + new Dimensions(null, null), + [], + ); $rendererBridge ->shouldReceive('renderNotFound') @@ -66,7 +77,17 @@ public function testSingleTemplateShouldBeRendered(): void $renderer = new Renderer($bannersResolver, $rendererBridge); $banner = new Banner('1234', 'Main', 0, null, null, null, []); - $position = new ResponsePosition('1234', 'homepage.top', 'Homepage top', 0, ResponsePosition::DisplayTypeSingle, ResponsePosition::BreakpointTypeMin, ResponsePosition::ModeManaged, [$banner]); + $position = new ResponsePosition( + '1234', + 'homepage.top', + 'Homepage top', + 0, + ResponsePosition::DisplayTypeSingle, + ResponsePosition::BreakpointTypeMin, + ResponsePosition::ModeManaged, + new Dimensions(null, null), + [$banner], + ); $bannersResolver ->shouldReceive('resolveSingle') @@ -90,7 +111,17 @@ public function testRandomTemplateShouldBeRendered(): void $renderer = new Renderer($bannersResolver, $rendererBridge); $banner = new Banner('1234', 'Main', 0, null, null, null, []); - $position = new ResponsePosition('1234', 'homepage.top', 'Homepage top', 0, ResponsePosition::DisplayTypeRandom, ResponsePosition::BreakpointTypeMin, ResponsePosition::ModeManaged, [$banner]); + $position = new ResponsePosition( + '1234', + 'homepage.top', + 'Homepage top', + 0, + ResponsePosition::DisplayTypeRandom, + ResponsePosition::BreakpointTypeMin, + ResponsePosition::ModeManaged, + new Dimensions(null, null), + [$banner], + ); $bannersResolver ->shouldReceive('resolveRandom') @@ -117,7 +148,17 @@ public function testMultipleTemplateShouldBeRendered(): void new Banner('1234', 'Main', 0, null, null, null, []), new Banner('1235', 'Secondary', 0, null, null, null, []), ]; - $position = new ResponsePosition('1234', 'homepage.top', 'Homepage top', 0, ResponsePosition::DisplayTypeMultiple, ResponsePosition::BreakpointTypeMin, ResponsePosition::ModeManaged, $banners); + $position = new ResponsePosition( + '1234', + 'homepage.top', + 'Homepage top', + 0, + ResponsePosition::DisplayTypeMultiple, + ResponsePosition::BreakpointTypeMin, + ResponsePosition::ModeManaged, + new Dimensions(null, null), + $banners, + ); $bannersResolver ->shouldReceive('resolveMultiple') @@ -178,7 +219,17 @@ public function testRendererExceptionShouldBeThrownOnRenderingWhenBridgeThrowsTh $rendererBridge = Mockery::mock(RendererBridgeInterface::class); $renderer = new Renderer($bannersResolver, $rendererBridge); - $position = new ResponsePosition(null, 'homepage.top', null, 0, null, ResponsePosition::BreakpointTypeMin, ResponsePosition::ModeManaged, []); + $position = new ResponsePosition( + null, + 'homepage.top', + null, + 0, + null, + ResponsePosition::BreakpointTypeMin, + ResponsePosition::ModeManaged, + new Dimensions(null, null), + [], + ); $rendererBridge ->shouldReceive('renderNotFound') @@ -220,7 +271,17 @@ public function testRendererExceptionShouldBeThrownOnRenderingWhenBridgeThrowsAn $rendererBridge = Mockery::mock(RendererBridgeInterface::class); $renderer = new Renderer($bannersResolver, $rendererBridge); - $position = new ResponsePosition(null, 'homepage.top', null, 0, null, ResponsePosition::BreakpointTypeMin, ResponsePosition::ModeManaged, []); + $position = new ResponsePosition( + null, + 'homepage.top', + null, + 0, + null, + ResponsePosition::BreakpointTypeMin, + ResponsePosition::ModeManaged, + new Dimensions(null, null), + [], + ); $rendererBridge ->shouldReceive('renderNotFound') diff --git a/tests/resources/renderer/multiple/data-provider.php b/tests/resources/renderer/multiple/data-provider.php index 21e5a9e..d80cec4 100644 --- a/tests/resources/renderer/multiple/data-provider.php +++ b/tests/resources/renderer/multiple/data-provider.php @@ -3,13 +3,36 @@ declare(strict_types=1); use SixtyEightPublishers\AmpClient\Response\ValueObject\Banner; +use SixtyEightPublishers\AmpClient\Response\ValueObject\Dimensions; use SixtyEightPublishers\AmpClient\Response\ValueObject\HtmlContent; use SixtyEightPublishers\AmpClient\Response\ValueObject\ImageContent; use SixtyEightPublishers\AmpClient\Response\ValueObject\Position; use SixtyEightPublishers\AmpClient\Response\ValueObject\Position as ResponsePosition; use SixtyEightPublishers\AmpClient\Response\ValueObject\Source; -$position = new Position('1234', 'homepage.top', 'Homepage top', 0, Position::DisplayTypeMultiple, Position::BreakpointTypeMin, ResponsePosition::ModeManaged, []); +$position = new Position( + '1234', + 'homepage.top', + 'Homepage top', + 0, + Position::DisplayTypeMultiple, + Position::BreakpointTypeMin, + ResponsePosition::ModeManaged, + new Dimensions(800, 300), + [], +); + +$positionWithoutDimensions = new Position( + '1234', + 'homepage.top', + 'Homepage top', + 0, + Position::DisplayTypeMultiple, + Position::BreakpointTypeMin, + ResponsePosition::ModeManaged, + new Dimensions(null, null), + [], +); $fullFeaturedBanners = [ new Banner('1234', 'Main', 0, null, null, null, [ @@ -127,4 +150,11 @@ ], __DIR__ . '/multipleBannersFullFeatured.withLazyLoadingFromOffset1.html', ], + 'Multiple banners - full featured without dimensions' => [ + $positionWithoutDimensions, + $fullFeaturedBanners, + [], + [], + __DIR__ . '/multipleBannersFullFeatured.withoutDimensions.html', + ], ]; diff --git a/tests/resources/renderer/multiple/multipleBannersFullFeatured.html b/tests/resources/renderer/multiple/multipleBannersFullFeatured.html index e094660..0a1ac31 100644 --- a/tests/resources/renderer/multiple/multipleBannersFullFeatured.html +++ b/tests/resources/renderer/multiple/multipleBannersFullFeatured.html @@ -1,4 +1,4 @@ -
+
@@ -9,14 +9,14 @@ - Main 1 + Main 1 - Main 2 + Main 2 @@ -24,7 +24,7 @@ diff --git a/tests/resources/renderer/multiple/multipleBannersFullFeatured.withLazyLoading.html b/tests/resources/renderer/multiple/multipleBannersFullFeatured.withLazyLoading.html index 0fb847f..a4ccefa 100644 --- a/tests/resources/renderer/multiple/multipleBannersFullFeatured.withLazyLoading.html +++ b/tests/resources/renderer/multiple/multipleBannersFullFeatured.withLazyLoading.html @@ -1,4 +1,4 @@ -
+
@@ -9,14 +9,14 @@ - Main 1 + Main 1 - Main 2 + Main 2 @@ -24,7 +24,7 @@ diff --git a/tests/resources/renderer/multiple/multipleBannersFullFeatured.withLazyLoadingFromOffset1.html b/tests/resources/renderer/multiple/multipleBannersFullFeatured.withLazyLoadingFromOffset1.html index 2ae6200..eb76863 100644 --- a/tests/resources/renderer/multiple/multipleBannersFullFeatured.withLazyLoadingFromOffset1.html +++ b/tests/resources/renderer/multiple/multipleBannersFullFeatured.withLazyLoadingFromOffset1.html @@ -1,4 +1,4 @@ -
+
@@ -9,14 +9,14 @@ - Main 1 + Main 1 - Main 2 + Main 2 @@ -24,7 +24,7 @@ diff --git a/tests/resources/renderer/multiple/multipleBannersFullFeatured.withoutDimensions.html b/tests/resources/renderer/multiple/multipleBannersFullFeatured.withoutDimensions.html new file mode 100644 index 0000000..ff2e7b6 --- /dev/null +++ b/tests/resources/renderer/multiple/multipleBannersFullFeatured.withoutDimensions.html @@ -0,0 +1,33 @@ +
+
+
+
+
+

Small content

+
+ + + + + Main 1 + + + + + + + Main 2 + + + +
+ +
+
+
diff --git a/tests/resources/renderer/multiple/multipleBannersWithoutContents.html b/tests/resources/renderer/multiple/multipleBannersWithoutContents.html index bd98e88..7a84ba7 100644 --- a/tests/resources/renderer/multiple/multipleBannersWithoutContents.html +++ b/tests/resources/renderer/multiple/multipleBannersWithoutContents.html @@ -1 +1 @@ -
+
diff --git a/tests/resources/renderer/multiple/noBanner.html b/tests/resources/renderer/multiple/noBanner.html index bd98e88..7a84ba7 100644 --- a/tests/resources/renderer/multiple/noBanner.html +++ b/tests/resources/renderer/multiple/noBanner.html @@ -1 +1 @@ -
+
diff --git a/tests/resources/renderer/multiple/noBanner.withAttributes.html b/tests/resources/renderer/multiple/noBanner.withAttributes.html index 14405ff..debae50 100644 --- a/tests/resources/renderer/multiple/noBanner.withAttributes.html +++ b/tests/resources/renderer/multiple/noBanner.withAttributes.html @@ -1 +1 @@ -
+
diff --git a/tests/resources/renderer/multiple/singleBannerWithoutContents.html b/tests/resources/renderer/multiple/singleBannerWithoutContents.html index bd98e88..7a84ba7 100644 --- a/tests/resources/renderer/multiple/singleBannerWithoutContents.html +++ b/tests/resources/renderer/multiple/singleBannerWithoutContents.html @@ -1 +1 @@ -
+
diff --git a/tests/resources/renderer/multiple/templates/multiple1.phtml b/tests/resources/renderer/multiple/templates/multiple1.phtml index 8b906ca..23d3971 100644 --- a/tests/resources/renderer/multiple/templates/multiple1.phtml +++ b/tests/resources/renderer/multiple/templates/multiple1.phtml @@ -7,4 +7,4 @@ use SixtyEightPublishers\AmpClient\Renderer\Phtml\Helpers; /** @var Position $position */ ?> -Random position "getCode()) ?>". +Multiple position "getCode()) ?>". diff --git a/tests/resources/renderer/not-found/data-provider.php b/tests/resources/renderer/not-found/data-provider.php index 51b03f5..297e780 100644 --- a/tests/resources/renderer/not-found/data-provider.php +++ b/tests/resources/renderer/not-found/data-provider.php @@ -2,10 +2,21 @@ declare(strict_types=1); +use SixtyEightPublishers\AmpClient\Response\ValueObject\Dimensions; use SixtyEightPublishers\AmpClient\Response\ValueObject\Position; use SixtyEightPublishers\AmpClient\Response\ValueObject\Position as ResponsePosition; -$position = new Position(null, 'homepage.top', null, 0, null, Position::BreakpointTypeMin, ResponsePosition::ModeManaged, []); +$position = new Position( + null, + 'homepage.top', + null, + 0, + null, + Position::BreakpointTypeMin, + ResponsePosition::ModeManaged, + new Dimensions(800, 300), + [], +); return [ 'Not found' => [ diff --git a/tests/resources/renderer/not-found/notFound.html b/tests/resources/renderer/not-found/notFound.html index cada5f2..b119569 100644 --- a/tests/resources/renderer/not-found/notFound.html +++ b/tests/resources/renderer/not-found/notFound.html @@ -1 +1 @@ -
+
diff --git a/tests/resources/renderer/not-found/notFound.withAttributes.html b/tests/resources/renderer/not-found/notFound.withAttributes.html index 56bfbc2..ee43108 100644 --- a/tests/resources/renderer/not-found/notFound.withAttributes.html +++ b/tests/resources/renderer/not-found/notFound.withAttributes.html @@ -1 +1 @@ -
+
diff --git a/tests/resources/renderer/not-found/notFound.withLazyLoading.html b/tests/resources/renderer/not-found/notFound.withLazyLoading.html index 983f275..8cd4f2e 100644 --- a/tests/resources/renderer/not-found/notFound.withLazyLoading.html +++ b/tests/resources/renderer/not-found/notFound.withLazyLoading.html @@ -1 +1 @@ -
+
diff --git a/tests/resources/renderer/random/bannerWithBreakpointHtmlContentOnly.html b/tests/resources/renderer/random/bannerWithBreakpointHtmlContentOnly.html index e87e59b..cbf4297 100644 --- a/tests/resources/renderer/random/bannerWithBreakpointHtmlContentOnly.html +++ b/tests/resources/renderer/random/bannerWithBreakpointHtmlContentOnly.html @@ -1,4 +1,4 @@ -
+

My Awesome content!

diff --git a/tests/resources/renderer/random/bannerWithBreakpointImageContentOnly.html b/tests/resources/renderer/random/bannerWithBreakpointImageContentOnly.html index c5610bb..5d6458e 100644 --- a/tests/resources/renderer/random/bannerWithBreakpointImageContentOnly.html +++ b/tests/resources/renderer/random/bannerWithBreakpointImageContentOnly.html @@ -1,8 +1,8 @@ -
+
- Main 1 + Main 1 diff --git a/tests/resources/renderer/random/bannerWithDefaultHtmlContentOnly.html b/tests/resources/renderer/random/bannerWithDefaultHtmlContentOnly.html index f741561..a85507b 100644 --- a/tests/resources/renderer/random/bannerWithDefaultHtmlContentOnly.html +++ b/tests/resources/renderer/random/bannerWithDefaultHtmlContentOnly.html @@ -1,4 +1,4 @@ -
+

My Awesome content!

diff --git a/tests/resources/renderer/random/bannerWithDefaultImageContentOnly.withLazyLoading.html b/tests/resources/renderer/random/bannerWithDefaultImageContentOnly.withLazyLoading.html index 55a4c52..f44cb15 100644 --- a/tests/resources/renderer/random/bannerWithDefaultImageContentOnly.withLazyLoading.html +++ b/tests/resources/renderer/random/bannerWithDefaultImageContentOnly.withLazyLoading.html @@ -1,10 +1,10 @@ -
+
diff --git a/tests/resources/renderer/random/bannerWithDefaultImageContentOnly.withOptionalValues.html b/tests/resources/renderer/random/bannerWithDefaultImageContentOnly.withOptionalValues.html index b77d2fd..142c2d1 100644 --- a/tests/resources/renderer/random/bannerWithDefaultImageContentOnly.withOptionalValues.html +++ b/tests/resources/renderer/random/bannerWithDefaultImageContentOnly.withOptionalValues.html @@ -1,10 +1,10 @@ -
+
diff --git a/tests/resources/renderer/random/bannerWithDefaultImageContentOnly.withoutDimensions.html b/tests/resources/renderer/random/bannerWithDefaultImageContentOnly.withoutDimensions.html new file mode 100644 index 0000000..3783216 --- /dev/null +++ b/tests/resources/renderer/random/bannerWithDefaultImageContentOnly.withoutDimensions.html @@ -0,0 +1,9 @@ +
+ +
diff --git a/tests/resources/renderer/random/bannerWithDefaultImageContentOnly.withoutOptionalValues.html b/tests/resources/renderer/random/bannerWithDefaultImageContentOnly.withoutOptionalValues.html index 4661727..bd95fc1 100644 --- a/tests/resources/renderer/random/bannerWithDefaultImageContentOnly.withoutOptionalValues.html +++ b/tests/resources/renderer/random/bannerWithDefaultImageContentOnly.withoutOptionalValues.html @@ -1,8 +1,8 @@ -
+
diff --git a/tests/resources/renderer/random/bannerWithMultipleContents.html b/tests/resources/renderer/random/bannerWithMultipleContents.html index 4286bff..b8b79e5 100644 --- a/tests/resources/renderer/random/bannerWithMultipleContents.html +++ b/tests/resources/renderer/random/bannerWithMultipleContents.html @@ -1,4 +1,4 @@ -
+

Small content

@@ -7,14 +7,14 @@ - Main 1 + Main 1 - Main 2 + Main 2 diff --git a/tests/resources/renderer/random/bannerWithoutContent.html b/tests/resources/renderer/random/bannerWithoutContent.html index 08aef83..cf4e95b 100644 --- a/tests/resources/renderer/random/bannerWithoutContent.html +++ b/tests/resources/renderer/random/bannerWithoutContent.html @@ -1 +1 @@ -
+
diff --git a/tests/resources/renderer/random/data-provider.php b/tests/resources/renderer/random/data-provider.php index 155f571..36e64ce 100644 --- a/tests/resources/renderer/random/data-provider.php +++ b/tests/resources/renderer/random/data-provider.php @@ -3,13 +3,36 @@ declare(strict_types=1); use SixtyEightPublishers\AmpClient\Response\ValueObject\Banner; +use SixtyEightPublishers\AmpClient\Response\ValueObject\Dimensions; use SixtyEightPublishers\AmpClient\Response\ValueObject\HtmlContent; use SixtyEightPublishers\AmpClient\Response\ValueObject\ImageContent; use SixtyEightPublishers\AmpClient\Response\ValueObject\Position; use SixtyEightPublishers\AmpClient\Response\ValueObject\Position as ResponsePosition; use SixtyEightPublishers\AmpClient\Response\ValueObject\Source; -$position = new Position('1234', 'homepage.top', 'Homepage top', 0, Position::DisplayTypeRandom, Position::BreakpointTypeMin, ResponsePosition::ModeManaged, []); +$position = new Position( + '1234', + 'homepage.top', + 'Homepage top', + 0, + Position::DisplayTypeRandom, + Position::BreakpointTypeMin, + ResponsePosition::ModeManaged, + new Dimensions(800, 300), + [], +); + +$positionWithoutDimensions = new Position( + '1234', + 'homepage.top', + 'Homepage top', + 0, + Position::DisplayTypeRandom, + Position::BreakpointTypeMin, + ResponsePosition::ModeManaged, + new Dimensions(null, null), + [], +); return [ 'No banner' => [ @@ -57,6 +80,25 @@ [], __DIR__ . '/bannerWithDefaultImageContentOnly.withoutOptionalValues.html', ], + 'Banner with default content only: image without dimensions' => [ + $positionWithoutDimensions, + new Banner('1234', 'Main', 0, null, null, null, [ + new ImageContent( + null, + 'https://www.example.com/main1', + null, + 'Main 1', + 'Main 1', + 'https://img.example.com/1000/main1.png', + 'https://img.example.com/500/main1.png 500w, https://img.example.com/1000/main1.png 1000w', + '(min-width: 1000px) calc(1000px - 2 * 16px), (min-width: 600px) calc(100vw - 2 * 16px), 100vw', + [], + ), + ]), + [], + [], + __DIR__ . '/bannerWithDefaultImageContentOnly.withoutDimensions.html', + ], 'Banner with default content only: image with optional value' => [ $position, new Banner('1234', 'Main', 0, null, null, null, [ diff --git a/tests/resources/renderer/random/noBanner.html b/tests/resources/renderer/random/noBanner.html index 08aef83..cf4e95b 100644 --- a/tests/resources/renderer/random/noBanner.html +++ b/tests/resources/renderer/random/noBanner.html @@ -1 +1 @@ -
+
diff --git a/tests/resources/renderer/random/noBanner.withAttributes.html b/tests/resources/renderer/random/noBanner.withAttributes.html index 7fd0cf0..22f2887 100644 --- a/tests/resources/renderer/random/noBanner.withAttributes.html +++ b/tests/resources/renderer/random/noBanner.withAttributes.html @@ -1 +1 @@ -
+
diff --git a/tests/resources/renderer/random/templates/random1.phtml b/tests/resources/renderer/random/templates/random1.phtml index 23d3971..8b906ca 100644 --- a/tests/resources/renderer/random/templates/random1.phtml +++ b/tests/resources/renderer/random/templates/random1.phtml @@ -7,4 +7,4 @@ use SixtyEightPublishers\AmpClient\Renderer\Phtml\Helpers; /** @var Position $position */ ?> -Multiple position "getCode()) ?>". +Random position "getCode()) ?>". diff --git a/tests/resources/renderer/single/bannerWithBreakpointHtmlContentOnly.html b/tests/resources/renderer/single/bannerWithBreakpointHtmlContentOnly.html index 0359246..402273f 100644 --- a/tests/resources/renderer/single/bannerWithBreakpointHtmlContentOnly.html +++ b/tests/resources/renderer/single/bannerWithBreakpointHtmlContentOnly.html @@ -1,4 +1,4 @@ -
+

My Awesome content!

diff --git a/tests/resources/renderer/single/bannerWithBreakpointImageContentOnly.html b/tests/resources/renderer/single/bannerWithBreakpointImageContentOnly.html index 041a706..ddd9194 100644 --- a/tests/resources/renderer/single/bannerWithBreakpointImageContentOnly.html +++ b/tests/resources/renderer/single/bannerWithBreakpointImageContentOnly.html @@ -1,8 +1,8 @@ -
+
- Main 1 + Main 1 diff --git a/tests/resources/renderer/single/bannerWithDefaultHtmlContentOnly.html b/tests/resources/renderer/single/bannerWithDefaultHtmlContentOnly.html index e178c4c..10fbff8 100644 --- a/tests/resources/renderer/single/bannerWithDefaultHtmlContentOnly.html +++ b/tests/resources/renderer/single/bannerWithDefaultHtmlContentOnly.html @@ -1,4 +1,4 @@ -
+

My Awesome content!

diff --git a/tests/resources/renderer/single/bannerWithDefaultImageContentOnly.withLazyLoading.html b/tests/resources/renderer/single/bannerWithDefaultImageContentOnly.withLazyLoading.html index 8773cfb..8b6ea73 100644 --- a/tests/resources/renderer/single/bannerWithDefaultImageContentOnly.withLazyLoading.html +++ b/tests/resources/renderer/single/bannerWithDefaultImageContentOnly.withLazyLoading.html @@ -1,10 +1,10 @@ -
+
diff --git a/tests/resources/renderer/single/bannerWithDefaultImageContentOnly.withOptionalValues.html b/tests/resources/renderer/single/bannerWithDefaultImageContentOnly.withOptionalValues.html index 85b5288..ad746e6 100644 --- a/tests/resources/renderer/single/bannerWithDefaultImageContentOnly.withOptionalValues.html +++ b/tests/resources/renderer/single/bannerWithDefaultImageContentOnly.withOptionalValues.html @@ -1,10 +1,10 @@ -
+
diff --git a/tests/resources/renderer/single/bannerWithDefaultImageContentOnly.withoutDimensions.html b/tests/resources/renderer/single/bannerWithDefaultImageContentOnly.withoutDimensions.html new file mode 100644 index 0000000..d08bfcd --- /dev/null +++ b/tests/resources/renderer/single/bannerWithDefaultImageContentOnly.withoutDimensions.html @@ -0,0 +1,16 @@ +
+ +
diff --git a/tests/resources/renderer/single/bannerWithDefaultImageContentOnly.withoutOptionalValues.html b/tests/resources/renderer/single/bannerWithDefaultImageContentOnly.withoutOptionalValues.html index 118e443..28ad2e0 100644 --- a/tests/resources/renderer/single/bannerWithDefaultImageContentOnly.withoutOptionalValues.html +++ b/tests/resources/renderer/single/bannerWithDefaultImageContentOnly.withoutOptionalValues.html @@ -1,8 +1,8 @@ -
+
diff --git a/tests/resources/renderer/single/bannerWithMultipleContents.html b/tests/resources/renderer/single/bannerWithMultipleContents.html index 1684757..5fd076c 100644 --- a/tests/resources/renderer/single/bannerWithMultipleContents.html +++ b/tests/resources/renderer/single/bannerWithMultipleContents.html @@ -1,4 +1,4 @@ -
+

Small content

@@ -7,14 +7,14 @@ - Main 1 + Main 1 - Main 2 + Main 2 diff --git a/tests/resources/renderer/single/bannerWithoutContent.html b/tests/resources/renderer/single/bannerWithoutContent.html index 170c63b..0f8e14d 100644 --- a/tests/resources/renderer/single/bannerWithoutContent.html +++ b/tests/resources/renderer/single/bannerWithoutContent.html @@ -1 +1 @@ -
+
diff --git a/tests/resources/renderer/single/data-provider.php b/tests/resources/renderer/single/data-provider.php index 2ae3def..e95d6c5 100644 --- a/tests/resources/renderer/single/data-provider.php +++ b/tests/resources/renderer/single/data-provider.php @@ -3,13 +3,36 @@ declare(strict_types=1); use SixtyEightPublishers\AmpClient\Response\ValueObject\Banner; +use SixtyEightPublishers\AmpClient\Response\ValueObject\Dimensions; use SixtyEightPublishers\AmpClient\Response\ValueObject\HtmlContent; use SixtyEightPublishers\AmpClient\Response\ValueObject\ImageContent; use SixtyEightPublishers\AmpClient\Response\ValueObject\Position; use SixtyEightPublishers\AmpClient\Response\ValueObject\Position as ResponsePosition; use SixtyEightPublishers\AmpClient\Response\ValueObject\Source; -$position = new Position('1234', 'homepage.top', 'Homepage top', 0, Position::DisplayTypeSingle, Position::BreakpointTypeMin, ResponsePosition::ModeManaged, []); +$position = new Position( + '1234', + 'homepage.top', + 'Homepage top', + 0, + Position::DisplayTypeSingle, + Position::BreakpointTypeMin, + ResponsePosition::ModeManaged, + new Dimensions(800, 300), + [], +); + +$positionWithoutDimensions = new Position( + '1234', + 'homepage.top', + 'Homepage top', + 0, + Position::DisplayTypeSingle, + Position::BreakpointTypeMin, + ResponsePosition::ModeManaged, + new Dimensions(null, null), + [], +); return [ 'No banner' => [ @@ -57,6 +80,25 @@ [], __DIR__ . '/bannerWithDefaultImageContentOnly.withoutOptionalValues.html', ], + 'Banner with default content only: image without dimensions' => [ + $positionWithoutDimensions, + new Banner('1234', 'Main', 0, null, null, null, [ + new ImageContent( + null, + 'https://www.example.com/main1', + null, + 'Main 1', + 'Main 1', + 'https://img.example.com/1000/main1.png', + 'https://img.example.com/500/main1.png 500w, https://img.example.com/1000/main1.png 1000w', + '(min-width: 1000px) calc(1000px - 2 * 16px), (min-width: 600px) calc(100vw - 2 * 16px), 100vw', + [], + ), + ]), + [], + [], + __DIR__ . '/bannerWithDefaultImageContentOnly.withoutDimensions.html', + ], 'Banner with default content only: image with optional value' => [ $position, new Banner('1234', 'Main', 0, null, null, null, [ diff --git a/tests/resources/renderer/single/noBanner.html b/tests/resources/renderer/single/noBanner.html index 170c63b..0f8e14d 100644 --- a/tests/resources/renderer/single/noBanner.html +++ b/tests/resources/renderer/single/noBanner.html @@ -1 +1 @@ -
+
diff --git a/tests/resources/renderer/single/noBanner.withAttributes.html b/tests/resources/renderer/single/noBanner.withAttributes.html index 16cfa77..8ad038f 100644 --- a/tests/resources/renderer/single/noBanner.withAttributes.html +++ b/tests/resources/renderer/single/noBanner.withAttributes.html @@ -1 +1 @@ -
+
diff --git a/tests/resources/response-body/fetch-banners.full.json b/tests/resources/response-body/fetch-banners.full.json index 8c6d4c3..ecb1c63 100644 --- a/tests/resources/response-body/fetch-banners.full.json +++ b/tests/resources/response-body/fetch-banners.full.json @@ -8,6 +8,10 @@ "display_type": "multiple", "breakpoint_type": "min", "mode": "managed", + "dimensions": { + "width": 1320, + "height": 400 + }, "banners": [ { "id": "d7275445-c287-47d2-b71a-3baff5b4d23c", @@ -72,6 +76,10 @@ "display_type": "random", "breakpoint_type": "min", "mode": "managed", + "dimensions": { + "width": 800, + "height": 300 + }, "banners": [] }, "homepage.missing": { @@ -81,6 +89,10 @@ "display_type": null, "breakpoint_type": "min", "mode": "managed", + "dimensions": { + "width": null, + "height": null + }, "banners": [] }, "homepage.bottom": { @@ -90,6 +102,10 @@ "display_type": "single", "breakpoint_type": "min", "mode": "managed", + "dimensions": { + "width": 800, + "height": 300 + }, "banners": [ { "id": "54c72f46-2b6c-4d80-a75e-28fed4d79f5c", diff --git a/tests/resources/response-body/fetch-banners.full.php b/tests/resources/response-body/fetch-banners.full.php index bf8de2f..d3fa981 100644 --- a/tests/resources/response-body/fetch-banners.full.php +++ b/tests/resources/response-body/fetch-banners.full.php @@ -4,6 +4,7 @@ use SixtyEightPublishers\AmpClient\Response\BannersResponse; use SixtyEightPublishers\AmpClient\Response\ValueObject\Banner; +use SixtyEightPublishers\AmpClient\Response\ValueObject\Dimensions; use SixtyEightPublishers\AmpClient\Response\ValueObject\HtmlContent; use SixtyEightPublishers\AmpClient\Response\ValueObject\ImageContent; use SixtyEightPublishers\AmpClient\Response\ValueObject\Position; @@ -18,6 +19,10 @@ Position::DisplayTypeMultiple, Position::BreakpointTypeMin, Position::ModeManaged, + new Dimensions( + 1320, + 400, + ), [ new Banner( 'd7275445-c287-47d2-b71a-3baff5b4d23c', @@ -81,6 +86,10 @@ Position::DisplayTypeRandom, Position::BreakpointTypeMin, Position::ModeManaged, + new Dimensions( + 800, + 300, + ), [], ), 'homepage.missing' => new Position( @@ -91,6 +100,10 @@ null, Position::BreakpointTypeMin, Position::ModeManaged, + new Dimensions( + null, + null, + ), [], ), 'homepage.bottom' => new Position( @@ -101,6 +114,10 @@ Position::DisplayTypeSingle, Position::BreakpointTypeMin, Position::ModeManaged, + new Dimensions( + 800, + 300, + ), [ new Banner( '54c72f46-2b6c-4d80-a75e-28fed4d79f5c',