ctools.plugins.test 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. /**
  3. * @file
  4. * Tests for different parts of the ctools plugin system.
  5. */
  6. /**
  7. * Test menu links depending on user permissions.
  8. */
  9. class CtoolsPluginsGetInfoTestCase extends DrupalWebTestCase {
  10. public static function getInfo() {
  11. return array(
  12. 'name' => 'Get plugin info',
  13. 'description' => 'Verify that plugin type definitions can properly set and overide values.',
  14. 'group' => 'ctools',
  15. );
  16. }
  17. function setUp() {
  18. // Additionally enable contact module.
  19. parent::setUp('ctools', 'ctools_plugin_test');
  20. }
  21. protected function assertPluginFunction($module, $type, $id, $function = 'function') {
  22. $func = ctools_plugin_load_function($module, $type, $id, $function);
  23. $this->assertTrue(function_exists($func), t('Plugin @plugin of plugin type @module:@type successfully retrieved @retrieved for @function.', array(
  24. '@plugin' => $id,
  25. '@module' => $module,
  26. '@type' => $type,
  27. '@function' => $function,
  28. '@retrieved' => $func,
  29. )));
  30. }
  31. protected function assertPluginMissingFunction($module, $type, $id, $function = 'function') {
  32. $func = ctools_plugin_load_function($module, $type, $id, $function);
  33. $this->assertEqual($func, NULL, t('Plugin @plugin of plugin type @module:@type for @function with missing function successfully failed.', array(
  34. '@plugin' => $id,
  35. '@module' => $module,
  36. '@type' => $type,
  37. '@function' => $func,
  38. )));
  39. }
  40. protected function assertPluginClass($module, $type, $id, $class = 'handler') {
  41. $class_name = ctools_plugin_load_class($module, $type, $id, $class);
  42. $this->assertTrue(class_exists($class_name), t('Plugin @plugin of plugin type @module:@type successfully retrieved @retrieved for @class.', array(
  43. '@plugin' => $id,
  44. '@module' => $module,
  45. '@type' => $type,
  46. '@class' => $class,
  47. '@retrieved' => $class_name,
  48. )));
  49. }
  50. protected function assertPluginMissingClass($module, $type, $id, $class = 'handler') {
  51. $class_name = ctools_plugin_load_class($module, $type, $id, $class);
  52. $this->assertEqual($class_name, NULL, t('Plugin @plugin of plugin type @module:@type for @class with missing class successfully failed.', array(
  53. '@plugin' => $id,
  54. '@module' => $module,
  55. '@type' => $type,
  56. '@class' => $class,
  57. )));
  58. }
  59. /**
  60. * Test that plugins are loaded correctly.
  61. */
  62. function testPluginLoading() {
  63. ctools_include('plugins');
  64. $module = 'ctools_plugin_test';
  65. $type = 'not_cached';
  66. // Test function retrieval for plugins using different definition methods.
  67. $this->assertPluginFunction($module, $type, 'plugin_array', 'function');
  68. $this->assertPluginFunction($module, $type, 'plugin_array2', 'function');
  69. $this->assertPluginMissingFunction($module, $type, 'plugin_array_dne', 'function');
  70. $this->assertPluginFunction($module, "big_hook_$type", 'test1', 'function');
  71. // Test class retrieval for plugins using different definition methods.
  72. $this->assertPluginClass($module, $type, 'plugin_array', 'handler');
  73. $this->assertPluginClass($module, $type, 'plugin_array2', 'handler');
  74. $this->assertPluginMissingClass($module, $type, 'plugin_array_dne', 'handler');
  75. // TODO Test big hook plugins.
  76. $type = 'cached';
  77. // Test function retrieval for plugins using different definition methods.
  78. $this->assertPluginFunction($module, $type, 'plugin_array', 'function');
  79. $this->assertPluginFunction($module, $type, 'plugin_array2', 'function');
  80. $this->assertPluginMissingFunction($module, $type, 'plugin_array_dne', 'function');
  81. $this->assertPluginFunction($module, "big_hook_$type", 'test1', 'function');
  82. // Test class retrieval for plugins using different definition methods.
  83. $this->assertPluginClass($module, $type, 'plugin_array', 'handler');
  84. $this->assertPluginClass($module, $type, 'plugin_array2', 'handler');
  85. $this->assertPluginMissingClass($module, $type, 'plugin_array_dne', 'handler');
  86. // TODO Test big hook plugins.
  87. }
  88. }