Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/b-7.3.x-add-parent-theme-data-OX…
Browse files Browse the repository at this point in the history
…DEV-8593' into b-7.3.x
  • Loading branch information
MarcelOxid committed Dec 12, 2024
2 parents bf2f233 + 3b126da commit b55457a
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 7 deletions.
8 changes: 4 additions & 4 deletions .github/oxid-esales/graphql-configuration-access_light.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
27 changes: 27 additions & 0 deletions src/Theme/DataType/ThemeDataType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
4 changes: 3 additions & 1 deletion src/Theme/DataType/ThemeDataTypeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
);
}
}
9 changes: 9 additions & 0 deletions src/Theme/DataType/ThemeDataTypeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
3 changes: 2 additions & 1 deletion tests/Codeception/Acceptance/Theme/ThemeListCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -40,6 +39,8 @@ private function runThemeListQuery(AcceptanceTester $I): array
version
description
active
parentTheme
parentVersions
}
}'
);
Expand Down
6 changes: 6 additions & 0 deletions tests/Unit/Theme/DataType/ThemeDataTypeFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public function testCreateThemeDataType(): void
$expectedVersion = uniqid();
$expectedDescription = uniqid();
$expectedActive = true;
$expectedParentTheme = uniqid();
$expectedParentVersions = [uniqid(), uniqid()];

$themeMock->method('getInfo')
->willReturnMap([
Expand All @@ -36,6 +38,8 @@ public function testCreateThemeDataType(): void
['version', $expectedVersion],
['description', $expectedDescription],
['active', $expectedActive],
['parentTheme', $expectedParentTheme],
['parentVersions', $expectedParentVersions],
]);

$factory = new ThemeDataTypeFactory();
Expand All @@ -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());
}
}
23 changes: 22 additions & 1 deletion tests/Unit/Theme/DataType/ThemeDataTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

/**
* @covers \OxidEsales\GraphQL\ConfigurationAccess\Shared\DataType\AbstractComponentDataType
* @covers \OxidEsales\GraphQL\ConfigurationAccess\Theme\DataType\ThemeDataType
*/
class ThemeDataTypeTest extends TestCase
{
Expand All @@ -25,14 +26,34 @@ 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());
$this->assertSame($id, $sut->getId());
$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());
}
}

0 comments on commit b55457a

Please sign in to comment.