Skip to content

Commit

Permalink
OXDEV-8489: Rename identifier to themeId for switchTheme-mutation
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcelOxid committed Aug 14, 2024
1 parent 574c975 commit 20b7179
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 24 deletions.
6 changes: 3 additions & 3 deletions src/Theme/Controller/ThemeSwitchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ public function __construct(

/**
* Mutation of Configuration Access Module
* @param string $identifier
* @param string $themeId
* @return bool
*/
#[Mutation]
#[Logged]
#[Right('CHANGE_CONFIGURATION')]
public function switchTheme(string $identifier): bool
public function switchTheme(string $themeId): bool
{
return $this->themeSwitchService->switchTheme($identifier);
return $this->themeSwitchService->switchTheme($themeId);
}
}
4 changes: 2 additions & 2 deletions src/Theme/Infrastructure/ThemeSwitchInfrastructure.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ public function __construct(
) {
}

public function switchTheme(string $identifier): bool
public function switchTheme(string $themeId): bool
{
try {
$coreThemeService = $this->coreThemeFactory->create();
if (!$coreThemeService->load($identifier)) {
if (!$coreThemeService->load($themeId)) {
throw new ThemeActivationException(self::THEME_NOT_EXIST);
}
$coreThemeService->activate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ interface ThemeSwitchInfrastructureInterface
/**
*@throws ThemeActivationException
*/
public function switchTheme(string $identifier): bool;
public function switchTheme(string $themeId): bool;
}
4 changes: 2 additions & 2 deletions src/Theme/Service/ThemeSwitchService.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public function __construct(
private readonly ThemeSwitchInfrastructureInterface $themeSwitchInfrastructure
) {
}
public function switchTheme(string $identifier): bool
public function switchTheme(string $themeId): bool
{
return $this->themeSwitchInfrastructure->switchTheme(identifier: $identifier);
return $this->themeSwitchInfrastructure->switchTheme(themeId: $themeId);
}
}
2 changes: 1 addition & 1 deletion src/Theme/Service/ThemeSwitchServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@

interface ThemeSwitchServiceInterface
{
public function switchTheme(string $identifier): bool;
public function switchTheme(string $themeId): bool;
}
2 changes: 1 addition & 1 deletion tests/Codeception/Acceptance/Theme/ThemeSwitchCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private function runThemeSwitchMutation(AcceptanceTester $I): array

$I->sendGQLQuery(
'mutation switchThemeCest{
switchTheme(identifier: "' . $themeId . '")
switchTheme(themeId: "' . $themeId . '")
}'
);

Expand Down
10 changes: 5 additions & 5 deletions tests/Unit/Theme/Controller/ThemeSwitchControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,30 @@ class ThemeSwitchControllerTest extends TestCase
{
/** @dataProvider switchThemeProvider */
public function testSwitchTheme(
string $identifier,
string $themeId,
bool $expectedResult
): void {
$themeSwitchServiceMock = $this->createMock(ThemeSwitchServiceInterface::class);
$themeSwitchServiceMock
->method('switchTheme')
->with($identifier)
->with($themeId)
->willReturn($expectedResult);

$themeSwitchController = new ThemeSwitchController($themeSwitchServiceMock);
$response = $themeSwitchController->switchTheme($identifier);
$response = $themeSwitchController->switchTheme($themeId);

$this->assertSame($expectedResult, $response);
}

public static function switchThemeProvider(): \Generator
{
yield 'test switch theme successful case' => [
'identifier' => 'validThemeId',
'themeId' => 'validThemeId',
'expectedResult' => true
];

yield 'test switch theme failure case' => [
'identifier' => 'invalidThemeId',
'themeId' => 'invalidThemeId',
'expectedResult' => false
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,23 @@ class ThemeSwitchInfrastructureTest extends TestCase
private const THEME_NOT_EXIST = "The specified theme doesn't exist.";
public function testSwitchTheme(): void
{
$identifier = 'apex';
$themeId = 'apex';
$coreThemeMock = $this->createMock(Theme::class);
$coreThemeMock->expects($this->once())->method('load')->with($identifier)->willReturn(true);
$coreThemeMock->expects($this->once())->method('load')->with($themeId)->willReturn(true);
$coreThemeMock->expects($this->once())->method('activate');

$coreThemeFactoryMock = $this->getCoreThemeFactoryMock(coreThemeMock: $coreThemeMock);
$sut = $this->getSut(coreThemeFactory: $coreThemeFactoryMock);

$serviceResponse = $sut->switchTheme($identifier);
$serviceResponse = $sut->switchTheme($themeId);
$this->assertTrue($serviceResponse);
}

public function testThemeNotActivatedException(): void
{
$identifier = 'apex';
$themeId = 'apex';
$coreThemeMock = $this->createMock(Theme::class);
$coreThemeMock->expects($this->once())->method('load')->with($identifier)->willReturn(true);
$coreThemeMock->expects($this->once())->method('load')->with($themeId)->willReturn(true);
$coreThemeMock->expects($this->once())->method('activate')
->will($this->throwException(
new StandardException(self::THEME_NOT_ACTIVATED)
Expand All @@ -52,7 +52,7 @@ public function testThemeNotActivatedException(): void

$this->expectException(ThemeActivationException::class);
$this->expectExceptionMessage(self::THEME_NOT_ACTIVATED);
$sut->switchTheme($identifier);
$sut->switchTheme($themeId);
}

public function testThemeNotFoundException(): void
Expand Down
6 changes: 3 additions & 3 deletions tests/Unit/Theme/Service/ThemeSwitchServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ class ThemeSwitchServiceTest extends TestCase
public function testSwitchTheme(
bool $expectedResult
): void {
$identifier = uniqid();
$themeId = uniqid();
$themeSwitchInfrastructureMock = $this->createMock(ThemeSwitchInfrastructureInterface::class);
$themeSwitchInfrastructureMock
->method('switchTheme')
->with($identifier)
->with($themeId)
->willReturn($expectedResult);

$themeSwitchInfrastructure = new ThemeSwitchService($themeSwitchInfrastructureMock);
$response = $themeSwitchInfrastructure->switchTheme($identifier);
$response = $themeSwitchInfrastructure->switchTheme($themeId);

$this->assertSame($expectedResult, $response);
}
Expand Down

0 comments on commit 20b7179

Please sign in to comment.