abstract class FocalPointUnitTestCase in Focal Point 8
Focal point unit test case.
@group Focal Point
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\focal_point\Unit\FocalPointUnitTestCase
Expanded class hierarchy of FocalPointUnitTestCase
1 file declares its use of FocalPointUnitTestCase
- FocalPointEffectsTest.php in tests/
src/ Unit/ Effects/ FocalPointEffectsTest.php
File
- tests/
src/ Unit/ FocalPointUnitTestCase.php, line 21
Namespace
Drupal\Tests\focal_point\UnitView source
abstract class FocalPointUnitTestCase extends UnitTestCase {
/**
* Drupal container.
*
* @var \Symfony\Component\DependencyInjection\ContainerInterface
*/
protected $container;
/**
* Focal point manager.
*
* @var \Drupal\focal_point\FocalPointManagerInterface
*/
protected $focalPointManager;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$crop_storage = $this
->prophesize(CropStorageInterface::class);
$entity_type_manager = $this
->prophesize(EntityTypeManager::class);
$entity_type_manager
->getStorage('crop')
->willReturn($crop_storage);
$this->container = $this
->prophesize(ContainerInterface::class);
$this->container
->get('entity_type.manager')
->willReturn($entity_type_manager);
$request = $this
->prophesize(Request::class);
$this->container
->get('request')
->willReturn($request);
$this->focalPointManager = new FocalPointManager($entity_type_manager
->reveal());
$this->container
->get('focal_point.manager')
->willReturn($this->focalPointManager);
\Drupal::setContainer($this->container
->reveal());
}
/**
* Get the test effects.
*
* @param \Drupal\Core\Image\ImageInterface|null $original_image
* Original Image.
*
* @return \Drupal\focal_point\Plugin\ImageEffect\FocalPointCropImageEffect
* Effect.
*/
protected function getTestEffect(ImageInterface $original_image = NULL) {
if (is_null($original_image)) {
$original_image = $this
->getTestImage(0, 0);
}
$logger = $this
->prophesize(LoggerInterface::class);
$crop_storage = $this
->prophesize(CropStorageInterface::class);
$immutable_config = $this
->prophesize(ImmutableConfig::class);
$request = $this
->prophesize(Request::class);
$effect = new FocalPointCropImageEffect([], 'plugin_id', [], $logger
->reveal(), $this->focalPointManager, $crop_storage
->reveal(), $immutable_config
->reveal(), $request
->reveal());
$effect
->setOriginalImageSize($original_image
->getWidth(), $original_image
->getHeight());
return $effect;
}
/**
* Get the test image.
*
* @param int $width
* Width.
* @param int $height
* Height.
*
* @return object
* The image.
*/
protected function getTestImage($width, $height) {
$image = $this
->prophesize(ImageInterface::class);
$image
->getWidth()
->willReturn($width);
$image
->getHeight()
->willReturn($height);
return $image
->reveal();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FocalPointUnitTestCase:: |
protected | property | Drupal container. | |
FocalPointUnitTestCase:: |
protected | property | Focal point manager. | |
FocalPointUnitTestCase:: |
protected | function | Get the test effects. | |
FocalPointUnitTestCase:: |
protected | function | Get the test image. | |
FocalPointUnitTestCase:: |
protected | function |
Overrides UnitTestCase:: |
1 |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
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 | Mocks a block with a block plugin. | 1 |
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. |