forked from cakephp/codeception
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuthTrait.php
More file actions
54 lines (49 loc) · 1.33 KB
/
Copy pathAuthTrait.php
File metadata and controls
54 lines (49 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
namespace Cake\Codeception\Helper;
trait AuthTrait
{
/**
* Sets the currently logged in user for the application. Takes a user
* data array to store in the session.
*
* This method works but is NOT complete.
*
* @param array $user User data.
*/
public function amLoggedAs($user)
{
$this->client->getSession()->write(['Auth' => ['User' => $user]]);
}
/**
* Logs user out.
*
* @return void
*/
public function logout()
{
if (empty($this->client->cake['auth'])) {
$this->fail('The AuthComponent is not loaded');
}
$this->client->cake['auth']->logout();
}
/**
* Asserts request has logged in user.
*/
public function seeAuthentication()
{
if (empty($this->client->cake['auth'])) {
$this->fail('The AuthComponent is not loaded');
}
$this->assertTrue(is_array($this->client->cake['auth']->user()), 'User is not logged in');
}
/**
* Asserts request has no logged in user.
*/
public function dontSeeAuthentication()
{
if (empty($this->client->cake['auth'])) {
$this->fail('The AuthComponent is not loaded');
}
$this->assertFalse($this->client->getSession()->check('Auth.User'), 'User is logged in');
}
}