cakephp.
http://book.cakephp.org/3.0/en/development/testing.html#testing-actions-that-require-authentication
,
AuthComponent, , AuthComponent . IntegrationTestCase. , ArticleController, , , :
public function testAddUnauthenticatedFails()
{
$this->get('/articles/add');
$this->assertRedirect(['controller' => 'Users', 'action' => 'login']);
}
public function testAddAuthenticated()
{
$this->session([
'Auth' => [
'User' => [
'id' => 1,
'username' => 'testing',
]
]
]);
$this->get('/articles/add');
$this->assertResponseOk();
}
// Set session data
$this->session(['Auth.User.id' => 1]);
, :
public function testDisplay()
{
$this->session(['Auth.User.id' => 1, 'Auth.User.role' => 'admin']);
$this->get('/pages/home');
$this->assertResponseOk();
$this->assertResponseContains('CakePHP');
$this->assertResponseContains('<html>');
}