-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUpdateNotificationsTest.php
More file actions
166 lines (139 loc) · 3.63 KB
/
UpdateNotificationsTest.php
File metadata and controls
166 lines (139 loc) · 3.63 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
/**
* Notification::updateNotifications()のテスト
*
* @property Notification $Notification
*
* @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
*/
App::uses('NetCommonsModelTestCase', 'NetCommons.TestSuite');
/**
* Notification::updateNotifications()のテスト
*
* @author Shohei Nakajima <nakajimashouhei@gmail.com>
* @package NetCommons\Notifications\Test\Case\Model
*/
class NotificationUpdateNotificationsTest extends NetCommonsModelTestCase {
/**
* Fixtures
*
* @var array
*/
public $fixtures = array(
'plugin.notifications.notification4nodata',
);
/**
* Plugin name
*
* @var array
*/
public $plugin = 'notifications';
/**
* Model name
*
* @var array
*/
protected $_modelName = 'Notification';
/**
* Method name
*
* @var array
*/
protected $_methodName = 'updateNotifications';
/**
* updateNotificationsによるテスト
*
* @return void
*/
protected function _getData() {
$model = $this->_modelName;
//テスト用データ取得
$url = App::pluginPath(Inflector::camelize($this->plugin)) . 'Test' . DS . 'Fixture' . DS . 'rss_v2.xml';
return $this->$model->serialize($url);
}
/**
* updateNotificationsによるテスト
*
* @return void
*/
public function testUpdateNotifications() {
$model = $this->_modelName;
$method = $this->_methodName;
//テスト用データ取得
$data = $this->_getData();
//テスト実行
$result = $this->$model->$method(array('Notification' => $data));
//チェック
$this->assertTrue($result);
$count = $this->$model->find('count');
$this->assertCount($count, $data);
}
/**
* データ上書きによるテスト
*
* @return void
*/
public function testUpdateNotificationsByOverwrite() {
$model = $this->_modelName;
$method = $this->_methodName;
//事前テスト
$this->testUpdateNotifications();
//テスト用データ取得
$data = $this->_getData();
$data = Hash::insert($data, '{n}.title', 'Overwrite content title');
//テスト実行
$result = $this->$model->$method(array('Notification' => $data));
//チェック
$this->assertTrue($result);
$count = $this->$model->find('count', array(
'conditions' => array('Notification.title' => 'Overwrite content title'),
));
$this->assertCount($count, $data);
}
/**
* エラー用のDataProvider
*
* #### 戻り値
* - string $mockModel Mockのモデル
* - string $mockMethod Mockのメソッド
* - bool $exception Exceptionかどうか
*
* @return array
*/
public function dataProviderOnError() {
$results = array(
array($this->_modelName, 'validateMany', false),
array($this->_modelName, 'deleteAll', true),
array($this->_modelName, 'saveMany', true),
);
return $results;
}
/**
* updateNotificationsのErrorテスト
*
* @param string $mockModel Mockのモデル
* @param string $mockMethod Mockのメソッド
* @param bool $exception Exceptionかどうか
* @dataProvider dataProviderOnError
* @return void
*/
public function testUpdateNotificationsOnError($mockModel, $mockMethod, $exception) {
$model = $this->_modelName;
$method = $this->_methodName;
$this->_mockForReturnFalse($model, $mockModel, $mockMethod);
//テスト用データ取得
$data = $this->_getData();
//テスト実行
if ($exception) {
$this->setExpectedException('InternalErrorException');
}
$result = $this->$model->$method(array('Notification' => $data));
if (! $exception) {
$this->assertFalse($result);
}
}
}