diff --git a/.github/oxid-esales/graphql-configuration-access_light.yaml b/.github/oxid-esales/graphql-configuration-access_light.yaml index 9ae5286..28c5798 100644 --- a/.github/oxid-esales/graphql-configuration-access_light.yaml +++ b/.github/oxid-esales/graphql-configuration-access_light.yaml @@ -57,10 +57,10 @@ sonarcloud: project_key: 'OXID-eSales_graphql-configuration-access' project_name: 'oxid-esales/graphql-configuration-access' parameters: | - -Dsonar.language=php - -Dsonar.scm.provider=git - -Dsonar.sources=src - -Dsonar.tests=tests + -Dsonar.language=php \ + -Dsonar.scm.provider=git \ + -Dsonar.sources=src \ + -Dsonar.tests=tests \ -Dsonar.php.phpstan.reportPaths=coverage-reports/phpstan.report.json finish: diff --git a/CHANGELOG.md b/CHANGELOG.md index d13feff..f872149 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). +## [2.0.0] - 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..c1a8cde 100644 --- a/tests/Codeception/Acceptance/Theme/ThemeListCest.php +++ b/tests/Codeception/Acceptance/Theme/ThemeListCest.php @@ -9,7 +9,6 @@ namespace OxidEsales\GraphQL\ConfigurationAccess\Tests\Codeception\Acceptance\Theme; -use OxidEsales\GraphQL\ConfigurationAccess\Shared\Enum\FieldType; use OxidEsales\GraphQL\ConfigurationAccess\Tests\Codeception\Acceptance\BaseCest; use OxidEsales\GraphQL\ConfigurationAccess\Tests\Codeception\AcceptanceTester; @@ -40,6 +39,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..7a9b46e 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(); @@ -47,5 +51,7 @@ public function testCreateThemeDataType(): void $this->assertEquals($expectedVersion, $themeDataType->getVersion()); $this->assertEquals($expectedDescription, $themeDataType->getDescription()); $this->assertTrue($themeDataType->isActive()); + $this->assertEquals($expectedParentTheme, $themeDataType->getParentTheme()); + $this->assertEquals($expectedParentVersions, $themeDataType->getParentVersions()); } } diff --git a/tests/Unit/Theme/DataType/ThemeDataTypeTest.php b/tests/Unit/Theme/DataType/ThemeDataTypeTest.php index cb8d7b9..94a6c9d 100644 --- a/tests/Unit/Theme/DataType/ThemeDataTypeTest.php +++ b/tests/Unit/Theme/DataType/ThemeDataTypeTest.php @@ -15,6 +15,7 @@ /** * @covers \OxidEsales\GraphQL\ConfigurationAccess\Shared\DataType\AbstractComponentDataType + * @covers \OxidEsales\GraphQL\ConfigurationAccess\Theme\DataType\ThemeDataType */ class ThemeDataTypeTest extends TestCase { @@ -25,8 +26,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 +37,23 @@ 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()); + } + + public function testThemeDataTypeWithNullableValues(): void + { + $name = uniqid(); + $id = uniqid(); + $version = uniqid(); + $description = uniqid(); + $active = (bool)random_int(0, 1); + $parentTheme = null; + $parentVersions = null; + + $sut = new ThemeDataType($id, $name, $version, $description, $active, $parentTheme, $parentVersions); + + $this->assertNull($sut->getParentTheme()); + $this->assertNull($sut->getParentVersions()); } }