LanguageDependencyInjectionTest.php 2.66 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
<?php

/**
 * @file
 * Definition of Drupal\language\Tests\LanguageDependencyInjectionTest.
 */

namespace Drupal\language\Tests;

use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Language\Language;
use Drupal\simpletest\WebTestBase;

/**
 * Test for dependency injected language object.
 */
class LanguageDependencyInjectionTest extends WebTestBase {
18 19 20 21 22 23 24 25

  /**
   * Modules to enable.
   *
   * @var array
   */
  public static $modules = array('language');

26 27 28 29 30 31 32 33 34
  public static function getInfo() {
    return array(
        'name' => 'Language dependency injection',
        'description' => 'Compares the default language from $GLOBALS against the dependency injected language object.',
        'group' => 'Language',
    );
  }

  function setUp() {
35
    parent::setUp();
36

37
    // Ensure we are building a new Language object for each test.
38
    language(NULL, TRUE);
39 40 41 42 43 44 45 46 47 48 49 50
  }


  /**
   * Test dependency injected languages against a new Language object.
   *
   * @see Drupal\Core\Language\Language
   */
  function testDependencyInjectedNewLanguage() {
    // Initialize the language system.
    drupal_language_initialize();

51
    $expected = language_default();
52
    $result = language(LANGUAGE_TYPE_INTERFACE);
53
    foreach ($expected as $property => $value) {
54
      $this->assertEqual($expected->$property, $result->$property, format_string('The dependency injected language object %prop property equals the new Language object %prop property.', array('%prop' => $property)));
55 56 57 58 59 60 61 62 63 64 65
    }
  }

  /**
   * Test dependency injected Language object against a new default language
   * object.
   *
   * @see Drupal\Core\Language\Language
   */
  function testDependencyInjectedNewDefaultLanguage() {
    // Change the language default object to different values.
66
    $new_language_default = array(
67 68 69 70
      'langcode' => 'fr',
      'name' => 'French',
      'direction' => 0,
      'weight' => 0,
71
      'method_id' => 'language-default',
72 73 74 75 76 77 78
      'default' => TRUE,
    );
    variable_set('language_default', $new_language_default);

    // Initialize the language system.
    drupal_language_initialize();

79
    // The language system creates a Language object which contains the
80
    // same properties as the new default language object.
81
    $expected = new Language($new_language_default);
82
    $result = language(LANGUAGE_TYPE_INTERFACE);
83
    foreach ($expected as $property => $value) {
84
      $this->assertEqual($expected->$property, $result->$property, format_string('The dependency injected language object %prop property equals the default language object %prop property.', array('%prop' => $property)));
85 86 87 88 89 90
    }

    // Delete the language_default variable we previously set.
    variable_del('language_default');
  }
}