protected function TestBase::assert

Internal helper: stores the assert.

Parameters

$status: Can be 'pass', 'fail', 'exception'. TRUE is a synonym for 'pass', FALSE for 'fail'.

$message: (optional) A message to display with the assertion. Do not translate messages: use format_string() to embed variables in the message text, not t(). If left blank, a default message will be displayed.

$group: (optional) The group this message is in, which is displayed in a column in test output. Use 'Debug' to indicate this is debugging output. Do not translate this string. Defaults to 'Other'; most tests do not override this default.

$caller: By default, the assert comes from a function whose name starts with 'test'. Instead, you can specify where this assert originates from by passing in an associative array as $caller. Key 'file' is the name of the source file, 'line' is the line number and 'function' is the caller function itself.

47 calls to TestBase::assert()
AggregatorRenderingTest::testBlockLinks in drupal/core/modules/aggregator/lib/Drupal/aggregator/Tests/AggregatorRenderingTest.php
Add a feed block to the page and checks its links.
AlterTest::testExecutionOrder in drupal/core/modules/system/lib/Drupal/system/Tests/Form/AlterTest.php
Tests execution order of hook_form_alter() and hook_form_FORM_ID_alter().
BackendChainImplementationUnitTest::testGetMultiple in drupal/core/modules/system/lib/Drupal/system/Tests/Cache/BackendChainImplementationUnitTest.php
Test the get multiple feature.
BackendChainImplementationUnitTest::testNotEmptyIfOneBackendHasTheKey in drupal/core/modules/system/lib/Drupal/system/Tests/Cache/BackendChainImplementationUnitTest.php
Test that the chain is not empty when at least one backend has data.
CascadingStylesheetsTest::testAlter in drupal/core/modules/system/lib/Drupal/system/Tests/Common/CascadingStylesheetsTest.php
Tests Locale module's CSS Alter to include RTL overrides.

... See full list

File

drupal/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php, line 182
Definition of Drupal\simpletest\TestBase.

Class

TestBase
Base class for Drupal tests.

Namespace

Drupal\simpletest

Code

protected function assert($status, $message = '', $group = 'Other', array $caller = NULL) {

  // Convert boolean status to string status.
  if (is_bool($status)) {
    $status = $status ? 'pass' : 'fail';
  }

  // Increment summary result counter.
  $this->results['#' . $status]++;

  // Get the function information about the call to the assertion method.
  if (!$caller) {
    $caller = $this
      ->getAssertionCall();
  }

  // Creation assertion array that can be displayed while tests are running.
  $this->assertions[] = $assertion = array(
    'test_id' => $this->testId,
    'test_class' => get_class($this),
    'status' => $status,
    'message' => $message,
    'message_group' => $group,
    'function' => $caller['function'],
    'line' => $caller['line'],
    'file' => $caller['file'],
  );

  // Store assertion for display after the test has completed.
  self::getDatabaseConnection()
    ->insert('simpletest')
    ->fields($assertion)
    ->execute();

  // We do not use a ternary operator here to allow a breakpoint on
  // test failure.
  if ($status == 'pass') {
    return TRUE;
  }
  else {
    return FALSE;
  }
}