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

LanguageTest::testLanguageId()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 46
Code Lines 38

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 38
nc 1
nop 0
dl 0
loc 46
rs 8.9411
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' => '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
    $metadata->setCacheTags(array_diff($metadata->getCacheTags(), ['entity_bundles']));
61
62
    $this->assertResults($this->getQueryFromFile('languages.gql'), [], [
63
      'languages' => [
64
        0 => [
65
          'id' => 'en',
66
          'name' => 'English',
67
          'isDefault' => TRUE,
68
          'isLocked' => FALSE,
69
          'direction' => 'ltr',
70
          'weight' => 0,
71
          'argument' => 'en',
72
        ],
73
        1 => [
74
          'id' => 'fr',
75
          'name' => 'French',
76
          'isDefault' => FALSE,
77
          'isLocked' => FALSE,
78
          'direction' => 'ltr',
79
          'weight' => 1,
80
          'argument' => 'fr',
81
        ],
82
        2 => [
83
          'id' => 'es',
84
          'name' => 'Spanish',
85
          'isDefault' => FALSE,
86
          'isLocked' => FALSE,
87
          'direction' => 'ltr',
88
          'weight' => 2,
89
          'argument' => 'es',
90
        ],
91
        3 => [
92
          'id' => 'pt-br',
93
          'name' => 'Portuguese, Brazil',
94
          'isDefault' => FALSE,
95
          'isLocked' => FALSE,
96
          'direction' => 'ltr',
97
          'weight' => 3,
98
          'argument' => 'pt_br',
99
        ],
100
      ],
101
    ], $metadata);
102
  }
103
104
  /**
105
   * Test language switch links.
106
   */
107
  public function testLanguageSwitchLinks() {
108
    // TODO: Check cache metadata.
109
    $metadata = $this->defaultCacheMetaData();
110
111
    $this->assertResults($this->getQueryFromFile('language_switch_links.gql'), [], [
112
      'route' => [
113
        'links' => [
114
          0 => [
115
            'language' => [
116
              'id' => 'en',
117
            ],
118
            'url' => [
119
              'path' => '/en',
120
            ],
121
            'title' => 'English',
122
            'active' => TRUE,
123
          ],
124
          1 => [
125
            'language' => [
126
              'id' => 'fr',
127
            ],
128
            'url' => [
129
              'path' => '/fr',
130
            ],
131
            'title' => NULL,
132
            'active' => FALSE,
133
          ],
134
          2 => [
135
            'language' => [
136
              'id' => 'es',
137
            ],
138
            'url' => [
139
              'path' => '/es',
140
            ],
141
            'title' => NULL,
142
            'active' => FALSE,
143
          ],
144
          3 => [
145
            'language' => [
146
              'id' => 'pt-br',
147
            ],
148
            'url' => [
149
              'path' => '/',
150
            ],
151
            'title' => NULL,
152
            'active' => FALSE,
153
          ],
154
        ],
155
      ],
156
    ], $metadata);
157
  }
158
}
159