-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPluginManagerControllerIndexTest.php
More file actions
164 lines (147 loc) · 3.77 KB
/
PluginManagerControllerIndexTest.php
File metadata and controls
164 lines (147 loc) · 3.77 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
<?php
/**
* PluginManagerControllerIndexTest
*
* @copyright Copyright 2014, NetCommons Project
* @author Kohei Teraguchi <kteraguchi@commonsnet.org>
* @link http://www.netcommons.org NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
*/
App::uses('NetCommonsControllerTestCase', 'NetCommons.TestSuite');
/**
* PluginManagerControllerIndexTest
*
*/
class PluginManagerControllerIndexTest extends NetCommonsControllerTestCase {
/**
* Fixtures
*
* @var array
*/
public $fixtures = [];
/**
* Plugin name
*
* @var string
*/
public $plugin = 'plugin_manager';
/**
* Controller name
*
* @var string
*/
protected $_controller = 'plugin_manager';
/**
* setUp method
*
* @return void
*/
public function setUp() {
parent::setUp();
TestAuthGeneral::login($this);
// PluginsRole.plugin_key が 'test_plugin' しかないので Permission denied になる
// fixture に追加でも良かったが、とりあえずMockで対応
// @see https://github.com/NetCommons3/NetCommons/blob/3.1.3/Utility/Current.php#L450
$this->controller = $this->generate('PluginManager.PluginManager',
array(
'components' => array(
'Security',
)
)
);
$MockPermission = $this->getMock('PermissionComponent', ['startup'], [$this->controller->Components]);
$MockPermission
->expects($this->once())
->method('startup')
->will($this->returnValue(true));
$this->controller->Components->set('Permission', $MockPermission);
$this->controller->Components->enable('Permission');
// Config.ManagerPlugins はInstall時にapplication.yml に書き込まれ情報を使用するため、Travis でこける
// https://github.com/NetCommons3/NetCommons/blob/3.1.3/Config/routes.php#L37-L47
// の処理で配置プラグインとして進んでしまう。
// なので、書き込んどく
Configure::write('ManagerPlugins', ['PluginManager']);
}
/**
* tearDown method
*
* @return void
*/
public function tearDown() {
TestAuthGeneral::logout($this);
parent::tearDown();
}
/**
* type data provider
*
* @return array
*/
public function typeProvider() {
return [
[null],
[0],
[1],
[2],
[3],
[4],
[5],
[6],
[7],
];
}
/**
* testNoPluginData
*
* @param int $type Plugin.type
* @dataProvider typeProvider
* @return void
*/
public function testNgClickValue($type) {
$this->controller->Plugin = $this->getMockForModel('PluginManager.Plugin', ['getPlugins']);
$value = [
'Plugin' => [
'id' => '2',
'language_id' => '2',
'is_origin' => true,
'is_translation' => false,
'is_original_copy' => false,
'key' => 'plugin_manager',
'is_m17n' => true,
'name' => 'Lorem ipsum dolor sit amet',
'namespace' => 'Lorem ipsum dolor sit amet',
'weight' => '1',
'type' => '1',
'version' => null,
'commit_version' => null,
'commited' => null,
'default_action' => '',
'default_setting_action' => '',
'frame_add_action' => null,
'display_topics' => false,
'display_search' => false,
'serialize_data' => array(),
'created_user' => null,
'created' => null,
'modified_user' => null,
'modified' => null,
'package_url' => 'Lorem ipsum dolor sit amet'
],
'latest' => null
];
$count = 1;
if ($type == Plugin::PLUGIN_TYPE_FOR_NOT_YET) {
$count = 0;
}
$this->controller->Plugin
->expects($this->exactly($count))
->method('getPlugins')
->will($this->returnValue($value));
$needle = '<a href="" ng-click="showView(plugin.plugin.type, plugin.plugin.key)">';
$view = $this->testAction('plugin_manager/plugin_manager/index/' . $type, ['return' => 'view']);
if ($type == Plugin::PLUGIN_TYPE_FOR_SYSTEM_MANGER) {
$this->assertNotContains($needle, $view);
return;
}
$this->assertContains($needle, $view);
}
}