From 8d6fbc935de104c523542c39e847ef5510554600 Mon Sep 17 00:00:00 2001 From: Tomasz Kowalewski Date: Fri, 6 Dec 2024 13:55:35 +0100 Subject: [PATCH] OXDEV-8593 Added parentTheme and parentVersions fields to the ThemeDataType --- CHANGELOG.md | 5 ++++ src/Theme/DataType/ThemeDataType.php | 27 +++++++++++++++++++ src/Theme/DataType/ThemeDataTypeFactory.php | 4 ++- src/Theme/DataType/ThemeDataTypeInterface.php | 9 +++++++ .../Acceptance/Theme/ThemeListCest.php | 2 ++ .../DataType/ThemeDataTypeFactoryTest.php | 4 +++ .../Unit/Theme/DataType/ThemeDataTypeTest.php | 6 ++++- 7 files changed, 55 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d13feff..932d3a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. 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). +## [undecided] - Unreleased + +### Added +- New `parentTheme` and `parentVersions` fields in the `ThemeDataType` + ## [1.2.0] - 2024-11-27 This is the stable release of v1.2.0. No changes have been made since v1.2.0-rc.1. diff --git a/src/Theme/DataType/ThemeDataType.php b/src/Theme/DataType/ThemeDataType.php index 07cda0f..13e5bcb 100644 --- a/src/Theme/DataType/ThemeDataType.php +++ b/src/Theme/DataType/ThemeDataType.php @@ -10,9 +10,36 @@ namespace OxidEsales\GraphQL\ConfigurationAccess\Theme\DataType; use OxidEsales\GraphQL\ConfigurationAccess\Shared\DataType\AbstractComponentDataType; +use TheCodingMachine\GraphQLite\Annotations\Field; use TheCodingMachine\GraphQLite\Annotations\Type; #[Type] class ThemeDataType extends AbstractComponentDataType implements ThemeDataTypeInterface { + public function __construct( + string $id, + string $title, + string $version, + string $description, + bool $active, + private readonly ?string $parentTheme, + private readonly ?array $parentVersions, + ) { + parent::__construct($id, $title, $version, $description, $active); + } + + #[Field] + public function getParentTheme(): ?string + { + return $this->parentTheme; + } + + /** + * @return ?string[] + */ + #[Field] + public function getParentVersions(): ?array + { + return $this->parentVersions; + } } diff --git a/src/Theme/DataType/ThemeDataTypeFactory.php b/src/Theme/DataType/ThemeDataTypeFactory.php index 8809fbf..b9dd45e 100644 --- a/src/Theme/DataType/ThemeDataTypeFactory.php +++ b/src/Theme/DataType/ThemeDataTypeFactory.php @@ -21,7 +21,9 @@ public function createFromCoreTheme( title: $theme->getInfo('title'), version: $theme->getInfo('version'), description: $theme->getInfo('description'), - active: $theme->getInfo('active') + active: $theme->getInfo('active'), + parentTheme: $theme->getInfo('parentTheme'), + parentVersions: $theme->getInfo('parentVersions'), ); } } diff --git a/src/Theme/DataType/ThemeDataTypeInterface.php b/src/Theme/DataType/ThemeDataTypeInterface.php index 3aab3bf..86ddd03 100644 --- a/src/Theme/DataType/ThemeDataTypeInterface.php +++ b/src/Theme/DataType/ThemeDataTypeInterface.php @@ -3,9 +3,18 @@ namespace OxidEsales\GraphQL\ConfigurationAccess\Theme\DataType; use OxidEsales\GraphQL\ConfigurationAccess\Shared\DataType\ComponentDataTypeInterface; +use TheCodingMachine\GraphQLite\Annotations\Field; use TheCodingMachine\GraphQLite\Annotations\Type; #[Type] interface ThemeDataTypeInterface extends ComponentDataTypeInterface { + #[Field] + public function getParentTheme(): ?string; + + /** + * @return ?string[] + */ + #[Field] + public function getParentVersions(): ?array; } diff --git a/tests/Codeception/Acceptance/Theme/ThemeListCest.php b/tests/Codeception/Acceptance/Theme/ThemeListCest.php index 8786783..fcdb928 100644 --- a/tests/Codeception/Acceptance/Theme/ThemeListCest.php +++ b/tests/Codeception/Acceptance/Theme/ThemeListCest.php @@ -40,6 +40,8 @@ private function runThemeListQuery(AcceptanceTester $I): array version description active + parentTheme + parentVersions } }' ); diff --git a/tests/Unit/Theme/DataType/ThemeDataTypeFactoryTest.php b/tests/Unit/Theme/DataType/ThemeDataTypeFactoryTest.php index 011e35c..fe69093 100644 --- a/tests/Unit/Theme/DataType/ThemeDataTypeFactoryTest.php +++ b/tests/Unit/Theme/DataType/ThemeDataTypeFactoryTest.php @@ -28,6 +28,8 @@ public function testCreateThemeDataType(): void $expectedVersion = uniqid(); $expectedDescription = uniqid(); $expectedActive = true; + $expectedParentTheme = uniqid(); + $expectedParentVersions = [uniqid(), uniqid()]; $themeMock->method('getInfo') ->willReturnMap([ @@ -36,6 +38,8 @@ public function testCreateThemeDataType(): void ['version', $expectedVersion], ['description', $expectedDescription], ['active', $expectedActive], + ['parentTheme', $expectedParentTheme], + ['parentVersions', $expectedParentVersions], ]); $factory = new ThemeDataTypeFactory(); diff --git a/tests/Unit/Theme/DataType/ThemeDataTypeTest.php b/tests/Unit/Theme/DataType/ThemeDataTypeTest.php index cb8d7b9..058b63a 100644 --- a/tests/Unit/Theme/DataType/ThemeDataTypeTest.php +++ b/tests/Unit/Theme/DataType/ThemeDataTypeTest.php @@ -25,8 +25,10 @@ public function testThemeDataType(): void $version = uniqid(); $description = uniqid(); $active = (bool)random_int(0, 1); + $parentTheme = uniqid(); + $parentVersions = [uniqid(), uniqid()]; - $sut = new ThemeDataType($id, $name, $version, $description, $active); + $sut = new ThemeDataType($id, $name, $version, $description, $active, $parentTheme, $parentVersions); $this->assertInstanceOf(ComponentDataTypeInterface::class, $sut); $this->assertSame($name, $sut->getTitle()); @@ -34,5 +36,7 @@ public function testThemeDataType(): void $this->assertSame($version, $sut->getVersion()); $this->assertSame($description, $sut->getDescription()); $this->assertSame($active, $sut->isActive()); + $this->assertSame($parentTheme, $sut->getParentTheme()); + $this->assertSame($parentVersions, $sut->getParentVersions()); } }