You are here

public function TaxonomyMenuUnitTest::testTaxonomyMenuCustomMenu in Taxonomy menu 8

Tests creation of menu links in a custom menu.

File

lib/Drupal/taxonomy_menu/Tests/TaxonomyMenuUnitTest.php, line 149
Contains \Drupal\taxonomy_menu\Tests\TaxonomyMenuUnitTest.

Class

TaxonomyMenuUnitTest
Tests for taxonomy vocabulary functions.

Namespace

Drupal\taxonomy_menu\Tests

Code

public function testTaxonomyMenuCustomMenu() {
  $vocabulary = $this->vocabulary;
  $terms = $this->terms_hierarchy;
  $custom_menu_name = $this
    ->randomName(16);
  $menu_machine_name = substr(hash('sha256', $custom_menu_name), 0, MENU_MAX_MENU_NAME_LENGTH_UI);

  // Submit the menu creation form.
  $menu_edit = array(
    'id' => $menu_machine_name,
    'description' => '',
    'label' => $custom_menu_name,
  );
  $this
    ->drupalPostForm('admin/structure/menu/add', $menu_edit, t('Save'));
  $this
    ->assertResponse(200);

  // Submit the vocabulary edit form.
  $vocab_edit = array();
  $vocab_edit['taxonomy_menu[vocab_parent]'] = $menu_machine_name . ':0';
  $this
    ->drupalPostForm('admin/structure/taxonomy/manage/' . $vocabulary
    ->id(), $vocab_edit, 'Save');
  $this
    ->assertResponse(200);

  // Check that the menu links were created in the custom menu.
  $this
    ->assertEqualNumberTermsMenuLinks(count($terms), $vocabulary, $menu_machine_name);
}