Completed
Pull Request — 8.x-3.x (#509)
by Sebastian
02:54
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
    $metadata->addCacheTags(['languages:language_url']);
111
112
    $this->assertResults($this->getQueryFromFile('language_switch_links.gql'), [], [
113
      'route' => [
114
        'links' => [
115
          0 => [
116
            'language' => [
117
              'id' => 'en',
118
            ],
119
            'url' => [
120
              'path' => '/en',
121
            ],
122
            'title' => 'English',
123
            'active' => TRUE,
124
          ],
125
          1 => [
126
            'language' => [
127
              'id' => 'fr',
128
            ],
129
            'url' => [
130
              'path' => '/fr',
131
            ],
132
            'title' => NULL,
133
            'active' => FALSE,
134
          ],
135
          2 => [
136
            'language' => [
137
              'id' => 'es',
138
            ],
139
            'url' => [
140
              'path' => '/es',
141
            ],
142
            'title' => NULL,
143
            'active' => FALSE,
144
          ],
145
          3 => [
146
            'language' => [
147
              'id' => 'pt-br',
148
            ],
149
            'url' => [
150
              'path' => '/',
151
            ],
152
            'title' => NULL,
153
            'active' => FALSE,
154
          ],
155
        ],
156
      ],
157
    ], $metadata);
158
  }
159
}
160