forked from CakeDC/users
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProfileTraitTest.php
More file actions
113 lines (105 loc) · 3.03 KB
/
Copy pathProfileTraitTest.php
File metadata and controls
113 lines (105 loc) · 3.03 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
/**
* Copyright 2010 - 2017, Cake Development Corporation (https://www.cakedc.com)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2010 - 2017, Cake Development Corporation (https://www.cakedc.com)
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
namespace CakeDC\Users\Test\TestCase\Controller\Traits;
use CakeDC\Users\Controller\Traits\ProfileTrait;
use CakeDC\Users\Test\TestCase\Controller\Traits\BaseTraitTest;
use Cake\ORM\TableRegistry;
class ProfileTraitTest extends BaseTraitTest
{
/**
* Fixtures
*
* @var array
*/
public $fixtures = [
'plugin.CakeDC/Users.users',
'plugin.CakeDC/Users.social_accounts',
];
/**
* setUp
*
* @return void
*/
public function setUp()
{
$this->traitClassName = 'CakeDC\Users\Controller\Traits\ProfileTrait';
$this->traitMockMethods = ['set', 'getUsersTable', 'redirect', 'validate'];
parent::setUp();
}
/**
* test
*
* @return void
*/
public function testProfileGetNotLoggedInUserNotFound()
{
$userId = '00000000-0000-0000-0000-000000000000'; //not found
$this->_mockRequestGet();
$this->_mockAuth();
$this->_mockFlash();
$this->Trait->Flash->expects($this->once())
->method('error')
->with('User was not found');
$this->Trait->profile($userId);
}
/**
* test
*
* @return void
*/
public function testProfileGetLoggedInUserNotFound()
{
$userId = '00000000-0000-0000-0000-000000000000'; //not found
$this->_mockRequestGet();
$this->_mockAuthLoggedIn();
$this->_mockFlash();
$this->Trait->Flash->expects($this->once())
->method('error')
->with('User was not found');
$this->Trait->profile($userId);
}
/**
* test
*
* @return void
*/
public function testProfileGetNotLoggedInEmptyId()
{
$this->_mockRequestGet();
$this->_mockAuth();
$this->_mockFlash();
$this->Trait->Flash->expects($this->once())
->method('error')
->with('Not authorized, please login first');
$this->Trait->profile();
}
/**
* test
*
* @return void
*/
public function testProfileGetLoggedInMyProfile()
{
$this->_mockRequestGet();
$this->_mockAuthLoggedIn();
$this->_mockFlash();
$this->Trait->expects($this->any())
->method('set')
->will($this->returnCallback(function ($param1, $param2 = null) {
if ($param1 === 'avatarPlaceholder') {
BaseTraitTest::assertEquals('CakeDC/Users.avatar_placeholder.png', $param2);
} elseif (is_array($param1)) {
BaseTraitTest::assertEquals('user-1', $param1['user']->username);
}
}));
$this->Trait->profile();
}
}