forked from NetCommons3/NetCommons
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateTest.php
More file actions
116 lines (100 loc) · 3.11 KB
/
CreateTest.php
File metadata and controls
116 lines (100 loc) · 3.11 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
<?php
/**
* NetCommonsApp Test Case
*
* @author Ryuji AMANO <ryuji@ryus.co.jp>
* @link http://www.netcommons.org NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
*/
App::uses('Current', 'NetCommons.Utility');
App::uses('NetCommonsCakeTestCase', 'NetCommons.TestSuite');
App::uses('NetCommonsControllerTestCase', 'NetCommons.TestSuite');
/**
* Summary for NetCommonsApp Test Case
*/
class NetCommonsAppModelCreateTest extends NetCommonsCakeTestCase {
/**
* @var array fixture
*/
public $fixtures = array(
'plugin.site_manager.site_setting',
'plugin.net_commons.create_profile',
);
/**
* setUp method
*
* @return void
*/
public function setUp() {
parent::setUp();
NetCommonsControllerTestCase::loadTestPlugin($this, 'NetCommons', 'TestNetCommons');
Current::$current['Language']['id'] = '5';
}
/**
* tearDown method
*
* @return void
*/
public function tearDown() {
Current::$current = array();
parent::tearDown();
}
/**
* createでnot nullカラムのデフォルトがnullにならないこと
*
* @see https://github.com/NetCommons3/NetCommons3/issues/7
* @return void
*/
public function testNotNullFieldDefaultIsNotNull() {
$SiteSetting = ClassRegistry::init('SiteManager.SiteSetting');
$newData = $SiteSetting->create();
// Tableでnot null なカラムにnullがセットされちゃダメ
$this->assertNotNull($newData['SiteSetting']['key']);
$this->assertNotNull($newData['SiteSetting']['label']);
// CurrentがあればCurrentで上書きされる
App::uses('Current', 'NetCommons.Utility');
Current::$current['Language']['id'] = 5;
$newDataWithCurrent = $SiteSetting->create();
$this->assertEquals(5, $newDataWithCurrent['SiteSetting']['language_id']);
// $data が渡れれば$dataを優先する
$data = array();
$data['SiteSetting']['language_id'] = 10;
$newDataWithCurrent = $SiteSetting->create($data);
$this->assertEquals(10, $newDataWithCurrent['SiteSetting']['language_id']);
// nullを渡すと空が返る
$newDataWithCurrent = $SiteSetting->create(null);
$this->assertEmpty($newDataWithCurrent);
// falseを渡すと空が返る
$newDataWithCurrent = $SiteSetting->create(false);
$this->assertEmpty($newDataWithCurrent);
}
/**
* create()でモデル名付きの配列を渡すとデフォルト値がセットされなかったバグの修正テスト
* ```
* var_dump($this->Announcement->create(array('Announcement' => array(
* 'id' => null,
* ))));
* var_dump($this->Announcement->create(array(
* 'id' => null,
* )));
* 上記の結果が同じになるように修正した
* ```
*
* @return void
*/
public function testCreateWithModelNameData() {
$TestCreateProfile = ClassRegistry::init('TestNetCommons.TestCreateProfile');
$data = [
'name' => 'foo'
];
$newData = $TestCreateProfile->create($data);
$dataWithModelName = [
'TestCreateProfile' => [
'name' => 'foo'
]
];
$newDataWithModelName = $TestCreateProfile->create($dataWithModelName);
$this->assertEquals($newData, $newDataWithModelName);
$this->assertEquals(5, $newData['TestCreateProfile']['language_id']);
}
}