function ToolkitTestTrait::assertToolkitOperationsCalled

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Traits/Core/Image/ToolkitTestTrait.php \Drupal\Tests\Traits\Core\Image\ToolkitTestTrait::assertToolkitOperationsCalled()
  2. 11.x core/tests/Drupal/Tests/Traits/Core/Image/ToolkitTestTrait.php \Drupal\Tests\Traits\Core\Image\ToolkitTestTrait::assertToolkitOperationsCalled()

Assert that all of the specified image toolkit operations were called once.

Parameters

string[] $expected: String array containing the operation names, e.g. load, save, crop, etc.

7 calls to ToolkitTestTrait::assertToolkitOperationsCalled()
ToolkitTest::testApply in core/tests/Drupal/KernelTests/Core/Image/ToolkitTest.php
Tests the 'apply' method.
ToolkitTest::testApplyNoParameters in core/tests/Drupal/KernelTests/Core/Image/ToolkitTest.php
Tests the 'apply' method without parameters.
ToolkitTest::testFailingOperation in core/tests/Drupal/KernelTests/Core/Image/ToolkitTest.php
Tests calling a failing image operation plugin.
ToolkitTest::testGetAvailableToolkits in core/tests/Drupal/KernelTests/Core/Image/ToolkitTest.php
Tests that the toolkit manager only returns available toolkits.
ToolkitTest::testLoad in core/tests/Drupal/KernelTests/Core/Image/ToolkitTest.php
Tests Image's methods.

... See full list

File

core/tests/Drupal/Tests/Traits/Core/Image/ToolkitTestTrait.php, line 34

Class

ToolkitTestTrait
Provides common methods for image toolkit kernel tests.

Namespace

Drupal\Tests\Traits\Core\Image

Code

public function assertToolkitOperationsCalled(array $expected) : void {
    // 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',
        'failing',
    ];
    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);
    $this->assertEmpty($uncalled);
    // 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);
    $assert = !(count($unexpected) && (!in_array('apply', $expected) || count(array_intersect($unexpected, $operations)) !== count($unexpected)));
    $this->assertTrue($assert);
}

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