From 41bc9862d03f1f3eed8d82e8ee3c8f7d69fd1d9b Mon Sep 17 00:00:00 2001 From: Anton Fedurtsya Date: Mon, 13 Nov 2023 18:50:04 +0200 Subject: [PATCH] OXDEV-7557 Split ModuleSettingCest to Queries and Mutations Signed-off-by: Anton Fedurtsya --- tests/Codeception/Acceptance/BaseCest.php | 6 - .../Acceptance/ModuleSettingBaseCest.php | 106 ++++ .../Acceptance/ModuleSettingCest.php | 599 ------------------ .../Acceptance/ModuleSettingMutationsCest.php | 301 +++++++++ .../Acceptance/ModuleSettingQueriesCest.php | 194 ++++++ 5 files changed, 601 insertions(+), 605 deletions(-) create mode 100644 tests/Codeception/Acceptance/ModuleSettingBaseCest.php delete mode 100644 tests/Codeception/Acceptance/ModuleSettingCest.php create mode 100644 tests/Codeception/Acceptance/ModuleSettingMutationsCest.php create mode 100644 tests/Codeception/Acceptance/ModuleSettingQueriesCest.php diff --git a/tests/Codeception/Acceptance/BaseCest.php b/tests/Codeception/Acceptance/BaseCest.php index 459670f..9eab6d5 100644 --- a/tests/Codeception/Acceptance/BaseCest.php +++ b/tests/Codeception/Acceptance/BaseCest.php @@ -13,7 +13,6 @@ abstract class BaseCest { - private const TEST_MODULE_ID = 'awesomeModule'; private const TEST_THEME_ID = 'awesomeTheme'; private const AGENT_USERNAME = 'JanvierJaimesVelasquez@cuvox.de'; @@ -29,11 +28,6 @@ public function _after(AcceptanceTester $I): void $I->logout(); } - protected function getTestModuleName(): string - { - return self::TEST_MODULE_ID; - } - protected function getTestThemeName(): string { return self::TEST_THEME_ID; diff --git a/tests/Codeception/Acceptance/ModuleSettingBaseCest.php b/tests/Codeception/Acceptance/ModuleSettingBaseCest.php new file mode 100644 index 0000000..93e3a99 --- /dev/null +++ b/tests/Codeception/Acceptance/ModuleSettingBaseCest.php @@ -0,0 +1,106 @@ +prepareConfiguration(); + } + + protected function prepareConfiguration(): void + { + $shopConfiguration = $this->getShopConfiguration(); + + $integerSetting = new Setting(); + $integerSetting + ->setName('intSetting') + ->setValue(123) + ->setType(FieldType::NUMBER); + + $floatSetting = new Setting(); + $floatSetting + ->setName('floatSetting') + ->setValue(1.23) + ->setType(FieldType::NUMBER); + + $booleanSetting = new Setting(); + $booleanSetting + ->setName('boolSetting') + ->setValue(false) + ->setType(FieldType::BOOLEAN); + + $stringSetting = new Setting(); + $stringSetting + ->setName('stringSetting') + ->setValue('default') + ->setType(FieldType::STRING); + + $collectionSetting = new Setting(); + $collectionSetting + ->setName('arraySetting') + ->setValue(['nice', 'values']) + ->setType(FieldType::ARRAY); + + + $moduleConfiguration = new ModuleConfiguration(); + $moduleConfiguration + ->setId(self::TEST_MODULE_ID) + ->setModuleSource('testPath') + ->addModuleSetting($integerSetting) + ->addModuleSetting($floatSetting) + ->addModuleSetting($booleanSetting) + ->addModuleSetting($stringSetting) + ->addModuleSetting($collectionSetting); + + $shopConfiguration->addModuleConfiguration($moduleConfiguration); + $this->getShopConfigurationDao()->save($shopConfiguration, 1); + } + + protected function getShopConfiguration(): ShopConfiguration + { + $shopConfigurationDao = $this->getShopConfigurationDao(); + $shopConfiguration = $shopConfigurationDao->get(1); + + return $shopConfiguration; + } + + public function _after(AcceptanceTester $I): void + { + $this->removeConfiguration(self::TEST_MODULE_ID); + BaseCest::_after($I); + } + + protected function removeConfiguration(string $moduleId): void + { + $shopConfiguration = $this->getShopConfiguration(); + $shopConfiguration->deleteModuleConfiguration($moduleId); + } + + protected function getShopConfigurationDao(): ShopConfigurationDao + { + $container = ContainerFactory::getInstance()->getContainer(); + /** @var ShopConfigurationDao $shopConfigurationDao */ + $shopConfigurationDao = $container->get(ShopConfigurationDaoInterface::class); + return $shopConfigurationDao; + } +} diff --git a/tests/Codeception/Acceptance/ModuleSettingCest.php b/tests/Codeception/Acceptance/ModuleSettingCest.php deleted file mode 100644 index d4935bf..0000000 --- a/tests/Codeception/Acceptance/ModuleSettingCest.php +++ /dev/null @@ -1,599 +0,0 @@ -prepareConfiguration(); - } - - public function _after(AcceptanceTester $I): void - { - $this->removeConfiguration($this->getTestModuleName()); - parent::_after($I); - } - - public function testGetIntegerSettingNotAuthorized(AcceptanceTester $I): void - { - $I->login($this->getAgentUsername(), $this->getAgentPassword()); - - $result = $this->runGetIntegerQueryAndGetResult($I, 'intSetting'); - - $this->assertQueryNotFoundErrorInResult($I, $result, 'moduleSettingInteger'); - } - - public function testGetIntegerSettingAuthorized(AcceptanceTester $I): void - { - $I->login($this->getAdminUsername(), $this->getAdminPassword()); - - $result = $this->runGetIntegerQueryAndGetResult($I, 'intSetting'); - - $I->assertArrayNotHasKey('errors', $result); - - $setting = $result['data']['moduleSettingInteger']; - $I->assertSame('intSetting', $setting['name']); - $I->assertSame(123, $setting['value']); - } - - private function runGetIntegerQueryAndGetResult(AcceptanceTester $I, string $name): array - { - $I->sendGQLQuery( - 'query q($name: ID!, $moduleId: String!){ - moduleSettingInteger(name: $name, moduleId: $moduleId) { - name - value - } - }', - [ - 'name' => $name, - 'moduleId' => $this->getTestModuleName() - ] - ); - - $I->seeResponseIsJson(); - - return $I->grabJsonResponseAsArray(); - } - - public function testGetFloatSettingNotAuthorized(AcceptanceTester $I): void - { - $I->login($this->getAgentUsername(), $this->getAgentPassword()); - - $result = $this->runGetFloatQueryAndGetResult($I, 'floatSetting'); - - $this->assertQueryNotFoundErrorInResult($I, $result, 'moduleSettingFloat'); - } - - public function testGetFloatSettingAuthorized(AcceptanceTester $I): void - { - $I->login($this->getAdminUsername(), $this->getAdminPassword()); - - $result = $this->runGetFloatQueryAndGetResult($I, 'floatSetting'); - - $I->assertArrayNotHasKey('errors', $result); - - $setting = $result['data']['moduleSettingFloat']; - $I->assertSame('floatSetting', $setting['name']); - $I->assertSame(1.23, $setting['value']); - } - - private function runGetFloatQueryAndGetResult(AcceptanceTester $I, string $name): array - { - $I->sendGQLQuery( - 'query q($name: ID!, $moduleId: String!){ - moduleSettingFloat(name: $name, moduleId: $moduleId) { - name - value - } - }', - [ - 'name' => $name, - 'moduleId' => $this->getTestModuleName() - ] - ); - - $I->seeResponseIsJson(); - - return $I->grabJsonResponseAsArray(); - } - - public function testGetBooleanSettingNotAuthorized(AcceptanceTester $I): void - { - $I->login($this->getAgentUsername(), $this->getAgentPassword()); - - $result = $this->runGetBooleanQueryAndGetResult($I, 'boolSetting'); - - $this->assertQueryNotFoundErrorInResult($I, $result, 'moduleSettingBoolean'); - } - - public function testGetBooleanSettingAuthorized(AcceptanceTester $I): void - { - $I->login($this->getAdminUsername(), $this->getAdminPassword()); - - $result = $this->runGetBooleanQueryAndGetResult($I, 'boolSetting'); - - $I->assertArrayNotHasKey('errors', $result); - - $setting = $result['data']['moduleSettingBoolean']; - $I->assertSame('boolSetting', $setting['name']); - $I->assertSame(false, $setting['value']); - } - - private function runGetBooleanQueryAndGetResult(AcceptanceTester $I, string $name): array - { - $I->sendGQLQuery( - 'query q($name: ID!, $moduleId: String!){ - moduleSettingBoolean(name: $name, moduleId: $moduleId) { - name - value - } - }', - [ - 'name' => $name, - 'moduleId' => $this->getTestModuleName() - ] - ); - - $I->seeResponseIsJson(); - - return $I->grabJsonResponseAsArray(); - } - - public function testGetStringSettingNotAuthorized(AcceptanceTester $I): void - { - $I->login($this->getAgentUsername(), $this->getAgentPassword()); - - $result = $this->runGetStringQueryAndGetResult($I, 'stringSetting'); - - $this->assertQueryNotFoundErrorInResult($I, $result, 'moduleSettingString'); - } - - public function testGetStringSettingAuthorized(AcceptanceTester $I): void - { - $I->login($this->getAdminUsername(), $this->getAdminPassword()); - - $result = $this->runGetStringQueryAndGetResult($I, 'stringSetting'); - - $I->assertArrayNotHasKey('errors', $result); - - $setting = $result['data']['moduleSettingString']; - $I->assertSame('stringSetting', $setting['name']); - $I->assertSame('default', $setting['value']); - } - - private function runGetStringQueryAndGetResult(AcceptanceTester $I, string $name): array - { - $I->sendGQLQuery( - 'query q($name: ID!, $moduleId: String!){ - moduleSettingString(name: $name, moduleId: $moduleId) { - name - value - } - }', - [ - 'name' => $name, - 'moduleId' => $this->getTestModuleName() - ] - ); - - $I->seeResponseIsJson(); - - return $I->grabJsonResponseAsArray(); - } - - public function testGetCollectionSettingNotAuthorized(AcceptanceTester $I): void - { - $I->login($this->getAgentUsername(), $this->getAgentPassword()); - - $result = $this->runGetCollectionQueryAndGetResult($I, 'arraySetting'); - - $this->assertQueryNotFoundErrorInResult($I, $result, 'moduleSettingCollection'); - } - - public function testGetCollectionSettingAuthorized(AcceptanceTester $I): void - { - $I->login($this->getAdminUsername(), $this->getAdminPassword()); - - $result = $this->runGetCollectionQueryAndGetResult($I, 'arraySetting'); - - $I->assertArrayNotHasKey('errors', $result); - - $setting = $result['data']['moduleSettingCollection']; - $I->assertSame('arraySetting', $setting['name']); - $I->assertSame('["nice","values"]', $setting['value']); - } - - private function runGetCollectionQueryAndGetResult(AcceptanceTester $I, string $name): array - { - $I->sendGQLQuery( - 'query q($name: ID!, $moduleId: String!){ - moduleSettingCollection(name: $name, moduleId: $moduleId) { - name - value - } - }', - [ - 'name' => $name, - 'moduleId' => $this->getTestModuleName() - ] - ); - - $I->seeResponseIsJson(); - - return $I->grabJsonResponseAsArray(); - } - - 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()); - - $result = $this->runChangeIntegerMutationAndGetResult($I, 'intSetting', 124); - - $I->assertArrayNotHasKey('errors', $result); - - $setting = $result['data']['changeModuleSettingInteger']; - $I->assertSame('intSetting', $setting['name']); - $I->assertSame(124, $setting['value']); - } - - private function runChangeIntegerMutationAndGetResult(AcceptanceTester $I, string $name, int $value): array - { - $I->sendGQLQuery( - 'mutation m($name: ID!, $value: Int!, $moduleId: String!){ - changeModuleSettingInteger(name: $name, value: $value, moduleId: $moduleId) { - name - value - } - }', - [ - 'name' => $name, - 'value' => $value, - 'moduleId' => $this->getTestModuleName() - ] - ); - - $I->seeResponseIsJson(); - - 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()); - - $result = $this->runFloatMutationAndGetResult($I, 'floatSetting', 1.24); - $I->assertArrayNotHasKey('errors', $result); - - $setting = $result['data']['changeModuleSettingFloat']; - $I->assertSame('floatSetting', $setting['name']); - $I->assertSame(1.24, $setting['value']); - } - - private function runFloatMutationAndGetResult(AcceptanceTester $I, string $name, float $value): array - { - $I->sendGQLQuery( - 'mutation m($name: ID!, $value: Float!, $moduleId: String!){ - changeModuleSettingFloat(name: $name, value: $value, moduleId: $moduleId) { - name - value - } - }', - [ - 'name' => $name, - 'value' => $value, - 'moduleId' => $this->getTestModuleName() - ] - ); - - $I->seeResponseIsJson(); - - 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()); - - $result = $this->runChangeBooleanMutationAndGetResult($I, 'boolSetting', false); - - $I->assertArrayNotHasKey('errors', $result); - - $setting = $result['data']['changeModuleSettingBoolean']; - $I->assertSame('boolSetting', $setting['name']); - $I->assertSame(false, $setting['value']); - } - - private function runChangeBooleanMutationAndGetResult(AcceptanceTester $I, string $name, bool $value): array - { - $I->sendGQLQuery( - 'mutation m($name: ID!, $value: Boolean!, $moduleId: String!){ - changeModuleSettingBoolean(name: $name, value: $value, moduleId: $moduleId) { - name - value - } - }', - [ - 'name' => $name, - 'value' => $value, - 'moduleId' => $this->getTestModuleName() - ] - ); - - $I->seeResponseIsJson(); - - 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()); - - $result = $this->runChangeStringMutationAndGetResult($I, 'stringSetting', 'default'); - - $I->assertArrayNotHasKey('errors', $result); - - $setting = $result['data']['changeModuleSettingString']; - $I->assertSame('stringSetting', $setting['name']); - $I->assertSame('default', $setting['value']); - } - - private function runChangeStringMutationAndGetResult(AcceptanceTester $I, string $name, string $value): array - { - $I->sendGQLQuery( - 'mutation m($name: ID!, $value: String!, $moduleId: String!){ - changeModuleSettingString(name: $name, value: $value, moduleId: $moduleId) { - name - value - } - }', - [ - 'name' => $name, - 'value' => $value, - 'moduleId' => $this->getTestModuleName() - ] - ); - - $I->seeResponseIsJson(); - - 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()); - - $result = $this->runChangeCollectionMutationAndGetResult($I, 'arraySetting', '[3, "interesting", "values"]'); - - $I->assertArrayNotHasKey('errors', $result); - - $setting = $result['data']['changeModuleSettingCollection']; - $I->assertSame('arraySetting', $setting['name']); - $I->assertSame('[3, "interesting", "values"]', $setting['value']); - } - - private function runChangeCollectionMutationAndGetResult(AcceptanceTester $I, string $name, string $value): array - { - $I->sendGQLQuery( - 'mutation m($name: ID!, $value: String!, $moduleId: String!){ - changeModuleSettingCollection(name: $name, value: $value, moduleId: $moduleId) { - name - value - } - }', - [ - 'name' => $name, - 'value' => $value, - 'moduleId' => $this->getTestModuleName() - ] - ); - - $I->seeResponseIsJson(); - - 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' => $this->getTestModuleName()] - ); - - $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' => $this->getTestModuleName()] - ); - - $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 - ); - } - - private function prepareConfiguration(): void - { - $shopConfiguration = $this->getShopConfiguration(); - - $integerSetting = new Setting(); - $integerSetting - ->setName('intSetting') - ->setValue(123) - ->setType(FieldType::NUMBER); - - $floatSetting = new Setting(); - $floatSetting - ->setName('floatSetting') - ->setValue(1.23) - ->setType(FieldType::NUMBER); - - $booleanSetting = new Setting(); - $booleanSetting - ->setName('boolSetting') - ->setValue(false) - ->setType(FieldType::BOOLEAN); - - $stringSetting = new Setting(); - $stringSetting - ->setName('stringSetting') - ->setValue('default') - ->setType(FieldType::STRING); - - $collectionSetting = new Setting(); - $collectionSetting - ->setName('arraySetting') - ->setValue(['nice', 'values']) - ->setType(FieldType::ARRAY); - - - $moduleConfiguration = new ModuleConfiguration(); - $moduleConfiguration - ->setId($this->getTestModuleName()) - ->setModuleSource('testPath') - ->addModuleSetting($integerSetting) - ->addModuleSetting($floatSetting) - ->addModuleSetting($booleanSetting) - ->addModuleSetting($stringSetting) - ->addModuleSetting($collectionSetting); - - $shopConfiguration->addModuleConfiguration($moduleConfiguration); - $this->getShopConfigurationDao()->save($shopConfiguration, 1); - } - - private function removeConfiguration(string $moduleId): void - { - $shopConfiguration = $this->getShopConfiguration(); - $shopConfiguration->deleteModuleConfiguration($moduleId); - } - - private function getShopConfiguration(): ShopConfiguration - { - $shopConfigurationDao = $this->getShopConfigurationDao(); - $shopConfiguration = $shopConfigurationDao->get(1); - - return $shopConfiguration; - } - - private function getShopConfigurationDao(): ShopConfigurationDao - { - $container = ContainerFactory::getInstance()->getContainer(); - /** @var ShopConfigurationDao $shopConfigurationDao */ - $shopConfigurationDao = $container->get(ShopConfigurationDaoInterface::class); - return $shopConfigurationDao; - } -} diff --git a/tests/Codeception/Acceptance/ModuleSettingMutationsCest.php b/tests/Codeception/Acceptance/ModuleSettingMutationsCest.php new file mode 100644 index 0000000..3057431 --- /dev/null +++ b/tests/Codeception/Acceptance/ModuleSettingMutationsCest.php @@ -0,0 +1,301 @@ +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()); + + $result = $this->runChangeIntegerMutationAndGetResult($I, 'intSetting', 124); + + $I->assertArrayNotHasKey('errors', $result); + + $setting = $result['data']['changeModuleSettingInteger']; + $I->assertSame('intSetting', $setting['name']); + $I->assertSame(124, $setting['value']); + } + + private function runChangeIntegerMutationAndGetResult(AcceptanceTester $I, string $name, int $value): array + { + $I->sendGQLQuery( + 'mutation m($name: ID!, $value: Int!, $moduleId: String!){ + changeModuleSettingInteger(name: $name, value: $value, moduleId: $moduleId) { + name + value + } + }', + [ + 'name' => $name, + 'value' => $value, + 'moduleId' => self::TEST_MODULE_ID + ] + ); + + $I->seeResponseIsJson(); + + 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()); + + $result = $this->runFloatMutationAndGetResult($I, 'floatSetting', 1.24); + $I->assertArrayNotHasKey('errors', $result); + + $setting = $result['data']['changeModuleSettingFloat']; + $I->assertSame('floatSetting', $setting['name']); + $I->assertSame(1.24, $setting['value']); + } + + private function runFloatMutationAndGetResult(AcceptanceTester $I, string $name, float $value): array + { + $I->sendGQLQuery( + 'mutation m($name: ID!, $value: Float!, $moduleId: String!){ + changeModuleSettingFloat(name: $name, value: $value, moduleId: $moduleId) { + name + value + } + }', + [ + 'name' => $name, + 'value' => $value, + 'moduleId' => self::TEST_MODULE_ID + ] + ); + + $I->seeResponseIsJson(); + + 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()); + + $result = $this->runChangeBooleanMutationAndGetResult($I, 'boolSetting', false); + + $I->assertArrayNotHasKey('errors', $result); + + $setting = $result['data']['changeModuleSettingBoolean']; + $I->assertSame('boolSetting', $setting['name']); + $I->assertSame(false, $setting['value']); + } + + private function runChangeBooleanMutationAndGetResult(AcceptanceTester $I, string $name, bool $value): array + { + $I->sendGQLQuery( + 'mutation m($name: ID!, $value: Boolean!, $moduleId: String!){ + changeModuleSettingBoolean(name: $name, value: $value, moduleId: $moduleId) { + name + value + } + }', + [ + 'name' => $name, + 'value' => $value, + 'moduleId' => self::TEST_MODULE_ID + ] + ); + + $I->seeResponseIsJson(); + + 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()); + + $result = $this->runChangeStringMutationAndGetResult($I, 'stringSetting', 'default'); + + $I->assertArrayNotHasKey('errors', $result); + + $setting = $result['data']['changeModuleSettingString']; + $I->assertSame('stringSetting', $setting['name']); + $I->assertSame('default', $setting['value']); + } + + private function runChangeStringMutationAndGetResult(AcceptanceTester $I, string $name, string $value): array + { + $I->sendGQLQuery( + 'mutation m($name: ID!, $value: String!, $moduleId: String!){ + changeModuleSettingString(name: $name, value: $value, moduleId: $moduleId) { + name + value + } + }', + [ + 'name' => $name, + 'value' => $value, + 'moduleId' => self::TEST_MODULE_ID + ] + ); + + $I->seeResponseIsJson(); + + 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()); + + $result = $this->runChangeCollectionMutationAndGetResult($I, 'arraySetting', '[3, "interesting", "values"]'); + + $I->assertArrayNotHasKey('errors', $result); + + $setting = $result['data']['changeModuleSettingCollection']; + $I->assertSame('arraySetting', $setting['name']); + $I->assertSame('[3, "interesting", "values"]', $setting['value']); + } + + private function runChangeCollectionMutationAndGetResult(AcceptanceTester $I, string $name, string $value): array + { + $I->sendGQLQuery( + 'mutation m($name: ID!, $value: String!, $moduleId: String!){ + changeModuleSettingCollection(name: $name, value: $value, moduleId: $moduleId) { + name + value + } + }', + [ + 'name' => $name, + 'value' => $value, + 'moduleId' => self::TEST_MODULE_ID + ] + ); + + $I->seeResponseIsJson(); + + 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 + ); + } +} diff --git a/tests/Codeception/Acceptance/ModuleSettingQueriesCest.php b/tests/Codeception/Acceptance/ModuleSettingQueriesCest.php new file mode 100644 index 0000000..475e189 --- /dev/null +++ b/tests/Codeception/Acceptance/ModuleSettingQueriesCest.php @@ -0,0 +1,194 @@ +login($this->getAgentUsername(), $this->getAgentPassword()); + + $result = $this->runSettingGetterQuery($I, 'moduleSettingInteger', 'intSetting'); + + $this->assertQueryNotFoundErrorInResult($I, $result, 'moduleSettingInteger'); + } + + public function testGetIntegerSettingAuthorized(AcceptanceTester $I): void + { + $I->login($this->getAdminUsername(), $this->getAdminPassword()); + + $result = $this->runSettingGetterQuery($I, 'moduleSettingInteger', 'intSetting'); + + $I->assertArrayNotHasKey('errors', $result); + + $setting = $result['data']['moduleSettingInteger']; + $I->assertSame('intSetting', $setting['name']); + $I->assertSame(123, $setting['value']); + } + + public function testGetFloatSettingNotAuthorized(AcceptanceTester $I): void + { + $I->login($this->getAgentUsername(), $this->getAgentPassword()); + + $result = $this->runSettingGetterQuery($I, 'moduleSettingFloat', 'floatSetting'); + + $this->assertQueryNotFoundErrorInResult($I, $result, 'moduleSettingFloat'); + } + + public function testGetFloatSettingAuthorized(AcceptanceTester $I): void + { + $I->login($this->getAdminUsername(), $this->getAdminPassword()); + + $result = $this->runSettingGetterQuery($I, 'moduleSettingFloat', 'floatSetting'); + + $I->assertArrayNotHasKey('errors', $result); + + $setting = $result['data']['moduleSettingFloat']; + $I->assertSame('floatSetting', $setting['name']); + $I->assertSame(1.23, $setting['value']); + } + + public function testGetBooleanSettingNotAuthorized(AcceptanceTester $I): void + { + $I->login($this->getAgentUsername(), $this->getAgentPassword()); + + $result = $this->runSettingGetterQuery($I, 'moduleSettingBoolean', 'boolSetting'); + + $this->assertQueryNotFoundErrorInResult($I, $result, 'moduleSettingBoolean'); + } + + public function testGetBooleanSettingAuthorized(AcceptanceTester $I): void + { + $I->login($this->getAdminUsername(), $this->getAdminPassword()); + + $result = $this->runSettingGetterQuery($I, 'moduleSettingBoolean', 'boolSetting'); + + $I->assertArrayNotHasKey('errors', $result); + + $setting = $result['data']['moduleSettingBoolean']; + $I->assertSame('boolSetting', $setting['name']); + $I->assertSame(false, $setting['value']); + } + + public function testGetStringSettingNotAuthorized(AcceptanceTester $I): void + { + $I->login($this->getAgentUsername(), $this->getAgentPassword()); + + $result = $this->runSettingGetterQuery($I, 'moduleSettingString', 'stringSetting'); + + $this->assertQueryNotFoundErrorInResult($I, $result, 'moduleSettingString'); + } + + public function testGetStringSettingAuthorized(AcceptanceTester $I): void + { + $I->login($this->getAdminUsername(), $this->getAdminPassword()); + + $result = $this->runSettingGetterQuery($I, 'moduleSettingString', 'stringSetting'); + + $I->assertArrayNotHasKey('errors', $result); + + $setting = $result['data']['moduleSettingString']; + $I->assertSame('stringSetting', $setting['name']); + $I->assertSame('default', $setting['value']); + } + + public function testGetCollectionSettingNotAuthorized(AcceptanceTester $I): void + { + $I->login($this->getAgentUsername(), $this->getAgentPassword()); + + $result = $this->runSettingGetterQuery($I, 'moduleSettingCollection', 'arraySetting'); + + $this->assertQueryNotFoundErrorInResult($I, $result, 'moduleSettingCollection'); + } + + public function testGetCollectionSettingAuthorized(AcceptanceTester $I): void + { + $I->login($this->getAdminUsername(), $this->getAdminPassword()); + + $result = $this->runSettingGetterQuery($I, 'moduleSettingCollection', 'arraySetting'); + + $I->assertArrayNotHasKey('errors', $result); + + $setting = $result['data']['moduleSettingCollection']; + $I->assertSame('arraySetting', $setting['name']); + $I->assertSame('["nice","values"]', $setting['value']); + } + + 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(); + } + + 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()); + + $result = $this->runChangeIntegerMutationAndGetResult($I, 'intSetting', 124); + + $I->assertArrayNotHasKey('errors', $result); + + $setting = $result['data']['changeModuleSettingInteger']; + $I->assertSame('intSetting', $setting['name']); + $I->assertSame(124, $setting['value']); + } + + private function runChangeIntegerMutationAndGetResult(AcceptanceTester $I, string $name, int $value): array + { + $I->sendGQLQuery( + 'mutation m($name: ID!, $value: Int!, $moduleId: String!){ + changeModuleSettingInteger(name: $name, value: $value, moduleId: $moduleId) { + name + value + } + }', + [ + 'name' => $name, + 'value' => $value, + 'moduleId' => self::TEST_MODULE_ID + ] + ); + + $I->seeResponseIsJson(); + + return $I->grabJsonResponseAsArray(); + } +}