From 4b10b550a2449827c643c896424eb0277c43b049 Mon Sep 17 00:00:00 2001 From: brettp Date: Fri, 3 Dec 2010 03:11:49 +0000 Subject: Refs #1986 #2170 #2225. Added semantic manifest.xml support and unit tests. Also added plugin dependencies system. See engine/tests/test_files/plugin_18/manifest.xml for examples. Not closing tickets pending discussion. git-svn-id: http://code.elgg.org/elgg/trunk@7512 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/tests/api/plugins.php | 250 ++++++++++++++++++++++++++----------------- 1 file changed, 153 insertions(+), 97 deletions(-) (limited to 'engine/tests/api') diff --git a/engine/tests/api/plugins.php b/engine/tests/api/plugins.php index 66e87c91e..61e2cdde6 100644 --- a/engine/tests/api/plugins.php +++ b/engine/tests/api/plugins.php @@ -2,83 +2,30 @@ /** * Elgg Plugins Test * - * @package Elgg - * @subpackage Test + * @package Elgg.Core + * @subpackage Plugins.Test */ class ElggCorePluginsAPITest extends ElggCoreUnitTest { - var $manifest_file_18 = <<<___END - - - 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.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($this->manifest_file_18, 'unit_test'); - $this->manifest17 = new ElggPluginManifest($this->manifest_file_17); + $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'); } /** @@ -89,38 +36,30 @@ ___END; $this->swallowErrors(); } - // generic tests public function testElggPluginManifestFromString() { - $manifest = new ElggPluginManifest($this->manifest_file_17); + $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('dataroot') . '/manifest_test.xml'; - $fp = fopen($file, 'wb'); - fputs($fp, $this->manifest_file_17); - fclose($fp); - + $file = get_config('path') . 'engine/tests/test_files/plugin_17/manifest.xml'; $manifest = new ElggPluginManifest($file); $this->assertIsA($manifest, 'ElggPluginManifest'); - - unlink($file); } - public function testElggPluginManifestFromXML() { - $xml = xml_to_object($this->manifest_file_17); + 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', @@ -132,23 +71,33 @@ ___END; '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'), + 'requires' => array( + array('type' => 'elgg', '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'), ), - 'screenshots' => array( + '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', 'value' => 'profile') + array('type' => 'plugin', 'name' => 'profile_api', 'version' => 1.0) ), 'provides' => array( - array('name' => 'profile_api', 'version' => 1.3) + array('type' => 'plugin', 'name' => 'profile_api', 'version' => 1.3), + array('type' => 'php_extension', 'name' => 'big_math', 'version' => 1.0) ), 'admin' => array( @@ -161,53 +110,160 @@ ___END; $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' + ); + + $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'); } - // 1.7 interface + public function testElggPluginManifestGetRequires() { + $requires = array( + array('type' => 'elgg', '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'), + ); - 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->package18->getManifest()->getRequires(), $requires); + + $this->assertEqual($this->package17->getManifest()->getRequires(), array()); + } + + 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!', ); - $this->assertEqual($this->manifest17->getManifest(), $manifest_array); + 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()); + } + + // ElggPluginPackage + public function testElggPluginPackageDetectIDFromPath() { + $this->assertEqual($this->package18->getID(), 'plugin_18'); + } + + public function testElggPluginPackageDetectIDFromPluginID() { + $package = new ElggPluginPackage('profile'); + $this->assertEqual($package->getID(), 'profile'); + } } -- cgit v1.2.3