1 locale.test | LocaleContentFunctionalTest::testContentTypeDirLang() |
Test if a dir and lang tags exist in node's attributes.
File
- core/
modules/ locale/ tests/ locale.test, line 1970 - Tests for locale.module.
Class
- LocaleContentFunctionalTest
- Functional tests for multilingual support on nodes.
Code
function testContentTypeDirLang() {
// 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', 'edit own post content'));
// Login as admin.
$this->backdropLogin($admin_user);
// Install Arabic language.
$edit = array();
$edit['predefined_langcode'] = 'ar';
$this->backdropPost('admin/config/regional/language/add', $edit, t('Add language'));
// Install Spanish language.
$edit = array();
$edit['predefined_langcode'] = 'es';
$this->backdropPost('admin/config/regional/language/add', $edit, t('Add language'));
// Set "Post" content type to use multilingual support.
$this->backdropGet('admin/structure/types/manage/post');
$edit = array(
'language' => 1,
);
$this->backdropPost('admin/structure/types/manage/post', $edit, t('Save content type'));
$this->assertRaw(t('The content type %type has been updated.', array('%type' => 'Post')), 'Post content type has been updated.');
$this->backdropLogout();
// Login as web user to add new post.
$this->backdropLogin($web_user);
// Create three nodes: English, Arabic and Spanish.
$node_en = $this->createNodePost('en');
$node_ar = $this->createNodePost('ar');
$node_es = $this->createNodePost('es');
$this->backdropGet('node');
// Check if English node does not have lang tag.
$pattern = '|id="node-' . $node_en->nid . '"[^<>]*lang="en"|';
$this->assertNoPattern($pattern, 'The lang tag has not been assigned to the English node.');
// Check if English node does not have dir tag.
$pattern = '|id="node-' . $node_en->nid . '"[^<>]*dir="ltr"|';
$this->assertNoPattern($pattern, 'The dir tag has not been assigned to the English node.');
// Check if Arabic node has lang="ar" & dir="rtl" tags.
$pattern = '|id="node-' . $node_ar->nid . '"[^<>]*lang="ar" dir="rtl"|';
$this->assertPattern($pattern, 'The lang and dir tags have been assigned correctly to the Arabic node.');
// Check if Spanish node has lang="es" tag.
$pattern = '|id="node-' . $node_es->nid . '"[^<>]*lang="es"|';
$this->assertPattern($pattern, 'The lang tag has been assigned correctly to the Spanish node.');
// Check if Spanish node does not have dir="ltr" tag.
$pattern = '|id="node-' . $node_es->nid . '"[^<>]*lang="es" dir="ltr"|';
$this->assertNoPattern($pattern, 'The dir tag has not been assigned to the Spanish node.');
$this->backdropLogout();
}