From 5e40ccbe496656cb668422721a03b0141069cf2b Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Wed, 3 Aug 2016 15:58:12 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20API=20=D0=B2=D1=8B=D0=B7=D0=BE=D0=B2=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20=D0=BF=D0=BE=D0=BB=D1=83=D1=87=D0=B5=D0=BD=D0=B8=D1=8F?= =?UTF-8?q?=20=D0=B0=D0=BA=D1=82=D0=B8=D0=B2=D0=BD=D0=BE=D0=B3=D0=BE=20Rec?= =?UTF-8?q?aptcha=20public=20key?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/components/ReCaptcha/Component.php | 10 +++++-- api/controllers/OptionsController.php | 30 +++++++++++++++++++ environments/dev/api/config/main-local.php | 1 + environments/docker/api/config/main-local.php | 1 + environments/prod/api/config/main-local.php | 1 + tests/codeception/api/_pages/OptionsRoute.php | 16 ++++++++++ .../api/functional/OptionsCest.php | 28 +++++++++++++++++ 7 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 api/controllers/OptionsController.php create mode 100644 tests/codeception/api/_pages/OptionsRoute.php create mode 100644 tests/codeception/api/functional/OptionsCest.php diff --git a/api/components/ReCaptcha/Component.php b/api/components/ReCaptcha/Component.php index bf16832..309748e 100644 --- a/api/components/ReCaptcha/Component.php +++ b/api/components/ReCaptcha/Component.php @@ -5,11 +5,17 @@ use yii\base\InvalidConfigException; class Component extends \yii\base\Component { + public $public; + public $secret; public function init() { - if ($this->secret === NULL) { - throw new InvalidConfigException(''); + if ($this->public === null) { + throw new InvalidConfigException('Public is required'); + } + + if ($this->secret === null) { + throw new InvalidConfigException('Secret is required'); } } diff --git a/api/controllers/OptionsController.php b/api/controllers/OptionsController.php new file mode 100644 index 0000000..2be2db8 --- /dev/null +++ b/api/controllers/OptionsController.php @@ -0,0 +1,30 @@ + [ + 'except' => ['recaptcha-public-key'], + ], + ]); + } + + public function verbs() { + return [ + 'recaptcha-public-key' => ['GET'], + ]; + } + + public function actionRecaptchaPublicKey() { + Yii::$app->response->format = Response::FORMAT_RAW; + + return Yii::$app->reCaptcha->public; + } + +} diff --git a/environments/dev/api/config/main-local.php b/environments/dev/api/config/main-local.php index 4c7c9bc..0d7edf0 100644 --- a/environments/dev/api/config/main-local.php +++ b/environments/dev/api/config/main-local.php @@ -7,6 +7,7 @@ $config = [ 'cookieValidationKey' => '', ], 'reCaptcha' => [ + 'public' => '', 'secret' => '', ], ], diff --git a/environments/docker/api/config/main-local.php b/environments/docker/api/config/main-local.php index 224f3dd..05a72f3 100644 --- a/environments/docker/api/config/main-local.php +++ b/environments/docker/api/config/main-local.php @@ -7,6 +7,7 @@ $config = [ 'cookieValidationKey' => '', ], 'reCaptcha' => [ + 'public' => '', 'secret' => '', ], ], diff --git a/environments/prod/api/config/main-local.php b/environments/prod/api/config/main-local.php index 9bf259c..19e08c8 100644 --- a/environments/prod/api/config/main-local.php +++ b/environments/prod/api/config/main-local.php @@ -6,6 +6,7 @@ return [ 'cookieValidationKey' => '', ], 'reCaptcha' => [ + 'public' => '', 'secret' => '', ], ], diff --git a/tests/codeception/api/_pages/OptionsRoute.php b/tests/codeception/api/_pages/OptionsRoute.php new file mode 100644 index 0000000..68ec646 --- /dev/null +++ b/tests/codeception/api/_pages/OptionsRoute.php @@ -0,0 +1,16 @@ +route = ['options/recaptcha-public-key']; + $this->actor->sendGET($this->getUrl()); + } + +} diff --git a/tests/codeception/api/functional/OptionsCest.php b/tests/codeception/api/functional/OptionsCest.php new file mode 100644 index 0000000..f995da6 --- /dev/null +++ b/tests/codeception/api/functional/OptionsCest.php @@ -0,0 +1,28 @@ +route = new OptionsRoute($I); + } + + public function testRecaptchaPublicKey(FunctionalTester $I) { + $I->wantTo('Get recaptcha public key'); + + $this->route->recaptchaPublicKey(); + $I->canSeeResponseCodeIs(200); + // TODO: эта проверка не проходит, т.к внутри почему-то после запроса не устанавливаются http заголовки + //$I->seeHttpHeader('Content-Type', 'text/html; charset=UTF-8'); + $I->canSeeResponseEquals('public-key'); + } + +}