function PhpTestBase::setUp

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 Drupal\simpletest\WebTestBase::$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 WebTestBase::setUp

See also

Drupal\simpletest\WebTestBase::prepareDatabasePrefix()

Drupal\simpletest\WebTestBase::changeDatabasePrefix()

Drupal\simpletest\WebTestBase::prepareEnvironment()

File

drupal/core/modules/php/lib/Drupal/php/Tests/PhpTestBase.php, line 26
Definition of Drupal\php\Tests\PhpTestBase.

Class

PhpTestBase
Defines a base PHP test case class.

Namespace

Drupal\php\Tests

Code

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

  // Create Basic page node type.
  $this
    ->drupalCreateContentType(array(
    'type' => 'page',
    'name' => 'Basic page',
  ));

  // 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.');
}