View source
<?php
namespace Drupal\node\Tests;
use Drupal\Core\Language\LanguageInterface;
class NodeTypeInitialLanguageTest extends NodeTestBase {
public static $modules = array(
'language',
'field_ui',
);
protected function setUp() {
parent::setUp();
$web_user = $this
->drupalCreateUser(array(
'bypass node access',
'administer content types',
'administer node fields',
'administer node form display',
'administer node display',
'administer languages',
));
$this
->drupalLogin($web_user);
}
function testNodeTypeInitialLanguageDefaults() {
$this
->drupalGet('admin/structure/types/manage/article');
$this
->assertOptionSelected('edit-language-configuration-langcode', LanguageInterface::LANGCODE_SITE_DEFAULT, 'The default initial language is the site default.');
$this
->assertNoFieldChecked('edit-language-configuration-language-alterable', 'Language selector is hidden by default.');
$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.');
$edit = array(
'predefined_langcode' => 'hu',
);
$this
->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));
$edit = array(
'site_default_language' => 'hu',
);
$this
->drupalPostForm('admin/config/regional/language', $edit, t('Save configuration'));
$edit = array(
'language_configuration[language_alterable]' => TRUE,
);
$this
->drupalPostForm('admin/structure/types/manage/article', $edit, t('Save content type'));
$this
->drupalGet('node/add/article');
$this
->assertField('langcode[0][value]', 'Language is selectable on node add/edit page when language not hidden.');
$this
->assertOptionSelected('edit-langcode-0-value', 'hu', 'The initial language is the site default on the node add page after the site default language is changed.');
$this
->drupalGet('admin/structure/types/manage/article/form-display');
$language_field = $this
->xpath('//*[@id="langcode"]');
$this
->assert(!empty($language_field), 'Language field is visible on manage form display tab.');
$this
->drupalGet('admin/structure/types/manage/article/display');
$language_display = $this
->xpath('//*[@id="langcode"]');
$this
->assert(!empty($language_display), 'Language field is visible on manage display tab.');
$this
->assertOptionSelected('edit-fields-langcode-type', 'hidden', 'Language is hidden by default on manage display tab.');
$edit = array(
'language_configuration[langcode]' => 'en',
);
$this
->drupalPostForm('admin/structure/types/manage/article', $edit, t('Save content type'));
$this
->drupalGet('node/add/article');
$this
->assertOptionSelected('edit-langcode-0-value', 'en', 'The initial language is the defined language.');
}
function testLanguageFieldVisibility() {
$edit = array(
'title[0][value]' => $this
->randomMachineName(8),
'body[0][value]' => $this
->randomMachineName(16),
);
$this
->drupalPostForm('node/add/article', $edit, t('Save'));
$node = $this
->drupalGetNodeByTitle($edit['title[0][value]']);
$this
->assertTrue($node, 'Node found in database.');
$this
->drupalGet('node/' . $node
->id());
$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.');
$edit = array(
'fields[langcode][type]' => 'language',
);
$this
->drupalPostForm('admin/structure/types/manage/article/display', $edit, t('Save'));
$this
->drupalGet('admin/structure/types/manage/article/display');
$this
->assertOptionSelected('edit-fields-langcode-type', 'language', 'Language field has been set to visible.');
$this
->drupalGet('node/' . $node
->id());
$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.');
}
}