diff --git a/tests/Codeception/Acceptance/BaseCest.php b/tests/Codeception/Acceptance/BaseCest.php index 9eab6d5..e4f21a8 100644 --- a/tests/Codeception/Acceptance/BaseCest.php +++ b/tests/Codeception/Acceptance/BaseCest.php @@ -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 = 'JanvierJaimesVelasquez@cuvox.de'; @@ -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); - } } diff --git a/tests/Codeception/Acceptance/ModuleSettingBaseCest.php b/tests/Codeception/Acceptance/ModuleSettingBaseCest.php index 93e3a99..5445f33 100644 --- a/tests/Codeception/Acceptance/ModuleSettingBaseCest.php +++ b/tests/Codeception/Acceptance/ModuleSettingBaseCest.php @@ -20,8 +20,6 @@ abstract class ModuleSettingBaseCest extends BaseCest { - protected const TEST_MODULE_ID = 'awesomeModule'; - public function _before(AcceptanceTester $I): void { $this->prepareConfiguration(); diff --git a/tests/Codeception/Acceptance/ModuleSettingGettersCest.php b/tests/Codeception/Acceptance/ModuleSettingGettersCest.php new file mode 100644 index 0000000..414ebf1 --- /dev/null +++ b/tests/Codeception/Acceptance/ModuleSettingGettersCest.php @@ -0,0 +1,88 @@ +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(); + } +} diff --git a/tests/Codeception/Acceptance/ModuleSettingListCest.php b/tests/Codeception/Acceptance/ModuleSettingListCest.php new file mode 100644 index 0000000..44a3e56 --- /dev/null +++ b/tests/Codeception/Acceptance/ModuleSettingListCest.php @@ -0,0 +1,65 @@ +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/ModuleSettingMutationsCest.php b/tests/Codeception/Acceptance/ModuleSettingMutationsCest.php index 3057431..25a6d60 100644 --- a/tests/Codeception/Acceptance/ModuleSettingMutationsCest.php +++ b/tests/Codeception/Acceptance/ModuleSettingMutationsCest.php @@ -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; /** @@ -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()); @@ -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()); @@ -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()); @@ -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()); @@ -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()); @@ -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 - ); - } } diff --git a/tests/Codeception/Acceptance/ModuleSettingQueriesCest.php b/tests/Codeception/Acceptance/ModuleSettingQueriesCest.php deleted file mode 100644 index 475e189..0000000 --- a/tests/Codeception/Acceptance/ModuleSettingQueriesCest.php +++ /dev/null @@ -1,194 +0,0 @@ -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(); - } -} diff --git a/tests/Codeception/Acceptance/NotAuthorizedAccessCest.php b/tests/Codeception/Acceptance/NotAuthorizedAccessCest.php new file mode 100644 index 0000000..95a60d5 --- /dev/null +++ b/tests/Codeception/Acceptance/NotAuthorizedAccessCest.php @@ -0,0 +1,128 @@ +login($this->getAgentUsername(), $this->getAgentPassword()); + + $result = $this->runSimplifiedAccessCheckQuery( + I: $I, + queryType: $example['queryType'], + queryName: $example['queryName'], + field: $example['field'] + ); + + $this->assertQueryNotFoundErrorInResult($I, $result, $example['queryName'], $example['queryType']); + } + + protected function themeGettersDataProvider(): \Generator + { + yield ['queryType' => 'query', 'queryName' => 'themeSettingInteger', 'field' => 'name']; + yield ['queryType' => 'query', 'queryName' => 'themeSettingFloat', 'field' => 'name']; + yield ['queryType' => 'query', 'queryName' => 'themeSettingBoolean', 'field' => 'name']; + yield ['queryType' => 'query', 'queryName' => 'themeSettingString', 'field' => 'name']; + yield ['queryType' => 'query', 'queryName' => 'themeSettingSelect', 'field' => 'name']; + yield ['queryType' => 'query', 'queryName' => 'themeSettingCollection', 'field' => 'name']; + yield ['queryType' => 'query', 'queryName' => 'themeSettingAssocCollection', 'field' => 'name']; + } + + protected function themeMutationsDataProvider(): \Generator + { + yield ['queryType' => 'mutation', 'queryName' => 'changeThemeSettingInteger', 'field' => 'name']; + yield ['queryType' => 'mutation', 'queryName' => 'changeThemeSettingFloat', 'field' => 'name']; + yield ['queryType' => 'mutation', 'queryName' => 'changeThemeSettingBoolean', 'field' => 'name']; + yield ['queryType' => 'mutation', 'queryName' => 'changeThemeSettingString', 'field' => 'name']; + yield ['queryType' => 'mutation', 'queryName' => 'changeThemeSettingCollection', 'field' => 'name']; + } + + protected function listQueriesDataProvider(): \Generator + { + yield ['queryType' => 'query', 'queryName' => 'themeSettingsList', 'field' => 'name']; + yield ['queryType' => 'query', 'queryName' => 'moduleSettingsList', 'field' => 'name']; + yield ['queryType' => 'query', 'queryName' => 'shopSettingsList', 'field' => 'name']; + } + + protected function moduleGettersDataProvider(): \Generator + { + yield ['queryType' => 'query', 'queryName' => 'moduleSettingInteger', 'field' => 'name']; + yield ['queryType' => 'query', 'queryName' => 'moduleSettingFloat', 'field' => 'name']; + yield ['queryType' => 'query', 'queryName' => 'moduleSettingBoolean', 'field' => 'name']; + yield ['queryType' => 'query', 'queryName' => 'moduleSettingString', 'field' => 'name']; + yield ['queryType' => 'query', 'queryName' => 'moduleSettingCollection', 'field' => 'name']; + } + + protected function moduleMutationsDataProvider(): \Generator + { + yield ['queryType' => 'mutation', 'queryName' => 'changeModuleSettingInteger', 'field' => 'name']; + yield ['queryType' => 'mutation', 'queryName' => 'changeModuleSettingFloat', 'field' => 'name']; + yield ['queryType' => 'mutation', 'queryName' => 'changeModuleSettingBoolean', 'field' => 'name']; + yield ['queryType' => 'mutation', 'queryName' => 'changeModuleSettingString', 'field' => 'name']; + yield ['queryType' => 'mutation', 'queryName' => 'changeModuleSettingCollection', 'field' => 'name']; + } + + protected function shopGettersDataProvider(): \Generator + { + yield ['queryType' => 'query', 'queryName' => 'shopSettingInteger', 'field' => 'name']; + yield ['queryType' => 'query', 'queryName' => 'shopSettingFloat', 'field' => 'name']; + yield ['queryType' => 'query', 'queryName' => 'shopSettingBoolean', 'field' => 'name']; + yield ['queryType' => 'query', 'queryName' => 'shopSettingString', 'field' => 'name']; + yield ['queryType' => 'query', 'queryName' => 'shopSettingSelect', 'field' => 'name']; + yield ['queryType' => 'query', 'queryName' => 'shopSettingCollection', 'field' => 'name']; + yield ['queryType' => 'query', 'queryName' => 'shopSettingAssocCollection', 'field' => 'name']; + } + + private function runSimplifiedAccessCheckQuery( + AcceptanceTester $I, + string $queryType, + string $queryName, + string $field, + ): array { + $I->sendGQLQuery( + $queryType . '{ + ' . $queryName . '{ + ' . $field . ' + } + }' + ); + + $I->seeResponseIsJson(); + + return $I->grabJsonResponseAsArray(); + } + + protected function assertQueryNotFoundErrorInResult( + AcceptanceTester $I, + array $result, + string $query, + string $queryType + ): void { + $errorMessage = $result['errors'][0]['message']; + $I->assertSame( + 'Cannot query field "' . $query . '" on type "' . ucfirst($queryType) . '".', $errorMessage + ); + } +} diff --git a/tests/Codeception/Acceptance/ShopSettingCest.php b/tests/Codeception/Acceptance/ShopSettingCest.php deleted file mode 100644 index 3ad2e01..0000000 --- a/tests/Codeception/Acceptance/ShopSettingCest.php +++ /dev/null @@ -1,394 +0,0 @@ -login($this->getAgentUsername(), $this->getAgentPassword()); - - $I->sendGQLQuery( - 'query{ - shopSettingInteger(name: "intSetting") { - name - value - } - }' - ); - - $I->seeResponseIsJson(); - - $result = $I->grabJsonResponseAsArray(); - $errorMessage = $result['errors'][0]['message']; - $I->assertSame('Cannot query field "shopSettingInteger" on type "Query".', $errorMessage); - } - - public function testGetIntegerSettingAuthorized(AcceptanceTester $I): void - { - $I->login($this->getAdminUsername(), $this->getAdminPassword()); - - $I->sendGQLQuery( - 'query{ - shopSettingInteger(name: "intSetting") { - name - value - } - }' - ); - - $I->seeResponseIsJson(); - - $result = $I->grabJsonResponseAsArray(); - $I->assertArrayNotHasKey('errors', $result); - - $setting = $result['data']['shopSettingInteger']; - $I->assertSame('intSetting', $setting['name']); - $I->assertSame(123, $setting['value']); - } - - public function testGetFloatSettingNotAuthorized(AcceptanceTester $I): void - { - $I->login($this->getAgentUsername(), $this->getAgentPassword()); - - $I->sendGQLQuery( - 'query{ - shopSettingFloat(name: "floatSetting") { - name - value - } - }' - ); - - $I->seeResponseIsJson(); - - $result = $I->grabJsonResponseAsArray(); - $errorMessage = $result['errors'][0]['message']; - $I->assertSame('Cannot query field "shopSettingFloat" on type "Query".', $errorMessage); - } - - public function testGetFloatSettingAuthorized(AcceptanceTester $I): void - { - $I->login($this->getAdminUsername(), $this->getAdminPassword()); - - $I->sendGQLQuery( - 'query{ - shopSettingFloat(name: "floatSetting") { - name - value - } - }' - ); - - $I->seeResponseIsJson(); - - $result = $I->grabJsonResponseAsArray(); - $I->assertArrayNotHasKey('errors', $result); - - $setting = $result['data']['shopSettingFloat']; - $I->assertSame('floatSetting', $setting['name']); - $I->assertSame(1.23, $setting['value']); - } - - public function testGetBooleanSettingNotAuthorized(AcceptanceTester $I): void - { - $I->login($this->getAgentUsername(), $this->getAgentPassword()); - - $I->sendGQLQuery( - 'query{ - shopSettingBoolean(name: "boolSetting") { - name - value - } - }' - ); - - $I->seeResponseIsJson(); - - $result = $I->grabJsonResponseAsArray(); - $errorMessage = $result['errors'][0]['message']; - $I->assertSame('Cannot query field "shopSettingBoolean" on type "Query".', $errorMessage); - } - - public function testGetBooleanSettingAuthorized(AcceptanceTester $I): void - { - $I->login($this->getAdminUsername(), $this->getAdminPassword()); - - $I->sendGQLQuery( - 'query{ - shopSettingBoolean(name: "boolSetting") { - name - value - } - }' - ); - - $I->seeResponseIsJson(); - - $result = $I->grabJsonResponseAsArray(); - $I->assertArrayNotHasKey('errors', $result); - - $setting = $result['data']['shopSettingBoolean']; - $I->assertSame('boolSetting', $setting['name']); - $I->assertSame(false, $setting['value']); - } - - public function testGetStringSettingNotAuthorized(AcceptanceTester $I): void - { - $I->login($this->getAgentUsername(), $this->getAgentPassword()); - - $I->sendGQLQuery( - 'query{ - shopSettingString(name: "stringSetting") { - name - value - } - }' - ); - - $I->seeResponseIsJson(); - - $result = $I->grabJsonResponseAsArray(); - $errorMessage = $result['errors'][0]['message']; - $I->assertSame('Cannot query field "shopSettingString" on type "Query".', $errorMessage); - } - - public function testGetStringSettingAuthorized(AcceptanceTester $I): void - { - $I->login($this->getAdminUsername(), $this->getAdminPassword()); - - $I->sendGQLQuery( - 'query{ - shopSettingString(name: "stringSetting") { - name - value - } - }' - ); - - $I->seeResponseIsJson(); - - $result = $I->grabJsonResponseAsArray(); - $I->assertArrayNotHasKey('errors', $result); - - $setting = $result['data']['shopSettingString']; - $I->assertSame('stringSetting', $setting['name']); - $I->assertSame('default', $setting['value']); - } - - public function testGetSelectSettingNotAuthorized(AcceptanceTester $I): void - { - $I->login($this->getAgentUsername(), $this->getAgentPassword()); - - $I->sendGQLQuery( - 'query{ - shopSettingSelect(name: "selectSetting") { - name - value - } - }' - ); - - $I->seeResponseIsJson(); - - $result = $I->grabJsonResponseAsArray(); - $errorMessage = $result['errors'][0]['message']; - $I->assertSame('Cannot query field "shopSettingSelect" on type "Query".', $errorMessage); - } - - public function testGetSelectSettingAuthorized(AcceptanceTester $I): void - { - $I->login($this->getAdminUsername(), $this->getAdminPassword()); - - $I->sendGQLQuery( - 'query{ - shopSettingSelect(name: "selectSetting") { - name - value - } - }' - ); - - $I->seeResponseIsJson(); - - $result = $I->grabJsonResponseAsArray(); - $I->assertArrayNotHasKey('errors', $result); - - $setting = $result['data']['shopSettingSelect']; - $I->assertSame('selectSetting', $setting['name']); - $I->assertSame('selectString', $setting['value']); - } - - public function testGetCollectionSettingNotAuthorized(AcceptanceTester $I): void - { - $I->login($this->getAgentUsername(), $this->getAgentPassword()); - - $I->sendGQLQuery( - 'query{ - shopSettingCollection(name: "arraySetting") { - name - value - } - }' - ); - - $I->seeResponseIsJson(); - - $result = $I->grabJsonResponseAsArray(); - $errorMessage = $result['errors'][0]['message']; - $I->assertSame('Cannot query field "shopSettingCollection" on type "Query".', $errorMessage); - } - - public function testGetCollectionSettingAuthorized(AcceptanceTester $I): void - { - $I->login($this->getAdminUsername(), $this->getAdminPassword()); - - $I->sendGQLQuery( - 'query{ - shopSettingCollection(name: "arraySetting") { - name - value - } - }' - ); - - $I->seeResponseIsJson(); - - $result = $I->grabJsonResponseAsArray(); - $I->assertArrayNotHasKey('errors', $result); - - $setting = $result['data']['shopSettingCollection']; - $I->assertSame('arraySetting', $setting['name']); - $I->assertSame('["10","20","50","100"]', $setting['value']); - } - - public function testGetAssocCollectionSettingNotAuthorized(AcceptanceTester $I): void - { - $I->login($this->getAgentUsername(), $this->getAgentPassword()); - - $I->sendGQLQuery( - 'query{ - shopSettingAssocCollection(name: "aarraySetting") { - name - value - } - }' - ); - - $I->seeResponseIsJson(); - - $result = $I->grabJsonResponseAsArray(); - $errorMessage = $result['errors'][0]['message']; - $I->assertSame('Cannot query field "shopSettingAssocCollection" on type "Query".', $errorMessage); - } - - public function testGetAssocCollectionSettingAuthorized(AcceptanceTester $I): void - { - $I->login($this->getAdminUsername(), $this->getAdminPassword()); - - $I->sendGQLQuery( - 'query{ - shopSettingAssocCollection(name: "aarraySetting") { - name - value - } - }' - ); - - $I->seeResponseIsJson(); - - $result = $I->grabJsonResponseAsArray(); - $I->assertArrayNotHasKey('errors', $result); - - $setting = $result['data']['shopSettingAssocCollection']; - $I->assertSame('aarraySetting', $setting['name']); - $I->assertSame('{"first":"10","second":"20","third":"50"}', $setting['value']); - } - - public function testGetShopSettingsListNotAuthorized(AcceptanceTester $I): void - { - $I->login($this->getAgentUsername(), $this->getAgentPassword()); - - $I->sendGQLQuery( - 'query{ - shopSettingsList { - name - type - supported - } - }' - ); - - $I->seeResponseIsJson(); - - $result = $I->grabJsonResponseAsArray(); - $errorMessage = $result['errors'][0]['message']; - $I->assertSame('Cannot query field "shopSettingsList" on type "Query".', $errorMessage); - } - - public function testGetShopSettingsListAuthorized(AcceptanceTester $I): void - { - $I->login($this->getAdminUsername(), $this->getAdminPassword()); - - $I->sendGQLQuery( - 'query{ - shopSettingsList { - name - type - supported - } - }' - ); - - $I->seeResponseIsJson(); - - $result = $I->grabJsonResponseAsArray(); - $I->assertArrayNotHasKey('errors', $result); - - $settingsList = $result['data']['shopSettingsList']; - $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' => 'selectSetting', 'type' => FieldType::SELECT, 'supported' => true], - $settingsList - ); - $I->assertContains( - ['name' => 'arraySetting', 'type' => FieldType::ARRAY, 'supported' => true], - $settingsList - ); - $I->assertContains( - ['name' => 'aarraySetting', 'type' => FieldType::ASSOCIATIVE_ARRAY, 'supported' => true], - $settingsList - ); - } -} diff --git a/tests/Codeception/Acceptance/ShopSettingGettersCest.php b/tests/Codeception/Acceptance/ShopSettingGettersCest.php new file mode 100644 index 0000000..9383ae3 --- /dev/null +++ b/tests/Codeception/Acceptance/ShopSettingGettersCest.php @@ -0,0 +1,99 @@ +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' => 'shopSettingInteger', + 'settingName' => 'intSetting', + 'expectedValue' => 123 + ]; + + yield [ + 'queryName' => 'shopSettingFloat', + 'settingName' => 'floatSetting', + 'expectedValue' => 1.23 + ]; + + yield [ + 'queryName' => 'shopSettingBoolean', + 'settingName' => 'boolSetting', + 'expectedValue' => false + ]; + + yield [ + 'queryName' => 'shopSettingString', + 'settingName' => 'stringSetting', + 'expectedValue' => 'default' + ]; + + yield [ + 'queryName' => 'shopSettingSelect', + 'settingName' => 'selectSetting', + 'expectedValue' => 'selectString' + ]; + + yield [ + 'queryName' => 'shopSettingCollection', + 'settingName' => 'arraySetting', + 'expectedValue' => '["10","20","50","100"]' + ]; + + yield [ + 'queryName' => 'shopSettingAssocCollection', + 'settingName' => 'aarraySetting', + 'expectedValue' => '{"first":"10","second":"20","third":"50"}' + ]; + } + + private function runSettingGetterQuery(AcceptanceTester $I, string $queryName, string $settingName): array + { + $I->sendGQLQuery( + 'query q($name: ID!){ + ' . $queryName . '(name: $name) { + name + value + } + }', + [ + 'name' => $settingName + ] + ); + + $I->seeResponseIsJson(); + + return $I->grabJsonResponseAsArray(); + } +} diff --git a/tests/Codeception/Acceptance/ShopSettingListCest.php b/tests/Codeception/Acceptance/ShopSettingListCest.php new file mode 100644 index 0000000..8a0660f --- /dev/null +++ b/tests/Codeception/Acceptance/ShopSettingListCest.php @@ -0,0 +1,71 @@ +login($this->getAdminUsername(), $this->getAdminPassword()); + + $I->sendGQLQuery( + 'query{ + shopSettingsList { + name + type + supported + } + }' + ); + + $I->seeResponseIsJson(); + + $result = $I->grabJsonResponseAsArray(); + $I->assertArrayNotHasKey('errors', $result); + + $settingsList = $result['data']['shopSettingsList']; + $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' => 'selectSetting', 'type' => FieldType::SELECT, 'supported' => true], + $settingsList + ); + $I->assertContains( + ['name' => 'arraySetting', 'type' => FieldType::ARRAY, 'supported' => true], + $settingsList + ); + $I->assertContains( + ['name' => 'aarraySetting', 'type' => FieldType::ASSOCIATIVE_ARRAY, 'supported' => true], + $settingsList + ); + } +} diff --git a/tests/Codeception/Acceptance/ThemeSettingCest.php b/tests/Codeception/Acceptance/ThemeSettingCest.php deleted file mode 100644 index d2edd9b..0000000 --- a/tests/Codeception/Acceptance/ThemeSettingCest.php +++ /dev/null @@ -1,620 +0,0 @@ -login($this->getAgentUsername(), $this->getAgentPassword()); - - $I->sendGQLQuery( - 'query{ - themeSettingInteger(name: "intSetting", themeId: "' . $this->getTestThemeName() . '") { - name - value - } - }' - ); - - $I->seeResponseIsJson(); - - $result = $I->grabJsonResponseAsArray(); - $errorMessage = $result['errors'][0]['message']; - $I->assertSame('Cannot query field "themeSettingInteger" on type "Query".', $errorMessage); - } - - public function testGetIntegerSettingAuthorized(AcceptanceTester $I): void - { - $I->login($this->getAdminUsername(), $this->getAdminPassword()); - - $I->sendGQLQuery( - 'query{ - themeSettingInteger(name: "intSetting", themeId: "' . $this->getTestThemeName() . '") { - name - value - } - }' - ); - - $I->seeResponseIsJson(); - - $result = $I->grabJsonResponseAsArray(); - $I->assertArrayNotHasKey('errors', $result); - - $setting = $result['data']['themeSettingInteger']; - $I->assertSame('intSetting', $setting['name']); - $I->assertSame(123, $setting['value']); - } - - public function testGetFloatSettingNotAuthorized(AcceptanceTester $I): void - { - $I->login($this->getAgentUsername(), $this->getAgentPassword()); - - $I->sendGQLQuery( - 'query{ - themeSettingFloat(name: "floatSetting", themeId: "' . $this->getTestThemeName() . '") { - name - value - } - }' - ); - - $I->seeResponseIsJson(); - - $result = $I->grabJsonResponseAsArray(); - $errorMessage = $result['errors'][0]['message']; - $I->assertSame('Cannot query field "themeSettingFloat" on type "Query".', $errorMessage); - } - - public function testGetFloatSettingAuthorized(AcceptanceTester $I): void - { - $I->login($this->getAdminUsername(), $this->getAdminPassword()); - - $I->sendGQLQuery( - 'query{ - themeSettingFloat(name: "floatSetting", themeId: "' . $this->getTestThemeName() . '") { - name - value - } - }' - ); - - $I->seeResponseIsJson(); - - $result = $I->grabJsonResponseAsArray(); - $I->assertArrayNotHasKey('errors', $result); - - $setting = $result['data']['themeSettingFloat']; - $I->assertSame('floatSetting', $setting['name']); - $I->assertSame(1.23, $setting['value']); - } - - public function testGetBooleanSettingNotAuthorized(AcceptanceTester $I): void - { - $I->login($this->getAgentUsername(), $this->getAgentPassword()); - - $I->sendGQLQuery( - 'query{ - themeSettingBoolean(name: "boolSetting", themeId: "' . $this->getTestThemeName() . '") { - name - value - } - }' - ); - - $I->seeResponseIsJson(); - - $result = $I->grabJsonResponseAsArray(); - $errorMessage = $result['errors'][0]['message']; - $I->assertSame('Cannot query field "themeSettingBoolean" on type "Query".', $errorMessage); - } - - public function testGetBooleanSettingAuthorized(AcceptanceTester $I): void - { - $I->login($this->getAdminUsername(), $this->getAdminPassword()); - - $I->sendGQLQuery( - 'query{ - themeSettingBoolean(name: "boolSetting", themeId: "' . $this->getTestThemeName() . '") { - name - value - } - }' - ); - - $I->seeResponseIsJson(); - - $result = $I->grabJsonResponseAsArray(); - $I->assertArrayNotHasKey('errors', $result); - - $setting = $result['data']['themeSettingBoolean']; - $I->assertSame('boolSetting', $setting['name']); - $I->assertSame(false, $setting['value']); - } - - public function testGetStringSettingNotAuthorized(AcceptanceTester $I): void - { - $I->login($this->getAgentUsername(), $this->getAgentPassword()); - - $I->sendGQLQuery( - 'query{ - themeSettingString(name: "stringSetting", themeId: "' . $this->getTestThemeName() . '") { - name - value - } - }' - ); - - $I->seeResponseIsJson(); - - $result = $I->grabJsonResponseAsArray(); - $errorMessage = $result['errors'][0]['message']; - $I->assertSame('Cannot query field "themeSettingString" on type "Query".', $errorMessage); - } - - public function testGetStringSettingAuthorized(AcceptanceTester $I): void - { - $I->login($this->getAdminUsername(), $this->getAdminPassword()); - - $I->sendGQLQuery( - 'query{ - themeSettingString(name: "stringSetting", themeId: "' . $this->getTestThemeName() . '") { - name - value - } - }' - ); - - $I->seeResponseIsJson(); - - $result = $I->grabJsonResponseAsArray(); - $I->assertArrayNotHasKey('errors', $result); - - $setting = $result['data']['themeSettingString']; - $I->assertSame('stringSetting', $setting['name']); - $I->assertSame('default', $setting['value']); - } - - public function testGetSelectSettingNotAuthorized(AcceptanceTester $I): void - { - $I->login($this->getAgentUsername(), $this->getAgentPassword()); - - $I->sendGQLQuery( - 'query{ - themeSettingSelect(name: "selectSetting", themeId: "' . $this->getTestThemeName() . '") { - name - value - } - }' - ); - - $I->seeResponseIsJson(); - - $result = $I->grabJsonResponseAsArray(); - $errorMessage = $result['errors'][0]['message']; - $I->assertSame('Cannot query field "themeSettingSelect" on type "Query".', $errorMessage); - } - - public function testGetSelectSettingAuthorized(AcceptanceTester $I): void - { - $I->login($this->getAdminUsername(), $this->getAdminPassword()); - - $I->sendGQLQuery( - 'query{ - themeSettingSelect(name: "selectSetting", themeId: "' . $this->getTestThemeName() . '") { - name - value - } - }' - ); - - $I->seeResponseIsJson(); - - $result = $I->grabJsonResponseAsArray(); - $I->assertArrayNotHasKey('errors', $result); - - $setting = $result['data']['themeSettingSelect']; - $I->assertSame('selectSetting', $setting['name']); - $I->assertSame('selectString', $setting['value']); - } - - public function testGetCollectionSettingNotAuthorized(AcceptanceTester $I): void - { - $I->login($this->getAgentUsername(), $this->getAgentPassword()); - - $I->sendGQLQuery( - 'query{ - themeSettingCollection(name: "arraySetting", themeId: "' . $this->getTestThemeName() . '") { - name - value - } - }' - ); - - $I->seeResponseIsJson(); - - $result = $I->grabJsonResponseAsArray(); - $errorMessage = $result['errors'][0]['message']; - $I->assertSame('Cannot query field "themeSettingCollection" on type "Query".', $errorMessage); - } - - public function testGetCollectionSettingAuthorized(AcceptanceTester $I): void - { - $I->login($this->getAdminUsername(), $this->getAdminPassword()); - - $I->sendGQLQuery( - 'query{ - themeSettingCollection(name: "arraySetting", themeId: "' . $this->getTestThemeName() . '") { - name - value - } - }' - ); - - $I->seeResponseIsJson(); - - $result = $I->grabJsonResponseAsArray(); - $I->assertArrayNotHasKey('errors', $result); - - $setting = $result['data']['themeSettingCollection']; - $I->assertSame('arraySetting', $setting['name']); - $I->assertSame('["10","20","50","100"]', $setting['value']); - } - - public function testGetAssocCollectionSettingNotAuthorized(AcceptanceTester $I): void - { - $I->login($this->getAgentUsername(), $this->getAgentPassword()); - - $I->sendGQLQuery( - 'query{ - themeSettingAssocCollection(name: "aarraySetting", themeId: "' . $this->getTestThemeName() . '") { - name - value - } - }' - ); - - $I->seeResponseIsJson(); - - $result = $I->grabJsonResponseAsArray(); - $errorMessage = $result['errors'][0]['message']; - $I->assertSame('Cannot query field "themeSettingAssocCollection" on type "Query".', $errorMessage); - } - - public function testGetAssocCollectionSettingAuthorized(AcceptanceTester $I): void - { - $I->login($this->getAdminUsername(), $this->getAdminPassword()); - - $I->sendGQLQuery( - 'query{ - themeSettingAssocCollection(name: "aarraySetting", themeId: "' . $this->getTestThemeName() . '") { - name - value - } - }' - ); - - $I->seeResponseIsJson(); - - $result = $I->grabJsonResponseAsArray(); - $I->assertArrayNotHasKey('errors', $result); - - $setting = $result['data']['themeSettingAssocCollection']; - $I->assertSame('aarraySetting', $setting['name']); - $I->assertSame('{"first":"10","second":"20","third":"50"}', $setting['value']); - } - - public function testGetThemeSettingsListNotAuthorized(AcceptanceTester $I): void - { - $I->login($this->getAgentUsername(), $this->getAgentPassword()); - - $I->sendGQLQuery( - 'query getSettings($themeId: String!){ - themeSettingsList(themeId: $themeId) { - name - type - supported - } - }', - ['themeId' => $this->getTestThemeName()] - ); - - $I->seeResponseIsJson(); - - $result = $I->grabJsonResponseAsArray(); - $errorMessage = $result['errors'][0]['message']; - $I->assertSame('Cannot query field "themeSettingsList" on type "Query".', $errorMessage); - } - - public function testGetThemeSettingsListAuthorized(AcceptanceTester $I): void - { - $I->login($this->getAdminUsername(), $this->getAdminPassword()); - - $I->sendGQLQuery( - 'query getSettings($themeId: String!){ - themeSettingsList(themeId: $themeId) { - name - type - supported - } - }', - ['themeId' => $this->getTestThemeName()] - ); - - $I->seeResponseIsJson(); - - $result = $I->grabJsonResponseAsArray(); - $I->assertArrayNotHasKey('errors', $result); - - $settingsList = $result['data']['themeSettingsList']; - $I->assertCount(7, $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' => 'selectSetting', 'type' => FieldType::SELECT, 'supported' => true], - $settingsList - ); - $I->assertContains( - ['name' => 'arraySetting', 'type' => FieldType::ARRAY, 'supported' => true], - $settingsList - ); - $I->assertContains( - ['name' => 'aarraySetting', 'type' => FieldType::ASSOCIATIVE_ARRAY, 'supported' => true], - $settingsList - ); - } - - public function testChangeIntegerSettingNotAuthorized(AcceptanceTester $I): void - { - $I->login($this->getAgentUsername(), $this->getAgentPassword()); - - $I->sendGQLQuery( - 'mutation{ - changeThemeSettingInteger(name: "intSettingEditable", value: 124, themeId: "' . $this->getTestThemeName( - ) . '") { - name - value - } - }' - ); - - $I->seeResponseIsJson(); - - $result = $I->grabJsonResponseAsArray(); - $errorMessage = $result['errors'][0]['message']; - $I->assertSame('Cannot query field "changeThemeSettingInteger" on type "Mutation".', $errorMessage); - } - - public function testChangeIntegerSettingAuthorized(AcceptanceTester $I): void - { - $I->login($this->getAdminUsername(), $this->getAdminPassword()); - - $I->sendGQLQuery( - 'mutation{ - changeThemeSettingInteger(name: "intSettingEditable", value: 124, themeId: "' . $this->getTestThemeName( - ) . '") { - name - value - } - }' - ); - - $I->seeResponseIsJson(); - - $result = $I->grabJsonResponseAsArray(); - $I->assertArrayNotHasKey('errors', $result); - - $setting = $result['data']['changeThemeSettingInteger']; - $I->assertSame('intSettingEditable', $setting['name']); - $I->assertSame(124, $setting['value']); - } - - public function testChangeFloatSettingNotAuthorized(AcceptanceTester $I): void - { - $I->login($this->getAgentUsername(), $this->getAgentPassword()); - - $I->sendGQLQuery( - 'mutation{ - changeThemeSettingFloat(name: "floatSettingEditable", value: 1.24, themeId: "' . $this->getTestThemeName( - ) . '") { - name - value - } - }' - ); - - $I->seeResponseIsJson(); - - $result = $I->grabJsonResponseAsArray(); - $errorMessage = $result['errors'][0]['message']; - $I->assertSame('Cannot query field "changeThemeSettingFloat" on type "Mutation".', $errorMessage); - } - - public function testChangeFloatSettingAuthorized(AcceptanceTester $I): void - { - $I->login($this->getAdminUsername(), $this->getAdminPassword()); - - $I->sendGQLQuery( - 'mutation{ - changeThemeSettingFloat(name: "floatSettingEditable", value: 1.24, themeId: "' . $this->getTestThemeName( - ) . '") { - name - value - } - }' - ); - - $I->seeResponseIsJson(); - - $result = $I->grabJsonResponseAsArray(); - $I->assertArrayNotHasKey('errors', $result); - - $setting = $result['data']['changeThemeSettingFloat']; - $I->assertSame('floatSettingEditable', $setting['name']); - $I->assertSame(1.24, $setting['value']); - } - - public function testChangeBooleanSettingNotAuthorized(AcceptanceTester $I): void - { - $I->login($this->getAgentUsername(), $this->getAgentPassword()); - - $I->sendGQLQuery( - 'mutation{ - changeThemeSettingBoolean(name: "boolSettingEditable", value: False, themeId: "' . $this->getTestThemeName( - ) . '") { - name - value - } - }' - ); - - $I->seeResponseIsJson(); - - $result = $I->grabJsonResponseAsArray(); - $errorMessage = $result['errors'][0]['message']; - $I->assertSame('Cannot query field "changeThemeSettingBoolean" on type "Mutation".', $errorMessage); - } - - public function testChangeBooleanSettingAuthorized(AcceptanceTester $I): void - { - $I->login($this->getAdminUsername(), $this->getAdminPassword()); - - $I->sendGQLQuery( - 'mutation{ - changeThemeSettingBoolean(name: "boolSettingEditable", value: true, themeId: "' . $this->getTestThemeName( - ) . '") { - name - value - } - }' - ); - - $I->seeResponseIsJson(); - - $result = $I->grabJsonResponseAsArray(); - $I->assertArrayNotHasKey('errors', $result); - - $setting = $result['data']['changeThemeSettingBoolean']; - $I->assertSame('boolSettingEditable', $setting['name']); - $I->assertSame(true, $setting['value']); - } - - public function testChangeStringSettingNotAuthorized(AcceptanceTester $I): void - { - $I->login($this->getAgentUsername(), $this->getAgentPassword()); - - $I->sendGQLQuery( - 'mutation{ - changeThemeSettingString(name: "stringSettingEditable", value: "default", themeId: "' . $this->getTestThemeName( - ) . '") { - name - value - } - }' - ); - - $I->seeResponseIsJson(); - - $result = $I->grabJsonResponseAsArray(); - $errorMessage = $result['errors'][0]['message']; - $I->assertSame('Cannot query field "changeThemeSettingString" on type "Mutation".', $errorMessage); - } - - public function testChangeStringSettingAuthorized(AcceptanceTester $I): void - { - $I->login($this->getAdminUsername(), $this->getAdminPassword()); - - $I->sendGQLQuery( - 'mutation{ - changeThemeSettingString(name: "stringSetting", value: "default", themeId: "' . $this->getTestThemeName( - ) . '") { - name - value - } - }' - ); - - $I->seeResponseIsJson(); - - $result = $I->grabJsonResponseAsArray(); - $I->assertArrayNotHasKey('errors', $result); - - $setting = $result['data']['changeThemeSettingString']; - $I->assertSame('stringSetting', $setting['name']); - $I->assertSame('default', $setting['value']); - } - - public function testChangeCollectionSettingNotAuthorized(AcceptanceTester $I): void - { - $I->login($this->getAgentUsername(), $this->getAgentPassword()); - - $I->sendGQLQuery( - 'mutation{ - changeThemeSettingCollection(name: "arraySetting", themeId: "' . $this->getTestThemeName() . '") { - name - value - } - }' - ); - - $I->seeResponseIsJson(); - - $result = $I->grabJsonResponseAsArray(); - $errorMessage = $result['errors'][0]['message']; - $I->assertSame('Cannot query field "changeThemeSettingCollection" on type "Mutation".', $errorMessage); - } - - public function testChangeCollectionSettingAuthorized(AcceptanceTester $I): void - { - $I->login($this->getAdminUsername(), $this->getAdminPassword()); - - $I->sendGQLQuery( - 'mutation{ - changeThemeSettingCollection(name: "arraySetting", themeId: "' . $this->getTestThemeName() . '", value: "[3, \"interesting\", \"values\"]") { - name - value - } - }' - ); - - $I->seeResponseIsJson(); - - $result = $I->grabJsonResponseAsArray(); - $I->assertArrayNotHasKey('errors', $result); - - $setting = $result['data']['changeThemeSettingCollection']; - $I->assertSame('arraySetting', $setting['name']); - $I->assertSame('[3, "interesting", "values"]', $setting['value']); - } -} diff --git a/tests/Codeception/Acceptance/ThemeSettingGettersCest.php b/tests/Codeception/Acceptance/ThemeSettingGettersCest.php new file mode 100644 index 0000000..912a159 --- /dev/null +++ b/tests/Codeception/Acceptance/ThemeSettingGettersCest.php @@ -0,0 +1,100 @@ +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' => 'themeSettingInteger', + 'settingName' => 'intSetting', + 'expectedValue' => 123 + ]; + + yield [ + 'queryName' => 'themeSettingFloat', + 'settingName' => 'floatSetting', + 'expectedValue' => 1.23 + ]; + + yield [ + 'queryName' => 'themeSettingBoolean', + 'settingName' => 'boolSetting', + 'expectedValue' => false + ]; + + yield [ + 'queryName' => 'themeSettingString', + 'settingName' => 'stringSetting', + 'expectedValue' => 'default' + ]; + + yield [ + 'queryName' => 'themeSettingSelect', + 'settingName' => 'selectSetting', + 'expectedValue' => 'selectString' + ]; + + yield [ + 'queryName' => 'themeSettingCollection', + 'settingName' => 'arraySetting', + 'expectedValue' => '["10","20","50","100"]' + ]; + + yield [ + 'queryName' => 'themeSettingAssocCollection', + 'settingName' => 'aarraySetting', + 'expectedValue' => '{"first":"10","second":"20","third":"50"}' + ]; + } + + private function runSettingGetterQuery(AcceptanceTester $I, string $queryName, string $settingName): array + { + $I->sendGQLQuery( + 'query q($name: ID!, $themeId: String!){ + ' . $queryName . '(name: $name, themeId: $themeId) { + name + value + } + }', + [ + 'name' => $settingName, + 'themeId' => self::TEST_THEME_ID + ] + ); + + $I->seeResponseIsJson(); + + return $I->grabJsonResponseAsArray(); + } +} diff --git a/tests/Codeception/Acceptance/ThemeSettingListCest.php b/tests/Codeception/Acceptance/ThemeSettingListCest.php new file mode 100644 index 0000000..b1102b6 --- /dev/null +++ b/tests/Codeception/Acceptance/ThemeSettingListCest.php @@ -0,0 +1,97 @@ +login($this->getAdminUsername(), $this->getAdminPassword()); + $I->sendGQLQuery( + 'query getSettings($themeId: String!){ + themeSettingsList(themeId: $themeId) { + name + type + supported + } + }', + ['themeId' => $this->getTestThemeName()] + ); + $I->seeResponseIsJson(); + $result = $I->grabJsonResponseAsArray(); + $I->assertArrayNotHasKey('errors', $result); + $settingsList = $result['data']['themeSettingsList']; + $I->assertCount(14, $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' => 'selectSetting', 'type' => FieldType::SELECT, 'supported' => true], + $settingsList + ); + $I->assertContains( + ['name' => 'arraySetting', 'type' => FieldType::ARRAY, 'supported' => true], + $settingsList + ); + $I->assertContains( + ['name' => 'aarraySetting', 'type' => FieldType::ASSOCIATIVE_ARRAY, 'supported' => true], + $settingsList + ); + $I->assertContains( + ['name' => 'intSettingEditable', 'type' => FieldType::NUMBER, 'supported' => true], + $settingsList + ); + $I->assertContains( + ['name' => 'floatSettingEditable', 'type' => FieldType::NUMBER, 'supported' => true], + $settingsList + ); + $I->assertContains( + ['name' => 'boolSettingEditable', 'type' => FieldType::BOOLEAN, 'supported' => true], + $settingsList + ); + $I->assertContains( + ['name' => 'stringSettingEditable', 'type' => FieldType::STRING, 'supported' => true], + $settingsList + ); + $I->assertContains( + ['name' => 'selectSettingEditable', 'type' => FieldType::SELECT, 'supported' => true], + $settingsList + ); + $I->assertContains( + ['name' => 'arraySettingEditable', 'type' => FieldType::ARRAY, 'supported' => true], + $settingsList + ); + $I->assertContains( + ['name' => 'assocArraySettingEditable', 'type' => FieldType::ASSOCIATIVE_ARRAY, 'supported' => true], + $settingsList + ); + } +} diff --git a/tests/Codeception/Acceptance/ThemeSettingMutationsCest.php b/tests/Codeception/Acceptance/ThemeSettingMutationsCest.php new file mode 100644 index 0000000..5531f07 --- /dev/null +++ b/tests/Codeception/Acceptance/ThemeSettingMutationsCest.php @@ -0,0 +1,139 @@ +login($this->getAdminUsername(), $this->getAdminPassword()); + + $I->sendGQLQuery( + 'mutation{ + changeThemeSettingInteger(name: "intSettingEditable", value: 124, themeId: "' . $this->getTestThemeName( + ) . '") { + name + value + } + }' + ); + + $I->seeResponseIsJson(); + + $result = $I->grabJsonResponseAsArray(); + $I->assertArrayNotHasKey('errors', $result); + + $setting = $result['data']['changeThemeSettingInteger']; + $I->assertSame('intSettingEditable', $setting['name']); + $I->assertSame(124, $setting['value']); + } + + public function testChangeFloatSettingAuthorized(AcceptanceTester $I): void + { + $I->login($this->getAdminUsername(), $this->getAdminPassword()); + + $I->sendGQLQuery( + 'mutation{ + changeThemeSettingFloat(name: "floatSettingEditable", value: 1.24, themeId: "' . $this->getTestThemeName( + ) . '") { + name + value + } + }' + ); + + $I->seeResponseIsJson(); + + $result = $I->grabJsonResponseAsArray(); + $I->assertArrayNotHasKey('errors', $result); + + $setting = $result['data']['changeThemeSettingFloat']; + $I->assertSame('floatSettingEditable', $setting['name']); + $I->assertSame(1.24, $setting['value']); + } + + public function testChangeBooleanSettingAuthorized(AcceptanceTester $I): void + { + $I->login($this->getAdminUsername(), $this->getAdminPassword()); + + $I->sendGQLQuery( + 'mutation{ + changeThemeSettingBoolean(name: "boolSettingEditable", value: true, themeId: "' . $this->getTestThemeName( + ) . '") { + name + value + } + }' + ); + + $I->seeResponseIsJson(); + + $result = $I->grabJsonResponseAsArray(); + $I->assertArrayNotHasKey('errors', $result); + + $setting = $result['data']['changeThemeSettingBoolean']; + $I->assertSame('boolSettingEditable', $setting['name']); + $I->assertSame(true, $setting['value']); + } + + public function testChangeStringSettingAuthorized(AcceptanceTester $I): void + { + $I->login($this->getAdminUsername(), $this->getAdminPassword()); + + $I->sendGQLQuery( + 'mutation{ + changeThemeSettingString(name: "stringSetting", value: "default", themeId: "' . $this->getTestThemeName( + ) . '") { + name + value + } + }' + ); + + $I->seeResponseIsJson(); + + $result = $I->grabJsonResponseAsArray(); + $I->assertArrayNotHasKey('errors', $result); + + $setting = $result['data']['changeThemeSettingString']; + $I->assertSame('stringSetting', $setting['name']); + $I->assertSame('default', $setting['value']); + } + + public function testChangeCollectionSettingAuthorized(AcceptanceTester $I): void + { + $I->login($this->getAdminUsername(), $this->getAdminPassword()); + + $I->sendGQLQuery( + 'mutation{ + changeThemeSettingCollection(name: "arraySetting", themeId: "' . $this->getTestThemeName() . '", value: "[3, \"interesting\", \"values\"]") { + name + value + } + }' + ); + + $I->seeResponseIsJson(); + + $result = $I->grabJsonResponseAsArray(); + $I->assertArrayNotHasKey('errors', $result); + + $setting = $result['data']['changeThemeSettingCollection']; + $I->assertSame('arraySetting', $setting['name']); + $I->assertSame('[3, "interesting", "values"]', $setting['value']); + } +}