public function VocabularyUiTest::testVocabularyInterface in Drupal 9
Same name and namespace in other branches
- 8 core/modules/taxonomy/tests/src/Functional/VocabularyUiTest.php \Drupal\Tests\taxonomy\Functional\VocabularyUiTest::testVocabularyInterface()
Create, edit and delete a vocabulary via the user interface.
File
- core/
modules/ taxonomy/ tests/ src/ Functional/ VocabularyUiTest.php, line 38
Class
- VocabularyUiTest
- Tests the taxonomy vocabulary interface.
Namespace
Drupal\Tests\taxonomy\FunctionalCode
public function testVocabularyInterface() {
// Visit the main taxonomy administration page.
$this
->drupalGet('admin/structure/taxonomy');
// Create a new vocabulary.
$this
->clickLink('Add vocabulary');
$edit = [];
$vid = mb_strtolower($this
->randomMachineName());
$edit['name'] = $this
->randomMachineName();
$edit['description'] = $this
->randomMachineName();
$edit['vid'] = $vid;
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains("Created new vocabulary {$edit['name']}.");
// Edit the vocabulary.
$this
->drupalGet('admin/structure/taxonomy');
$this
->assertSession()
->pageTextContains($edit['name']);
$this
->assertSession()
->pageTextContains($edit['description']);
$this
->assertSession()
->linkByHrefExists(Url::fromRoute('entity.taxonomy_term.add_form', [
'taxonomy_vocabulary' => $edit['vid'],
])
->toString());
$this
->clickLink('Edit vocabulary');
$edit = [];
$edit['name'] = $this
->randomMachineName();
$edit['description'] = $this
->randomMachineName();
$this
->submitForm($edit, 'Save');
$this
->drupalGet('admin/structure/taxonomy');
$this
->assertSession()
->pageTextContains($edit['name']);
$this
->assertSession()
->pageTextContains($edit['description']);
// Try to submit a vocabulary with a duplicate machine name.
$edit['vid'] = $vid;
$this
->drupalGet('admin/structure/taxonomy/add');
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains('The machine-readable name is already in use. It must be unique.');
// Try to submit an invalid machine name.
$edit['vid'] = '!&^%';
$this
->drupalGet('admin/structure/taxonomy/add');
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains('The machine-readable name must contain only lowercase letters, numbers, and underscores.');
// Ensure that vocabulary titles are escaped properly.
$edit = [];
$edit['name'] = 'Don\'t Panic';
$edit['description'] = $this
->randomMachineName();
$edit['vid'] = 'don_t_panic';
$this
->drupalGet('admin/structure/taxonomy/add');
$this
->submitForm($edit, 'Save');
$site_name = $this
->config('system.site')
->get('name');
$this
->assertSession()
->titleEquals("Don't Panic | {$site_name}");
}