locale_test.module

  1. drupal
    1. 8
    2. 7

Mock module for locale layer tests.

Functions & methods

NameDescription
locale_test_bootImplements hook_boot().
locale_test_initImplements hook_init().
locale_test_language_negotiation_infoImplements hook_language_negotiation_info().
locale_test_language_negotiation_info_alterImplements hook_language_negotiation_info_alter().
locale_test_language_providerTest language provider.
locale_test_language_types_infoImplements hook_language_types_info().
locale_test_language_types_info_alterImplements hook_language_types_info_alter().
locale_test_localeImplements hook_locale().
locale_test_store_language_negotiationStore the last negotiated languages.
View source
<?php

/**
 * @file
 * Mock module for locale layer tests.
 */

/**
 * Implements hook_locale().
 */
function locale_test_locale($op = 'groups') {
  switch ($op) {
    case 'groups':
      return array('custom' => t('Custom'));
  }
}

/**
 * Implements hook_boot().
 *
 * For testing domain language negotiation, we fake it by setting
 * the HTTP_HOST here
 */
function locale_test_boot() {
  if (variable_get('locale_test_domain')) {
    $_SERVER['HTTP_HOST'] = variable_get('locale_test_domain');
  }
}

/**
 * Implements hook_init().
 */
function locale_test_init() {
  locale_test_store_language_negotiation();
}

/**
 * Implements hook_language_types_info().
 */
function locale_test_language_types_info() {
  if (variable_get('locale_test_language_types', FALSE)) {
    return array(
      'test_language_type' => array(
        'name' => t('Test'),
        'description' => t('A test language type.'),
      ),
      'fixed_test_language_type' => array(
        'fixed' => array('test_language_provider'),
      ),
    );
  }
}

/**
 * Implements hook_language_types_info_alter().
 */
function locale_test_language_types_info_alter(array &$language_types) {
  if (variable_get('locale_test_content_language_type', FALSE)) {
    unset($language_types[LANGUAGE_TYPE_CONTENT]['fixed']);
  }
}

/**
 * Implements hook_language_negotiation_info().
 */
function locale_test_language_negotiation_info() {
  if (variable_get('locale_test_language_negotiation_info', FALSE)) {
    $info = array(
      'callbacks' => array(
        'language' => 'locale_test_language_provider',
      ),
      'file' => drupal_get_path('module', 'locale_test') .'/locale_test.module',
      'weight' => -10,
      'description' => t('This is a test language provider.'),
    );

    return array(
      'test_language_provider' => array(
        'name' => t('Test'),
        'types' => array(LANGUAGE_TYPE_CONTENT, 'test_language_type', 'fixed_test_language_type'),
      ) + $info,
      'test_language_provider_ts' => array(
        'name' => t('Type-specific test'),
        'types' => array('test_language_type'),
      ) + $info,
    );
  }
}

/**
 * Implements hook_language_negotiation_info_alter().
 */
function locale_test_language_negotiation_info_alter(array &$language_providers) {
  if (variable_get('locale_test_language_negotiation_info_alter', FALSE)) {
    unset($language_providers[LOCALE_LANGUAGE_NEGOTIATION_INTERFACE]);
  }
}

/**
 * Store the last negotiated languages.
 */
function locale_test_store_language_negotiation() {
  $last = array();
  foreach (language_types() as $type) {
    $last[$type] = $GLOBALS[$type]->language;
  }
  variable_set('locale_test_language_negotiation_last', $last);
}

/**
 * Test language provider.
 */
function locale_test_language_provider($languages) {
  return 'it';
}