| 1 admin_bar.test | AdminBarDynamicLinksTestCase::testNode() | 
Tests node type links.
File
- core/modules/ admin_bar/ tests/ admin_bar.test, line 277 
- Tests for the Administration bar module.
Class
- AdminBarDynamicLinksTestCase
- Tests appearance, localization, and escaping of dynamic links.
Code
function testNode() {
  $this->backdropCreateContentType(array('type' => 'post', 'name' => 'Post'));
  // Create a content-type with special characters.
  $this->backdropCreateContentType(array('type' => 'special', 'name' => 'Cool & Special'));
  $permissions = $this->basePermissions + array(
    'administer content types',
    'create post content',
    'create special content',
  );
  $this->admin_user = $this->backdropCreateUser($permissions);
  $this->backdropLogin($this->admin_user);
  // Verify that dynamic links are displayed.
  $cid = 'admin_bar:' . $this->admin_user->uid . ':' . session_id() . ':en';
  $hash = admin_bar_cache_get($cid);
  $this->backdropGet('js/admin_bar/cache/' . $hash);
  $this->assertElementByXPath('//div[@id="admin-bar"]', array(), t('Administration bar found.'));
  $this->assertElementByXPath('//div[@id="admin-bar"]//a[contains(@href, :path)]', array(':path' => 'admin/structure/types'), "Structure » Content types link found.");
  // Verify link title output escaping.
  $this->assertNoRaw('Cool & Special');
  $this->assertRaw(check_plain('Cool & Special'));
  // Verify Manage content type links.
  $links = array(
    'admin/structure/types/manage/post' => 'Post',
    'admin/structure/types/manage/special' => 'Cool & Special',
  );
  foreach ($links as $path => $title) {
    $this->assertElementByXPath('//div[@id="admin-bar"]//a[contains(@href, :path)]//*[contains(text(), :text)]', array(
      ':path' => $path,
      ':text' => $title,
    ), "Structure » Content types » $title link found.");
  }
  // Verify Add content links.
  $links = array(
    'node/add/post' => 'Post',
    'node/add/special' => 'Cool & Special',
  );
  foreach ($links as $path => $title) {
    $this->assertElementByXPath('//div[@id="admin-bar"]//a[contains(@href, :path)]//*[contains(text(), :text)]', array(
      ':path' => $path,
      ':text' => $title,
    ), "Add content » $title link found.");
  }
  // Remove the node/add items from the management menu and check that the add
  // links are still added to the menu.
  module_load_include('inc', 'admin_bar');
  $link = db_query("SELECT * FROM {menu_links} WHERE router_path LIKE 'node/add%' AND module = 'system'")->fetchAssoc();
  $link = menu_link_load($link['mlid']);
  $link['menu_name'] = 'main-menu';
  menu_link_save($link);
  // Delete the special type and check that the link disappears.
  $this->backdropPost('admin/structure/types/manage/special/delete', array(), t('Delete'));
  $this->backdropGet('js/admin_bar/cache/' . $hash);
  $this->assertElementByXPath('//div[@id="admin-bar"]//a[contains(@href, :path)]//*[contains(text(), :text)]', array(
    ':path' => 'node/add/post',
    ':text' => 'Post',
  ), "Add content » Post link found after moving Add Content into a different menu.");
  $this->assertNoElementByXPath('//div[@id="admin-bar"]//a[contains(@href, :path)]//*[contains(text(), :text)]', array(
    ':path' => 'node/add/special',
    ':text' => 'Cool & Special',
  ), "Add content » Cool & Special link no longer present after deleting the content type.");
}
