1 admin_bar.test AdminBarCustomizedTestCase::testCustomDisabled()

Test disabled custom links.

File

core/modules/admin_bar/tests/admin_bar.test, line 453
Tests for the Administration bar module.

Class

AdminBarCustomizedTestCase
Tests customized menu links.

Code

function testCustomDisabled() {
  $type = $this->backdropCreateContentType();
  $node = $this->backdropCreateNode(array('type' => $type->type));
  $text = $this->randomName();
  $xpath = $this->buildXPathQuery('//div[@id=:id]//span[contains(@class, "admin-bar-link-text") and contains(text(), :text)]', array(
    ':id' => 'admin-bar',
    ':text' => $text,
  ));

  // Verify that the link does not appear in the menu.
  $this->backdropGet('admin/config/administration/admin_bar');
  $elements = $this->xpath($xpath);
  $this->assertFalse($elements, 'Custom link not found.');

  // Add a custom link to the node to the menu.
  $edit = array(
    'link_path' => 'node/' . $node->nid,
    'link_title' => $text,
    'parent' => 'management:' . $this->queryMlidByPath('admin'),
  );
  $this->backdropPost('admin/structure/menu/manage/management/add', $edit, t('Save'));

  // Verify that the link appears in the menu.
  $cid = 'admin_bar:' . $this->admin_user->uid . ':' . session_id() . ':en';
  $hash = admin_bar_cache_get($cid);
  $this->backdropGet('js/admin_bar/cache/' . $hash);
  $elements = $this->xpath($xpath);
  $this->assertTrue($elements, 'Custom link found.');

  // Disable the link.
  $edit = array(
    'enabled' => FALSE,
  );
  $this->backdropPost('admin/structure/menu/item/' . $this->queryMlidByPath('node/' . $node->nid) . '/edit', $edit, t('Save'));

  // Verify that the disabled link does not appear in the menu.
  $this->backdropGet('admin/config/administration/admin_bar');
  $elements = $this->xpath($xpath);
  $this->assertFalse($elements, 'Disabled custom link not found.');
}