You are here

protected function TestBase::assert in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/simpletest/src/TestBase.php \Drupal\simpletest\TestBase::assert()

Internal helper: stores the assert.

Parameters

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

string|\Drupal\Component\Render\MarkupInterface $message: (optional) A message to display with the assertion. Do not translate messages: use \Drupal\Component\Utility\SafeMarkup::format() 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.

39 calls to TestBase::assert()
AggregatorRenderingTest::testBlockLinks in core/modules/aggregator/src/Tests/AggregatorRenderingTest.php
Adds a feed block to the page and checks its links.
AlterTest::testExecutionOrder in core/modules/system/src/Tests/Form/AlterTest.php
Tests execution order of hook_form_alter() and hook_form_FORM_ID_alter().
ConfigExportUITest::testExport in core/modules/config/src/Tests/ConfigExportUITest.php
Tests export of configuration.
ConfigInstallProfileUnmetDependenciesTest::error in core/modules/config/src/Tests/ConfigInstallProfileUnmetDependenciesTest.php
Override the error method so we can test for the expected exception.
DefaultViewsTest::testDefaultViews in core/modules/views/src/Tests/DefaultViewsTest.php
Test that all Default views work as expected.

... See full list

File

core/modules/simpletest/src/TestBase.php, line 396
Contains \Drupal\simpletest\TestBase.

Class

TestBase
Base class for Drupal tests.

Namespace

Drupal\simpletest

Code

protected function assert($status, $message = '', $group = 'Other', array $caller = NULL) {
  if ($message instanceof MarkupInterface) {
    $message = (string) $message;
  }

  // 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.
  $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.
  $message_id = $this
    ->storeAssertion($assertion);
  $assertion['message_id'] = $message_id;
  $this->assertions[] = $assertion;

  // We do not use a ternary operator here to allow a breakpoint on
  // test failure.
  if ($status == 'pass') {
    return TRUE;
  }
  else {
    if ($this->dieOnFail && ($status == 'fail' || $status == 'exception')) {
      exit(1);
    }
    return FALSE;
  }
}