-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrepareTest.php
More file actions
166 lines (145 loc) · 3.89 KB
/
PrepareTest.php
File metadata and controls
166 lines (145 loc) · 3.89 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
162
163
164
165
166
<?php
/**
* TinydbAppController::initTinydb()のテスト
*
* @author Noriko Arai <arai@nii.ac.jp>
* @author Ryuji AMANO <ryuji@ryus.co.jp>
* @link http://www.netcommons.org NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
* @copyright Copyright 2014, NetCommons Project
*/
/**
* require
*/
require_once CakePlugin::path('Tinydb') . 'Lib/TinydbFunctions.php';
App::uses('NetCommonsControllerTestCase', 'NetCommons.TestSuite');
App::uses('UserRole', 'UserRoles.Model');
/**
* TinydbAppController::initTinydb()のテスト
*
* @author Ryuji AMANO <ryuji@ryus.co.jp>
* @package NetCommons\Tinydb\Test\Case\Controller\TinydbAppController
*/
class TinydbAppControllerPrepareTest extends NetCommonsControllerTestCase {
/**
* Fixtures
*
* @var array
*/
public $fixtures = array(
'plugin.tinydb.tinydb',
'plugin.tinydb.tinydb_item',
'plugin.tinydb.tinydb_frame_setting',
'plugin.tinydb.block_setting_for_tinydb',
'plugin.categories.category',
'plugin.categories.category_order',
'plugin.categories.categories_language',
'plugin.workflow.workflow_comment',
);
/**
* Plugin name
*
* @var string
*/
public $plugin = 'tinydb';
/**
* setUp method
*
* @return void
*/
public function setUp() {
parent::setUp();
//テストプラグインのロード
NetCommonsCakeTestCase::loadTestPlugin($this, 'Tinydb', 'TestTinydb');
$this->generateNc('TestTinydb.TestTinydbAppControllerIndex');
//ログイン
TestAuthGeneral::login($this);
}
/**
* tearDown method
*
* @return void
*/
public function tearDown() {
//ログアウト
TestAuthGeneral::logout($this);
parent::tearDown();
}
/**
* initTinydb()のテスト
*
* @return void
*/
public function testPrepare() {
//テストデータ
$frameId = '6';
$blockId = '2';
$urlOptions = [
'plugin' => 'test_tinydb',
'controller' => 'test_tinydb_app_controller_index',
'action' => 'index',
'block_id' => $blockId,
'frame_id' => $frameId
];
//テスト実行
$this->_testGetAction($urlOptions, ['method' => 'assertNotEmpty']);
$this->assertEquals('BlockId2Tinydb', $this->vars['tinydb']['Tinydb']['name']);
$this->assertEquals('content_block_1', $this->vars['tinydbSetting']['tinydb_key']);
$frameSetting = new ReflectionProperty($this->controller, '_frameSetting');
$frameSetting->setAccessible(true);
$value = $frameSetting->getValue($this->controller);
$this->assertEquals($frameId, $value['TinydbFrameSetting']['id']);
}
/**
* tinydbデータが取得できなければBadRequest
*
* @return void
*/
public function testTinydbNotFound() {
$frameId = null;
$blockId = '3';
$urlOptions = [
'plugin' => 'test_tinydb',
'controller' => 'test_tinydb_app_controller_index',
'action' => 'index',
'block_id' => $blockId,
'frame_id' => $frameId
];
//テスト実行
$this->_testGetAction($urlOptions, false, 'BadRequestException');
}
/**
* 新規ブログ作成時にTinydbSettingが取得できないので、デフォルト値でViewにセット
*
* @return void
*/
public function testTinydbSettingNotFound() {
$frameId = '6';
$blockId = '2';
$urlOptions = [
'plugin' => 'test_tinydb',
'controller' => 'test_tinydb_app_controller_index',
'action' => 'index',
'block_id' => $blockId,
'frame_id' => $frameId
];
//$this->_mockForReturn('Tinydb.TinydbSetting', 'getTinydbSetting', false, 1);
$mockModel = 'Tinydb.TinydbSetting';
$mockMethod = 'getTinydbSetting';
list($mockPlugin, $mockModel) = pluginSplit($mockModel);
$this->controller->$mockModel = $this->getMockForModel(
$mockPlugin . '.' . $mockModel,
array($mockMethod),
array('plugin' => 'Tinydb')
);
//テスト実行
$this->_testGetAction(
$urlOptions,
[
'method' => 'assertNotEmpty'
]
);
$this->assertNull($this->vars['tinydbSetting']['tinydb_key']);
//$this->assertEquals(1, $this->vars['tinydbSetting']['use_sns']);
}
}