summaryrefslogtreecommitdiffstats
path: root/core/modules/system/tests/modules/system_test/system_test.module
blob: fb1538d608e2ccdb142aaa0ec94cee37535d2d79 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php

use Drupal\Core\Extension\Extension;

/**
 * Implements hook_modules_installed().
 */
function system_test_modules_installed($modules) {
  if (\Drupal::state()->get('system_test.verbose_module_hooks')) {
    foreach ($modules as $module) {
      drupal_set_message(t('hook_modules_installed fired for @module', array('@module' => $module)));
    }
  }
}

/**
 * Implements hook_modules_uninstalled().
 */
function system_test_modules_uninstalled($modules) {
  if (\Drupal::state()->get('system_test.verbose_module_hooks')) {
    foreach ($modules as $module) {
      drupal_set_message(t('hook_modules_uninstalled fired for @module', array('@module' => $module)));
    }
  }
}

/**
 * Implements hook_system_info_alter().
 */
function system_test_system_info_alter(&$info, Extension $file, $type) {
  // We need a static otherwise the last test will fail to alter common_test.
  static $test;
  if (($dependencies = \Drupal::state()->get('system_test.dependencies')) || $test) {
    if ($file->getName() == 'module_test') {
      $info['hidden'] = FALSE;
      $info['dependencies'][] = array_shift($dependencies);
      \Drupal::state()->set('system_test.dependencies', $dependencies);
      $test = TRUE;
    }
    if ($file->getName() == 'common_test') {
      $info['hidden'] = FALSE;
      $info['version'] = '8.x-2.4-beta3';
    }
  }

  // Make the system_dependencies_test visible by default.
  if ($file->getName() == 'system_dependencies_test') {
    $info['hidden'] = FALSE;
  }
  if (in_array($file->getName(), array(
    'system_incompatible_module_version_dependencies_test',
    'system_incompatible_core_version_dependencies_test',
    'system_incompatible_module_version_test',
    'system_incompatible_core_version_test',
  ))) {
    $info['hidden'] = FALSE;
  }
  if ($file->getName() == 'requirements1_test' || $file->getName() == 'requirements2_test') {
    $info['hidden'] = FALSE;
  }
  if ($file->getName() == 'system_test') {
    $info['hidden'] = \Drupal::state()->get('system_test.module_hidden', TRUE);
  }
}

/**
 * Implements hook_page_attachments().
 */
function system_test_page_attachments(array &$page) {
  // Used by FrontPageTestCase to get the results of
  // \Drupal::service('path.matcher')->isFrontPage().
  $frontpage = \Drupal::state()->get('system_test.front_page_output') ?: 0;
  if ($frontpage && \Drupal::service('path.matcher')->isFrontPage()) {
    drupal_set_message(t('On front page.'));
  }
}

/**
 * Dummy shutdown function which registers another shutdown function.
 */
function _system_test_first_shutdown_function($arg1, $arg2) {
  // Set something to ensure that this function got called.
  \Drupal::state()->set('_system_test_first_shutdown_function', array($arg1, $arg2));
  drupal_register_shutdown_function('_system_test_second_shutdown_function', $arg1, $arg2);
}

/**
 * Dummy shutdown function.
 */
function _system_test_second_shutdown_function($arg1, $arg2) {
  // Set something to ensure that this function got called.
  \Drupal::state()->set('_system_test_second_shutdown_function', array($arg1, $arg2));

  // Throw an exception with an HTML tag. Since this is called in a shutdown
  // function, it will not bubble up to the default exception handler but will
  // be caught in _drupal_shutdown_function() and be displayed through
  // \Drupal\Core\Utility\Error::renderExceptionSafe() if possible.
  throw new Exception('Drupal is <blink>awesome</blink>.');
}

/**
 * Implements hook_filetransfer_info().
 */
function system_test_filetransfer_info() {
  return array(
    'system_test' => array(
      'title' => t('System Test FileTransfer'),
      'class' => 'Drupal\system_test\MockFileTransfer',
      'weight' => -10,
    ),
  );
}

/**
 * Implements hook_module_preinstall().
 */
function system_test_module_preinstall($module) {
  \Drupal::state()->set('system_test_preinstall_module', $module);
}

/**
 * Implements hook_module_preuninstall().
 */
function system_test_module_preuninstall($module) {
  \Drupal::state()->set('system_test_preuninstall_module', $module);
}