You are here

extlink.test in External Links 7

External Link tests.

File

tests/extlink.test
View source
<?php

/**
 * @file
 * External Link tests.
 */

/**
 * Base class for External Link tests.
 *
 * Provides common setup stuff and various helper functions.
 */
class ExtlinkBaseWebTestCase extends DrupalWebTestCase {

  /**
   * User with various administrative permissions.
   *
   * @var Drupaluser
   */
  protected $adminUser;

  /**
   * Normal visitor with limited permissions.
   *
   * @var Drupaluser
   */
  protected $normalUser;

  /**
   * Drupal path of the (general) External Links admin page.
   */
  const EXTLINK_ADMIN_PATH = 'admin/config/user-interface/extlink';

  /**
   * Set up tests.
   */
  public function setUp() {

    // Enable any module that you will need in your tests.
    parent::setUp('extlink');

    // Create a normal user without permission.
    $permissions = array(
      'access comments',
      'post comments',
      'skip comment approval',
      'access content',
      'create page content',
      'edit own page content',
    );
    $this->normalUser = $this
      ->drupalCreateUser($permissions);

    // Create an admin user.
    $permissions[] = 'administer external link';
    $this->adminUser = $this
      ->drupalCreateUser($permissions);
  }

}

/**
 * Test Case for External Links administration functionality.
 */
class ExtlinkAdminTestCase extends ExtlinkBaseWebTestCase {

  /**
   * Get test info.
   */
  public static function getInfo() {
    return array(
      'name' => t('External Links administration functionality'),
      'description' => t('Testing of the External Links administration interface and functionality.'),
      'group' => t('External Links'),
    );
  }

  /**
   * Test access to the admin pages.
   */
  public function testAdminAccess() {
    $this
      ->drupalLogin($this->normalUser);
    $this
      ->drupalGet(self::EXTLINK_ADMIN_PATH);
    $this
      ->assertText(t('Access denied'), 'Normal users should not be able to access the External Links admin pages', 'External Links');
    $this
      ->drupalLogin($this->adminUser);
    $this
      ->drupalGet(self::EXTLINK_ADMIN_PATH);
    $this
      ->assertNoText(t('Access denied'), 'Admin users should be able to access the External Links admin pages', 'External Links');
  }

}

Classes

Namesort descending Description
ExtlinkAdminTestCase Test Case for External Links administration functionality.
ExtlinkBaseWebTestCase Base class for External Link tests.