From d9987a3185afcdec9b03d34c2cb0083fc3a2e26c Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Wed, 24 Feb 2016 01:34:01 +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=20=D1=8D=D0=BA=D1=88=D0=B5=D0=BD=20=D0=B4=D0=BB=D1=8F=20?= =?UTF-8?q?=D0=BF=D0=BE=D0=BB=D1=83=D1=87=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B8?= =?UTF-8?q?=D0=BD=D1=84=D1=8B=20=D0=BE=20=D1=82=D0=B5=D0=BA=D1=83=D1=89?= =?UTF-8?q?=D0=B5=D0=BC=20=D0=B0=D1=83=D1=82=D0=B5=D0=BD=D1=82=D0=B8=D1=84?= =?UTF-8?q?=D0=B8=D1=86=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=BD=D0=BE?= =?UTF-8?q?=D0=BC=20=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D1=82?= =?UTF-8?q?=D0=B5=D0=BB=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/controllers/UsersController.php | 44 +++++++++++++++++++ tests/codeception/api/_pages/UsersRoute.php | 16 +++++++ .../codeception/api/functional/UsersCest.php | 36 +++++++++++++++ 3 files changed, 96 insertions(+) create mode 100644 api/controllers/UsersController.php create mode 100644 tests/codeception/api/_pages/UsersRoute.php create mode 100644 tests/codeception/api/functional/UsersCest.php diff --git a/api/controllers/UsersController.php b/api/controllers/UsersController.php new file mode 100644 index 0000000..473b61d --- /dev/null +++ b/api/controllers/UsersController.php @@ -0,0 +1,44 @@ + [ + 'class' => AccessControl::class, + 'rules' => [ + [ + 'actions' => ['current'], + 'allow' => true, + 'roles' => ['@'], + ], + ], + ], + ]); + } + + public function verbs() { + return [ + 'current' => ['GET'], + ]; + } + + public function actionCurrent() { + /** @var Account $account */ + $account = Yii::$app->user->identity; + + return [ + 'id' => $account->id, + 'username' => $account->username, + 'email' => $account->email, + 'shouldChangePassword' => $account->password_hash_strategy === Account::PASS_HASH_STRATEGY_OLD_ELY, + ]; + } + +} diff --git a/tests/codeception/api/_pages/UsersRoute.php b/tests/codeception/api/_pages/UsersRoute.php new file mode 100644 index 0000000..8780f53 --- /dev/null +++ b/tests/codeception/api/_pages/UsersRoute.php @@ -0,0 +1,16 @@ +route = ['users/current']; + $this->actor->sendGET($this->getUrl()); + } + +} diff --git a/tests/codeception/api/functional/UsersCest.php b/tests/codeception/api/functional/UsersCest.php new file mode 100644 index 0000000..ebebd9a --- /dev/null +++ b/tests/codeception/api/functional/UsersCest.php @@ -0,0 +1,36 @@ +route = new UsersRoute($I); + } + + public function testCurrent(FunctionalTester $I, Scenario $scenario) { + $I = new AccountSteps($scenario); + $I->loggedInAsActiveAccount(); + + $this->route->current(); + $I->canSeeResponseCodeIs(200); + $I->canSeeResponseIsJson(); + $I->canSeeResponseContainsJson([ + 'id' => 1, + 'username' => 'Admin', + 'email' => 'admin@ely.by', + 'shouldChangePassword' => false, + ]); + } + +}