You are here

public function TaxonomyMenuConfigurationTest::testTaxonomyMenuFlattenOption in Taxonomy menu 8

Tests Taxonommy Menu "Flatten" option.

File

lib/Drupal/taxonomy_menu/Tests/TaxonomyMenuConfigurationTest.php, line 162
Contains \Drupal\taxonomy_menu\Tests\TaxonomyMenuConfigurationTest.

Class

TaxonomyMenuConfigurationTest
Tests Taxonomy menu configuration options.

Namespace

Drupal\taxonomy_menu\Tests

Code

public function testTaxonomyMenuFlattenOption() {
  $vid = $this->vocabulary
    ->id();

  // Set settings.
  $edit = array(
    'taxonomy_menu[vocab_parent]' => 'main:0',
    'taxonomy_menu[options_structure][flat]' => TRUE,
  );
  $this
    ->drupalPostForm('admin/structure/taxonomy/manage/' . $vid, $edit, t('Save'));

  // Assert that all of the menu links have no children with the root being
  // the menu.
  $query = db_select('menu_links', 'ml');
  $query
    ->join('taxonomy_menu', 'tm', 'ml.mlid = tm.mlid');
  $query
    ->fields('ml');
  $query
    ->condition('tm.vid', $this->vocabulary
    ->id())
    ->condition('ml.menu_name', 'main')
    ->condition('ml.module', 'taxonomy_menu')
    ->condition('ml.has_children', 0)
    ->condition('ml.plid', 0);
  $row_count = $query
    ->countQuery()
    ->execute()
    ->fetchField();
  $this
    ->assertEqual(count($this->terms_hierarchy), $row_count);

  // Assert that all of the menu links have no children with the root being
  // a menu item.
  $menu_link = entity_create('menu_link', array(
    'menu_name' => 'main',
    'weight' => 0,
    'link_title' => 'test',
    'link_path' => '<front>',
    'module' => 'taxonomy_menu',
  ));
  menu_link_save($menu_link);
  $mlid = entity_load_by_uuid('menu_link', $menu_link->uuid)->mlid;
  menu_cache_clear_all('main');
  $edit = array(
    'taxonomy_menu[vocab_parent]' => 'main:' . $mlid,
    'taxonomy_menu[options_structure][flat]' => TRUE,
  );
  $this
    ->drupalPostForm('admin/structure/taxonomy/manage/' . $vid, $edit, t('Save'));
  $query = db_select('menu_links', 'ml');
  $query
    ->join('taxonomy_menu', 'tm', 'ml.mlid = tm.mlid');
  $query
    ->fields('ml');
  $query
    ->condition('tm.vid', $this->vocabulary
    ->id())
    ->condition('ml.menu_name', 'main')
    ->condition('ml.module', 'taxonomy_menu')
    ->condition('ml.has_children', 0)
    ->condition('ml.plid', $mlid);
  $row_count = $query
    ->countQuery()
    ->execute()
    ->fetchField();
  $this
    ->assertEqual(count($this->terms_hierarchy), $row_count);
}