Skip to content

Commit

Permalink
OXDEV-8214 Prepared ThemeSwitch codeception test
Browse files Browse the repository at this point in the history
  • Loading branch information
RahatHameed committed Jun 25, 2024
1 parent d5287e6 commit bdc0841
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tests/Codeception/Acceptance/BaseCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,9 @@ protected function getAdminPassword(): string
{
return self::ADMIN_PASSWORD;
}

public function getThemeId(): string
{
return getenv('THEME_ID') ?: 'apex';
}
}
42 changes: 42 additions & 0 deletions tests/Codeception/Acceptance/NotAuthorizedAccessCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use OxidEsales\GraphQL\ConfigurationAccess\Tests\Codeception\AcceptanceTester;

/**
* @group theme_switch
* @group theme_list
* @group theme_setting
* @group setting_access
Expand Down Expand Up @@ -72,6 +73,20 @@ public function testGetSettingNotAuthorizedMutation(AcceptanceTester $I, \Codece
$this->assertQueryNotFoundErrorInResult($I, $result);
}

#[DataProvider('themeMutationsReturnsBoolDataProvider')]
public function testSwitchThemeNotAuthorizedMutation(AcceptanceTester $I, \Codeception\Example $example): void
{
$I->login($this->getAgentUsername(), $this->getAgentPassword());
$result = $this->runSimplifiedAccessCheckMutationForBool(
I: $I,
queryName: $example['queryName'],
field: $example['field'],
value: $example['value']
);

$this->assertQueryNotFoundErrorInResult($I, $result);
}

protected function themeGettersDataProvider(): \Generator
{
yield ['queryName' => 'themeSettingInteger', 'field' => 'name', 'location' => 'theme'];
Expand Down Expand Up @@ -193,6 +208,15 @@ protected function shopMutationsDataProvider(): \Generator
];
}

protected function themeMutationsReturnsBoolDataProvider(): \Generator
{
yield [
'queryName' => 'switchTheme',
'field' => 'identifier',
'value' => 'test'
];
}

private function runSimplifiedAccessCheckQuery(
AcceptanceTester $I,
string $queryName,
Expand Down Expand Up @@ -249,6 +273,24 @@ private function runSimplifiedAccessCheckMutation(
return $I->grabJsonResponseAsArray();
}

private function runSimplifiedAccessCheckMutationForBool(
AcceptanceTester $I,
string $queryName,
string $field,
mixed $value,
): array {
$parameters = $field . ': "' . $value . '"';
$I->sendGQLQuery(
'mutation {
' . $queryName . '(' . $parameters . ')
}'
);

$I->seeResponseIsJson();

return $I->grabJsonResponseAsArray();
}

private function getLocationParameterString(string $location): ?string
{
return match ($location) {
Expand Down
47 changes: 47 additions & 0 deletions tests/Codeception/Acceptance/Theme/ThemeSwitchCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

/**
* Copyright © OXID eSales AG. All rights reserved.
* See LICENSE file for license details.
*/

declare(strict_types=1);

namespace OxidEsales\GraphQL\ConfigurationAccess\Tests\Codeception\Acceptance\Theme;

use OxidEsales\GraphQL\ConfigurationAccess\Tests\Codeception\Acceptance\BaseCest;
use OxidEsales\GraphQL\ConfigurationAccess\Tests\Codeception\AcceptanceTester;

/**
* @group theme_switch
* @group setting_access
* @group oe_graphql_configuration_access
*/
final class ThemeSwitchCest extends BaseCest
{
public function testThemeSwitchAuthorized(AcceptanceTester $I): void
{
$I->login($this->getAdminUsername(), $this->getAdminPassword());

$result = $this->runThemeListQuery($I);

$I->assertArrayNotHasKey('errors', $result);
$response = $result['data']['switchTheme'];
$I->assertTrue($response);
}

public function runThemeListQuery(AcceptanceTester $I): array
{
$themeId = $this->getThemeId();

$I->login($this->getAdminUsername(), $this->getAdminPassword());
$I->sendGQLQuery(
'mutation switchThemeCest{
switchTheme(identifier: "' . $themeId . '")
}'
);

$I->seeResponseIsJson();
return $I->grabJsonResponseAsArray();
}
}

0 comments on commit bdc0841

Please sign in to comment.