ctools.plugins.test 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. /**
  3. * Test menu links depending on user permissions.
  4. */
  5. class CtoolsPluginsGetInfoTestCase extends DrupalWebTestCase {
  6. /**
  7. * {@inheritdoc}
  8. */
  9. public static function getInfo() {
  10. return array(
  11. 'name' => 'Get plugin info',
  12. 'description' => 'Verify that plugin type definitions can properly set and overide values.',
  13. 'group' => 'ctools',
  14. 'dependencies' => array('ctools'),
  15. );
  16. }
  17. /**
  18. * {@inheritdoc}
  19. */
  20. public function setUp(array $modules = array()) {
  21. $modules[] = 'ctools';
  22. $modules[] = 'ctools_plugin_test';
  23. parent::setUp($modules);
  24. }
  25. /**
  26. * Assert helper to check that a specific plugin function exists.
  27. *
  28. * @param $module
  29. * The module that owns the plugin.
  30. * @param $type
  31. * The type of plugin.
  32. * @param $id
  33. * The id of the specific plugin to load.
  34. * @param $function
  35. * The identifier of the function. For example, 'settings form'.
  36. */
  37. protected function assertPluginFunction($module, $type, $id, $function = 'function') {
  38. $func = ctools_plugin_load_function($module, $type, $id, $function);
  39. $this->assertTrue(function_exists($func), t('Plugin @plugin of plugin type @module:@type successfully retrieved @retrieved for @function.', array(
  40. '@plugin' => $id,
  41. '@module' => $module,
  42. '@type' => $type,
  43. '@function' => $function,
  44. '@retrieved' => $func,
  45. )));
  46. }
  47. /**
  48. * Assert helper to check that a specific plugin function does NOT exist.
  49. *
  50. * @param $module
  51. * The module that owns the plugin.
  52. * @param $type
  53. * The type of plugin.
  54. * @param $id
  55. * The id of the specific plugin to load.
  56. * @param $function
  57. * The identifier of the function. For example, 'settings form'.
  58. */
  59. protected function assertPluginMissingFunction($module, $type, $id, $function = 'function') {
  60. $func = ctools_plugin_load_function($module, $type, $id, $function);
  61. $this->assertEqual($func, NULL, t('Plugin @plugin of plugin type @module:@type for @function with missing function successfully failed.', array(
  62. '@plugin' => $id,
  63. '@module' => $module,
  64. '@type' => $type,
  65. '@function' => $func,
  66. )));
  67. }
  68. /**
  69. * Assert helper to check that a plugin can be loaded using a named class.
  70. *
  71. * @param $module
  72. * The module that owns the plugin.
  73. * @param $type
  74. * The type of plugin.
  75. * @param $id
  76. * The id of the specific plugin to load.
  77. * @param string $class
  78. * The name of the PHP class to load.
  79. */
  80. protected function assertPluginClass($module, $type, $id, $class = 'handler') {
  81. $class_name = ctools_plugin_load_class($module, $type, $id, $class);
  82. $this->assertTrue(class_exists($class_name), t('Plugin @plugin of plugin type @module:@type successfully retrieved @retrieved for @class.', array(
  83. '@plugin' => $id,
  84. '@module' => $module,
  85. '@type' => $type,
  86. '@class' => $class,
  87. '@retrieved' => $class_name,
  88. )));
  89. }
  90. /**
  91. * Assert helper to check that a plugin DOES NOT contain the named class.
  92. *
  93. * @param $module
  94. * The module that owns the plugin.
  95. * @param $type
  96. * The type of plugin.
  97. * @param $id
  98. * The id of the specific plugin to load.
  99. * @param string $class
  100. * The name of the PHP class to load.
  101. */
  102. protected function assertPluginMissingClass($module, $type, $id, $class = 'handler') {
  103. $class_name = ctools_plugin_load_class($module, $type, $id, $class);
  104. $this->assertEqual($class_name, NULL, t('Plugin @plugin of plugin type @module:@type for @class with missing class successfully failed.', array(
  105. '@plugin' => $id,
  106. '@module' => $module,
  107. '@type' => $type,
  108. '@class' => $class,
  109. )));
  110. }
  111. /**
  112. * Test that plugins are loaded correctly.
  113. */
  114. public function testPluginLoading() {
  115. ctools_include('plugins');
  116. $module = 'ctools_plugin_test';
  117. $type = 'not_cached';
  118. // Test function retrieval for plugins using different definition methods.
  119. $this->assertPluginFunction($module, $type, 'plugin_array', 'function');
  120. $this->assertPluginFunction($module, $type, 'plugin_array2', 'function');
  121. $this->assertPluginMissingFunction($module, $type, 'plugin_array_dne', 'function');
  122. $this->assertPluginFunction($module, "big_hook_$type", 'test1', 'function');
  123. // Test class retrieval for plugins using different definition methods.
  124. $this->assertPluginClass($module, $type, 'plugin_array', 'handler');
  125. $this->assertPluginClass($module, $type, 'plugin_array2', 'handler');
  126. $this->assertPluginMissingClass($module, $type, 'plugin_array_dne', 'handler');
  127. // @todo Test big hook plugins.
  128. $type = 'cached';
  129. // Test function retrieval for plugins using different definition methods.
  130. $this->assertPluginFunction($module, $type, 'plugin_array', 'function');
  131. $this->assertPluginFunction($module, $type, 'plugin_array2', 'function');
  132. $this->assertPluginMissingFunction($module, $type, 'plugin_array_dne', 'function');
  133. $this->assertPluginFunction($module, "big_hook_$type", 'test1', 'function');
  134. // Test class retrieval for plugins using different definition methods.
  135. $this->assertPluginClass($module, $type, 'plugin_array', 'handler');
  136. $this->assertPluginClass($module, $type, 'plugin_array2', 'handler');
  137. $this->assertPluginMissingClass($module, $type, 'plugin_array_dne', 'handler');
  138. // @todo Test big hook plugins.
  139. }
  140. }