-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathBlogSettingTest.php
More file actions
144 lines (126 loc) · 3.74 KB
/
BlogSettingTest.php
File metadata and controls
144 lines (126 loc) · 3.74 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
<?php
/**
* BlogSetting 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('BlogSetting', 'Blogs.Model');
/**
* Summary for BlogSetting Test Case
*
* @property BlogSetting $BlogSetting
*/
class BlogSettingTest extends CakeTestCase {
/**
* Fixtures
*
* @var array
*/
public $fixtures = array(
'plugin.blogs.blog_setting',
'plugin.blocks.block_role_permission',
'plugin.users.user',
);
/**
* setUp method
*
* @return void
*/
public function setUp() {
parent::setUp();
$this->BlogSetting = ClassRegistry::init('Blogs.BlogSetting');
}
/**
* tearDown method
*
* @return void
*/
public function tearDown() {
unset($this->BlogSetting);
parent::tearDown();
}
/**
* testGetBlogSetting method
*
* @return void
*/
public function testGetBlogSetting() {
$blogKey = 'blog1';
$blogSetting = $this->BlogSetting->getBlogSetting($blogKey);
$this->assertEquals(1, $blogSetting['BlogSetting']['id']);
}
/**
* testSaveBlogSetting method
*
* @return void
*/
public function testSaveBlogSetting() {
$data = $this->BlogSetting->getNew();
$data['BlogSetting']['blog_key'] = 'new_blog_key';
$data['BlockRolePermission'] = array();
$resultTrue = $this->BlogSetting->saveBlogSetting($data);
$this->assertTrue($resultTrue);
// validate fail
$BlogSettingMock = $this->getMockForModel('Blogs.BlogSetting', ['validateBlogSetting']);
$BlogSettingMock->expects($this->once())
->method('validateBlogSetting')
->will($this->returnValue(false));
$data = $this->BlogSetting->getNew();
$data['BlogSetting']['blog_key'] = 'new_blog_key';
$data['BlockRolePermission'] = array();
$resultFalse = $BlogSettingMock->saveBlogSetting($data);
$this->assertFalse($resultFalse);
// save fail
$BlogSettingMock = $this->getMockForModel('Blogs.BlogSetting', ['save']);
$BlogSettingMock->expects($this->once())
->method('save')
->will($this->returnValue(false));
$data = $this->BlogSetting->getNew();
$data['BlogSetting']['blog_key'] = 'new_blog_key';
$data['BlockRolePermission'] = array();
$this->setExpectedException('InternalErrorException');
$BlogSettingMock->saveBlogSetting($data);
}
/**
* test saveBlogSetting BlockRolePermission保存失敗系テスト
*
* @return void
*/
public function testSaveBlogSettingWithBlockRolePermissionFail() {
// blockRolePermission validate fail
$Mock = $this->getMockForModel('Blocks.BlockRolePermission', ['validateBlockRolePermissions']);
$Mock->expects($this->once())
->method('validateBlockRolePermissions')
->will($this->returnValue(false));
$data = $this->BlogSetting->getNew();
$data['BlogSetting']['blog_key'] = 'new_blog_key';
$data['BlockRolePermission'] = array('dummy');
$resultFalse = $this->BlogSetting->saveBlogSetting($data);
$this->assertFalse($resultFalse);
$Mock = $this->getMockForModel('Blocks.BlockRolePermission', ['validateBlockRolePermissions', 'saveMany']);
$Mock->expects($this->once())
->method('validateBlockRolePermissions')
->will($this->returnValue(true));
$Mock->expects($this->once())
->method('saveMany')
->will($this->returnValue(false));
$data = $this->BlogSetting->getNew();
$data['BlogSetting']['blog_key'] = 'new_blog_key';
$data['BlockRolePermission'] = array('dummy');
$this->setExpectedException('InternalErrorException');
$this->BlogSetting->saveBlogSetting($data);
}
/**
* testValidateBlogSetting method
*
* @return void
*/
public function testValidateBlogSetting() {
$data = $this->BlogSetting->getNew();
$data['BlogSetting']['blog_key'] = 'new_blog_key';
$resultTrue = $this->BlogSetting->validateBlogSetting($data);
$this->assertTrue($resultTrue);
}
}