Projet

Général

Profil

Paste
Télécharger (3,76 ko) Statistiques
| Branche: | Révision:

root / drupal7 / modules / simpletest / tests / module_test.module @ 76597ebf

1
<?php
2

    
3
/**
4
 * Implements hook_permission().
5
 */
6
function module_test_permission() {
7
  return array(
8
    'module_test perm' => t('example perm for module_test module'),
9
  );
10
}
11

    
12
/**
13
 * Implements hook_system_info_alter().
14
 *
15
 * Manipulate module dependencies to test dependency chains.
16
 */
17
function module_test_system_info_alter(&$info, $file, $type) {
18
  if (variable_get('dependency_test', FALSE) == 'missing dependency') {
19
    if ($file->name == 'forum') {
20
      // Make forum module depend on poll.
21
      $info['dependencies'][] = 'poll';
22
    }
23
    elseif ($file->name == 'poll') {
24
      // Make poll depend on a made-up module.
25
      $info['dependencies'][] = 'foo';
26
    }
27
  }
28
  elseif (variable_get('dependency_test', FALSE) == 'dependency') {
29
    if ($file->name == 'forum') {
30
      // Make the forum module depend on poll.
31
      $info['dependencies'][] = 'poll';
32
    }
33
    elseif ($file->name == 'poll') {
34
      // Make poll depend on php module.
35
      $info['dependencies'][] = 'php';
36
    }
37
  }
38
  elseif (variable_get('dependency_test', FALSE) == 'version dependency') {
39
    if ($file->name == 'forum') {
40
      // Make the forum module depend on poll.
41
      $info['dependencies'][] = 'poll';
42
    }
43
    elseif ($file->name == 'poll') {
44
      // Make poll depend on a specific version of php module.
45
      $info['dependencies'][] = 'php (1.x)';
46
    }
47
    elseif ($file->name == 'php') {
48
      // Set php module to a version compatible with the above.
49
      $info['version'] = '7.x-1.0';
50
    }
51
  }
52
  if ($file->name == 'seven' && $type == 'theme') {
53
    $info['regions']['test_region'] = t('Test region');
54
  }
55
}
56

    
57
/**
58
 * Implements hook_hook_info().
59
 */
60
function module_test_hook_info() {
61
  $hooks['test_hook'] = array(
62
    'group' => 'file',
63
  );
64
  return $hooks;
65
}
66

    
67
/**
68
 * Implements hook_menu().
69
 */
70
function module_test_menu() {
71
  $items['module-test/hook-dynamic-loading-invoke'] = array(
72
    'title' => 'Test hook dynamic loading (invoke)',
73
    'page callback' => 'module_test_hook_dynamic_loading_invoke',
74
    'access arguments' => array('access content'),
75
  );
76
  $items['module-test/hook-dynamic-loading-invoke-all'] = array(
77
    'title' => 'Test hook dynamic loading (invoke_all)',
78
    'page callback' => 'module_test_hook_dynamic_loading_invoke_all',
79
    'access arguments' => array('access content'),
80
  );
81
  return $items;
82
}
83

    
84
/**
85
 * Page callback for 'hook dynamic loading' test.
86
 *
87
 * If the hook is dynamically loaded correctly, the menu callback should
88
 * return 'success!'.
89
 */
90
function module_test_hook_dynamic_loading_invoke() {
91
  $result = module_invoke('module_test', 'test_hook');
92
  return $result['module_test'];
93
}
94

    
95
/**
96
 * Page callback for 'hook dynamic loading' test.
97
 *
98
 * If the hook is dynamically loaded correctly, the menu callback should
99
 * return 'success!'.
100
 */
101
function module_test_hook_dynamic_loading_invoke_all() {
102
  $result = module_invoke_all('test_hook');
103
  return $result['module_test'];
104
}
105

    
106
/**
107
 * Implements hook_modules_enabled().
108
 */
109
function module_test_modules_enabled($modules) {
110
  // Record the ordered list of modules that were passed in to this hook so we
111
  // can check that the modules were enabled in the correct sequence.
112
  variable_set('test_module_enable_order', $modules);
113
}
114

    
115
/**
116
 * Implements hook_modules_disabled().
117
 */
118
function module_test_modules_disabled($modules) {
119
  // Record the ordered list of modules that were passed in to this hook so we
120
  // can check that the modules were disabled in the correct sequence.
121
  variable_set('test_module_disable_order', $modules);
122
}
123

    
124
/**
125
 * Implements hook_modules_uninstalled().
126
 */
127
function module_test_modules_uninstalled($modules) {
128
  // Record the ordered list of modules that were passed in to this hook so we
129
  // can check that the modules were uninstalled in the correct sequence.
130
  variable_set('test_module_uninstall_order', $modules);
131
}