You are here

public function TaxonomyMenuFunctionalTest::testTaxonomyMenuTermInterface in Taxonomy menu 8

Saves, edits and deletes a term using the user interface.

File

lib/Drupal/taxonomy_menu/Tests/TaxonomyMenuFunctionalTest.php, line 102
Contains \Drupal\taxonomy_menu\Tests\TaxonomyMenuFunctionalTest.

Class

TaxonomyMenuFunctionalTest
Tests the taxonomy vocabulary interface.

Namespace

Drupal\taxonomy_menu\Tests

Code

public function testTaxonomyMenuTermInterface() {
  $menu_name = 'main';

  // Create a taxonomy menu.
  $vocab_settings['taxonomy_menu[vocab_parent]'] = $menu_name . ':0';
  $this
    ->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary
    ->id(), $vocab_settings, t('Save'));

  // Create a new term from the interface.
  $term_settings = array(
    'name[0][value]' => $this
      ->randomName(12),
    'description[0][value]' => $this
      ->randomName(100),
  );
  $this
    ->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary
    ->id() . '/add', $term_settings, t('Save'));
  $terms = taxonomy_term_load_multiple_by_name($term_settings['name[0][value]']);
  $term = reset($terms);
  $this
    ->assertRaw(t('Added term %term to taxonomy menu %menu_name.', array(
    '%term' => $term_settings['name[0][value]'],
    '%menu_name' => $menu_name,
  )));

  // Update an existing term from the interface.
  $new_term_settings = array(
    'name[0][value]' => $this
      ->randomName(12),
    'description[0][value]' => $this
      ->randomName(100),
  );
  $this
    ->drupalPostForm('taxonomy/term/' . $term
    ->id() . '/edit', $new_term_settings, t('Save'));
  $this
    ->assertRaw(t('Updated term %term in taxonomy menu %menu_name.', array(
    '%term' => $new_term_settings['name[0][value]'],
    '%menu_name' => $menu_name,
  )));

  // Delete an existing term from the interface.
  $this
    ->clickLink(t('Delete'));
  $this
    ->drupalPostForm(NULL, NULL, t('Delete'));
  $this
    ->assertRaw(t('Deleted term %term from taxonomy menu %menu_name.', array(
    '%term' => $new_term_settings['name[0][value]'],
    '%menu_name' => $menu_name,
  )));
}