summaryrefslogtreecommitdiffstats
path: root/core/modules/node/lib/Drupal/node/Tests/NodeTypeInitialLanguageTest.php
blob: 3ba3fe669d52e754b51c0029906752395c189c5f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php

/**
 * @file
 * Definition of Drupal\node\Tests\NodeTypeInitalLanguageTest.
 */

namespace Drupal\node\Tests;

/**
 * Tests related to node type initial language.
 */
class NodeTypeInitialLanguageTest extends NodeTestBase {

  /**
   * Modules to enable.
   *
   * @var array
   */
  public static $modules = array('language', 'field_ui');

  public static function getInfo() {
    return array(
      'name' => 'Node type initial language',
      'description' => 'Tests node type initial language settings.',
      'group' => 'Node',
    );
  }

  function setUp() {
    parent::setUp();

    $web_user = $this->drupalCreateUser(array('bypass node access', 'administer content types', 'administer languages'));
    $this->drupalLogin($web_user);
  }

  /**
   * Tests the node type initial language defaults, and modify them.
   *
   * The default initial language must be the site's default, and the language
   * locked option must be on.
   */
  function testNodeTypeInitialLanguageDefaults() {
    $this->drupalGet('admin/structure/types/manage/article');
    $this->assertOptionSelected('edit-node-type-language-default', 'site_default', 'The default inital language is the site default.');
    $this->assertFieldChecked('edit-node-type-language-hidden', 'Language selector is hidden by default.');

    // Tests if the language field cannot be rearranged on the manage fields tab.
    $this->drupalGet('admin/structure/types/manage/article/fields');
    $language_field = $this->xpath('//*[@id="field-overview"]/*[@id="language"]');
    $this->assert(empty($language_field), 'Language field is not visible on manage fields tab.');

    $this->drupalGet('node/add/article');
    $this->assertNoField('langcode', 'Language is not selectable on node add/edit page by default.');

    // Adds a new language and set it as default.
    $edit = array(
      'predefined_langcode' => 'hu',
    );
    $this->drupalPost('admin/config/regional/language/add', $edit, t('Add language'));
    $edit = array(
      'site_default' => 'hu',
    );
    $this->drupalPost('admin/config/regional/language', $edit, t('Save configuration'));

    // Tests the initial language after changing the site default language.
    // First unhide the language selector
    $edit = array(
      'node_type_language_hidden' => FALSE,
    );
    $this->drupalPost('admin/structure/types/manage/article', $edit, t('Save content type'));
    $this->drupalGet('node/add/article');
    $this->assertField('langcode', 'Language is selectable on node add/edit page when language not hidden.');
    $this->assertOptionSelected('edit-langcode', 'hu', 'The inital language is the site default on the node add page after the site default language is changed.');

    // Tests if the language field can be rearranged on the manage fields tab.
    $this->drupalGet('admin/structure/types/manage/article/fields');
    $language_field = $this->xpath('//*[@id="language"]');
    $this->assert(!empty($language_field), 'Language field is visible on manage fields tab.');

    // Changes the inital language settings.
    $edit = array(
      'node_type_language_default' => 'en',
    );
    $this->drupalPost('admin/structure/types/manage/article', $edit, t('Save content type'));
    $this->drupalGet('node/add/article');
    $this->assertOptionSelected('edit-langcode', 'en', 'The inital language is the defined language.');
  }
}