class ImageStyleGenerationTraitTest in Flysystem 3.x
Same name and namespace in other branches
- 8 tests/src/Unit/Plugin/ImageStyleGenerationTraitTest.php \Drupal\Tests\flysystem\Unit\Plugin\ImageStyleGenerationTraitTest
- 2.0.x tests/src/Unit/Plugin/ImageStyleGenerationTraitTest.php \Drupal\Tests\flysystem\Unit\Plugin\ImageStyleGenerationTraitTest
- 3.0.x tests/src/Unit/Plugin/ImageStyleGenerationTraitTest.php \Drupal\Tests\flysystem\Unit\Plugin\ImageStyleGenerationTraitTest
@coversDefaultClass \Drupal\flysystem\Plugin\ImageStyleGenerationTrait @group flysystem
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, PhpUnitCompatibilityTrait, PhpUnitWarnings
- class \Drupal\Tests\flysystem\Unit\Plugin\ImageStyleGenerationTraitTest
Expanded class hierarchy of ImageStyleGenerationTraitTest
File
- tests/
src/ Unit/ Plugin/ ImageStyleGenerationTraitTest.php, line 21
Namespace
Drupal\Tests\flysystem\Unit\PluginView source
class ImageStyleGenerationTraitTest extends UnitTestCase {
/**
* @covers ::generateImageStyle
*/
public function testGenerateImageStyle() {
vfsStream::setup('flysystem');
touch('vfs://flysystem/foo.jpg');
mkdir('vfs://flysystem/styles/pass', 0777, TRUE);
$container = new ContainerBuilder();
$image_style = $this
->prophesize(ImageStyle::class);
$image_style
->buildUri('vfs://flysystem/foo.jpg')
->willReturn('vfs://flysystem/styles/pass/foo.jpg');
$image_style
->buildUri('vfs://flysystem/foo.jpg.png')
->willReturn('vfs://flysystem/styles/pass/foo.jpg.png');
$image_style
->id()
->willReturn('pass');
$image_style
->createDerivative('vfs://flysystem/foo.jpg', 'vfs://flysystem/styles/pass/foo.jpg')
->willReturn(TRUE);
$image_style
->createDerivative('vfs://flysystem/foo.jpg', 'vfs://flysystem/styles/pass/foo.jpg.png')
->willReturn(TRUE);
$storage = $this
->prophesize(EntityStorageInterface::class);
$storage
->load('pass')
->willReturn($image_style
->reveal());
$storage
->load('fail')
->willReturn(FALSE);
$entity_type_manager = $this
->prophesize(EntityTypeManagerInterface::class);
$entity_tyep_repository = $this
->prophesize(EntityTypeRepositoryInterface::class);
$entity_tyep_repository
->getEntityTypeFromClass(ImageStyle::class)
->willReturn('image_style');
$entity_type_manager
->getStorage('image_style')
->willReturn($storage
->reveal());
$container
->set('entity_type.repository', $entity_tyep_repository
->reveal());
$container
->set('entity_type.manager', $entity_type_manager
->reveal());
$container
->set('lock', new NullLockBackend());
\Drupal::setContainer($container);
$trait = $this
->getMockForTrait(ImageStyleGenerationTrait::class);
$method = (new \ReflectionMethod($trait, 'generateImageStyle'))
->getClosure($trait);
// Test invlid paths.
$this
->assertFalse($method('foo/bar'));
$this
->assertFalse($method('styles/image_style/vfs'));
// Test invalid image style.
$this
->assertFalse($method('styles/fail/vfs/flysystem/foo.jpg'));
// Test existing derivative.
touch('vfs://flysystem/styles/pass/foo.jpg');
$this
->assertTrue($method('styles/pass/vfs/flysystem/foo.jpg'));
unlink('vfs://flysystem/styles/pass/foo.jpg');
// Basic passing.
$this
->assertTrue($method('styles/pass/vfs/flysystem/foo.jpg'));
$this
->assertTrue($method('styles/pass/vfs/flysystem/foo.jpg.png'));
// Test failed lock.
$fail_lock = $this
->prophesize(LockBackendInterface::class);
$fail_lock
->acquire(Argument::type('string'))
->willReturn(FALSE);
$container
->set('lock', $fail_lock
->reveal());
$this
->assertFalse($method('styles/pass/vfs/flysystem/foo.jpg'));
$container
->set('lock', new NullLockBackend());
// Test missing source.
unlink('vfs://flysystem/foo.jpg');
$this
->assertFalse($method('styles/pass/vfs/flysystem/foo.jpg.png'));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ImageStyleGenerationTraitTest:: |
public | function | @covers ::generateImageStyle | |
PhpUnitWarnings:: |
private static | property | Deprecation warnings from PHPUnit to raise with @trigger_error(). | |
PhpUnitWarnings:: |
public | function | Converts PHPUnit deprecation warnings to E_USER_DEPRECATED. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
protected | function | 308 | |
UnitTestCase:: |
public static | function |