From 85d109910f07da7f54739b37768267712e48679c Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Wed, 1 Nov 2017 19:56:23 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B0=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B8=20=D0=BF=D0=BE=D0=BF=D1=8B=D1=82=D0=BA=D0=B5?= =?UTF-8?q?=20=D0=BE=D1=82=D0=BF=D1=80=D0=B0=D0=B2=D0=B8=D1=82=D1=8C=20?= =?UTF-8?q?=D1=81=D0=BE=D0=BE=D0=B1=D1=89=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B2?= =?UTF-8?q?=20=D1=84=D0=BE=D1=80=D0=BC=D1=83=20=D0=BE=D0=B1=D1=80=D0=B0?= =?UTF-8?q?=D1=82=D0=BD=D0=BE=D0=B9=20=D1=81=D0=B2=D1=8F=D0=B7=D0=B8,=20?= =?UTF-8?q?=D0=B1=D1=83=D0=B4=D1=83=D1=87=D0=B8=20=D0=B7=D0=B0=D0=BB=D0=BE?= =?UTF-8?q?=D0=B3=D0=B8=D0=BD=D0=B5=D0=BD=D0=BD=D1=8B=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/models/FeedbackForm.php | 13 ++++--- .../api/functional/FeedbackCest.php | 37 +++++++++++++++++++ 2 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 tests/codeception/api/functional/FeedbackCest.php diff --git a/api/models/FeedbackForm.php b/api/models/FeedbackForm.php index 1c2ce12..52d899f 100644 --- a/api/models/FeedbackForm.php +++ b/api/models/FeedbackForm.php @@ -3,6 +3,7 @@ namespace api\models; use common\helpers\Error as E; use api\models\base\ApiForm; +use common\models\Account; use Yii; use yii\base\ErrorException; use yii\base\InvalidConfigException; @@ -58,11 +59,13 @@ class FeedbackForm extends ApiForm { return true; } - /** - * @return \common\models\Account|null $account - */ - protected function getAccount() { - return Yii::$app->user->identity; + protected function getAccount(): ?Account { + $identity = Yii::$app->user->identity; + if ($identity === null) { + return null; + } + + return $identity->getAccount(); } } diff --git a/tests/codeception/api/functional/FeedbackCest.php b/tests/codeception/api/functional/FeedbackCest.php new file mode 100644 index 0000000..abcda6e --- /dev/null +++ b/tests/codeception/api/functional/FeedbackCest.php @@ -0,0 +1,37 @@ +sendPOST('/feedback', [ + 'subject' => 'Test', + 'email' => 'email@ely.by', + 'type' => 0, + 'message' => 'Hello world', + ]); + $I->canSeeResponseCodeIs(200); + $I->canSeeResponseIsJson(); + $I->canSeeResponseContainsJson([ + 'success' => true, + ]); + } + + public function testFeedbackWithAuth(FunctionalTester $I) { + $I->amAuthenticated(); + $I->sendPOST('/feedback', [ + 'subject' => 'Test', + 'email' => 'email@ely.by', + 'type' => 0, + 'message' => 'Hello world', + ]); + $I->canSeeResponseCodeIs(200); + $I->canSeeResponseIsJson(); + $I->canSeeResponseContainsJson([ + 'success' => true, + ]); + } + +}