NodeTypeInitialLanguageTest.php 5.45 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 display', 'administer languages'));
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 60 61 62 63 64 65 66
    $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.
67
    // First unhide the language selector.
68
    $edit = array(
69
      'language_configuration[language_show]' => TRUE,
70 71 72 73
    );
    $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.');
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 79 80
    // 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.');

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

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

  /**
98
   * Tests language field visibility features.
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
   */
  function testLanguageFieldVisibility() {
    $langcode = LANGUAGE_NOT_SPECIFIED;

    // Creates a node to test Language field visibility feature.
    $edit = array(
      'title' => $this->randomName(8),
      "body[$langcode][0][value]" => $this->randomName(16),
    );
    $this->drupalPost('node/add/article', $edit, t('Save'));
    $node = $this->drupalGetNodeByTitle($edit['title']);
    $this->assertTrue($node, 'Node found in database.');

    // Loads node page and check if Language field is hidden by default.
    $this->drupalGet('node/' . $node->nid);
    $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(
121
      'fields[language][type]' => 'visible',
122 123 124
    );
    $this->drupalPost('admin/structure/types/manage/article/display', $edit, t('Save'));
    $this->drupalGet('admin/structure/types/manage/article/display');
125
    $this->assertOptionSelected('edit-fields-language-type', 'visible', 'Language field has been set to visible.');
126 127 128 129 130 131 132 133

    // Loads node page and check if Language field is shown.
    $this->drupalGet('node/' . $node->nid);
    $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.');
  }
134
}