class AdminMenuWebTestCase

  1. nittany7 modules/contrib/admin_menu/tests/admin_menu.test AdminMenuWebTestCase
  2. cis7 modules/contrib/admin_menu/tests/admin_menu.test AdminMenuWebTestCase
  3. mooc7 modules/contrib/admin_menu/tests/admin_menu.test AdminMenuWebTestCase

Base class for all administration menu web test cases.

Hierarchy

Expanded class hierarchy of AdminMenuWebTestCase

Members

Contains filters are case sensitive
Namesort descending Modifiers Type Description
AdminMenuWebTestCase::$basePermissions protected property
AdminMenuWebTestCase::$profile protected property
AdminMenuWebTestCase::assertElementByXPath protected function Check that an element exists in HTML markup.
AdminMenuWebTestCase::assertLinkTrailByTitle protected function Asserts that links appear in the menu in a specified trail.
AdminMenuWebTestCase::assertNoElementByXPath protected function Check that an element does not exist in HTML markup.
AdminMenuWebTestCase::assertNoLinkTrailByTitle protected function Asserts that no link appears in the menu for a specified trail.
AdminMenuWebTestCase::setUp function

File

modules/contrib/admin_menu/tests/admin_menu.test, line 11
Tests for the Administration menu module.

View source
class AdminMenuWebTestCase extends DrupalWebTestCase {
  protected $profile = 'testing';

  protected $basePermissions = array(
    'system' => 'access administration pages',
    'admin_menu' => 'access administration menu',
  );

  function setUp() {
    // Enable admin menu module and any other modules.
    $modules = func_get_args();
    $modules = isset($modules[0]) ? $modules[0] : $modules;
    $modules[] = 'admin_menu';
    parent::setUp($modules);

    // Disable client-side caching.
    variable_set('admin_menu_cache_client', FALSE);
    // Disable Clean URLs to ensure drupal.org testbot compatibility.
    variable_set('clean_url', 0);
  }

  /**
   * Check that an element exists in HTML markup.
   *
   * @param $xpath
   *   An XPath expression.
   * @param array $arguments
   *   (optional) An associative array of XPath replacement tokens to pass to
   *   DrupalWebTestCase::buildXPathQuery().
   * @param $message
   *   The message to display along with the assertion.
   * @param $group
   *   The type of assertion - examples are "Browser", "PHP".
   *
   * @return
   *   TRUE if the assertion succeeded, FALSE otherwise.
   */
  protected function assertElementByXPath($xpath, array $arguments = array(), $message, $group = 'Other') {
    $elements = $this->xpath($xpath, $arguments);
    return $this->assertTrue(!empty($elements[0]), $message, $group);
  }

  /**
   * Check that an element does not exist in HTML markup.
   *
   * @param $xpath
   *   An XPath expression.
   * @param array $arguments
   *   (optional) An associative array of XPath replacement tokens to pass to
   *   DrupalWebTestCase::buildXPathQuery().
   * @param $message
   *   The message to display along with the assertion.
   * @param $group
   *   The type of assertion - examples are "Browser", "PHP".
   *
   * @return
   *   TRUE if the assertion succeeded, FALSE otherwise.
   */
  protected function assertNoElementByXPath($xpath, array $arguments = array(), $message, $group = 'Other') {
    $elements = $this->xpath($xpath, $arguments);
    return $this->assertTrue(empty($elements), $message, $group);
  }

  /**
   * Asserts that links appear in the menu in a specified trail.
   *
   * @param array $trail
   *   A list of menu link titles to assert in the menu.
   */
  protected function assertLinkTrailByTitle(array $trail) {
    $xpath = array();
    $args = array();
    $message = '';
    foreach ($trail as $i => $title) {
      $xpath[] = '/li/a[text()=:title' . $i . ']';
      $args[':title' . $i] = $title;
      $message .= ($i ? ' » ' : '') . check_plain($title);
    }
    $xpath = '//div[@id="admin-menu"]/div/ul' . implode('/parent::li/ul', $xpath);
    $this->assertElementByXPath($xpath, $args, $message . ' link found.');
  }

  /**
   * Asserts that no link appears in the menu for a specified trail.
   *
   * @param array $trail
   *   A list of menu link titles to assert in the menu.
   */
  protected function assertNoLinkTrailByTitle(array $trail) {
    $xpath = array();
    $args = array();
    $message = '';
    foreach ($trail as $i => $title) {
      $xpath[] = '/li/a[text()=:title' . $i . ']';
      $args[':title' . $i] = $title;
      $message .= ($i ? ' » ' : '') . check_plain($title);
    }
    $xpath = '//div[@id="admin-menu"]/div/ul' . implode('/parent::li/ul', $xpath);
    $this->assertNoElementByXPath($xpath, $args, $message . ' link not found.');
  }
}