Completed
Pull Request — 8.x-3.x (#509)
by Sebastian
02:47
created

LanguageTest::testLanguageId()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 45
Code Lines 37

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 37
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 45
rs 8.8571
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' => 'fr',
34
      'weight' => 1,
35
    ])->save();
36
37
    ConfigurableLanguage::create([
38
      'id' => 'es',
39
      'weight' => 2,
40
    ])->save();
41
42
    ConfigurableLanguage::create([
43
      'id' => 'pt-br',
44
      'weight' => 3,
45
    ])->save();
46
47
    $config = $this->config('language.negotiation');
48
    $config->set('url.prefixes', ['en' => 'en', 'es' => 'es', 'fr' => 'fr'])
49
      ->save();
50
51
    $this->container->get('kernel')->rebuildContainer();
52
  }
53
54
  /**
55
   * Test listing of available languages.
56
   */
57
  public function testLanguageId() {
58
    // TODO: Check cache metadata.
59
    $metadata = $this->defaultCacheMetaData();
60
61
    $this->assertResults($this->getQueryFromFile('languages.gql'), [], [
62
      'languages' => [
63
        0 => [
64
          'id' => 'en',
65
          'name' => 'English',
66
          'isDefault' => TRUE,
67
          'isLocked' => FALSE,
68
          'direction' => 'ltr',
69
          'weight' => 0,
70
          'argument' => 'en',
71
        ],
72
        1 => [
73
          'id' => 'fr',
74
          'name' => 'French',
75
          'isDefault' => FALSE,
76
          'isLocked' => FALSE,
77
          'direction' => 'ltr',
78
          'weight' => 1,
79
          'argument' => 'fr',
80
        ],
81
        2 => [
82
          'id' => 'es',
83
          'name' => 'Spanish',
84
          'isDefault' => FALSE,
85
          'isLocked' => FALSE,
86
          'direction' => 'ltr',
87
          'weight' => 2,
88
          'argument' => 'es',
89
        ],
90
        3 => [
91
          'id' => 'pt-br',
92
          'name' => 'Portuguese, Brazil',
93
          'isDefault' => FALSE,
94
          'isLocked' => FALSE,
95
          'direction' => 'ltr',
96
          'weight' => 3,
97
          'argument' => 'pt_br',
98
        ],
99
      ],
100
    ], $metadata);
101
  }
102
103
  /**
104
   * Test language switch links.
105
   */
106
  public function testLanguageSwitchLinks() {
107
    // TODO: Check cache metadata.
108
    $metadata = $this->defaultCacheMetaData();
109
    $metadata->addCacheContexts(['languages:language_url']);
110
    $metadata->addCacheTags([
111
      'config:language.entity.en',
112
      'config:language.entity.es',
113
      'config:language.entity.fr',
114
      'config:language.entity.pt-br',
115
    ]);
116
117
    $this->assertResults($this->getQueryFromFile('language_switch_links.gql'), [], [
118
      'route' => [
119
        'links' => [
120
          0 => [
121
            'language' => [
122
              'id' => 'en',
123
            ],
124
            'url' => [
125
              'path' => '/en',
126
            ],
127
            'title' => 'English',
128
            'active' => TRUE,
129
          ],
130
          1 => [
131
            'language' => [
132
              'id' => 'fr',
133
            ],
134
            'url' => [
135
              'path' => '/fr',
136
            ],
137
            'title' => NULL,
138
            'active' => FALSE,
139
          ],
140
          2 => [
141
            'language' => [
142
              'id' => 'es',
143
            ],
144
            'url' => [
145
              'path' => '/es',
146
            ],
147
            'title' => NULL,
148
            'active' => FALSE,
149
          ],
150
          3 => [
151
            'language' => [
152
              'id' => 'pt-br',
153
            ],
154
            'url' => [
155
              'path' => '/',
156
            ],
157
            'title' => NULL,
158
            'active' => FALSE,
159
          ],
160
        ],
161
      ],
162
    ], $metadata);
163
  }
164
165
  /**
166
   * {@inheritdoc}
167
   */
168
  protected function defaultCacheTags() {
169
    $tags = parent::defaultCacheTags();
170
    return array_diff($tags, ['entity_bundles']);
171
  }
172
}
173