1 image.test ImageToolkitTestCase::assertToolkitOperationsCalled(array $expected)

Assert that all of the specified image toolkit operations were called exactly once once, other values result in failure.

Parameters

$expected: Array with string containing with the operation name, e.g. 'load', 'save', 'crop', etc.

File

core/modules/simpletest/tests/image.test, line 50
Tests for core image handling API.

Class

ImageToolkitTestCase
Base class for image manipulation testing.

Code

function assertToolkitOperationsCalled(array $expected) {
  // Determine which operations were called.
  $actual = array_keys(array_filter(image_test_get_all_calls()));

  // Determine if there were any expected that were not called.
  $uncalled = array_diff($expected, $actual);
  if (count($uncalled)) {
    $this->assertTrue(FALSE, format_string('Expected operations %expected to be called but %uncalled was not called.', array('%expected' => implode(', ', $expected), '%uncalled' => implode(', ', $uncalled))));
  }
  else {
    $this->assertTrue(TRUE, format_string('All the expected operations were called: %expected', array('%expected' => implode(', ', $expected))));
  }

  // Determine if there were any unexpected calls.
  $unexpected = array_diff($actual, $expected);
  if (count($unexpected)) {
    $this->assertTrue(FALSE, format_string('Unexpected operations were called: %unexpected.', array('%unexpected' => implode(', ', $unexpected))));
  }
  else {
    $this->assertTrue(TRUE, 'No unexpected operations were called.');
  }
}