summaryrefslogtreecommitdiffstats
path: root/core/modules/language/lib/Drupal/language/Tests/LanguageDependencyInjectionTest.php
blob: 92a419be04784d46dac97338f5ba9f6e91624e2e (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
<?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 {

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

  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() {
    parent::setUp();

    // Ensure we are building a new Language object for each test.
    $this->container->get('language_manager')->reset();
  }


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

    $expected = language_default();
    $result = language(LANGUAGE_TYPE_INTERFACE);
    foreach ($expected as $property => $value) {
      $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)));
    }
  }

  /**
   * 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.
    $new_language_default = array(
      'langcode' => 'fr',
      'name' => 'French',
      'direction' => 0,
      'weight' => 0,
      'method_id' => 'language-default',
      'default' => TRUE,
    );
    variable_set('language_default', $new_language_default);

    // Initialize the language system.
    drupal_language_initialize();

    // The language system creates a Language object which contains the
    // same properties as the new default language object.
    $expected = new Language($new_language_default);
    $result = language(LANGUAGE_TYPE_INTERFACE);
    foreach ($expected as $property => $value) {
      $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)));
    }

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