-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSetUserRoleAdminOnBasicTest.php
More file actions
150 lines (132 loc) · 3.84 KB
/
SetUserRoleAdminOnBasicTest.php
File metadata and controls
150 lines (132 loc) · 3.84 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php
/**
* UserManagerComponent::setUserRoleAdminOnBasic()のテスト
*
* @author Noriko Arai <arai@nii.ac.jp>
* @author Shohei Nakajima <nakajimashouhei@gmail.com>
* @link http://www.netcommons.org NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
* @copyright Copyright 2014, NetCommons Project
*/
App::uses('UserManagerControllerTestCase', 'UserManager.TestSuite');
/**
* UserManagerComponent::setUserRoleAdminOnBasic()のテスト
*
* @author Shohei Nakajima <nakajimashouhei@gmail.com>
* @package NetCommons\UserManager\Test\Case\Controller\Component\UserManagerComponent
*/
class UserManagerComponentSetUserRoleAdminOnBasicTest extends UserManagerControllerTestCase {
/**
* setUp method
*
* @return void
*/
public function setUp() {
parent::setUp();
//テストプラグインのロード
NetCommonsCakeTestCase::loadTestPlugin($this, 'UserManager', 'TestUserManager');
//テストコントローラ生成
$this->generateNc('TestUserManager.TestUserManagerComponent');
}
/**
* tearDown method
*
* @return void
*/
public function tearDown() {
//ログアウト
TestAuthGeneral::logout($this);
parent::tearDown();
}
/**
* setUserRoleAdminOnBasic()のテスト
*
* @return void
*/
public function testSystemAdministrator() {
//ログイン
TestAuthGeneral::login($this);
//テストアクション実行
$this->_testGetAction('/test_user_manager/test_user_manager_component/index',
array('method' => 'assertNotEmpty'), null, 'view');
$pattern = '/' . preg_quote('Controller/Component/TestUserManagerComponent', '/') . '/';
$this->assertRegExp($pattern, $this->view);
//テスト実行
$this->controller->UserManager->setUserRoleAdminOnBasic();
$result = $this->controller->viewVars['userAttributes']['1']['1']['6'];
$this->assertEquals($result['UserAttribute']['key'], 'role_key');
$expected = array(
1 => array(
'id' => '1',
'language_id' => '2',
'key' => 'system_administrator',
'name' => 'System administrator',
'user_attribute_id' => '10',
),
2 => array(
'id' => '2',
'language_id' => '2',
'key' => 'administrator',
'name' => 'Site administrator',
'user_attribute_id' => '10',
),
3 => array(
'id' => '3',
'language_id' => '2',
'key' => 'common_user',
'name' => 'Common user',
'user_attribute_id' => '10',
),
4 => array(
'id' => '4',
'language_id' => '2',
'key' => 'test_user',
'name' => 'Test user',
'user_attribute_id' => '10',
),
);
$this->assertEquals($result['UserAttributeChoice'], $expected);
}
/**
* setUserRoleAdminOnBasic()のテスト
*
* @return void
*/
public function testSiteAdministrator() {
//ログイン
TestAuthGeneral::login($this, Role::ROOM_ROLE_KEY_CHIEF_EDITOR);
//テストアクション実行
$this->_testGetAction('/test_user_manager/test_user_manager_component/index',
array('method' => 'assertNotEmpty'), null, 'view');
$pattern = '/' . preg_quote('Controller/Component/TestUserManagerComponent', '/') . '/';
$this->assertRegExp($pattern, $this->view);
//テスト実行
$this->controller->UserManager->setUserRoleAdminOnBasic();
$result = $this->controller->viewVars['userAttributes']['1']['1']['6'];
$this->assertEquals($result['UserAttribute']['key'], 'role_key');
$expected = array(
2 => array(
'id' => '2',
'language_id' => '2',
'key' => 'administrator',
'name' => 'Site administrator',
'user_attribute_id' => '10',
),
3 => array(
'id' => '3',
'language_id' => '2',
'key' => 'common_user',
'name' => 'Common user',
'user_attribute_id' => '10',
),
4 => array(
'id' => '4',
'language_id' => '2',
'key' => 'test_user',
'name' => 'Test user',
'user_attribute_id' => '10',
),
);
$this->assertEquals($result['UserAttributeChoice'], $expected);
}
}