/var/www/vhosts/ihelp.ro/httpdocs/vendor/cakephp/authentication/docs/en
NameSizeModeActions
authentication-component.rst39750644editdlrm
authenticators.rst206610644editdlrm
conf.py2610644editdlrm
contents.rst3290644editdlrm
identifiers.rst65500644editdlrm
identity-object.rst33580644editdlrm
impersonation.rst22160644editdlrm
index.rst88770644editdlrm
middleware.rst26330644editdlrm
migration-from-the-authcomponent.rst113610644editdlrm
password-hashers.rst27040644editdlrm
testing.rst17990644editdlrm
url-checkers.rst10400644editdlrm
view-helper.rst7310644editdlrm
Edit: /var/www/vhosts/ihelp.ro/httpdocs/vendor/cakephp/authentication/docs/en/testing.rst (1799B)
Testing with Authentication ########################### With the ``authentication`` middleware active in your application you'll need to simulate authentication credentials in your integration tests. First, ensure that your controller or middleware tests are using the ``IntegrationTestTrait``:: // In a controller test. use Cake\TestSuite\IntegrationTestTrait; use Cake\TestSuite\TestCase; class ArticlesControllerTest extends TestCase { use IntegrationTestTrait; // Test methods and helpers to follow. } Based on the type of authentication you're using you will need to simulate credentials differently. Lets review a few more common types of authentication. Session based authentication ============================ Session based authentication requires simulating the User data that normally would be found in the session. In your test cases you can define a helper method that lets you 'login':: protected function login($userId = 1) { $users = TableRegistry::getTableLocator()->get('Users'); $user = $users->get($userId); $this->session(['Auth' => $user]); } In your integration tests you can use ``login()`` to simulate a user being logged in:: public function testGet() { $this->login(); $this->get('/bookmarks/1'); $this->assertResponseOk(); } Token based authentication ========================== With token based authentication you need to simulate the ``Authorization`` header. After getting valid token setup the request:: public function testGet() { $token = $this->getToken(); $this->configRequest([ 'headers' => ['Authorization' => 'Bearer ' . $token] ]); $this->get('/api/bookmarks'); $this->assertResponseOk(); }