function ImageTest::testChmodFails

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Image/ImageTest.php \Drupal\Tests\Core\Image\ImageTest::testChmodFails()
  2. 8.9.x core/tests/Drupal/Tests/Core/Image/ImageTest.php \Drupal\Tests\Core\Image\ImageTest::testChmodFails()
  3. 11.x core/tests/Drupal/Tests/Core/Image/ImageTest.php \Drupal\Tests\Core\Image\ImageTest::testChmodFails()

Tests \Drupal\Core\Image\Image::save().

File

core/tests/Drupal/Tests/Core/Image/ImageTest.php, line 255

Class

ImageTest
Tests the image class.

Namespace

Drupal\Tests\Core\Image

Code

public function testChmodFails() : void {
    $this->getTestImage();
    // This will fail if save() method isn't called on the toolkit.
    $toolkit = $this->getToolkitMock();
    $toolkit->expects($this->once())
        ->method('save')
        ->willReturn(TRUE);
    $image = new Image($toolkit, $this->image
        ->getSource());
    $file_system = $this->prophesize(FileSystemInterface::class);
    $file_system->chmod($this->image
        ->getSource())
        ->willReturn(FALSE);
    $container = $this->getMockBuilder('Symfony\\Component\\DependencyInjection\\ContainerBuilder')
        ->onlyMethods([
        'get',
    ])
        ->getMock();
    $container->expects($this->once())
        ->method('get')
        ->with('file_system')
        ->willReturn($file_system->reveal());
    \Drupal::setContainer($container);
    $this->assertFalse($image->save());
}

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