NodeTypeInitialLanguageTest.php 5.54 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
<?php

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

namespace Drupal\node\Tests;

/**
 * Tests related to node type initial language.
 */
class NodeTypeInitialLanguageTest extends NodeTestBase {
14 15 16 17 18 19

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

22 23 24 25 26 27 28 29 30
  public static function getInfo() {
    return array(
      'name' => 'Node type initial language',
      'description' => 'Tests node type initial language settings.',
      'group' => 'Node',
    );
  }

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

33
    $web_user = $this->drupalCreateUser(array('bypass node access', 'administer content types', 'administer node fields', 'administer node form display', 'administer node display', 'administer languages', 'administer site configuration'));
34 35 36 37
    $this->drupalLogin($web_user);
  }

  /**
38
   * Tests the node type initial language defaults, and modifies them.
39 40 41 42 43 44
   *
   * 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');
45 46
    $this->assertOptionSelected('edit-language-configuration-langcode', 'site_default', 'The default initial language is the site default.');
    $this->assertNoFieldChecked('edit-language-configuration-language-show', 'Language selector is hidden by default.');
47

48 49 50 51 52
    // 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.');

53 54 55 56 57 58 59
    $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',
    );
60
    $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));
61
    $edit = array(
62
      'site_default_language' => 'hu',
63
    );
64
    $this->drupalPostForm('admin/config/regional/settings', $edit, t('Save configuration'));
65 66

    // Tests the initial language after changing the site default language.
67
    // First unhide the language selector.
68
    $edit = array(
69
      'language_configuration[language_show]' => TRUE,
70
    );
71
    $this->drupalPostForm('admin/structure/types/manage/article', $edit, t('Save content type'));
72 73
    $this->drupalGet('node/add/article');
    $this->assertField('langcode', 'Language is selectable on node add/edit page when language not hidden.');
74
    $this->assertOptionSelected('edit-langcode', 'hu', 'The initial language is the site default on the node add page after the site default language is changed.');
75

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

82 83
    // Tests if the language field can be rearranged on the manage display tab.
    $this->drupalGet('admin/structure/types/manage/article/display');
84
    $language_display = $this->xpath('//*[@id="langcode"]');
85 86
    $this->assert(!empty($language_display), 'Language field is visible on manage display tab.');
    // Tests if the language field is hidden by default.
87
    $this->assertOptionSelected('edit-fields-langcode-type', 'hidden', 'Language is hidden by default on manage display tab.');
88

89
    // Changes the initial language settings.
90
    $edit = array(
91
      'language_configuration[langcode]' => 'en',
92
    );
93
    $this->drupalPostForm('admin/structure/types/manage/article', $edit, t('Save content type'));
94
    $this->drupalGet('node/add/article');
95
    $this->assertOptionSelected('edit-langcode', 'en', 'The initial language is the defined language.');
96
  }
97 98

  /**
99
   * Tests language field visibility features.
100 101 102 103
   */
  function testLanguageFieldVisibility() {
    // Creates a node to test Language field visibility feature.
    $edit = array(
104
      'title[0][value]' => $this->randomName(8),
105
      'body[0][value]' => $this->randomName(16),
106
    );
107
    $this->drupalPostForm('node/add/article', $edit, t('Save'));
108
    $node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
109 110 111
    $this->assertTrue($node, 'Node found in database.');

    // Loads node page and check if Language field is hidden by default.
112
    $this->drupalGet('node/' . $node->id());
113 114 115 116 117 118 119
    $language_field = $this->xpath('//div[@id=:id]/div', array(
      ':id' => 'field-language-display',
    ));
    $this->assertTrue(empty($language_field), 'Language field value is not shown by default on node page.');

    // Changes Language field visibility to true and check if it is saved.
    $edit = array(
120
      'fields[langcode][type]' => 'visible',
121
    );
122
    $this->drupalPostForm('admin/structure/types/manage/article/display', $edit, t('Save'));
123
    $this->drupalGet('admin/structure/types/manage/article/display');
124
    $this->assertOptionSelected('edit-fields-langcode-type', 'visible', 'Language field has been set to visible.');
125 126

    // Loads node page and check if Language field is shown.
127
    $this->drupalGet('node/' . $node->id());
128 129 130 131 132
    $language_field = $this->xpath('//div[@id=:id]/div', array(
      ':id' => 'field-language-display',
    ));
    $this->assertFalse(empty($language_field), 'Language field value is shown on node page.');
  }
133
}