Skip to content

Commit

Permalink
OXDEV-7557 Cleanup codeception tests
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Fedurtsya <[email protected]>
  • Loading branch information
Sieg committed Nov 14, 2023
1 parent f09b496 commit c9ce469
Show file tree
Hide file tree
Showing 14 changed files with 790 additions and 1,336 deletions.
15 changes: 2 additions & 13 deletions tests/Codeception/Acceptance/BaseCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@

abstract class BaseCest
{
private const TEST_THEME_ID = 'awesomeTheme';
public const TEST_MODULE_ID = 'awesomeModule';
public const TEST_THEME_ID = 'awesomeTheme';

private const AGENT_USERNAME = '[email protected]';

Expand Down Expand Up @@ -52,16 +53,4 @@ protected function getAdminPassword(): string
{
return self::ADMIN_PASSWORD;
}

protected function assertQueryNotFoundErrorInResult(AcceptanceTester $I, array $result, string $query): void
{
$errorMessage = $result['errors'][0]['message'];
$I->assertSame('Cannot query field "' . $query . '" on type "Query".', $errorMessage);
}

protected function assertMutationNotFoundErrorInResult(AcceptanceTester $I, array $result, string $mutation): void
{
$errorMessage = $result['errors'][0]['message'];
$I->assertSame('Cannot query field "' . $mutation . '" on type "Mutation".', $errorMessage);
}
}
2 changes: 0 additions & 2 deletions tests/Codeception/Acceptance/ModuleSettingBaseCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

abstract class ModuleSettingBaseCest extends BaseCest
{
protected const TEST_MODULE_ID = 'awesomeModule';

public function _before(AcceptanceTester $I): void
{
$this->prepareConfiguration();
Expand Down
88 changes: 88 additions & 0 deletions tests/Codeception/Acceptance/ModuleSettingGettersCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?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;

use Codeception\Attribute\DataProvider;
use OxidEsales\GraphQL\ConfigurationAccess\Tests\Codeception\AcceptanceTester;

/**
* @group module_setting
* @group setting_access
* @group oe_graphql_configuration_access
*/
final class ModuleSettingGettersCest extends ModuleSettingBaseCest
{
#[DataProvider('queryMethodsDataProvider')]
public function testGetSettingAuthorized(AcceptanceTester $I, \Codeception\Example $example): void
{
$I->login($this->getAdminUsername(), $this->getAdminPassword());

$result = $this->runSettingGetterQuery($I, $example['queryName'], $example['settingName']);

$I->assertArrayNotHasKey('errors', $result);

$setting = $result['data'][$example['queryName']];
$I->assertSame($example['settingName'], $setting['name']);
$I->assertSame($example['expectedValue'], $setting['value']);
}

protected function queryMethodsDataProvider(): \Generator
{
yield [
'queryName' => 'moduleSettingInteger',
'settingName' => 'intSetting',
'expectedValue' => 123
];

yield [
'queryName' => 'moduleSettingFloat',
'settingName' => 'floatSetting',
'expectedValue' => 1.23
];

yield [
'queryName' => 'moduleSettingBoolean',
'settingName' => 'boolSetting',
'expectedValue' => false
];

yield [
'queryName' => 'moduleSettingString',
'settingName' => 'stringSetting',
'expectedValue' => 'default'
];

yield [
'queryName' => 'moduleSettingCollection',
'settingName' => 'arraySetting',
'expectedValue' => '["nice","values"]'
];
}

private function runSettingGetterQuery(AcceptanceTester $I, string $queryName, string $settingName): array
{
$I->sendGQLQuery(
'query q($name: ID!, $moduleId: String!){
' . $queryName . '(name: $name, moduleId: $moduleId) {
name
value
}
}',
[
'name' => $settingName,
'moduleId' => self::TEST_MODULE_ID
]
);

$I->seeResponseIsJson();

return $I->grabJsonResponseAsArray();
}
}
65 changes: 65 additions & 0 deletions tests/Codeception/Acceptance/ModuleSettingListCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?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;

use OxidEsales\GraphQL\ConfigurationAccess\Setting\Enum\FieldType;
use OxidEsales\GraphQL\ConfigurationAccess\Tests\Codeception\AcceptanceTester;

/**
* @group module_setting
* @group setting_access
* @group oe_graphql_configuration_access
*/
final class ModuleSettingListCest extends ModuleSettingBaseCest
{
public function testGetModuleSettingsListAuthorized(AcceptanceTester $I): void
{
$I->login($this->getAdminUsername(), $this->getAdminPassword());

$I->sendGQLQuery(
'query getSettings($moduleId: String!){
moduleSettingsList(moduleId: $moduleId) {
name
type
supported
}
}',
['moduleId' => self::TEST_MODULE_ID]
);

$I->seeResponseIsJson();

$result = $I->grabJsonResponseAsArray();
$I->assertArrayNotHasKey('errors', $result);

$settingsList = $result['data']['moduleSettingsList'];
$I->assertCount(5, $settingsList);
$I->assertContains(
['name' => 'intSetting', 'type' => FieldType::NUMBER, 'supported' => true],
$settingsList
);
$I->assertContains(
['name' => 'floatSetting', 'type' => FieldType::NUMBER, 'supported' => true],
$settingsList
);
$I->assertContains(
['name' => 'boolSetting', 'type' => FieldType::BOOLEAN, 'supported' => true],
$settingsList
);
$I->assertContains(
['name' => 'stringSetting', 'type' => FieldType::STRING, 'supported' => true],
$settingsList
);
$I->assertContains(
['name' => 'arraySetting', 'type' => FieldType::ARRAY, 'supported' => true],
$settingsList
);
}
}
114 changes: 1 addition & 113 deletions tests/Codeception/Acceptance/ModuleSettingMutationsCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@

declare(strict_types=1);

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

use OxidEsales\GraphQL\ConfigurationAccess\Setting\Enum\FieldType;
use OxidEsales\GraphQL\ConfigurationAccess\Tests\Codeception\Acceptance\ModuleSettingBaseCest;
use OxidEsales\GraphQL\ConfigurationAccess\Tests\Codeception\AcceptanceTester;

/**
Expand All @@ -20,15 +18,6 @@
*/
final class ModuleSettingMutationsCest extends ModuleSettingBaseCest
{
public function testChangeIntegerSettingNotAuthorized(AcceptanceTester $I): void
{
$I->login($this->getAgentUsername(), $this->getAgentPassword());

$result = $this->runChangeIntegerMutationAndGetResult($I, 'intSetting', 124);

$this->assertMutationNotFoundErrorInResult($I, $result, 'changeModuleSettingInteger');
}

public function testChangeIntegerSettingAuthorized(AcceptanceTester $I): void
{
$I->login($this->getAdminUsername(), $this->getAdminPassword());
Expand Down Expand Up @@ -63,15 +52,6 @@ private function runChangeIntegerMutationAndGetResult(AcceptanceTester $I, strin
return $I->grabJsonResponseAsArray();
}

public function testChangeFloatSettingNotAuthorized(AcceptanceTester $I): void
{
$I->login($this->getAgentUsername(), $this->getAgentPassword());

$result = $this->runFloatMutationAndGetResult($I, 'floatSetting', 1.24);

$this->assertMutationNotFoundErrorInResult($I, $result, 'changeModuleSettingFloat');
}

public function testChangeFloatSettingAuthorized(AcceptanceTester $I): void
{
$I->login($this->getAdminUsername(), $this->getAdminPassword());
Expand Down Expand Up @@ -105,15 +85,6 @@ private function runFloatMutationAndGetResult(AcceptanceTester $I, string $name,
return $I->grabJsonResponseAsArray();
}

public function testChangeBooleanSettingNotAuthorized(AcceptanceTester $I): void
{
$I->login($this->getAgentUsername(), $this->getAgentPassword());

$result = $this->runChangeBooleanMutationAndGetResult($I, 'boolSetting', false);

$this->assertMutationNotFoundErrorInResult($I, $result, 'changeModuleSettingBoolean');
}

public function testChangeBooleanSettingAuthorized(AcceptanceTester $I): void
{
$I->login($this->getAdminUsername(), $this->getAdminPassword());
Expand Down Expand Up @@ -148,15 +119,6 @@ private function runChangeBooleanMutationAndGetResult(AcceptanceTester $I, strin
return $I->grabJsonResponseAsArray();
}

public function testChangeStringSettingNotAuthorized(AcceptanceTester $I): void
{
$I->login($this->getAgentUsername(), $this->getAgentPassword());

$result = $this->runChangeStringMutationAndGetResult($I, 'stringSetting', 'default');

$this->assertMutationNotFoundErrorInResult($I, $result, 'changeModuleSettingString');
}

public function testChangeStringSettingAuthorized(AcceptanceTester $I): void
{
$I->login($this->getAdminUsername(), $this->getAdminPassword());
Expand Down Expand Up @@ -191,15 +153,6 @@ private function runChangeStringMutationAndGetResult(AcceptanceTester $I, string
return $I->grabJsonResponseAsArray();
}

public function testChangeCollectionSettingNotAuthorized(AcceptanceTester $I): void
{
$I->login($this->getAgentUsername(), $this->getAgentPassword());

$result = $this->runChangeCollectionMutationAndGetResult($I, 'arraySetting', '[3, "interesting", "values"]');

$this->assertMutationNotFoundErrorInResult($I, $result, 'changeModuleSettingCollection');
}

public function testChangeCollectionSettingAuthorized(AcceptanceTester $I): void
{
$I->login($this->getAdminUsername(), $this->getAdminPassword());
Expand Down Expand Up @@ -233,69 +186,4 @@ private function runChangeCollectionMutationAndGetResult(AcceptanceTester $I, st

return $I->grabJsonResponseAsArray();
}

public function testGetModuleSettingsListNotAuthorized(AcceptanceTester $I): void
{
$I->login($this->getAgentUsername(), $this->getAgentPassword());

$I->sendGQLQuery(
'query getSettings($moduleId: String!){
moduleSettingsList(moduleId: $moduleId) {
name
type
}
}',
['moduleId' => self::TEST_MODULE_ID]
);

$I->seeResponseIsJson();

$result = $I->grabJsonResponseAsArray();

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

public function testGetModuleSettingsListAuthorized(AcceptanceTester $I): void
{
$I->login($this->getAdminUsername(), $this->getAdminPassword());

$I->sendGQLQuery(
'query getSettings($moduleId: String!){
moduleSettingsList(moduleId: $moduleId) {
name
type
supported
}
}',
['moduleId' => self::TEST_MODULE_ID]
);

$I->seeResponseIsJson();

$result = $I->grabJsonResponseAsArray();
$I->assertArrayNotHasKey('errors', $result);

$settingsList = $result['data']['moduleSettingsList'];
$I->assertCount(5, $settingsList);
$I->assertContains(
['name' => 'intSetting', 'type' => FieldType::NUMBER, 'supported' => true],
$settingsList
);
$I->assertContains(
['name' => 'floatSetting', 'type' => FieldType::NUMBER, 'supported' => true],
$settingsList
);
$I->assertContains(
['name' => 'boolSetting', 'type' => FieldType::BOOLEAN, 'supported' => true],
$settingsList
);
$I->assertContains(
['name' => 'stringSetting', 'type' => FieldType::STRING, 'supported' => true],
$settingsList
);
$I->assertContains(
['name' => 'arraySetting', 'type' => FieldType::ARRAY, 'supported' => true],
$settingsList
);
}
}
Loading

0 comments on commit c9ce469

Please sign in to comment.