ElggCorePluginsAPITest.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. <?php
  2. /**
  3. * Elgg Plugins Test
  4. *
  5. * @package Elgg.Core
  6. * @subpackage Plugins.Test
  7. */
  8. class ElggCorePluginsAPITest extends \ElggCoreUnitTest {
  9. // 1.8 manifest object
  10. var $manifest18;
  11. // 1.8 package at test_files/plugin_18/
  12. var $package18;
  13. // 1.7 manifest object
  14. var $manifest17;
  15. // 1.7 package at test_files/plugin_17/
  16. var $package17;
  17. public function __construct() {
  18. parent::__construct();
  19. $this->manifest18 = new \ElggPluginManifest(get_config('path') . 'engine/tests/test_files/plugin_18/manifest.xml', 'plugin_test_18');
  20. $this->manifest17 = new \ElggPluginManifest(get_config('path') . 'engine/tests/test_files/plugin_17/manifest.xml', 'plugin_test_17');
  21. $this->package18 = new \ElggPluginPackage(get_config('path') . 'engine/tests/test_files/plugin_18');
  22. $this->package17 = new \ElggPluginPackage(get_config('path') . 'engine/tests/test_files/plugin_17');
  23. }
  24. // generic tests
  25. public function testElggPluginManifestFromString() {
  26. $manifest_file = file_get_contents(get_config('path') . 'engine/tests/test_files/plugin_17/manifest.xml');
  27. $manifest = new \ElggPluginManifest($manifest_file);
  28. $this->assertIsA($manifest, '\ElggPluginManifest');
  29. }
  30. public function testElggPluginManifestFromFile() {
  31. $file = get_config('path') . 'engine/tests/test_files/plugin_17/manifest.xml';
  32. $manifest = new \ElggPluginManifest($file);
  33. $this->assertIsA($manifest, '\ElggPluginManifest');
  34. }
  35. public function testElggPluginManifestFromXMLEntity() {
  36. $manifest_file = file_get_contents(get_config('path') . 'engine/tests/test_files/plugin_17/manifest.xml');
  37. $xml = new \ElggXMLElement($manifest_file);
  38. $manifest = new \ElggPluginManifest($xml);
  39. $this->assertIsA($manifest, '\ElggPluginManifest');
  40. }
  41. // exact manifest values
  42. // 1.8 interface
  43. public function testElggPluginManifest18() {
  44. $manifest_array = array(
  45. 'name' => 'Test Manifest',
  46. 'author' => 'Anyone',
  47. 'version' => '1.0',
  48. 'blurb' => 'A concise description.',
  49. 'description' => 'A longer, more interesting description.',
  50. 'website' => 'http://www.elgg.org/',
  51. 'repository' => 'https://github.com/Elgg/Elgg',
  52. 'bugtracker' => 'https://github.com/elgg/elgg/issues',
  53. 'donations' => 'http://elgg.org/supporter.php',
  54. 'copyright' => '(C) Elgg Foundation 2011',
  55. 'license' => 'GNU General Public License version 2',
  56. 'requires' => array(
  57. array('type' => 'elgg_version', 'version' => '3009030802', 'comparison' => 'lt'),
  58. array('type' => 'elgg_release', 'version' => '1.8-svn'),
  59. array('type' => 'php_extension', 'name' => 'gd'),
  60. array('type' => 'php_ini', 'name' => 'short_open_tag', 'value' => 'off'),
  61. array('type' => 'php_version', 'version' => '5.6'),
  62. array('type' => 'php_extension', 'name' => 'made_up', 'version' => '1.0'),
  63. array('type' => 'plugin', 'name' => 'fake_plugin', 'version' => '1.0'),
  64. array('type' => 'plugin', 'name' => 'profile', 'version' => '1.0'),
  65. array('type' => 'plugin', 'name' => 'profile_api', 'version' => '1.3', 'comparison' => 'lt'),
  66. array('type' => 'priority', 'priority' => 'after', 'plugin' => 'profile'),
  67. ),
  68. 'screenshot' => array(
  69. array('description' => 'Fun things to do 1', 'path' => 'graphics/plugin_ss1.png'),
  70. array('description' => 'Fun things to do 2', 'path' => 'graphics/plugin_ss2.png'),
  71. ),
  72. 'contributor' => array(
  73. array('name' => 'Evan Winslow', 'email' => 'evan@elgg.org', 'website' => 'http://evanwinslow.com/', 'username' => 'ewinslow', 'description' => "Description of Evan's role in the project"),
  74. array('name' => 'Cash Costello', 'email' => 'cash@elgg.org', 'description' => "Description of Cash's role in the project"),
  75. ),
  76. 'category' => array(
  77. 'Admin', 'ServiceAPI'
  78. ),
  79. 'conflicts' => array(
  80. array('type' => 'plugin', 'name' => 'profile_api', 'version' => '1.0')
  81. ),
  82. 'provides' => array(
  83. array('type' => 'plugin', 'name' => 'profile_api', 'version' => '1.3'),
  84. array('type' => 'php_extension', 'name' => 'big_math', 'version' => '1.0')
  85. ),
  86. 'suggests' => array(
  87. array('type' => 'plugin', 'name' => 'facebook_connect', 'version' => '1.0'),
  88. ),
  89. // string because we are reading from a file
  90. 'activate_on_install' => 'true',
  91. );
  92. $this->assertIdentical($this->manifest18->getManifest(), $manifest_array);
  93. }
  94. public function testElggPluginManifest17() {
  95. $manifest_array = array(
  96. 'author' => 'Anyone',
  97. 'version' => '1.0',
  98. 'description' => 'A 1.7-style manifest.',
  99. 'website' => 'http://www.elgg.org/',
  100. 'copyright' => '(C) Elgg Foundation 2011',
  101. 'license' => 'GNU General Public License version 2',
  102. 'elgg_version' => '2009030702',
  103. 'name' => 'Plugin Test 17',
  104. );
  105. $this->assertIdentical($this->manifest17->getManifest(), $manifest_array);
  106. }
  107. public function testElggPluginManifestGetApiVersion() {
  108. $this->assertEqual($this->manifest18->getApiVersion(), 1.8);
  109. $this->assertEqual($this->manifest17->getApiVersion(), 1.7);
  110. }
  111. public function testElggPluginManifestGetPluginID() {
  112. $this->assertEqual($this->manifest18->getPluginID(), 'plugin_test_18');
  113. $this->assertEqual($this->manifest17->getPluginID(), 'plugin_test_17');
  114. }
  115. // normalized attributes
  116. public function testElggPluginManifestGetName() {
  117. $this->assertEqual($this->manifest18->getName(), 'Test Manifest');
  118. $this->assertEqual($this->manifest17->getName(), 'Plugin Test 17');
  119. }
  120. public function testElggPluginManifestGetAuthor() {
  121. $this->assertEqual($this->manifest18->getAuthor(), 'Anyone');
  122. $this->assertEqual($this->manifest17->getAuthor(), 'Anyone');
  123. }
  124. public function testElggPluginManifestGetVersion() {
  125. $this->assertEqual($this->manifest18->getVersion(), 1.0);
  126. $this->assertEqual($this->manifest17->getVersion(), 1.0);
  127. }
  128. public function testElggPluginManifestGetBlurb() {
  129. $this->assertEqual($this->manifest18->getBlurb(), 'A concise description.');
  130. $this->assertEqual($this->manifest17->getBlurb(), 'A 1.7-style manifest.');
  131. }
  132. public function testElggPluginManifestGetWebsite() {
  133. $this->assertEqual($this->manifest18->getWebsite(), 'http://www.elgg.org/');
  134. $this->assertEqual($this->manifest17->getWebsite(), 'http://www.elgg.org/');
  135. }
  136. public function testElggPluginManifestGetRepository() {
  137. $this->assertEqual($this->manifest18->getRepositoryURL(), 'https://github.com/Elgg/Elgg');
  138. $this->assertEqual($this->manifest17->getRepositoryURL(), '');
  139. }
  140. public function testElggPluginManifestGetBugtracker() {
  141. $this->assertEqual($this->manifest18->getBugTrackerURL(), 'https://github.com/elgg/elgg/issues');
  142. $this->assertEqual($this->manifest17->getBugTrackerURL(), '');
  143. }
  144. public function testElggPluginManifestGetDonationsPage() {
  145. $this->assertEqual($this->manifest18->getDonationsPageURL(), 'http://elgg.org/supporter.php');
  146. $this->assertEqual($this->manifest17->getDonationsPageURL(), '');
  147. }
  148. public function testElggPluginManifestGetCopyright() {
  149. $this->assertEqual($this->manifest18->getCopyright(), '(C) Elgg Foundation 2011');
  150. $this->assertEqual($this->manifest18->getCopyright(), '(C) Elgg Foundation 2011');
  151. }
  152. public function testElggPluginManifestGetLicense() {
  153. $this->assertEqual($this->manifest18->getLicense(), 'GNU General Public License version 2');
  154. $this->assertEqual($this->manifest17->getLicense(), 'GNU General Public License version 2');
  155. }
  156. public function testElggPluginManifestGetRequires() {
  157. $requires = array(
  158. array('type' => 'elgg_version', 'version' => '3009030802', 'comparison' => 'lt'),
  159. array('type' => 'elgg_release', 'version' => '1.8-svn', 'comparison' => 'ge'),
  160. array('type' => 'php_extension', 'name' => 'gd', 'version' => '', 'comparison' => '='),
  161. array('type' => 'php_ini', 'name' => 'short_open_tag', 'value' => 0, 'comparison' => '='),
  162. array('type' => 'php_version', 'version' => '5.6', 'comparison' => 'ge'),
  163. array('type' => 'php_extension', 'name' => 'made_up', 'version' => '1.0', 'comparison' => '='),
  164. array('type' => 'plugin', 'name' => 'fake_plugin', 'version' => '1.0', 'comparison' => 'ge'),
  165. array('type' => 'plugin', 'name' => 'profile', 'version' => '1.0', 'comparison' => 'ge'),
  166. array('type' => 'plugin', 'name' => 'profile_api', 'version' => '1.3', 'comparison' => 'lt'),
  167. array('type' => 'priority', 'priority' => 'after', 'plugin' => 'profile'),
  168. );
  169. $this->assertIdentical($this->package18->getManifest()->getRequires(), $requires);
  170. $requires = array(
  171. array('type' => 'elgg_version', 'version' => '2009030702', 'comparison' => 'ge')
  172. );
  173. $this->assertIdentical($this->package17->getManifest()->getRequires(), $requires);
  174. }
  175. public function testElggPluginManifestGetSuggests() {
  176. $suggests = array(
  177. array('type' => 'plugin', 'name' => 'facebook_connect', 'version' => '1.0', 'comparison' => 'ge'),
  178. );
  179. $this->assertIdentical($this->package18->getManifest()->getSuggests(), $suggests);
  180. $suggests = array();
  181. $this->assertIdentical($this->package17->getManifest()->getSuggests(), $suggests);
  182. }
  183. public function testElggPluginManifestGetDescription() {
  184. $this->assertEqual($this->package18->getManifest()->getDescription(), 'A longer, more interesting description.');
  185. $this->assertEqual($this->package17->getManifest()->getDescription(), 'A 1.7-style manifest.');
  186. }
  187. public function testElggPluginManifestGetCategories() {
  188. $categories = array(
  189. 'Admin', 'ServiceAPI'
  190. );
  191. $this->assertIdentical($this->package18->getManifest()->getCategories(), $categories);
  192. $this->assertIdentical($this->package17->getManifest()->getCategories(), array());
  193. }
  194. public function testElggPluginManifestGetScreenshots() {
  195. $screenshots = array(
  196. array('description' => 'Fun things to do 1', 'path' => 'graphics/plugin_ss1.png'),
  197. array('description' => 'Fun things to do 2', 'path' => 'graphics/plugin_ss2.png'),
  198. );
  199. $this->assertIdentical($this->package18->getManifest()->getScreenshots(), $screenshots);
  200. $this->assertIdentical($this->package17->getManifest()->getScreenshots(), array());
  201. }
  202. public function testElggPluginManifestGetContributors() {
  203. $contributors = array(
  204. array('name' => 'Evan Winslow', 'email' => 'evan@elgg.org', 'website' => 'http://evanwinslow.com/', 'username' => 'ewinslow', 'description' => "Description of Evan's role in the project"),
  205. array('name' => 'Cash Costello', 'email' => 'cash@elgg.org', 'website' => '', 'username' => '', 'description' => "Description of Cash's role in the project"),
  206. );
  207. $this->assertIdentical($this->package18->getManifest()->getContributors(), $contributors);
  208. $this->assertIdentical($this->package17->getManifest()->getContributors(), array());
  209. }
  210. public function testElggPluginManifestGetProvides() {
  211. $provides = array(
  212. array('type' => 'plugin', 'name' => 'profile_api', 'version' => '1.3'),
  213. array('type' => 'php_extension', 'name' => 'big_math', 'version' => '1.0'),
  214. array('type' => 'plugin', 'name' => 'plugin_18', 'version' => '1.0')
  215. );
  216. $this->assertIdentical($this->package18->getManifest()->getProvides(), $provides);
  217. $provides = array(
  218. array('type' => 'plugin', 'name' => 'plugin_17', 'version' => '1.0')
  219. );
  220. $this->assertIdentical($this->package17->getManifest()->getProvides(), $provides);
  221. }
  222. public function testElggPluginManifestGetConflicts() {
  223. $conflicts = array(
  224. array(
  225. 'type' => 'plugin',
  226. 'name' => 'profile_api',
  227. 'version' => '1.0',
  228. 'comparison' => '='
  229. )
  230. );
  231. $this->assertIdentical($this->manifest18->getConflicts(), $conflicts);
  232. $this->assertIdentical($this->manifest17->getConflicts(), array());
  233. }
  234. public function testElggPluginManifestGetActivateOnInstall() {
  235. $this->assertIdentical($this->manifest18->getActivateOnInstall(), true);
  236. }
  237. // \ElggPluginPackage
  238. public function testElggPluginPackageDetectIDFromPath() {
  239. $this->assertEqual($this->package18->getID(), 'plugin_18');
  240. }
  241. public function testElggPluginPackageDetectIDFromPluginID() {
  242. $package = new \ElggPluginPackage('profile');
  243. $this->assertEqual($package->getID(), 'profile');
  244. }
  245. // \ElggPlugin
  246. public function testElggPluginIsValid() {
  247. $test_plugin = new \ElggPlugin('profile');
  248. $this->assertIdentical(true, $test_plugin->isValid());
  249. }
  250. public function testElggPluginGetID() {
  251. $test_plugin = new \ElggPlugin('profile');
  252. $this->assertIdentical('profile', $test_plugin->getID());
  253. }
  254. }