aboutsummaryrefslogtreecommitdiff
path: root/engine/tests/api/plugins.php
blob: ac1278410a802086c77958a81bb356b359769aa7 (plain)
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
<?php
/**
 * Elgg Plugins Test
 *
 * @package Elgg.Core
 * @subpackage Plugins.Test
 */
class ElggCorePluginsAPITest extends ElggCoreUnitTest {
	// 1.8 manifest object
	var $manifest18;

	// 1.8 package at test_files/plugin_18/
	var $package18;

	// 1.7 manifest object
	var $manifest17;

	// 1.7 package at test_files/plugin_17/
	var $package17;

	public function __construct() {
		parent::__construct();

		$this->manifest18 = new ElggPluginManifest(get_config('path') . 'engine/tests/test_files/plugin_18/manifest.xml', 'plugin_test_18');
		$this->manifest17 = new ElggPluginManifest(get_config('path') . 'engine/tests/test_files/plugin_17/manifest.xml', 'plugin_test_17');

		$this->package18 = new ElggPluginPackage(get_config('path') . 'engine/tests/test_files/plugin_18');
		$this->package17 = new ElggPluginPackage(get_config('path') . 'engine/tests/test_files/plugin_17');
	}

	/**
	 * Called after each test method.
	 */
	public function tearDown() {
		// do not allow SimpleTest to interpret Elgg notices as exceptions
		$this->swallowErrors();
	}

	// generic tests
	public function testElggPluginManifestFromString() {
		$manifest_file = file_get_contents(get_config('path') . 'engine/tests/test_files/plugin_17/manifest.xml');
		$manifest = new ElggPluginManifest($manifest_file);

		$this->assertIsA($manifest, 'ElggPluginManifest');
	}

	public function testElggPluginManifestFromFile() {
		$file = get_config('path') . 'engine/tests/test_files/plugin_17/manifest.xml';
		$manifest = new ElggPluginManifest($file);

		$this->assertIsA($manifest, 'ElggPluginManifest');
	}

	public function testElggPluginManifestFromXMLEntity() {
		$xml = xml_to_object($manifest_file = file_get_contents(get_config('path') . 'engine/tests/test_files/plugin_17/manifest.xml'));
		$manifest = new ElggPluginManifest($xml);

		$this->assertIsA($manifest, 'ElggPluginManifest');
	}

	// exact manifest values
	// 1.8 interface
	public function testElggPluginManifest18() {
		$manifest_array = array(
			'name' => 'Test Manifest',
			'author' => 'Anyone',
			'version' => '1.0',
			'blurb' => 'A concise description.',
			'description' => 'A longer, more interesting description.',
			'website' => 'http://www.elgg.org/',
			'copyright' => '(C) Elgg 2010',
			'license' => 'GNU Public License version 2',

			'requires' => array(
				array('type' => 'elgg_version', 'version' => '3009030802', 'comparison' => 'lt'),
				array('type' => 'elgg_release', 'version' => '1.8-svn'),
				array('type' => 'php_extension', 'name' => 'gd'),
				array('type' => 'php_ini', 'name' => 'short_open_tag', 'value' => 'off'),
				array('type' => 'php_extension', 'name' => 'made_up', 'version' => '1.0'),
				array('type' => 'plugin', 'name' => 'fake_plugin', 'version' => '1.0'),
				array('type' => 'plugin', 'name' => 'profile', 'version' => '1.0'),
				array('type' => 'plugin', 'name' => 'profile_api', 'version' => '1.3', 'comparison' => 'lt'),
				array('type' => 'priority', 'priority' => 'after', 'plugin' => 'profile'),
			),

			'screenshot' => array(
				array('description' => 'Fun things to do 1', 'path' => 'graphics/plugin_ss1.png'),
				array('description' => 'Fun things to do 2', 'path' => 'graphics/plugin_ss2.png'),
			),

			'category' => array(
				'Admin', 'ServiceAPI'
			),

			'conflicts' => array(
				array('type' => 'plugin', 'name' => 'profile_api', 'version' => 1.0)
			),

			'provides' => array(
				array('type' => 'plugin', 'name' => 'profile_api', 'version' => 1.3),
				array('type' => 'php_extension', 'name' => 'big_math', 'version' => 1.0)
			),

			'on_activate' => array('setup_function'),
			'on_deactivate' => array('teardown_function'),
			'admin_interface' => 'simple',
			'activate_on_install' => true
		);

		$this->assertEqual($this->manifest18->getManifest(), $manifest_array);
	}

	public function testElggPluginManifest17() {
		$manifest_array = array(
			'author' => 'Anyone',
			'version' => '1.0',
			'description' => 'A 1.7-style manifest.',
			'website' => 'http://www.elgg.org/',
			'copyright' => '(C) Elgg 2010',
			'license' => 'GNU Public License version 2',
			'elgg_version' => '2009030702',
			'name' => 'Plugin Test 17',
		);

		$this->assertEqual($this->manifest17->getManifest(), $manifest_array);
	}


	public function testElggPluginManifestGetApiVersion() {
		$this->assertEqual($this->manifest18->getApiVersion(), 1.8);
		$this->assertEqual($this->manifest17->getApiVersion(), 1.7);
	}

	public function testElggPluginManifestGetPluginID() {
		$this->assertEqual($this->manifest18->getPluginID(), 'plugin_test_18');
		$this->assertEqual($this->manifest17->getPluginID(), 'plugin_test_17');
	}


	// normalized attributes
	public function testElggPluginManifestGetName() {
		$this->assertEqual($this->manifest18->getName(), 'Test Manifest');
		$this->assertEqual($this->manifest17->getName(), 'Plugin Test 17');
	}

	public function testElggPluginManifestGetAuthor() {
		$this->assertEqual($this->manifest18->getAuthor(), 'Anyone');
		$this->assertEqual($this->manifest17->getAuthor(), 'Anyone');
	}

	public function testElggPluginManifestGetVersion() {
		$this->assertEqual($this->manifest18->getVersion(), 1.0);
		$this->assertEqual($this->manifest17->getVersion(), 1.0);
	}

	public function testElggPluginManifestGetBlurb() {
		$this->assertEqual($this->manifest18->getBlurb(), 'A concise description.');
		$this->assertEqual($this->manifest17->getBlurb(), 'A 1.7-style manifest.');
	}

	public function testElggPluginManifestGetWebsite() {
		$this->assertEqual($this->manifest18->getWebsite(), 'http://www.elgg.org/');
		$this->assertEqual($this->manifest17->getWebsite(), 'http://www.elgg.org/');
	}

	public function testElggPluginManifestGetCopyright() {
		$this->assertEqual($this->manifest18->getCopyright(), '(C) Elgg 2010');
		$this->assertEqual($this->manifest18->getCopyright(), '(C) Elgg 2010');
	}

	public function testElggPluginManifestGetLicense() {
		$this->assertEqual($this->manifest18->getLicense(), 'GNU Public License version 2');
		$this->assertEqual($this->manifest17->getLicense(), 'GNU Public License version 2');
	}


	public function testElggPluginManifestGetRequires() {
		$requires = array(
			array('type' => 'elgg_version', 'version' => '3009030802', 'comparison' => 'lt'),
			array('type' => 'elgg_release', 'version' => '1.8-svn', 'comparison' => 'ge'),
			array('type' => 'php_extension', 'name' => 'gd', 'version' => '', 'comparison' => '='),
			array('type' => 'php_ini', 'name' => 'short_open_tag', 'value' => 'off', 'comparison' => '='),
			array('type' => 'php_extension', 'name' => 'made_up', 'version' => '1.0', 'comparison' => '='),
			array('type' => 'plugin', 'name' => 'fake_plugin', 'version' => '1.0', 'comparison' => 'ge'),
			array('type' => 'plugin', 'name' => 'profile', 'version' => '1.0', 'comparison' => 'ge'),
			array('type' => 'plugin', 'name' => 'profile_api', 'version' => '1.3', 'comparison' => 'lt'),
			array('type' => 'priority', 'priority' => 'after', 'plugin' => 'profile'),
		);

		$this->assertEqual($this->package18->getManifest()->getRequires(), $requires);

		$requires = array(
			array('type' => 'elgg_version', 'version' => '2009030702', 'comparison' => 'ge')
		);

		$this->assertEqual($this->package17->getManifest()->getRequires(), $requires);
	}

	public function testElggPluginManifestGetDescription() {
		$this->assertEqual($this->package18->getManifest()->getDescription(), 'A longer, more interesting description.');
		$this->assertEqual($this->package17->getManifest()->getDescription(), 'A 1.7-style manifest.');
	}

	public function testElggPluginManifestGetDescriptionTranslated() {
		$en = array(
			$this->package18->getManifest()->getDescription() => 'A translated 1.8 description!',
			$this->package17->getManifest()->getDescription() => 'A translated 1.7 description!',
		);

		add_translation('en', $en);

		$this->assertEqual($this->package18->getManifest()->getDescription(), 'A translated 1.8 description!');
		$this->assertEqual($this->package17->getManifest()->getDescription(), 'A translated 1.7 description!');
	}

	public function testElggPluginManifestGetCategories() {
		$categories = array(
			'Admin', 'ServiceAPI'
		);

		$this->assertEqual($this->package18->getManifest()->getCategories(), $categories);
		$this->assertEqual($this->package17->getManifest()->getCategories(), array());
	}

	public function testElggPluginManifestGetScreenshots() {
		$screenshots = array(
			array('description' => 'Fun things to do 1', 'path' => 'graphics/plugin_ss1.png'),
			array('description' => 'Fun things to do 2', 'path' => 'graphics/plugin_ss2.png'),
		);

		$this->assertEqual($this->package18->getManifest()->getScreenshots(), $screenshots);
		$this->assertEqual($this->package17->getManifest()->getScreenshots(), array());
	}

	public function testElggPluginManifestGetProvides() {
		$provides = array(
			array('type' => 'plugin', 'name' => 'profile_api', 'version' => 1.3),
			array('type' => 'php_extension', 'name' => 'big_math', 'version' => 1.0),
			array('type' => 'plugin', 'name' => 'plugin_18', 'version' => 1.0)
		);

		$this->assertEqual($this->package18->getManifest()->getProvides(), $provides);


		$provides = array(
			array('type' => 'plugin', 'name' => 'plugin_17', 'version' => '1.0')
		);

		$this->assertEqual($this->package17->getManifest()->getProvides(), $provides);
	}

	public function testElggPluginManifestGetConflicts() {
		$conflicts = array(
			array(
				'type' => 'plugin',
				'name' => 'profile_api',
				'version' => '1.0',
				'comparison' => '='
			)
		);

		$this->assertEqual($this->manifest18->getConflicts(), $conflicts);
		$this->assertEqual($this->manifest17->getConflicts(), array());
	}

	public function testElggPluginManifestGetOnActivate() {
		$this->assertEqual($this->manifest18->getOnActivate(), array('setup_function'));
	}

	public function testElggPluginManifestGetOnDeactivate() {
		$this->assertEqual($this->manifest18->getOnDeactivate(), array('teardown_function'));
	}

	public function testElggPluginManifestGetAdminInterface() {
		$this->assertEqual($this->manifest18->getAdminInterface(), 'simple');
	}

	public function testElggPluginManifestGetActivateOnInstall() {
		$this->assertEqual($this->manifest18->getActivateOnInstall(), true);
	}

	// ElggPluginPackage
	public function testElggPluginPackageDetectIDFromPath() {
		$this->assertEqual($this->package18->getID(), 'plugin_18');
	}

	public function testElggPluginPackageDetectIDFromPluginID() {
		$package = new ElggPluginPackage('profile');
		$this->assertEqual($package->getID(), 'profile');
	}
}