Completed
Pull Request — 8.x-3.x (#509)
by Sebastian
03:03 queued 38s
created

LanguageTest::testLanguageSwitchLinks()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 51
Code Lines 34

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 34
nc 1
nop 0
dl 0
loc 51
rs 9.4109
c 0
b 0
f 0

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