1 locale.test LocaleContentFunctionalTest::testContentTypeLanguageConfiguration()

Test if a content type can be set to multilingual and language is present.

File

core/modules/locale/tests/locale.test, line 1853
Tests for locale.module.

Class

LocaleContentFunctionalTest
Functional tests for multilingual support on nodes.

Code

function testContentTypeLanguageConfiguration() {
  global $base_url;

  // User to add and remove language.
  $admin_user = $this->backdropCreateUser(array('administer languages', 'administer content types', 'access administration pages'));
  // User to create a node.
  $web_user = $this->backdropCreateUser(array('create post content', 'create page content', 'edit any page content'));

  // Add custom language.
  $this->backdropLogin($admin_user);
  // Code for the language.
  $langcode = 'xx';
  // The English name for the language.
  $name = $this->randomName(16);
  $edit = array(
    'predefined_langcode' => 'custom',
    'langcode' => $langcode,
    'name' => $name,
    'direction' => '0',
  );
  $this->backdropPost('admin/config/regional/language/add', $edit, t('Add custom language'));

  // Add disabled custom language.
  // Code for the language.
  $langcode_disabled = 'xx-yy';
  // The English name for the language.
  $name_disabled = $this->randomName(16);
  $edit = array(
    'predefined_langcode' => 'custom',
    'langcode' => $langcode_disabled,
    'name' => $name_disabled,
    'direction' => '0',
  );
  $this->backdropPost('admin/config/regional/language/add', $edit, t('Add custom language'));
  // Disable second custom language.
  $path = 'admin/config/regional/language';
  $edit = array(
    'languages[' . $langcode_disabled . '][enabled]' => FALSE,
  );
  $this->backdropPost($path, $edit, t('Save configuration'));

  // Set "Page" content type to use multilingual support.
  $this->backdropGet('admin/structure/types/manage/page');
  $this->assertText(t('Multilingual support'), 'Multilingual support fieldset present on content type configuration form.');
  $edit = array(
    'language' => 1,
  );
  $this->backdropPost('admin/structure/types/manage/page', $edit, t('Save content type'));
  $this->assertRaw(t('The content type %type has been updated.', array('%type' => 'Page')), 'Page content type has been updated.');
  $this->backdropLogout();

  // Verify language selection is not present on add post form.
  $this->backdropLogin($web_user);
  $this->backdropGet('node/add/post');
  // Verify language select list is not present.
  $this->assertNoFieldByName('language', NULL, 'Language select not present on add post form.');

  // Verify language selection appears on add "Page" form.
  $this->backdropGet('node/add/page');
  // Verify language select list is present.
  $this->assertFieldByName('langcode', NULL, 'Language select present on add Page form.');
  // Ensure enabled language appears.
  $this->assertText($name, 'Enabled language present.');
  // Ensure disabled language doesn't appear.
  $this->assertNoText($name_disabled, 'Disabled language not present.');

  // Create "Page" content.
  $node_title = $this->randomName();
  $node_body = $this->randomName();
  $edit = array(
    'type' => 'page',
    'title' => $node_title,
    'body' => array($langcode => array(array('value' => $node_body))),
    'langcode' => $langcode,
  );
  $node = $this->backdropCreateNode($edit);
  // Edit the content and ensure correct language is selected.
  $path = 'node/' . $node->nid . '/edit';
  $this->backdropGet($path);
  $this->assertRaw('<option value="' . $langcode . '" selected="selected">' . $name . '</option>', 'Correct language selected.');
  // Ensure we can change the node language.
  $edit = array(
    'langcode' => 'en',
  );
  $this->backdropPost($path, $edit, t('Save'));
  $this->assertRaw(t('%title has been updated.', array('%title' => $node_title)), 'Page content updated.');

  $this->backdropLogout();
}