forked from NetCommons3/NetCommons
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNetCommonsCakeTestCase.php
More file actions
161 lines (144 loc) · 4.07 KB
/
NetCommonsCakeTestCase.php
File metadata and controls
161 lines (144 loc) · 4.07 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
151
152
153
154
155
156
157
158
159
160
161
<?php
/**
* NetCommonsCakeTestCase
*
* @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
*/
CakeLog::drop('stdout');
CakeLog::drop('stderr');
App::uses('Current', 'NetCommons.Utility');
App::uses('NetCommonsTestSuite', 'NetCommons.TestSuite');
/**
* NetCommonsCakeTestCase class
*
* @package NetCommons\NetCommons\TestSuite
* @codeCoverageIgnore
*/
class NetCommonsCakeTestCase extends CakeTestCase {
/**
* Plugin name
*
* @var string
*/
public $plugin;
/**
* Fixture merge
*
* @var array
*/
protected $_isFixtureMerged = true;
/**
* Fixtures
*
* @var array
*/
protected $_defaultFixtures = array(
'plugin.blocks.block',
'plugin.blocks.block_role_permission',
'plugin.boxes.box',
'plugin.boxes.boxes_page',
'plugin.containers.container',
'plugin.containers.containers_page',
'plugin.data_types.data_type',
'plugin.data_types.data_type_choice',
'plugin.files.upload_file',
'plugin.files.upload_files_content',
'plugin.frames.frame',
'plugin.m17n.language',
'plugin.pages.page',
'plugin.plugin_manager.plugin',
//'plugin.plugin_manager.plugins_role',
//'plugin.roles.default_role_permission',
'plugin.roles.role',
'plugin.rooms.roles_room',
'plugin.rooms.roles_rooms_user',
'plugin.rooms.room',
'plugin.rooms.rooms_language',
//'plugin.rooms.room_role',
//'plugin.rooms.room_role_permission',
'plugin.rooms.space',
'plugin.user_attributes.user_attribute',
'plugin.user_attributes.user_attribute_choice',
'plugin.user_attributes.user_attribute_setting',
'plugin.user_roles.user_attributes_role',
'plugin.users.user',
//'plugin.users.users_language',
);
/**
* Fixtures load
*
* @param string $name The name parameter on PHPUnit_Framework_TestCase::__construct()
* @param array $data The data parameter on PHPUnit_Framework_TestCase::__construct()
* @param string $dataName The dataName parameter on PHPUnit_Framework_TestCase::__construct()
* @return void
*/
public function __construct($name = null, array $data = array(), $dataName = '') {
parent::__construct($name, $data, $dataName);
if ($this->_isFixtureMerged) {
$this->fixtures = array_merge($this->fixtures, $this->_defaultFixtures);
}
if ($this->plugin) {
NetCommonsTestSuite::$plugin = $this->plugin;
}
Configure::write('NetCommons.installed', true);
Configure::write('Config.language', 'ja');
}
/**
* setUp method
*
* @return void
*/
public function setUp() {
parent::setUp();
Configure::write('NetCommons.installed', true);
Configure::write('Config.language', 'ja');
foreach ($this->fixtures as $fixture) {
$split = pluginSplit($fixture);
if (! isset($split[0]) || ! isset($split[1]) || isset($split[0]) && strtolower($split[0]) !== 'plugin') {
continue;
}
list($plugin, $model) = pluginSplit($split[1]);
$plugin = Inflector::camelize($plugin);
$model = Inflector::camelize($model);
$classModel = ClassRegistry::init($plugin . '.' . $model, true);
if ($classModel) {
$model = $classModel->name;
$this->models[$model] = $plugin . '.' . $model;
}
}
foreach ($this->models as $model => $class) {
$this->$model = ClassRegistry::init($class);
}
}
/**
* tearDown method
*
* @return void
*/
public function tearDown() {
foreach ($this->models as $model) {
unset($this->$model);
}
Configure::write('NetCommons.installed', false);
Configure::write('Config.language', null);
parent::tearDown();
}
/**
* privateおよびprotectedメソッドのテスト
*
* @param Instance $instance インスタンス
* @param string $mockMethod Mockのメソッド
* @param array $params Mockのメソッドのパラメータ
* @return void
*/
protected function _testReflectionMethod($instance, $mockMethod, $params = array()) {
$method = new ReflectionMethod($instance, $mockMethod);
$method->setAccessible(true);
$result = $method->invokeArgs($instance, $params);
return $result;
}
}