You are here

public function TaxonomyMenuConfigurationTest::testTaxonomyMenuExpandedOption in Taxonomy menu 8

Tests Taxonommy Menu expand option.

File

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

Class

TaxonomyMenuConfigurationTest
Tests Taxonomy menu configuration options.

Namespace

Drupal\taxonomy_menu\Tests

Code

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

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

  // Build the base query.
  $base_query = db_select('menu_links', 'ml');
  $base_query
    ->join('taxonomy_menu', 'tm', 'ml.mlid = tm.mlid');
  $base_query
    ->fields('ml')
    ->condition('tm.vid', $this->vocabulary
    ->id())
    ->condition('ml.module', 'taxonomy_menu');

  // Assert that menu links are expanded.
  $query = $base_query
    ->condition('ml.expanded', TRUE);
  $row_count = $query
    ->countQuery()
    ->execute()
    ->fetchField();
  $this
    ->assertEqual(count($this->terms_hierarchy), $row_count);

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

  // Assert that menu links are not expanded anymore.
  $query = $base_query
    ->condition('ml.expanded', FALSE);
  $row_count = $query
    ->countQuery()
    ->execute()
    ->fetchField();
  $this
    ->assertEqual(0, $row_count);
}