You are here

function PHPTestCase::setUp in Drupal 7

Sets up a Drupal site for running functional and integration tests.

Generates a random database prefix and installs Drupal with the specified installation profile in DrupalWebTestCase::$profile into the prefixed database. Afterwards, installs any additional modules specified by the test.

After installation all caches are flushed and several configuration values are reset to the values of the parent site executing the test, since the default values may be incompatible with the environment in which tests are being executed.

Parameters

...: List of modules to enable for the duration of the test. This can be either a single array or a variable number of string arguments.

Overrides DrupalWebTestCase::setUp

See also

DrupalWebTestCase::prepareDatabasePrefix()

DrupalWebTestCase::changeDatabasePrefix()

DrupalWebTestCase::prepareEnvironment()

File

modules/php/php.test, line 14
Tests for php.module.

Class

PHPTestCase
Defines a base PHP test case class.

Code

function setUp() {
  parent::setUp('php');

  // Create and login admin user.
  $admin_user = $this
    ->drupalCreateUser(array(
    'administer filters',
  ));
  $this
    ->drupalLogin($admin_user);

  // Verify that the PHP code text format was inserted.
  $php_format_id = 'php_code';
  $this->php_code_format = filter_format_load($php_format_id);
  $this
    ->assertEqual($this->php_code_format->name, 'PHP code', 'PHP code text format was created.');

  // Verify that the format has the PHP code filter enabled.
  $filters = filter_list_format($php_format_id);
  $this
    ->assertTrue($filters['php_code']->status, 'PHP code filter is enabled.');

  // Verify that the format exists on the administration page.
  $this
    ->drupalGet('admin/config/content/formats');
  $this
    ->assertText('PHP code', 'PHP code text format was created.');

  // Verify that anonymous and authenticated user roles do not have access.
  $this
    ->drupalGet('admin/config/content/formats/' . $php_format_id);
  $this
    ->assertFieldByName('roles[' . DRUPAL_ANONYMOUS_RID . ']', FALSE, 'Anonymous users do not have access to PHP code format.');
  $this
    ->assertFieldByName('roles[' . DRUPAL_AUTHENTICATED_RID . ']', FALSE, 'Authenticated users do not have access to PHP code format.');
}