1 taxonomy.test | TaxonomyVocabularyFunctionalTest::testVocabularyInterface() |
Create, configure and delete a vocabulary via the user interface.
File
- core/
modules/ taxonomy/ tests/ taxonomy.test, line 69 - Tests for taxonomy.module.
Class
- TaxonomyVocabularyFunctionalTest
- Tests the taxonomy vocabulary interface.
Code
function testVocabularyInterface() {
// Visit the main taxonomy administration page.
$this->backdropGet('admin/structure/taxonomy');
// Create a new vocabulary and then add terms.
$this->clickLink(t('Add vocabulary'));
$edit = array();
$machine_name = backdrop_strtolower($this->randomName());
$edit['name'] = $this->randomName();
$edit['description'] = $this->randomName();
$edit['machine_name'] = $machine_name;
$this->backdropPost(NULL, $edit, t('Save and add terms'));
$this->assertRaw(t('Created new vocabulary %name.', array('%name' => $edit['name'])), 'Vocabulary created successfully.');
$this->assertRaw(t('Add term'), 'Redirected to add term form');
// Create a new vocabulary.
$this->backdropGet('admin/structure/taxonomy');
$this->clickLink(t('Add vocabulary'));
$edit = array();
$machine_name = backdrop_strtolower($this->randomName());
$edit['name'] = $this->randomName();
$edit['description'] = $this->randomName();
$edit['machine_name'] = $machine_name;
$this->backdropPost(NULL, $edit, t('Save vocabulary'));
$this->assertRaw(t('Created new vocabulary %name.', array('%name' => $edit['name'])), 'Vocabulary created successfully.');
$this->assertRaw(t('Add vocabulary'), 'Redirected to vocabulary listing page');
// Configure the vocabulary.
$this->backdropGet('admin/structure/taxonomy');
$this->assertText($edit['name'], 'Vocabulary found in the vocabulary overview listing.');
$this->clickLink(t('Configure'));
$edit = array();
$edit['name'] = $this->randomName();
$this->backdropPost(NULL, $edit, t('Save vocabulary'));
$this->backdropGet('admin/structure/taxonomy');
$this->assertText($edit['name'], 'Vocabulary found in the vocabulary overview listing.');
// Try to submit a vocabulary with a duplicate machine name.
$edit['machine_name'] = $machine_name;
$this->backdropPost('admin/structure/taxonomy/add', $edit, t('Save vocabulary'));
$this->assertText(t('The machine-readable name is already in use. It must be unique.'));
// Try to submit an invalid machine name.
$edit['machine_name'] = '!&^%';
$this->backdropPost('admin/structure/taxonomy/add', $edit, t('Save vocabulary'));
$this->assertText(t('The machine-readable name must contain only lowercase letters, numbers, and underscores.'));
// Ensure that vocabulary titles are escaped properly.
$edit = array();
$edit['name'] = 'Don\'t Panic';
$edit['description'] = $this->randomName();
$edit['machine_name'] = 'don_t_panic';
$this->backdropPost('admin/structure/taxonomy/add', $edit, t('Save vocabulary'));
$site_name = config_get('system.core', 'site_name');
$this->backdropGet('admin/structure/taxonomy/don_t_panic');
$this->assertTitle(t('Don\'t Panic | @site-name', array('@site-name' => $site_name)));
$this->assertNoTitle(t('Don't Panic | @site-name', array('@site-name' => $site_name)));
// Ensure the term counts on the vocabulary list page are accurate.
$vocabulary = $this->createVocabulary();
$this->backdropGet('admin/structure/taxonomy');
$this->assertText($vocabulary->name, 'Vocabulary created.');
$this->assertText('0', 'Vocabulary has term count of zero.');
$this->createTerm($vocabulary);
$this->backdropGet('admin/structure/taxonomy');
$this->assertText('1', 'Vocabulary has term count of one.');
$this->createTerm($vocabulary);
$this->backdropGet('admin/structure/taxonomy');
$this->assertText('2', 'Vocabulary has term count of two.');
}