Chris@0: drupalCreateUser(['administer languages', 'administer content types', 'access administration pages', 'administer site configuration']); Chris@0: Chris@0: // Log in as admin. Chris@0: $this->drupalLogin($admin_user); Chris@0: Chris@0: // Verify that the machine name field is LTR for a new content type. Chris@0: $this->drupalGet('admin/structure/types/add'); Chris@0: $this->assertFieldByXpath('//input[@name="type" and @dir="ltr"]', NULL, 'The machine name field is LTR when no additional language is configured.'); Chris@0: Chris@0: // Install the Arabic language (which is RTL) and configure as the default. Chris@0: $edit = []; Chris@0: $edit['predefined_langcode'] = 'ar'; Chris@0: $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language')); Chris@0: Chris@0: $edit = [ Chris@0: 'site_default_language' => 'ar', Chris@0: ]; Chris@0: $this->drupalPostForm('admin/config/regional/language', $edit, t('Save configuration')); Chris@0: Chris@0: // Verify that the machine name field is still LTR for a new content type. Chris@0: $this->drupalGet('admin/structure/types/add'); Chris@0: $this->assertFieldByXpath('//input[@name="type" and @dir="ltr"]', NULL, 'The machine name field is LTR when the default language is RTL.'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Test if a content type can be set to multilingual and language is present. Chris@0: */ Chris@0: public function testContentTypeLanguageConfiguration() { Chris@0: $type1 = $this->drupalCreateContentType(); Chris@0: $type2 = $this->drupalCreateContentType(); Chris@0: Chris@0: // User to add and remove language. Chris@0: $admin_user = $this->drupalCreateUser(['administer languages', 'administer content types', 'access administration pages']); Chris@0: // User to create a node. Chris@0: $web_user = $this->drupalCreateUser(["create {$type1->id()} content", "create {$type2->id()} content", "edit any {$type2->id()} content"]); Chris@0: Chris@0: // Add custom language. Chris@0: $this->drupalLogin($admin_user); Chris@0: // Code for the language. Chris@0: $langcode = 'xx'; Chris@0: // The English name for the language. Chris@0: $name = $this->randomMachineName(16); Chris@0: $edit = [ Chris@0: 'predefined_langcode' => 'custom', Chris@0: 'langcode' => $langcode, Chris@0: 'label' => $name, Chris@0: 'direction' => LanguageInterface::DIRECTION_LTR, Chris@0: ]; Chris@0: $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language')); Chris@0: Chris@0: // Set the content type to use multilingual support. Chris@0: $this->drupalGet("admin/structure/types/manage/{$type2->id()}"); Chris@0: $this->assertText(t('Language settings'), 'Multilingual support widget present on content type configuration form.'); Chris@0: $edit = [ Chris@0: 'language_configuration[language_alterable]' => TRUE, Chris@0: ]; Chris@0: $this->drupalPostForm("admin/structure/types/manage/{$type2->id()}", $edit, t('Save content type')); Chris@0: $this->assertRaw(t('The content type %type has been updated.', ['%type' => $type2->label()])); Chris@0: $this->drupalLogout(); Chris@0: \Drupal::languageManager()->reset(); Chris@0: Chris@0: // Verify language selection is not present on the node add form. Chris@0: $this->drupalLogin($web_user); Chris@0: $this->drupalGet("node/add/{$type1->id()}"); Chris@0: // Verify language select list is not present. Chris@0: $this->assertNoFieldByName('langcode[0][value]', NULL, 'Language select not present on the node add form.'); Chris@0: Chris@0: // Verify language selection appears on the node add form. Chris@0: $this->drupalGet("node/add/{$type2->id()}"); Chris@0: // Verify language select list is present. Chris@0: $this->assertFieldByName('langcode[0][value]', NULL, 'Language select present on the node add form.'); Chris@0: // Ensure language appears. Chris@0: $this->assertText($name, 'Language present.'); Chris@0: Chris@0: // Create a node. Chris@0: $node_title = $this->randomMachineName(); Chris@0: $node_body = $this->randomMachineName(); Chris@0: $edit = [ Chris@0: 'type' => $type2->id(), Chris@0: 'title' => $node_title, Chris@0: 'body' => [['value' => $node_body]], Chris@0: 'langcode' => $langcode, Chris@0: ]; Chris@0: $node = $this->drupalCreateNode($edit); Chris@0: // Edit the content and ensure correct language is selected. Chris@0: $path = 'node/' . $node->id() . '/edit'; Chris@0: $this->drupalGet($path); Chris@0: $this->assertRaw('', 'Correct language selected.'); Chris@0: // Ensure we can change the node language. Chris@0: $edit = [ Chris@0: 'langcode[0][value]' => 'en', Chris@0: ]; Chris@0: $this->drupalPostForm($path, $edit, t('Save')); Chris@0: $this->assertText(t('@title has been updated.', ['@title' => $node_title])); Chris@0: Chris@0: // Verify that the creation message contains a link to a node. Chris@0: $view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', [':href' => 'node/' . $node->id()]); Chris@0: $this->assert(isset($view_link), 'The message area contains the link to the edited node'); Chris@0: Chris@0: $this->drupalLogout(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Test if a dir and lang tags exist in node's attributes. Chris@0: */ Chris@0: public function testContentTypeDirLang() { Chris@0: $type = $this->drupalCreateContentType(); Chris@0: Chris@0: // User to add and remove language. Chris@0: $admin_user = $this->drupalCreateUser(['administer languages', 'administer content types', 'access administration pages']); Chris@0: // User to create a node. Chris@0: $web_user = $this->drupalCreateUser(["create {$type->id()} content", "edit own {$type->id()} content"]); Chris@0: Chris@0: // Log in as admin. Chris@0: $this->drupalLogin($admin_user); Chris@0: Chris@0: // Install Arabic language. Chris@0: $edit = []; Chris@0: $edit['predefined_langcode'] = 'ar'; Chris@0: $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language')); Chris@0: Chris@0: // Install Spanish language. Chris@0: $edit = []; Chris@0: $edit['predefined_langcode'] = 'es'; Chris@0: $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language')); Chris@0: \Drupal::languageManager()->reset(); Chris@0: Chris@0: // Set the content type to use multilingual support. Chris@0: $this->drupalGet("admin/structure/types/manage/{$type->id()}"); Chris@0: $edit = [ Chris@0: 'language_configuration[language_alterable]' => TRUE, Chris@0: ]; Chris@0: $this->drupalPostForm("admin/structure/types/manage/{$type->id()}", $edit, t('Save content type')); Chris@0: $this->assertRaw(t('The content type %type has been updated.', ['%type' => $type->label()])); Chris@0: $this->drupalLogout(); Chris@0: Chris@0: // Log in as web user to add new node. Chris@0: $this->drupalLogin($web_user); Chris@0: Chris@0: // Create three nodes: English, Arabic and Spanish. Chris@0: $nodes = []; Chris@0: foreach (['en', 'es', 'ar'] as $langcode) { Chris@0: $nodes[$langcode] = $this->drupalCreateNode([ Chris@0: 'langcode' => $langcode, Chris@0: 'type' => $type->id(), Chris@0: 'promote' => NodeInterface::PROMOTED, Chris@0: ]); Chris@0: } Chris@0: Chris@0: // Check if English node does not have lang tag. Chris@0: $this->drupalGet('node/' . $nodes['en']->id()); Chris@0: $element = $this->cssSelect('article.node[lang="en"]'); Chris@0: $this->assertTrue(empty($element), 'The lang tag has not been assigned to the English node.'); Chris@0: Chris@0: // Check if English node does not have dir tag. Chris@0: $element = $this->cssSelect('article.node[dir="ltr"]'); Chris@0: $this->assertTrue(empty($element), 'The dir tag has not been assigned to the English node.'); Chris@0: Chris@0: // Check if Arabic node has lang="ar" & dir="rtl" tags. Chris@0: $this->drupalGet('node/' . $nodes['ar']->id()); Chris@0: $element = $this->cssSelect('article.node[lang="ar"][dir="rtl"]'); Chris@0: $this->assertTrue(!empty($element), 'The lang and dir tags have been assigned correctly to the Arabic node.'); Chris@0: Chris@0: // Check if Spanish node has lang="es" tag. Chris@0: $this->drupalGet('node/' . $nodes['es']->id()); Chris@0: $element = $this->cssSelect('article.node[lang="es"]'); Chris@0: $this->assertTrue(!empty($element), 'The lang tag has been assigned correctly to the Spanish node.'); Chris@0: Chris@0: // Check if Spanish node does not have dir="ltr" tag. Chris@0: $element = $this->cssSelect('article.node[lang="es"][dir="ltr"]'); Chris@0: $this->assertTrue(empty($element), 'The dir tag has not been assigned to the Spanish node.'); Chris@0: } Chris@0: Chris@0: }