From 8173f672f06ad2783d3d0112e7b285d2240f488b Mon Sep 17 00:00:00 2001 From: brettp Date: Tue, 30 Nov 2010 03:56:34 +0000 Subject: Refs #1986 #2170 #2225 Added ElggPluginManifest, ElggPluginManifestParser, and its parser classes for 1.7 and 1.8 style manifests. Changed load_plugin_manifest() to use new parser. Added initial unit tests. git-svn-id: http://code.elgg.org/elgg/trunk@7481 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/tests/api/plugins.php | 213 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 213 insertions(+) create mode 100644 engine/tests/api/plugins.php (limited to 'engine/tests/api/plugins.php') diff --git a/engine/tests/api/plugins.php b/engine/tests/api/plugins.php new file mode 100644 index 000000000..66e87c91e --- /dev/null +++ b/engine/tests/api/plugins.php @@ -0,0 +1,213 @@ + + + Test Manifest + Anyone + 1.0 + A concise description. + A longer, more interesting description. + http://www.elgg.org/ + (C) Elgg 2010 + GNU Public License version 2 + + elgg + 2009030802 + + + graphics/plugin_ss1.png + graphics/plugin_ss2.png + + + setup_function + teardown_function + simple + + + + php_extension + gd + + + + php_ini + safe_mode + off + + + + plugin + profile + + + + profile_api + 1.3 + + + +___END; + + // 1.8 manifest object + var $manifest18; + + var $manifest_file_17 = <<<___END + + + + + + + + + + +___END; + + // 1.7 manifest object + var $manifest17; + + public function __construct() { + parent::__construct(); + + $this->manifest18 = new ElggPluginManifest($this->manifest_file_18, 'unit_test'); + $this->manifest17 = new ElggPluginManifest($this->manifest_file_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 = new ElggPluginManifest($this->manifest_file_17); + + $this->assertIsA($manifest, 'ElggPluginManifest'); + } + + public function testElggPluginManifestFromFile() { + $file = get_config('dataroot') . '/manifest_test.xml'; + $fp = fopen($file, 'wb'); + fputs($fp, $this->manifest_file_17); + fclose($fp); + + $manifest = new ElggPluginManifest($file); + + $this->assertIsA($manifest, 'ElggPluginManifest'); + + unlink($file); + } + + public function testElggPluginManifestFromXML() { + $xml = xml_to_object($this->manifest_file_17); + $manifest = new ElggPluginManifest($xml); + + $this->assertIsA($manifest, 'ElggPluginManifest'); + } + + + + // 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', + + 'depends' => array( + array('type' => 'elgg', 'value' => '2009030802'), + array('type' => 'php_extension', 'value' => 'gd'), + array('type' => 'php_ini', 'name' => 'safe_mode', 'value' => 'off'), + ), + + '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'), + ), + + 'conflicts' => array( + array('type' => 'plugin', 'value' => 'profile') + ), + + 'provides' => array( + array('name' => 'profile_api', 'version' => 1.3) + ), + + 'admin' => array( + 'on_enable' => 'setup_function', + 'on_disable' => 'teardown_function', + 'interface_type' => 'simple' + ) + ); + + $this->assertEqual($this->manifest18->getManifest(), $manifest_array); + } + + public function testElggPluginManifestGetApiVersion() { + $this->assertEqual($this->manifest18->getApiVersion(), 1.8); + } + + public function testElggPluginManifestGetName() { + $this->assertEqual($this->manifest18->getName(), 'Test Manifest'); + } + + public function testElggPluginManifestGetAuthor() { + $this->assertEqual($this->manifest18->getAuthor(), 'Anyone'); + } + + public function testElggPluginManifestGetVersion() { + $this->assertEqual($this->manifest18->getVersion(), 1.0); + } + + public function testElggPluginManifestGetBlurb() { + $this->assertEqual($this->manifest18->getBlurb(), 'A concise description.'); + } + + public function testElggPluginManifestGetWebsite() { + $this->assertEqual($this->manifest18->getWebsite(), 'http://www.elgg.org/'); + } + + public function testElggPluginManifestGetCopyright() { + $this->assertEqual($this->manifest18->getCopyright(), '(C) Elgg 2010'); + } + + public function testElggPluginManifestGetLicense() { + $this->assertEqual($this->manifest18->getLicense(), 'GNU Public License version 2'); + } + + + // 1.7 interface + + public function testElggPluginManifest17() { + $manifest_array = array( + 'author' => 'Anyone', + 'version' => '1.0', + 'description' => 'A 1.7-style manifest', + 'website' => 'http://www.elgg.org/', + 'copyright' => '(C) Elgg2008-2009', + 'license' => 'GNU Public License version 2', + 'elgg_version' => '2009030702' + ); + + $this->assertEqual($this->manifest17->getManifest(), $manifest_array); + } + +} -- cgit v1.2.3