1 taxonomy.test | TaxonomyLanguageFunctionalTest::testNodeTermLanguageCreation() |
Test term creation with a free-tagging vocabulary from the node form.
File
- core/
modules/ taxonomy/ tests/ taxonomy.test, line 1931 - Tests for taxonomy.module.
Class
- TaxonomyLanguageFunctionalTest
- Tests setting languages for taxonomy.
Code
function testNodeTermLanguageCreation() {
// Configure the vocabulary.
$this->backdropGet('admin/structure/taxonomy');
$this->clickLink(t('Configure'));
$edit = array();
$edit['language'] = TAXONOMY_LANGUAGE_ENABLED;
$this->backdropPost(NULL, $edit, t('Save vocabulary'));
$terms = array(
'term1' => $this->randomName(),
'term2' => $this->randomName(),
);
$edit = array();
$field_langcode = LANGUAGE_NONE;
$langcode = 'es';
$edit["title"] = $this->randomName();
$edit["body[$field_langcode][0][value]"] = $this->randomName();
// Insert the terms in a comma separated list. Vocabulary 1 is a
// free-tagging field created by the default profile.
$edit['field_tags' . "[$field_langcode]"] = backdrop_implode_tags($terms);
$edit['langcode'] = $langcode;
// taxonomy.module does not maintain its static caches.
backdrop_static_reset();
// Save, creating the terms.
$this->backdropPost('node/add/post', $edit, t('Save'));
$this->assertRaw(t('@type %title has been created.', array('@type' => t('Post'), '%title' => $edit["title"])), 'The node was created successfully.');
foreach ($terms as $term) {
$this->assertText($term, 'The term was saved and appears on the node page.');
}
// Get the created terms.
$term_objects = array();
foreach ($terms as $key => $term) {
$term_objects[$key] = taxonomy_term_load_multiple_by_name($term);
$term_objects[$key] = reset($term_objects[$key]);
}
// Test editing the node.
$node = $this->backdropGetNodeByTitle($edit["title"]);
$this->backdropPost('node/' . $node->nid . '/edit', $edit, t('Save'));
foreach ($terms as $term) {
$this->assertText($term, 'The term was retained after edit and still appears on the node page.');
}
// Test language of term - should be Spanish.
$this->backdropGet('taxonomy/term/' . $term_objects['term1']->tid . '/edit');
$this->assertOptionSelected('edit-langcode', 'es', 'Term is the same language as the node it was created in.');
}