diff --git a/tests/Codeception/Acceptance/ModuleSettingMutationsCest.php b/tests/Codeception/Acceptance/ModuleSettingMutationsCest.php index 25a6d60..04eae60 100644 --- a/tests/Codeception/Acceptance/ModuleSettingMutationsCest.php +++ b/tests/Codeception/Acceptance/ModuleSettingMutationsCest.php @@ -22,17 +22,6 @@ 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) { @@ -41,31 +30,27 @@ private function runChangeIntegerMutationAndGetResult(AcceptanceTester $I, strin } }', [ - 'name' => $name, - 'value' => $value, + 'name' => 'intSetting', + 'value' => 124, 'moduleId' => self::TEST_MODULE_ID ] ); $I->seeResponseIsJson(); - return $I->grabJsonResponseAsArray(); - } + $result = $I->grabJsonResponseAsArray(); - 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']); + $setting = $result['data']['changeModuleSettingInteger']; + $I->assertSame('intSetting', $setting['name']); + $I->assertSame(124, $setting['value']); } - private function runFloatMutationAndGetResult(AcceptanceTester $I, string $name, float $value): array + public function testChangeFloatSettingAuthorized(AcceptanceTester $I): void { + $I->login($this->getAdminUsername(), $this->getAdminPassword()); + $I->sendGQLQuery( 'mutation m($name: ID!, $value: Float!, $moduleId: String!){ changeModuleSettingFloat(name: $name, value: $value, moduleId: $moduleId) { @@ -74,32 +59,27 @@ private function runFloatMutationAndGetResult(AcceptanceTester $I, string $name, } }', [ - 'name' => $name, - 'value' => $value, + 'name' => 'floatSetting', + 'value' => 1.24, 'moduleId' => self::TEST_MODULE_ID ] ); $I->seeResponseIsJson(); - return $I->grabJsonResponseAsArray(); - } - - public function testChangeBooleanSettingAuthorized(AcceptanceTester $I): void - { - $I->login($this->getAdminUsername(), $this->getAdminPassword()); - - $result = $this->runChangeBooleanMutationAndGetResult($I, 'boolSetting', false); + $result = $I->grabJsonResponseAsArray(); $I->assertArrayNotHasKey('errors', $result); - $setting = $result['data']['changeModuleSettingBoolean']; - $I->assertSame('boolSetting', $setting['name']); - $I->assertSame(false, $setting['value']); + $setting = $result['data']['changeModuleSettingFloat']; + $I->assertSame('floatSetting', $setting['name']); + $I->assertSame(1.24, $setting['value']); } - private function runChangeBooleanMutationAndGetResult(AcceptanceTester $I, string $name, bool $value): array + public function testChangeBooleanSettingAuthorized(AcceptanceTester $I): void { + $I->login($this->getAdminUsername(), $this->getAdminPassword()); + $I->sendGQLQuery( 'mutation m($name: ID!, $value: Boolean!, $moduleId: String!){ changeModuleSettingBoolean(name: $name, value: $value, moduleId: $moduleId) { @@ -108,32 +88,27 @@ private function runChangeBooleanMutationAndGetResult(AcceptanceTester $I, strin } }', [ - 'name' => $name, - 'value' => $value, + 'name' => 'boolSetting', + 'value' => false, 'moduleId' => self::TEST_MODULE_ID ] ); $I->seeResponseIsJson(); - return $I->grabJsonResponseAsArray(); - } - - public function testChangeStringSettingAuthorized(AcceptanceTester $I): void - { - $I->login($this->getAdminUsername(), $this->getAdminPassword()); - - $result = $this->runChangeStringMutationAndGetResult($I, 'stringSetting', 'default'); + $result = $I->grabJsonResponseAsArray(); $I->assertArrayNotHasKey('errors', $result); - $setting = $result['data']['changeModuleSettingString']; - $I->assertSame('stringSetting', $setting['name']); - $I->assertSame('default', $setting['value']); + $setting = $result['data']['changeModuleSettingBoolean']; + $I->assertSame('boolSetting', $setting['name']); + $I->assertSame(false, $setting['value']); } - private function runChangeStringMutationAndGetResult(AcceptanceTester $I, string $name, string $value): array + public function testChangeStringSettingAuthorized(AcceptanceTester $I): void { + $I->login($this->getAdminUsername(), $this->getAdminPassword()); + $I->sendGQLQuery( 'mutation m($name: ID!, $value: String!, $moduleId: String!){ changeModuleSettingString(name: $name, value: $value, moduleId: $moduleId) { @@ -142,32 +117,27 @@ private function runChangeStringMutationAndGetResult(AcceptanceTester $I, string } }', [ - 'name' => $name, - 'value' => $value, + 'name' => 'stringSetting', + 'value' => 'default', 'moduleId' => self::TEST_MODULE_ID ] ); $I->seeResponseIsJson(); - return $I->grabJsonResponseAsArray(); - } - - public function testChangeCollectionSettingAuthorized(AcceptanceTester $I): void - { - $I->login($this->getAdminUsername(), $this->getAdminPassword()); - - $result = $this->runChangeCollectionMutationAndGetResult($I, 'arraySetting', '[3, "interesting", "values"]'); + $result = $I->grabJsonResponseAsArray(); $I->assertArrayNotHasKey('errors', $result); - $setting = $result['data']['changeModuleSettingCollection']; - $I->assertSame('arraySetting', $setting['name']); - $I->assertSame('[3, "interesting", "values"]', $setting['value']); + $setting = $result['data']['changeModuleSettingString']; + $I->assertSame('stringSetting', $setting['name']); + $I->assertSame('default', $setting['value']); } - private function runChangeCollectionMutationAndGetResult(AcceptanceTester $I, string $name, string $value): array + public function testChangeCollectionSettingAuthorized(AcceptanceTester $I): void { + $I->login($this->getAdminUsername(), $this->getAdminPassword()); + $I->sendGQLQuery( 'mutation m($name: ID!, $value: String!, $moduleId: String!){ changeModuleSettingCollection(name: $name, value: $value, moduleId: $moduleId) { @@ -176,14 +146,20 @@ private function runChangeCollectionMutationAndGetResult(AcceptanceTester $I, st } }', [ - 'name' => $name, - 'value' => $value, + 'name' => 'arraySetting', + 'value' => '[3, "interesting", "values"]', 'moduleId' => self::TEST_MODULE_ID ] ); $I->seeResponseIsJson(); - return $I->grabJsonResponseAsArray(); + $result = $I->grabJsonResponseAsArray(); + + $I->assertArrayNotHasKey('errors', $result); + + $setting = $result['data']['changeModuleSettingCollection']; + $I->assertSame('arraySetting', $setting['name']); + $I->assertSame('[3, "interesting", "values"]', $setting['value']); } } diff --git a/tests/Codeception/Acceptance/NotAuthorizedAccessCest.php b/tests/Codeception/Acceptance/NotAuthorizedAccessCest.php index 95a60d5..600d66d 100644 --- a/tests/Codeception/Acceptance/NotAuthorizedAccessCest.php +++ b/tests/Codeception/Acceptance/NotAuthorizedAccessCest.php @@ -122,7 +122,8 @@ protected function assertQueryNotFoundErrorInResult( ): void { $errorMessage = $result['errors'][0]['message']; $I->assertSame( - 'Cannot query field "' . $query . '" on type "' . ucfirst($queryType) . '".', $errorMessage + 'Cannot query field "' . $query . '" on type "' . ucfirst($queryType) . '".', + $errorMessage ); } } diff --git a/tests/Codeception/Acceptance/ThemeSettingMutationsCest.php b/tests/Codeception/Acceptance/ThemeSettingMutationsCest.php index 5531f07..24bdae2 100644 --- a/tests/Codeception/Acceptance/ThemeSettingMutationsCest.php +++ b/tests/Codeception/Acceptance/ThemeSettingMutationsCest.php @@ -23,13 +23,17 @@ public function testChangeIntegerSettingAuthorized(AcceptanceTester $I): void $I->login($this->getAdminUsername(), $this->getAdminPassword()); $I->sendGQLQuery( - 'mutation{ - changeThemeSettingInteger(name: "intSettingEditable", value: 124, themeId: "' . $this->getTestThemeName( - ) . '") { + 'mutation m($name: ID!, $value: Int!, $themeId: String!){ + changeThemeSettingInteger(name: $name, value: $value, themeId: $themeId) { name value } - }' + }', + [ + 'name' => 'intSettingEditable', + 'value' => 124, + 'themeId' => self::TEST_THEME_ID + ] ); $I->seeResponseIsJson(); @@ -47,13 +51,17 @@ public function testChangeFloatSettingAuthorized(AcceptanceTester $I): void $I->login($this->getAdminUsername(), $this->getAdminPassword()); $I->sendGQLQuery( - 'mutation{ - changeThemeSettingFloat(name: "floatSettingEditable", value: 1.24, themeId: "' . $this->getTestThemeName( - ) . '") { + 'mutation m($name: ID!, $value: Float!, $themeId: String!){ + changeThemeSettingFloat(name: $name, value: $value, themeId: $themeId) { name value } - }' + }', + [ + 'name' => 'floatSettingEditable', + 'value' => 1.24, + 'themeId' => self::TEST_THEME_ID + ] ); $I->seeResponseIsJson(); @@ -71,13 +79,17 @@ public function testChangeBooleanSettingAuthorized(AcceptanceTester $I): void $I->login($this->getAdminUsername(), $this->getAdminPassword()); $I->sendGQLQuery( - 'mutation{ - changeThemeSettingBoolean(name: "boolSettingEditable", value: true, themeId: "' . $this->getTestThemeName( - ) . '") { + 'mutation m($name: ID!, $value: Boolean!, $themeId: String!){ + changeThemeSettingBoolean(name: $name, value: $value, themeId: $themeId) { name value } - }' + }', + [ + 'name' => 'boolSettingEditable', + 'value' => true, + 'themeId' => self::TEST_THEME_ID + ] ); $I->seeResponseIsJson(); @@ -95,13 +107,17 @@ public function testChangeStringSettingAuthorized(AcceptanceTester $I): void $I->login($this->getAdminUsername(), $this->getAdminPassword()); $I->sendGQLQuery( - 'mutation{ - changeThemeSettingString(name: "stringSetting", value: "default", themeId: "' . $this->getTestThemeName( - ) . '") { + 'mutation m($name: ID!, $value: String!, $themeId: String!){ + changeThemeSettingString(name: $name, value: $value, themeId: $themeId) { name value } - }' + }', + [ + 'name' => 'stringSetting', + 'value' => 'default', + 'themeId' => self::TEST_THEME_ID + ] ); $I->seeResponseIsJson(); @@ -119,12 +135,17 @@ 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\"]") { + 'mutation m($name: ID!, $value: String!, $themeId: String!){ + changeThemeSettingCollection(name: $name, value: $value, themeId: $themeId) { name value } - }' + }', + [ + 'name' => 'arraySetting', + 'value' => '[3, "interesting", "values"]', + 'themeId' => self::TEST_THEME_ID + ] ); $I->seeResponseIsJson();