Completed
Pull Request — 8.x-3.x (#550)
by Philipp
02:18
created

LanguageTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 17
nc 1
nop 0
dl 0
loc 23
rs 9.0856
c 0
b 0
f 0
1
<?php
2
3
namespace Drupal\Tests\graphql_core\Kernel\Languages;
4
5
use Drupal\language\Entity\ConfigurableLanguage;
6
use Drupal\Tests\graphql_core\Kernel\GraphQLCoreTestBase;
7
8
/**
9
 * Test multilingual behavior.
10
 *
11
 * @group graphql_core
12
 */
13
class LanguageTest extends GraphQLCoreTestBase {
14
15
  /**
16
   * {@inheritdoc}
17
   */
18
  public static $modules = [
19
    'language',
20
  ];
21
22
  /**
23
   * {@inheritdoc}
24
   */
25
  protected function setUp() {
26
    parent::setUp();
27
28
    $this->installConfig(['language']);
29
    $this->installEntitySchema('configurable_language');
30
    $this->container->get('router.builder')->rebuild();
31
32
    ConfigurableLanguage::create([
33
      'id' => 'es',
34
      'weight' => 2,
35
    ])->save();
36
37
    ConfigurableLanguage::create([
38
      'id' => 'pt-br',
39
      'weight' => 3,
40
    ])->save();
41
42
    $config = $this->config('language.negotiation');
43
    $config->set('url.prefixes', ['en' => 'en', 'es' => 'es', 'fr' => 'fr'])
44
      ->save();
45
46
    $this->container->get('kernel')->rebuildContainer();
47
  }
48
49
  /**
50
   * Test listing of available languages.
51
   */
52
  public function testLanguageId() {
53
    // TODO: Check cache metadata.
54
    $metadata = $this->defaultCacheMetaData();
55
56
    $this->assertResults($this->getQueryFromFile('languages.gql'), [], [
57
      'languages' => [
58
        0 => [
59
          'id' => 'en',
60
          'name' => 'English',
61
          'isDefault' => TRUE,
62
          'isLocked' => FALSE,
63
          'direction' => 'ltr',
64
          'weight' => 0,
65
          'argument' => 'en',
66
        ],
67
        1 => [
68
          'id' => 'fr',
69
          'name' => 'French',
70
          'isDefault' => FALSE,
71
          'isLocked' => FALSE,
72
          'direction' => 'ltr',
73
          'weight' => 1,
74
          'argument' => 'fr',
75
        ],
76
        2 => [
77
          'id' => 'es',
78
          'name' => 'Spanish',
79
          'isDefault' => FALSE,
80
          'isLocked' => FALSE,
81
          'direction' => 'ltr',
82
          'weight' => 2,
83
          'argument' => 'es',
84
        ],
85
        3 => [
86
          'id' => 'pt-br',
87
          'name' => 'Portuguese, Brazil',
88
          'isDefault' => FALSE,
89
          'isLocked' => FALSE,
90
          'direction' => 'ltr',
91
          'weight' => 3,
92
          'argument' => 'pt_br',
93
        ],
94
      ],
95
    ], $metadata);
96
  }
97
98
  /**
99
   * Test language switch links.
100
   */
101
  public function testLanguageSwitchLinks() {
102
    // TODO: Check cache metadata.
103
    $metadata = $this->defaultCacheMetaData();
104
    $metadata->addCacheTags([
105
      'config:language.entity.en',
106
      'config:language.entity.es',
107
      'config:language.entity.fr',
108
      'config:language.entity.pt-br',
109
    ]);
110
111
    $metadata->addCacheContexts([
112
      'languages:language_interface',
113
      'languages:language_url',
114
    ]);
115
116
    $this->assertResults($this->getQueryFromFile('language_switch_links.gql'), [], [
117
      'route' => [
118
        'links' => [
119
          0 => [
120
            'language' => [
121
              'id' => 'en',
122
            ],
123
            'url' => [
124
              'path' => '/en/user/login',
125
            ],
126
            'title' => 'English',
127
            'active' => TRUE,
128
          ],
129
          1 => [
130
            'language' => [
131
              'id' => 'fr',
132
            ],
133
            'url' => [
134
              'path' => '/fr/user/login',
135
            ],
136
            'title' => NULL,
137
            'active' => FALSE,
138
          ],
139
          2 => [
140
            'language' => [
141
              'id' => 'es',
142
            ],
143
            'url' => [
144
              'path' => '/es/user/login',
145
            ],
146
            'title' => NULL,
147
            'active' => FALSE,
148
          ],
149
          3 => [
150
            'language' => [
151
              'id' => 'pt-br',
152
            ],
153
            'url' => [
154
              'path' => '/user/login',
155
            ],
156
            'title' => NULL,
157
            'active' => FALSE,
158
          ],
159
        ],
160
      ],
161
    ], $metadata);
162
  }
163
164
  /**
165
   * {@inheritdoc}
166
   */
167
  protected function defaultCacheTags() {
168
    $tags = parent::defaultCacheTags();
169
    return array_diff($tags, ['entity_bundles']);
170
  }
171
}
172