Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added integration of the new fields close_expiration #8

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- Added integration of the new fields `close_expiration` into Position and Banner entities and also into the `data-amp-banner-external` and `data-amp-banner-fingerprint` attributes.

## [1.3.1] - 2024-10-11
### Added
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ $ composer require 68publishers/amp-client
| `~1.1.0` | `~1.4.0` | `2.12.0` | `1` |
| `~1.2.0` | `~1.5.0` | `>=2.13.0 <= 2.15.1` | `1` |
| `~1.3.0` | `~1.6.0` | `>=2.16.0` | `1` |
| `~1.4.0` | `~1.7.0` | `>=2.17.0` | `1` |

## Integration without a framework

Expand Down
1 change: 1 addition & 0 deletions src/Renderer/AmpBannerExternalAttribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public function __toString(): string
'rotationSeconds' => $this->position->getRotationSeconds(),
'displayType' => $this->position->getDisplayType(),
'breakpointType' => $this->position->getBreakpointType(),
'closeExpiration' => $this->position->getCloseExpiration(),
],
'state' => [
'value' => $this->state,
Expand Down
1 change: 1 addition & 0 deletions src/Renderer/Fingerprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public static function create(Position $position, Banner $banner): self
'campaignId' => $banner->getCampaignId(),
'campaignCode' => $banner->getCampaignCode(),
'campaignName' => $banner->getCampaignName(),
'closeExpiration' => $banner->getCloseExpiration(),
];

try {
Expand Down
4 changes: 4 additions & 0 deletions src/Response/Hydrator/BannersResponseHydratorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
* campaign_id: string|null,
* campaign_code: string|null,
* campaign_name: string|null,
* close_expiration: int|null,
* contents: array<int, HtmlContentData|ImageContentData>,
* }
*
Expand All @@ -60,6 +61,7 @@
* display_type: string|null,
* breakpoint_type: string,
* mode?: string,
* close_expiration?: int|null,
* options?: array<string, string>,
* banners: array<int, BannerData>,
* }
Expand Down Expand Up @@ -93,6 +95,7 @@ public function hydrate($responseBody): BannersResponse
$positionData['display_type'] ?? null,
$positionData['breakpoint_type'],
$positionData['mode'] ?? Position::ModeManaged,
$positionData['close_expiration'] ?? null,
$positionData['options'] ?? [],
$this->hydrateBanners($positionData['banners']),
);
Expand All @@ -118,6 +121,7 @@ private function hydrateBanners(array $bannersData): array
$bannerData['campaign_id'],
$bannerData['campaign_code'],
$bannerData['campaign_name'],
$bannerData['close_expiration'] ?? null,
$this->hydrateContents($bannerData['contents']),
);
}
Expand Down
9 changes: 9 additions & 0 deletions src/Response/ValueObject/Banner.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ final class Banner

private ?string $campaignName;

private ?int $closeExpiration;

/** @var array<int, ContentInterface> */
private array $contents;

Expand All @@ -33,6 +35,7 @@ public function __construct(
?string $campaignId,
?string $campaignCode,
?string $campaignName,
?int $closeExpiration,
array $contents
) {
$this->id = $id;
Expand All @@ -41,6 +44,7 @@ public function __construct(
$this->campaignId = $campaignId;
$this->campaignCode = $campaignCode;
$this->campaignName = $campaignName;
$this->closeExpiration = $closeExpiration;
$this->contents = $contents;
}

Expand Down Expand Up @@ -77,6 +81,11 @@ public function getCampaignName(): ?string
return $this->campaignName;
}

public function getCloseExpiration(): ?int
{
return $this->closeExpiration;
}

/**
* @return array<int, ContentInterface>
*/
Expand Down
9 changes: 9 additions & 0 deletions src/Response/ValueObject/Position.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ final class Position

private string $mode;

private ?int $closeExpiration;

/** @var array<string, string> */
private array $options;

Expand All @@ -48,6 +50,7 @@ public function __construct(
?string $displayType,
string $breakpointType,
string $mode,
?int $closeExpiration,
array $options,
array $banners
) {
Expand All @@ -58,6 +61,7 @@ public function __construct(
$this->displayType = $displayType;
$this->breakpointType = $breakpointType;
$this->mode = $mode;
$this->closeExpiration = $closeExpiration;
$this->options = $options;
$this->banners = $banners;
}
Expand Down Expand Up @@ -97,6 +101,11 @@ public function getMode(): string
return $this->mode;
}

public function getCloseExpiration(): ?int
{
return $this->closeExpiration;
}

/**
* @return array<string, string>
*/
Expand Down
15 changes: 15 additions & 0 deletions tests/Bridge/Latte/RendererProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public function testInvokingDefaultInstanceWithoutResources(): void
ResponsePosition::DisplayTypeSingle,
ResponsePosition::BreakpointTypeMin,
ResponsePosition::ModeManaged,
null,
[],
[],
);
Expand Down Expand Up @@ -90,6 +91,7 @@ public function testInvokingDefaultInstanceWithSameModeAsDefault(): void
ResponsePosition::DisplayTypeSingle,
ResponsePosition::BreakpointTypeMin,
ResponsePosition::ModeManaged,
null,
[],
[],
);
Expand Down Expand Up @@ -135,6 +137,7 @@ public function testInvokingDefaultInstanceWithAttributes(): void
ResponsePosition::DisplayTypeSingle,
ResponsePosition::BreakpointTypeMin,
ResponsePosition::ModeManaged,
null,
[],
[],
);
Expand Down Expand Up @@ -180,6 +183,7 @@ public function testInvokingDefaultInstanceWithOptions(): void
ResponsePosition::DisplayTypeSingle,
ResponsePosition::BreakpointTypeMin,
ResponsePosition::ModeManaged,
null,
[],
[],
);
Expand Down Expand Up @@ -225,6 +229,7 @@ public function testInvokingDefaultInstanceWithResources(): void
ResponsePosition::DisplayTypeSingle,
ResponsePosition::BreakpointTypeMin,
ResponsePosition::ModeManaged,
null,
[],
[],
);
Expand Down Expand Up @@ -286,6 +291,7 @@ public function testInvokingDefaultInstanceWithPositionInEmbedMode(): void
ResponsePosition::DisplayTypeSingle,
ResponsePosition::BreakpointTypeMin,
$positionMode,
null,
[],
[],
);
Expand Down Expand Up @@ -332,6 +338,7 @@ public function testClientConfigurationEventsShouldBeInvokedBeforeFirstFetch():
ResponsePosition::DisplayTypeSingle,
ResponsePosition::BreakpointTypeMin,
ResponsePosition::ModeManaged,
null,
[],
[],
);
Expand Down Expand Up @@ -452,6 +459,7 @@ public function testExceptionShouldBeThrownWhenRendererThrowsExceptionInDebugMod
ResponsePosition::DisplayTypeSingle,
ResponsePosition::BreakpointTypeMin,
ResponsePosition::ModeManaged,
null,
[],
[],
);
Expand Down Expand Up @@ -491,6 +499,7 @@ public function testEmptyStringShouldBeReturnedWhenRendererThrowsExceptionInNonD
ResponsePosition::DisplayTypeSingle,
ResponsePosition::BreakpointTypeMin,
ResponsePosition::ModeManaged,
null,
[],
[],
);
Expand Down Expand Up @@ -528,6 +537,7 @@ public function testExceptionShouldBeLoggedWhenRendererThrowsExceptionInNonDebug
ResponsePosition::DisplayTypeSingle,
ResponsePosition::BreakpointTypeMin,
ResponsePosition::ModeManaged,
null,
[],
[],
);
Expand Down Expand Up @@ -615,6 +625,7 @@ public function testPositionsShouldBeQueuedAndReplacedInStringOutput(): void
ResponsePosition::DisplayTypeSingle,
ResponsePosition::BreakpointTypeMin,
ResponsePosition::ModeManaged,
null,
[],
[],
);
Expand All @@ -626,6 +637,7 @@ public function testPositionsShouldBeQueuedAndReplacedInStringOutput(): void
ResponsePosition::DisplayTypeSingle,
ResponsePosition::BreakpointTypeMin,
ResponsePosition::ModeManaged,
null,
[],
[],
);
Expand Down Expand Up @@ -727,6 +739,7 @@ public function testPositionsShouldBeQueuedAndReplacedInArrayOutput(): void
ResponsePosition::DisplayTypeSingle,
ResponsePosition::BreakpointTypeMin,
ResponsePosition::ModeManaged,
null,
[],
[],
);
Expand All @@ -738,6 +751,7 @@ public function testPositionsShouldBeQueuedAndReplacedInArrayOutput(): void
ResponsePosition::DisplayTypeSingle,
ResponsePosition::BreakpointTypeMin,
ResponsePosition::ModeManaged,
null,
[],
[],
);
Expand Down Expand Up @@ -829,6 +843,7 @@ public function testEmbedPositionReturnedFromApiShouldBeQueuedAndReplacedInStrin
ResponsePosition::DisplayTypeSingle,
ResponsePosition::BreakpointTypeMin,
ResponsePosition::ModeEmbed,
null,
[],
[],
);
Expand Down
30 changes: 18 additions & 12 deletions tests/Renderer/BannersResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public function testNullShouldBeReturnedWhenResolvingSinglePositionWithoutBanner
Position::DisplayTypeSingle,
Position::BreakpointTypeMin,
Position::ModeManaged,
null,
[],
[],
);
Expand All @@ -34,10 +35,10 @@ public function testNullShouldBeReturnedWhenResolvingSinglePositionWithoutBanner

public function testFirstBannerWithHighestScoreShouldBeReturnedWhenResolvingSinglePosition(): void
{
$banner1 = new Banner('1', '1', 0, null, null, null, []);
$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, []);
$banner1 = new Banner('1', '1', 0, null, null, null, null, []);
$banner2 = new Banner('2', '2', 2, null, null, null, null, []);
$banner3 = new Banner('3', '3', 1, null, null, null, null, []);
$banner4 = new Banner('4', '4', 2, null, null, null, null, []);
$position = new Position(
'1234',
'homepage.top',
Expand All @@ -46,6 +47,7 @@ public function testFirstBannerWithHighestScoreShouldBeReturnedWhenResolvingSing
Position::DisplayTypeSingle,
Position::BreakpointTypeMin,
Position::ModeManaged,
null,
[],
[$banner1, $banner2, $banner3, $banner4],
);
Expand All @@ -64,6 +66,7 @@ public function testEmptyArrayShouldBeReturnedWhenResolvingMultiplePositionWitho
Position::DisplayTypeMultiple,
Position::BreakpointTypeMin,
Position::ModeManaged,
null,
[],
[],
);
Expand All @@ -74,10 +77,10 @@ public function testEmptyArrayShouldBeReturnedWhenResolvingMultiplePositionWitho

public function testSortedBannersShouldBeReturnedWhenResolvingMultiplePosition(): void
{
$banner1 = new Banner('1', '1', 0, null, null, null, []);
$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, []);
$banner1 = new Banner('1', '1', 0, null, null, null, null, []);
$banner2 = new Banner('2', '2', 2, null, null, null, null, []);
$banner3 = new Banner('3', '3', 1, null, null, null, null, []);
$banner4 = new Banner('4', '4', 2, null, null, null, null, []);
$position = new Position(
'1234',
'homepage.top',
Expand All @@ -86,6 +89,7 @@ public function testSortedBannersShouldBeReturnedWhenResolvingMultiplePosition()
Position::DisplayTypeMultiple,
Position::BreakpointTypeMin,
Position::ModeManaged,
null,
[],
[$banner1, $banner2, $banner3, $banner4],
);
Expand All @@ -109,6 +113,7 @@ public function testNullShouldBeReturnedWhenResolvingRandomPositionWithoutBanner
Position::DisplayTypeRandom,
Position::BreakpointTypeMin,
Position::ModeManaged,
null,
[],
[],
);
Expand All @@ -119,10 +124,10 @@ public function testNullShouldBeReturnedWhenResolvingRandomPositionWithoutBanner

public function testRandomBannerShouldBeReturnedWhenResolvingRandomPosition(): void
{
$banner1 = new Banner('1', '1', 1, null, null, null, []);
$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, []);
$banner1 = new Banner('1', '1', 1, null, null, null, null, []);
$banner2 = new Banner('2', '2', 3, null, null, null, null, []);
$banner3 = new Banner('3', '3', 2, null, null, null, null, []);
$banner4 = new Banner('4', '4', 3, null, null, null, null, []);
$position = new Position(
'1234',
'homepage.top',
Expand All @@ -131,6 +136,7 @@ public function testRandomBannerShouldBeReturnedWhenResolvingRandomPosition(): v
Position::DisplayTypeRandom,
Position::BreakpointTypeMin,
Position::ModeManaged,
null,
[],
[$banner1, $banner2, $banner3, $banner4],
);
Expand Down
2 changes: 2 additions & 0 deletions tests/Renderer/BreakpointStyle/BreakpointStyleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ private function createBreakpointStyle(string $breakpointType, array $contents):
null,
null,
null,
null,
$contents,
);

Expand All @@ -132,6 +133,7 @@ private function createBreakpointStyle(string $breakpointType, array $contents):
Position::DisplayTypeSingle,
$breakpointType,
ResponsePosition::ModeManaged,
null,
[],
[$banner],
);
Expand Down
Loading
Loading