Completed
Pull Request — 8.x-3.x (#509)
by Sebastian
03:36 queued 01:04
created

LanguageTest::testLanguageSwitchLinks()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 53
Code Lines 36

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 36
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 53
rs 9.5797

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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