/var/www/vhosts/ihelp.ro/httpdocs/vendor/cakephp/authentication/docs/ja
NameSizeModeActions
authentication-component.rst49500644editdlrm
authenticators.rst176620644editdlrm
conf.py2610644editdlrm
contents.rst3100644editdlrm
identifiers.rst74090644editdlrm
identity-object.rst40480644editdlrm
index.rst76690644editdlrm
middleware.rst29700644editdlrm
migration-from-the-authcomponent.rst128900644editdlrm
password-hashers.rst35740644editdlrm
testing.rst17680644editdlrm
url-checkers.rst14030644editdlrm
view-helper.rst9340644editdlrm
Edit: /var/www/vhosts/ihelp.ro/httpdocs/vendor/cakephp/authentication/docs/ja/testing.rst (1768B)
認証によるテスト ###################### アプリケーションで ``authentication`` ミドルウェアがアクティブな状態であれば、 統合テストで認証情報をシミュレートする必要があります。 使用している認証の種類に応じて、クレデンシャルを異なる方法でシミュレートする必要があります。 認証の一般的なタイプをいくつか確認してみましょう。 セッションベースの認証 ============================ セッションベースの認証では、通常セッションで見つかるであろうユーザデータをシミュレートする必要があります。 テストケースでは、「ログイン」するためのヘルパーメソッドを定義することができます。:: protected function login($userId = 1) { $users = TableRegistry::getTableLocator()->get('Users'); $user = $users->get($userId); $this->session(['Auth' => $user]); } 統合テストでは ``login()`` を使ってユーザがログインしたときのシミュレーションをすることができます。:: public function testGet() { $this->login(); $this->get('/bookmarks/1'); $this->assertResponseOk(); } トークンベースの認証 ========================== トークンベースの認証では ``Authorization`` ヘッダーをシミュレートする必要があります。 有効なトークンを取得した後、リクエスト:: public function testGet() { $token = $this->getToken(); $this->configRequest([ 'headers' => ['Authorization' => 'Bearer ' . $token] ]); $this->get('/api/bookmarks'); $this->assertResponseOk(); }