-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathCreateAllTest.php
More file actions
134 lines (117 loc) · 3.34 KB
/
CreateAllTest.php
File metadata and controls
134 lines (117 loc) · 3.34 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
<?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 NetCommonsAppModelCreateAllTest extends NetCommonsCakeTestCase {
/**
* @var array fixture
*/
public $fixtures = array(
'plugin.net_commons.create_group',
'plugin.net_commons.create_profile',
'plugin.net_commons.create_user',
);
/**
* setUp method
*
* @return void
*/
public function setUp() {
parent::setUp();
NetCommonsControllerTestCase::loadTestPlugin($this, 'NetCommons', 'TestNetCommons');
Current::$current['Room']['id'] = '2';
Current::$current['Language']['id'] = '5';
}
/**
* tearDown method
*
* @return void
*/
public function tearDown() {
Current::$current = array();
parent::tearDown();
}
/**
* createAllのassociation(hasOne)のテスト
*
* @param array $data createAllの引数
* @dataProvider dataProviderCreateAllUser
* @return void
*/
public function testCreateAllUser($data = array()) {
$TestCreateUser = ClassRegistry::init('TestNetCommons.TestCreateUser');
$newData = $TestCreateUser->createAll($data);
$this->assertNotEmpty($newData['TestCreateUser']);
$this->assertNotEmpty($newData['TestCreateGroup']);
$this->assertArrayNotHasKey('TrackableCreator', $newData);
$this->assertArrayNotHasKey('TrackableUpdater', $newData);
if (isset($data['TestCreateGroup']['room_id'])) {
$expected = $data['TestCreateGroup']['room_id'];
} else {
$expected = Current::$current['Room']['id'];
}
$this->assertEquals($expected, $newData['TestCreateGroup']['room_id']);
}
/**
* createAllのassociation(belongTo)のテスト
*
* @param array $data createAllの引数
* @dataProvider dataProviderCreateAllProfile
* @return void
*/
public function testCreateAllProfile($data = array()) {
$TestCreateProfile = ClassRegistry::init('TestNetCommons.TestCreateProfile');
$newData = $TestCreateProfile->createAll($data);
$this->assertNotEmpty($newData['TestCreateUser']);
$this->assertNotEmpty($newData['TestCreateProfile']);
$this->assertArrayNotHasKey('TrackableCreator', $newData);
$this->assertArrayNotHasKey('TrackableUpdater', $newData);
if (isset($data['language_id'])) {
$expected = $data['language_id'];
} elseif (isset($data['TestCreateProfile']['language_id'])) {
$expected = $data['TestCreateProfile']['language_id'];
} else {
$expected = Current::$current['Language']['id'];
}
$this->assertEquals($expected, $newData['TestCreateProfile']['language_id']);
}
/**
* createAllのassociation(hasOne)のDataProvider
*
* #### 戻り値
* - data createAllの引数
*
* @return void
*/
public function dataProviderCreateAllUser() {
return array(
array(),
array(array('TestCreateGroup' => array('room_id' => '3'))),
);
}
/**
* createAllのassociation(hasOne)のDataProvider
*
* #### 戻り値
* - data createAllの引数
*
* @return void
*/
public function dataProviderCreateAllProfile() {
return array(
array(),
array(array('language_id' => '2')),
array(array('TestCreateProfile' => array('language_id' => '4'))),
);
}
}