You are here

function VocabularyUiTest::testVocabularyInterface in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/taxonomy/src/Tests/VocabularyUiTest.php \Drupal\taxonomy\Tests\VocabularyUiTest::testVocabularyInterface()

Create, edit and delete a vocabulary via the user interface.

File

core/modules/taxonomy/src/Tests/VocabularyUiTest.php, line 39
Contains \Drupal\taxonomy\Tests\VocabularyUiTest.

Class

VocabularyUiTest
Tests the taxonomy vocabulary interface.

Namespace

Drupal\taxonomy\Tests

Code

function testVocabularyInterface() {

  // Visit the main taxonomy administration page.
  $this
    ->drupalGet('admin/structure/taxonomy');

  // Create a new vocabulary.
  $this
    ->clickLink(t('Add vocabulary'));
  $edit = array();
  $vid = Unicode::strtolower($this
    ->randomMachineName());
  $edit['name'] = $this
    ->randomMachineName();
  $edit['description'] = $this
    ->randomMachineName();
  $edit['vid'] = $vid;
  $this
    ->drupalPostForm(NULL, $edit, t('Save'));
  $this
    ->assertRaw(t('Created new vocabulary %name.', array(
    '%name' => $edit['name'],
  )), 'Vocabulary created successfully.');

  // Edit the vocabulary.
  $this
    ->drupalGet('admin/structure/taxonomy');
  $this
    ->assertText($edit['name'], 'Vocabulary found in the vocabulary overview listing.');
  $this
    ->assertLinkByHref(Url::fromRoute('entity.taxonomy_term.add_form', [
    'taxonomy_vocabulary' => $edit['vid'],
  ])
    ->toString());
  $this
    ->clickLink(t('Edit vocabulary'));
  $edit = array();
  $edit['name'] = $this
    ->randomMachineName();
  $this
    ->drupalPostForm(NULL, $edit, t('Save'));
  $this
    ->drupalGet('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['vid'] = $vid;
  $this
    ->drupalPostForm('admin/structure/taxonomy/add', $edit, t('Save'));
  $this
    ->assertText(t('The machine-readable name is already in use. It must be unique.'));

  // Try to submit an invalid machine name.
  $edit['vid'] = '!&^%';
  $this
    ->drupalPostForm('admin/structure/taxonomy/add', $edit, t('Save'));
  $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
    ->randomMachineName();
  $edit['vid'] = 'don_t_panic';
  $this
    ->drupalPostForm('admin/structure/taxonomy/add', $edit, t('Save'));
  $site_name = $this
    ->config('system.site')
    ->get('name');
  $this
    ->assertTitle(t('Don\'t Panic | @site-name', array(
    '@site-name' => $site_name,
  )), 'The page title contains the escaped character.');
  $this
    ->assertNoTitle(t('Don't Panic | @site-name', array(
    '@site-name' => $site_name,
  )), 'The page title does not contain an encoded character.');
}