public function LocaleContentTest::testContentTypeLanguageConfiguration in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/locale/src/Tests/LocaleContentTest.php \Drupal\locale\Tests\LocaleContentTest::testContentTypeLanguageConfiguration()
Test if a content type can be set to multilingual and language is present.
File
- core/
modules/ locale/ src/ Tests/ LocaleContentTest.php, line 60 - Contains \Drupal\locale\Tests\LocaleContentTest.
Class
- LocaleContentTest
- Tests you can enable multilingual support on content types and configure a language for a node.
Namespace
Drupal\locale\TestsCode
public function testContentTypeLanguageConfiguration() {
$type1 = $this
->drupalCreateContentType();
$type2 = $this
->drupalCreateContentType();
// User to add and remove language.
$admin_user = $this
->drupalCreateUser(array(
'administer languages',
'administer content types',
'access administration pages',
));
// User to create a node.
$web_user = $this
->drupalCreateUser(array(
"create {$type1->id()} content",
"create {$type2->id()} content",
"edit any {$type2->id()} content",
));
// Add custom language.
$this
->drupalLogin($admin_user);
// Code for the language.
$langcode = 'xx';
// The English name for the language.
$name = $this
->randomMachineName(16);
$edit = array(
'predefined_langcode' => 'custom',
'langcode' => $langcode,
'label' => $name,
'direction' => LanguageInterface::DIRECTION_LTR,
);
$this
->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
// Set the content type to use multilingual support.
$this
->drupalGet("admin/structure/types/manage/{$type2->id()}");
$this
->assertText(t('Language settings'), 'Multilingual support widget present on content type configuration form.');
$edit = array(
'language_configuration[language_alterable]' => TRUE,
);
$this
->drupalPostForm("admin/structure/types/manage/{$type2->id()}", $edit, t('Save content type'));
$this
->assertRaw(t('The content type %type has been updated.', array(
'%type' => $type2
->label(),
)));
$this
->drupalLogout();
\Drupal::languageManager()
->reset();
// Verify language selection is not present on the node add form.
$this
->drupalLogin($web_user);
$this
->drupalGet("node/add/{$type1->id()}");
// Verify language select list is not present.
$this
->assertNoFieldByName('langcode[0][value]', NULL, 'Language select not present on the node add form.');
// Verify language selection appears on the node add form.
$this
->drupalGet("node/add/{$type2->id()}");
// Verify language select list is present.
$this
->assertFieldByName('langcode[0][value]', NULL, 'Language select present on the node add form.');
// Ensure language appears.
$this
->assertText($name, 'Language present.');
// Create a node.
$node_title = $this
->randomMachineName();
$node_body = $this
->randomMachineName();
$edit = array(
'type' => $type2
->id(),
'title' => $node_title,
'body' => array(
array(
'value' => $node_body,
),
),
'langcode' => $langcode,
);
$node = $this
->drupalCreateNode($edit);
// Edit the content and ensure correct language is selected.
$path = 'node/' . $node
->id() . '/edit';
$this
->drupalGet($path);
$this
->assertRaw('<option value="' . $langcode . '" selected="selected">' . $name . '</option>', 'Correct language selected.');
// Ensure we can change the node language.
$edit = array(
'langcode[0][value]' => 'en',
);
$this
->drupalPostForm($path, $edit, t('Save'));
$this
->assertRaw(t('%title has been updated.', array(
'%title' => $node_title,
)));
$this
->drupalLogout();
}