function ToolkitTestBase::assertToolkitOperationsCalled

Same name in this branch
  1. 8.9.x core/modules/system/src/Tests/Image/ToolkitTestBase.php \Drupal\system\Tests\Image\ToolkitTestBase::assertToolkitOperationsCalled()
Same name in other branches
  1. 9 core/tests/Drupal/FunctionalTests/Image/ToolkitTestBase.php \Drupal\FunctionalTests\Image\ToolkitTestBase::assertToolkitOperationsCalled()

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.

13 calls to ToolkitTestBase::assertToolkitOperationsCalled()
ImageEffectsTest::testConvertEffect in core/modules/image/tests/src/Functional/ImageEffectsTest.php
Tests the ConvertImageEffect plugin.
ImageEffectsTest::testCropEffect in core/modules/image/tests/src/Functional/ImageEffectsTest.php
Test the image_crop_effect() function.
ImageEffectsTest::testDesaturateEffect in core/modules/image/tests/src/Functional/ImageEffectsTest.php
Test the image_desaturate_effect() function.
ImageEffectsTest::testResizeEffect in core/modules/image/tests/src/Functional/ImageEffectsTest.php
Test the image_resize_effect() function.
ImageEffectsTest::testRotateEffect in core/modules/image/tests/src/Functional/ImageEffectsTest.php
Test the image_rotate_effect() function.

... See full list

File

core/tests/Drupal/FunctionalTests/Image/ToolkitTestBase.php, line 82

Class

ToolkitTestBase
Base class for image manipulation testing.

Namespace

Drupal\FunctionalTests\Image

Code

public function assertToolkitOperationsCalled(array $expected) {
    // If one of the image operations is expected, apply should be expected as
    // well.
    $operations = [
        'resize',
        'rotate',
        'crop',
        'desaturate',
        'create_new',
        'scale',
        'scale_and_crop',
        'my_operation',
        'convert',
    ];
    if (count(array_intersect($expected, $operations)) > 0 && !in_array('apply', $expected)) {
        $expected[] = 'apply';
    }
    // Determine which operations were called.
    $actual = array_keys(array_filter($this->imageTestGetAllCalls()));
    // Determine if there were any expected that were not called.
    $uncalled = array_diff($expected, $actual);
    if (count($uncalled)) {
        $this->assertTrue(FALSE, new FormattableMarkup('Expected operations %expected to be called but %uncalled was not called.', [
            '%expected' => implode(', ', $expected),
            '%uncalled' => implode(', ', $uncalled),
        ]));
    }
    else {
        $this->assertTrue(TRUE, new FormattableMarkup('All the expected operations were called: %expected', [
            '%expected' => implode(', ', $expected),
        ]));
    }
    // Determine if there were any unexpected calls.
    // If all unexpected calls are operations and apply was expected, we do not
    // count it as an error.
    $unexpected = array_diff($actual, $expected);
    if (count($unexpected) && (!in_array('apply', $expected) || count(array_intersect($unexpected, $operations)) !== count($unexpected))) {
        $this->assertTrue(FALSE, new FormattableMarkup('Unexpected operations were called: %unexpected.', [
            '%unexpected' => implode(', ', $unexpected),
        ]));
    }
    else {
        $this->assertTrue(TRUE, 'No unexpected operations were called.');
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.