-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathTokenHelperTest.php
More file actions
132 lines (114 loc) · 3.7 KB
/
TokenHelperTest.php
File metadata and controls
132 lines (114 loc) · 3.7 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
/**
* TokenHelper Test Case
*
* @copyright Copyright 2014, NetCommons Project
* @author Kohei Teraguchi <kteraguchi@commonsnet.org>
* @link http://www.netcommons.org NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
*/
App::uses('View', 'View');
App::uses('TokenHelper', 'NetCommons.View/Helper');
/**
* Summary for TokenHelper Test Case
*/
class TokenHelperTest extends CakeTestCase {
/**
* setUp method
*
* @return void
*/
public function setUp() {
parent::setUp();
$View = new View();
$this->Token = new TokenHelper($View);
$this->Token->request = new CakeRequest('test', false);
$this->Token->request->data = array(
'TestModel' => array(
'id' => 1,
'first_name' => 'Nate',
'last_name' => 'Abele',
'email' => 'nate@example.com',
'created' => '2014-12-5 05:04:42',
'created_user' => '1',
'modified' => '2014-12-09 05:04:42',
'modified_user' => '2'
)
);
$this->Token->request['_Token'] = array('key' => 'testKey');
}
/**
* tearDown method
*
* @return void
*/
public function tearDown() {
unset($this->Token);
parent::tearDown();
}
/**
* testGetToken method
*
* @return void
*/
public function testGetToken() {
$tokenFields = Hash::flatten($this->Token->request->data);
$hiddenFields = array('TestModel.email');
$tokens = $this->Token->getToken('TestModel', 'test', $tokenFields, $hiddenFields);
$this->assertEquals('testKey', $tokens['_Token']['key']);
$this->assertTextContains('TestModel.email', $tokens['_Token']['fields']);
$this->assertEmpty($tokens['_Token']['unlocked']);
}
/**
* testGetTokenUnlocked method
*
* @return void
*/
public function testGetTokenUnlocked() {
$tokenFields = Hash::flatten($this->Token->request->data);
$hiddenFields = array('TestModel.email');
$this->Token->request['_Token'] += array('unlockedFields' => 'TestModel.email');
$tokens = $this->Token->getToken('TestModel', 'test', $tokenFields, $hiddenFields);
$this->assertEquals('testKey', $tokens['_Token']['key']);
$this->assertNotContains('TestModel.email', $tokens['_Token']['fields']);
$this->assertEquals('TestModel.email', $tokens['_Token']['unlocked']);
}
/**
* testGetTokenBlacklist method
*
* @return void
*/
public function testGetTokenBlacklist() {
$tokenFields = Hash::flatten($this->Token->request->data);
$hiddenFields = array(
'TestModel.email',
'TestModel.created',
'TestModel.modified',
'TestModel.created_user',
'TestModel.modified_user'
);
$tokens = $this->Token->getToken('TestModel', 'test', $tokenFields, $hiddenFields);
$this->assertEquals('testKey', $tokens['_Token']['key']);
$this->assertContains('TestModel.email', $tokens['_Token']['fields']);
$this->assertNotContains('TestModel.created', $tokens['_Token']['fields']);
$this->assertNotContains('TestModel.modified', $tokens['_Token']['fields']);
$this->assertNotContains('TestModel.created_user', $tokens['_Token']['fields']);
$this->assertNotContains('TestModel.modified_user', $tokens['_Token']['fields']);
$this->assertEmpty($tokens['_Token']['unlocked']);
}
/**
* testGetTokenUnlocked method
*
* @return void
*/
public function testGetTokenBlacklistPass() {
$tokenFields = Hash::flatten($this->Token->request->data);
$hiddenFields = array('TestModel.email', 'TestModel.created');
$blackLists = array('TestModel.email');
$tokens = $this->Token->getToken('TestModel', 'test', $tokenFields, $hiddenFields, $blackLists);
$this->assertEquals('testKey', $tokens['_Token']['key']);
$this->assertNotContains('TestModel.email', $tokens['_Token']['fields']);
$this->assertContains('TestModel.created', $tokens['_Token']['fields']);
$this->assertEmpty($tokens['_Token']['unlocked']);
}
}