function ToolkitGdTest::testResourceDestruction

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Image/ToolkitGdTest.php \Drupal\KernelTests\Core\Image\ToolkitGdTest::testResourceDestruction()

Tests that GD resources are freed from memory.

File

core/tests/Drupal/KernelTests/Core/Image/ToolkitGdTest.php, line 432

Class

ToolkitGdTest
Tests that core image manipulations work properly: scale, resize, rotate, crop, scale and crop, and desaturate.

Namespace

Drupal\KernelTests\Core\Image

Code

public function testResourceDestruction() {
    // Test that an Image object going out of scope releases its GD resource.
    $image = $this->imageFactory
        ->get('core/tests/fixtures/files/image-test.png');
    $res = $image->getToolkit()
        ->getResource();
    $this->assertIsResource($res);
    $image = NULL;
    // @todo In https://www.drupal.org/node/3133236 convert this to
    //   $this->assertIsNotResource($res).
    $this->assertFalse(is_resource($res), 'Image resource was destroyed after losing scope.');
    // Test that 'create_new' operation does not leave orphaned GD resources.
    $image = $this->imageFactory
        ->get('core/tests/fixtures/files/image-test.png');
    $old_res = $image->getToolkit()
        ->getResource();
    // Check if resource has been created successfully.
    $this->assertIsResource($old_res);
    $image->createNew(20, 20);
    $new_res = $image->getToolkit()
        ->getResource();
    // Check if the original resource has been destroyed.
    // @todo In https://www.drupal.org/node/3133236 convert this to
    //   $this->assertIsNotResource($old_res).
    $this->assertFalse(is_resource($old_res));
    // Check if a new resource has been created successfully.
    $this->assertIsResource($new_res);
}

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