Projet

Général

Profil

Paste
Télécharger (5,33 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / ctools / tests / ctools.plugins.test @ 6e3ce7c2

1
<?php
2

    
3
/**
4
 * Test menu links depending on user permissions.
5
 */
6
class CtoolsPluginsGetInfoTestCase extends DrupalWebTestCase {
7

    
8
  /**
9
   * {@inheritdoc}
10
   */
11
  public static function getInfo() {
12
    return array(
13
      'name' => 'Get plugin info',
14
      'description' => 'Verify that plugin type definitions can properly set and overide values.',
15
      'group' => 'ctools',
16
      'dependencies' => array('ctools'),
17
    );
18
  }
19

    
20
  /**
21
   * {@inheritdoc}
22
   */
23
  public function setUp(array $modules = array()) {
24
    $modules[] = 'ctools';
25
    $modules[] = 'ctools_plugin_test';
26
    parent::setUp($modules);
27
  }
28

    
29
  /**
30
   * Assert helper to check that a specific plugin function exists.
31
   *
32
   * @param $module
33
   *   The module that owns the plugin.
34
   * @param $type
35
   *   The type of plugin.
36
   * @param $id
37
   *   The id of the specific plugin to load.
38
   * @param $function
39
   *   The identifier of the function. For example, 'settings form'.
40
   */
41
  protected function assertPluginFunction($module, $type, $id, $function = 'function') {
42
    $func = ctools_plugin_load_function($module, $type, $id, $function);
43
    $this->assertTrue(function_exists($func), t('Plugin @plugin of plugin type @module:@type successfully retrieved @retrieved for @function.', array(
44
      '@plugin' => $id,
45
      '@module' => $module,
46
      '@type' => $type,
47
      '@function' => $function,
48
      '@retrieved' => $func,
49
    )));
50
  }
51

    
52
  /**
53
   * Assert helper to check that a specific plugin function does NOT exist.
54
   *
55
   * @param $module
56
   *   The module that owns the plugin.
57
   * @param $type
58
   *   The type of plugin.
59
   * @param $id
60
   *   The id of the specific plugin to load.
61
   * @param $function
62
   *   The identifier of the function. For example, 'settings form'.
63
   */
64
  protected function assertPluginMissingFunction($module, $type, $id, $function = 'function') {
65
    $func = ctools_plugin_load_function($module, $type, $id, $function);
66
    $this->assertEqual($func, NULL, t('Plugin @plugin of plugin type @module:@type for @function with missing function successfully failed.', array(
67
      '@plugin' => $id,
68
      '@module' => $module,
69
      '@type' => $type,
70
      '@function' => $func,
71
    )));
72
  }
73

    
74
  /**
75
   * Assert helper to check that a plugin can be loaded using a named class.
76
   *
77
   * @param $module
78
   *   The module that owns the plugin.
79
   * @param $type
80
   *   The type of plugin.
81
   * @param $id
82
   *   The id of the specific plugin to load.
83
   * @param string $class
84
   *   The name of the PHP class to load.
85
   */
86
  protected function assertPluginClass($module, $type, $id, $class = 'handler') {
87
    $class_name = ctools_plugin_load_class($module, $type, $id, $class);
88
    $this->assertTrue(class_exists($class_name), t('Plugin @plugin of plugin type @module:@type successfully retrieved @retrieved for @class.', array(
89
      '@plugin' => $id,
90
      '@module' => $module,
91
      '@type' => $type,
92
      '@class' => $class,
93
      '@retrieved' => $class_name,
94
    )));
95
  }
96

    
97
  /**
98
   * Assert helper to check that a plugin DOES NOT contain the named class.
99
   *
100
   * @param $module
101
   *   The module that owns the plugin.
102
   * @param $type
103
   *   The type of plugin.
104
   * @param $id
105
   *   The id of the specific plugin to load.
106
   * @param string $class
107
   *   The name of the PHP class to load.
108
   */
109
  protected function assertPluginMissingClass($module, $type, $id, $class = 'handler') {
110
    $class_name = ctools_plugin_load_class($module, $type, $id, $class);
111
    $this->assertEqual($class_name, NULL, t('Plugin @plugin of plugin type @module:@type for @class with missing class successfully failed.', array(
112
      '@plugin' => $id,
113
      '@module' => $module,
114
      '@type' => $type,
115
      '@class' => $class,
116
    )));
117
  }
118

    
119
  /**
120
   * Test that plugins are loaded correctly.
121
   */
122
  public function testPluginLoading() {
123
    ctools_include('plugins');
124
    $module = 'ctools_plugin_test';
125
    $type = 'not_cached';
126

    
127
    // Test function retrieval for plugins using different definition methods.
128
    $this->assertPluginFunction($module, $type, 'plugin_array', 'function');
129
    $this->assertPluginFunction($module, $type, 'plugin_array2', 'function');
130
    $this->assertPluginMissingFunction($module, $type, 'plugin_array_dne', 'function');
131
    $this->assertPluginFunction($module, "big_hook_$type", 'test1', 'function');
132

    
133
    // Test class retrieval for plugins using different definition methods.
134
    $this->assertPluginClass($module, $type, 'plugin_array', 'handler');
135
    $this->assertPluginClass($module, $type, 'plugin_array2', 'handler');
136
    $this->assertPluginMissingClass($module, $type, 'plugin_array_dne', 'handler');
137
    // @todo Test big hook plugins.
138

    
139
    $type = 'cached';
140

    
141
    // Test function retrieval for plugins using different definition methods.
142
    $this->assertPluginFunction($module, $type, 'plugin_array', 'function');
143
    $this->assertPluginFunction($module, $type, 'plugin_array2', 'function');
144
    $this->assertPluginMissingFunction($module, $type, 'plugin_array_dne', 'function');
145
    $this->assertPluginFunction($module, "big_hook_$type", 'test1', 'function');
146

    
147
    // Test class retrieval for plugins using different definition methods.
148
    $this->assertPluginClass($module, $type, 'plugin_array', 'handler');
149
    $this->assertPluginClass($module, $type, 'plugin_array2', 'handler');
150
    $this->assertPluginMissingClass($module, $type, 'plugin_array_dne', 'handler');
151
    // @todo Test big hook plugins.
152
  }
153

    
154
}