|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Page::getPageWithFrame()のテスト |
| 4 | + * |
| 5 | + * @author Noriko Arai <arai@nii.ac.jp> |
| 6 | + * @author Shohei Nakajima <nakajimashouhei@gmail.com> |
| 7 | + * @link http://www.netcommons.org NetCommons Project |
| 8 | + * @license http://www.netcommons.org/license.txt NetCommons License |
| 9 | + * @copyright Copyright 2014, NetCommons Project |
| 10 | + */ |
| 11 | + |
| 12 | +App::uses('NetCommonsGetTest', 'NetCommons.TestSuite'); |
| 13 | + |
| 14 | +/** |
| 15 | + * Page::getPageWithFrame()のテスト |
| 16 | + * |
| 17 | + * @author Shohei Nakajima <nakajimashouhei@gmail.com> |
| 18 | + * @package NetCommons\Pages\Test\Case\Model\Page |
| 19 | + */ |
| 20 | +class PageGetPageWithFrameTest extends NetCommonsGetTest { |
| 21 | + |
| 22 | +/** |
| 23 | + * Fixtures |
| 24 | + * |
| 25 | + * @var array |
| 26 | + */ |
| 27 | + public $fixtures = array( |
| 28 | + 'plugin.pages.box4pages', |
| 29 | + 'plugin.pages.boxes_page4pages', |
| 30 | + 'plugin.pages.container4pages', |
| 31 | + 'plugin.pages.containers_page4pages', |
| 32 | + 'plugin.pages.frame4pages', |
| 33 | + 'plugin.pages.languages_page4pages', |
| 34 | + 'plugin.pages.page4pages', |
| 35 | + 'plugin.pages.plugin4pages', |
| 36 | + 'plugin.pages.plugins_room4pages', |
| 37 | + 'plugin.pages.room4pages', |
| 38 | + ); |
| 39 | + |
| 40 | +/** |
| 41 | + * Plugin name |
| 42 | + * |
| 43 | + * @var string |
| 44 | + */ |
| 45 | + public $plugin = 'pages'; |
| 46 | + |
| 47 | +/** |
| 48 | + * Model name |
| 49 | + * |
| 50 | + * @var string |
| 51 | + */ |
| 52 | + protected $_modelName = 'Page'; |
| 53 | + |
| 54 | +/** |
| 55 | + * Method name |
| 56 | + * |
| 57 | + * @var string |
| 58 | + */ |
| 59 | + protected $_methodName = 'getPageWithFrame'; |
| 60 | + |
| 61 | +/** |
| 62 | + * getPageWithFrame()のテスト |
| 63 | + * |
| 64 | + * @return void |
| 65 | + */ |
| 66 | + public function testGetPageWithFrame() { |
| 67 | + $model = $this->_modelName; |
| 68 | + $methodName = $this->_methodName; |
| 69 | + |
| 70 | + //データ生成 |
| 71 | + $permalink = 'test4'; |
| 72 | + |
| 73 | + //テスト実施 |
| 74 | + $result = $this->$model->$methodName($permalink); |
| 75 | + |
| 76 | + //チェック |
| 77 | + $expected = array('Page', 'Box', 'Container', 'Language'); |
| 78 | + $this->assertEquals($expected, array_keys($result)); |
| 79 | + |
| 80 | + $this->__assertPage($result['Page'], array()); |
| 81 | + $this->__assertBoxes($result['Box'], array( |
| 82 | + 'header' => array(), |
| 83 | + 'minor' => array(), |
| 84 | + 'major' => array(), |
| 85 | + 'footer' => array(), |
| 86 | + 'main' => array(), |
| 87 | + )); |
| 88 | + $this->__assertContainers($result['Container'], array()); |
| 89 | + } |
| 90 | + |
| 91 | +/** |
| 92 | + * getPageWithFrame()のテスト |
| 93 | + * |
| 94 | + * @return void |
| 95 | + */ |
| 96 | + public function testGetPageWithFrameByRoot() { |
| 97 | + $model = $this->_modelName; |
| 98 | + $methodName = $this->_methodName; |
| 99 | + Current::write('Room.page_id_top', '7'); |
| 100 | + |
| 101 | + //データ生成 |
| 102 | + $permalink = ''; |
| 103 | + |
| 104 | + //テスト実施 |
| 105 | + $result = $this->$model->$methodName($permalink); |
| 106 | + |
| 107 | + //チェック |
| 108 | + $expected = array('Page', 'Box', 'Container', 'Language'); |
| 109 | + $this->assertEquals($expected, array_keys($result)); |
| 110 | + |
| 111 | + $this->__assertPage($result['Page']); |
| 112 | + $this->__assertBoxes($result['Box']); |
| 113 | + $this->__assertContainers($result['Container']); |
| 114 | + } |
| 115 | + |
| 116 | +/** |
| 117 | + * Pageのチェック |
| 118 | + * |
| 119 | + * @param array $result 結果データ |
| 120 | + * @return void |
| 121 | + */ |
| 122 | + private function __assertPage($result) { |
| 123 | + $result = Hash::remove($result, 'created_user'); |
| 124 | + $result = Hash::remove($result, 'created'); |
| 125 | + $result = Hash::remove($result, 'modified_user'); |
| 126 | + $result = Hash::remove($result, 'modified'); |
| 127 | + |
| 128 | + $expected = array( |
| 129 | + 'id' => '7', 'room_id' => '1', 'root_id' => '1', 'parent_id' => '4', 'lft' => '3', 'rght' => '4', |
| 130 | + 'permalink' => 'test4', 'slug' => 'test4', 'is_container_fluid' => false, 'theme' => null, |
| 131 | + ); |
| 132 | + $this->assertEquals($expected, $result); |
| 133 | + } |
| 134 | + |
| 135 | +/** |
| 136 | + * Boxesのチェック |
| 137 | + * |
| 138 | + * @param array $result 結果データ |
| 139 | + * @return void |
| 140 | + */ |
| 141 | + private function __assertBoxes($result) { |
| 142 | + $result = Hash::remove($result, '{n}.created_user'); |
| 143 | + $result = Hash::remove($result, '{n}.created'); |
| 144 | + $result = Hash::remove($result, '{n}.modified_user'); |
| 145 | + $result = Hash::remove($result, '{n}.modified'); |
| 146 | + |
| 147 | + $result = Hash::remove($result, '{n}.{s}.created_user'); |
| 148 | + $result = Hash::remove($result, '{n}.{s}.created'); |
| 149 | + $result = Hash::remove($result, '{n}.{s}.modified_user'); |
| 150 | + $result = Hash::remove($result, '{n}.{s}.modified'); |
| 151 | + |
| 152 | + $this->assertCount(5, $result); |
| 153 | + $this->__assertBoxHeader(Hash::extract($result, '{n}[id=1]')[0]); |
| 154 | + $this->__assertBoxMinor(Hash::extract($result, '{n}[id=4]')[0]); |
| 155 | + $this->__assertBoxMajor(Hash::extract($result, '{n}[id=2]')[0]); |
| 156 | + $this->__assertBoxFooter(Hash::extract($result, '{n}[id=5]')[0]); |
| 157 | + $this->__assertBoxMain(Hash::extract($result, '{n}[id=17]')[0]); |
| 158 | + } |
| 159 | + |
| 160 | +/** |
| 161 | + * Boxのチェック(レフト) |
| 162 | + * |
| 163 | + * @param array $result 結果データ |
| 164 | + * @return void |
| 165 | + */ |
| 166 | + private function __assertBoxMajor($result) { |
| 167 | + $result = Hash::remove($result, 'Frame.{n}.created_user'); |
| 168 | + $result = Hash::remove($result, 'Frame.{n}.created'); |
| 169 | + $result = Hash::remove($result, 'Frame.{n}.modified_user'); |
| 170 | + $result = Hash::remove($result, 'Frame.{n}.modified'); |
| 171 | + |
| 172 | + $expected = array( |
| 173 | + // * Box |
| 174 | + 'id' => '2', 'container_id' => '2', 'type' => '1', 'space_id' => '2', |
| 175 | + 'room_id' => '1', 'page_id' => '1', 'weight' => '1', |
| 176 | + // * BoxesPage |
| 177 | + 'BoxesPage' => array( |
| 178 | + 'id' => '22', 'page_id' => '7', 'box_id' => '2', 'is_published' => true, |
| 179 | + ), |
| 180 | + // * Frame |
| 181 | + 'Frame' => array(0 => array( |
| 182 | + 'id' => '2', |
| 183 | + 'language_id' => '2', |
| 184 | + 'room_id' => '1', |
| 185 | + 'box_id' => '2', |
| 186 | + 'plugin_key' => 'test_pages', |
| 187 | + 'block_id' => '2', |
| 188 | + 'key' => 'frame_major', |
| 189 | + 'name' => 'Test frame major', |
| 190 | + 'header_type' => 'default', |
| 191 | + 'weight' => '1', |
| 192 | + 'is_deleted' => false, |
| 193 | + 'default_action' => '', |
| 194 | + )) |
| 195 | + ); |
| 196 | + $this->assertEquals($expected, $result); |
| 197 | + } |
| 198 | + |
| 199 | +/** |
| 200 | + * Boxのチェック(フッター) |
| 201 | + * |
| 202 | + * @param array $result 結果データ |
| 203 | + * @return void |
| 204 | + */ |
| 205 | + private function __assertBoxFooter($result) { |
| 206 | + $result = Hash::remove($result, 'Frame.{n}.created_user'); |
| 207 | + $result = Hash::remove($result, 'Frame.{n}.created'); |
| 208 | + $result = Hash::remove($result, 'Frame.{n}.modified_user'); |
| 209 | + $result = Hash::remove($result, 'Frame.{n}.modified'); |
| 210 | + |
| 211 | + $expected = array( |
| 212 | + // * Box |
| 213 | + 'id' => '5', 'container_id' => '5', 'type' => '1', 'space_id' => '2', |
| 214 | + 'room_id' => '1', 'page_id' => '1', 'weight' => '1', |
| 215 | + // * BoxesPage |
| 216 | + 'BoxesPage' => array( |
| 217 | + 'id' => '25', 'page_id' => '7', 'box_id' => '5', 'is_published' => true, |
| 218 | + ), |
| 219 | + // * Frame |
| 220 | + 'Frame' => array(0 => array( |
| 221 | + 'id' => '4', |
| 222 | + 'language_id' => '2', |
| 223 | + 'room_id' => '1', |
| 224 | + 'box_id' => '5', |
| 225 | + 'plugin_key' => 'test_pages', |
| 226 | + 'block_id' => '2', |
| 227 | + 'key' => 'frame_footer', |
| 228 | + 'name' => 'Test frame footer', |
| 229 | + 'header_type' => 'default', |
| 230 | + 'weight' => '1', |
| 231 | + 'is_deleted' => false, |
| 232 | + 'default_action' => '', |
| 233 | + )) |
| 234 | + ); |
| 235 | + $this->assertEquals($expected, $result); |
| 236 | + } |
| 237 | + |
| 238 | +/** |
| 239 | + * Boxのチェック(メイン) |
| 240 | + * |
| 241 | + * @param array $result 結果データ |
| 242 | + * @return void |
| 243 | + */ |
| 244 | + private function __assertBoxMain($result) { |
| 245 | + $expected = array( |
| 246 | + // * Box |
| 247 | + 'id' => '17', 'container_id' => '17', 'type' => '4', 'space_id' => '2', |
| 248 | + 'room_id' => '1', 'page_id' => '7', 'weight' => '1', |
| 249 | + // * BoxesPage |
| 250 | + 'BoxesPage' => array( |
| 251 | + 'id' => '23', 'page_id' => '7', 'box_id' => '17', 'is_published' => true, |
| 252 | + ), |
| 253 | + // * Frame |
| 254 | + //'Frame' => array() |
| 255 | + ); |
| 256 | + $this->assertEquals($expected, $result); |
| 257 | + } |
| 258 | + |
| 259 | +/** |
| 260 | + * Boxのチェック(ヘッダー) |
| 261 | + * |
| 262 | + * @param array $result 結果データ |
| 263 | + * @return void |
| 264 | + */ |
| 265 | + private function __assertBoxHeader($result) { |
| 266 | + $result = Hash::remove($result, 'Frame.{n}.created_user'); |
| 267 | + $result = Hash::remove($result, 'Frame.{n}.created'); |
| 268 | + $result = Hash::remove($result, 'Frame.{n}.modified_user'); |
| 269 | + $result = Hash::remove($result, 'Frame.{n}.modified'); |
| 270 | + |
| 271 | + $expected = array( |
| 272 | + // * Box |
| 273 | + 'id' => '1', 'container_id' => '1', 'type' => '1', 'space_id' => '2', |
| 274 | + 'room_id' => '1', 'page_id' => '1', 'weight' => '1', |
| 275 | + // * BoxesPage |
| 276 | + 'BoxesPage' => array( |
| 277 | + 'id' => '21', 'page_id' => '7', 'box_id' => '1', 'is_published' => true, |
| 278 | + ), |
| 279 | + // * Frame |
| 280 | + 'Frame' => array(0 => array( |
| 281 | + 'id' => '1', |
| 282 | + 'language_id' => '2', |
| 283 | + 'room_id' => '1', |
| 284 | + 'box_id' => '1', |
| 285 | + 'plugin_key' => 'test_pages', |
| 286 | + 'block_id' => '2', |
| 287 | + 'key' => 'frame_header', |
| 288 | + 'name' => 'Test frame header', |
| 289 | + 'header_type' => 'default', |
| 290 | + 'weight' => '1', |
| 291 | + 'is_deleted' => false, |
| 292 | + 'default_action' => '', |
| 293 | + )) |
| 294 | + ); |
| 295 | + $this->assertEquals($expected, $result); |
| 296 | + } |
| 297 | + |
| 298 | +/** |
| 299 | + * Boxのチェック(ライト) |
| 300 | + * |
| 301 | + * @param array $result 結果データ |
| 302 | + * @return void |
| 303 | + */ |
| 304 | + private function __assertBoxMinor($result) { |
| 305 | + $result = Hash::remove($result, 'Frame.{n}.created_user'); |
| 306 | + $result = Hash::remove($result, 'Frame.{n}.created'); |
| 307 | + $result = Hash::remove($result, 'Frame.{n}.modified_user'); |
| 308 | + $result = Hash::remove($result, 'Frame.{n}.modified'); |
| 309 | + |
| 310 | + $expected = array( |
| 311 | + // * Box |
| 312 | + 'id' => '4', 'container_id' => '4', 'type' => '1', 'space_id' => '2', |
| 313 | + 'room_id' => '1', 'page_id' => '1', 'weight' => '1', |
| 314 | + // * BoxesPage |
| 315 | + 'BoxesPage' => array( |
| 316 | + 'id' => '24', 'page_id' => '7', 'box_id' => '4', 'is_published' => true, |
| 317 | + ), |
| 318 | + // * Frame |
| 319 | + 'Frame' => array(0 => array( |
| 320 | + 'id' => '3', |
| 321 | + 'language_id' => '2', |
| 322 | + 'room_id' => '1', |
| 323 | + 'box_id' => '4', |
| 324 | + 'plugin_key' => 'test_pages', |
| 325 | + 'block_id' => '2', |
| 326 | + 'key' => 'frame_minor', |
| 327 | + 'name' => 'Test frame minor', |
| 328 | + 'header_type' => 'default', |
| 329 | + 'weight' => '1', |
| 330 | + 'is_deleted' => false, |
| 331 | + 'default_action' => '', |
| 332 | + )) |
| 333 | + ); |
| 334 | + $this->assertEquals($expected, $result); |
| 335 | + } |
| 336 | + |
| 337 | +/** |
| 338 | + * Containersのチェック |
| 339 | + * |
| 340 | + * @param array $result 結果データ |
| 341 | + * @return void |
| 342 | + */ |
| 343 | + private function __assertContainers($result) { |
| 344 | + $result = Hash::remove($result, '{n}.created_user'); |
| 345 | + $result = Hash::remove($result, '{n}.created'); |
| 346 | + $result = Hash::remove($result, '{n}.modified_user'); |
| 347 | + $result = Hash::remove($result, '{n}.modified'); |
| 348 | + |
| 349 | + $result = Hash::remove($result, '{n}.{s}.created_user'); |
| 350 | + $result = Hash::remove($result, '{n}.{s}.created'); |
| 351 | + $result = Hash::remove($result, '{n}.{s}.modified_user'); |
| 352 | + $result = Hash::remove($result, '{n}.{s}.modified'); |
| 353 | + |
| 354 | + $expected = array( |
| 355 | + 0 => array( |
| 356 | + 'id' => '1', 'type' => '1', |
| 357 | + 'ContainersPage' => array( |
| 358 | + 'id' => '21', 'page_id' => '7', 'container_id' => '1', 'is_published' => true, 'is_configured' => false, |
| 359 | + ) |
| 360 | + ), |
| 361 | + 1 => array( |
| 362 | + 'id' => '2', 'type' => '2', |
| 363 | + 'ContainersPage' => array( |
| 364 | + 'id' => '22', 'page_id' => '7', 'container_id' => '2', 'is_published' => true, 'is_configured' => false, |
| 365 | + ) |
| 366 | + ), |
| 367 | + 2 => array( |
| 368 | + 'id' => '17', 'type' => '3', |
| 369 | + 'ContainersPage' => array( |
| 370 | + 'id' => '23', 'page_id' => '7', 'container_id' => '17', 'is_published' => true, 'is_configured' => false, |
| 371 | + ) |
| 372 | + ), |
| 373 | + 3 => array( |
| 374 | + 'id' => '4', 'type' => '4', |
| 375 | + 'ContainersPage' => array( |
| 376 | + 'id' => '24', 'page_id' => '7', 'container_id' => '4', 'is_published' => true, 'is_configured' => false, |
| 377 | + ) |
| 378 | + ), |
| 379 | + 4 => array( |
| 380 | + 'id' => '5', 'type' => '5', |
| 381 | + 'ContainersPage' => array( |
| 382 | + 'id' => '25', 'page_id' => '7', 'container_id' => '5', 'is_published' => true, 'is_configured' => false, |
| 383 | + ) |
| 384 | + ) |
| 385 | + ); |
| 386 | + $this->assertEquals($expected, $result); |
| 387 | + } |
| 388 | + |
| 389 | +} |
0 commit comments