You are here

protected function UbercartTestHelper::assertAjaxHelper in Ubercart 7.3

Helper function to test for text in a drupal ajax response.

Parameters

$ajax: The ajax response to test. Must be an array of ajax commands as returned by drupalPostAjax().

$text: The text to search for.

$message: The assertion message.

$not_exists: TRUE to assert that the text is not present. FALSE (the default) to assert that it is present.

$plain: TRUE to check only the plain-text contents of the 'data' keys of each 'insert' command (i.e. what would be inserted into the page). FALSE to check the complete, json-encoded ajax response.

2 calls to UbercartTestHelper::assertAjaxHelper()
UbercartTestHelper::assertAjaxText in uc_store/tests/uc_store.test
Assert that the specified text is present in the plain text version of the html that would be inserted into the page if this ajax response were executed.
UbercartTestHelper::assertNoAjaxText in uc_store/tests/uc_store.test
Assert that the specified text is not present in the plain text version of the html that would be inserted into the page if this ajax response were executed.

File

uc_store/tests/uc_store.test, line 209
Test functionality provided by uc_store.

Class

UbercartTestHelper
Defines a base helper class for Ubercart tests.

Code

protected function assertAjaxHelper($ajax, $text, $message = FALSE, $not_exists = FALSE, $plain = TRUE) {
  $content = '';
  if ($plain) {
    foreach ($ajax as $command) {
      if ($command['command'] == 'insert' && !empty($command['data']) && is_string($command['data'])) {
        $content .= $command['data'];
      }
    }
    $content = filter_xss($content, array());
  }
  else {
    $content = drupal_json_encode($ajax);
  }
  if (!$message) {
    $message = !$not_exists ? t('"@text" found in ajax response', array(
      '@text' => $text,
    )) : t('"@text" not found in ajax response', array(
      '@text' => $text,
    ));
  }
  $this
    ->assert($not_exists == (strpos($content, $text) === FALSE), $message);
}