1.20.x admin_bar.test AdminBarDynamicLinksTestCase::testNode()

Tests node type links.

File

modules/admin_bar/tests/admin_bar.test, line 256
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) and text()=:title]', array(
      ':path' => $path,
      ':title' => $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) and text()=:title]', array(
      ':path' => $path,
      ':title' => $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) and text()=:title]', array(
    ':path' => 'node/add/post',
    ':title' => 'Post',
  ), "Add content » Post link found after moving Add Content into a different menu.");
  $this->assertNoElementByXPath('//div[@id="admin-bar"]//a[contains(@href, :path) and text()=:title]', array(
    ':path' => 'node/add/special',
    ':title' => 'Cool & Special',
  ), "Add content » Cool & Special link no longer present after deleting the content type.");
}