You are here

abstract class FocalPointUnitTestCase in Focal Point 8

Focal point unit test case.

@group Focal Point

Hierarchy

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\Unit
View 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

Namesort descending Modifiers Type Description Overrides
FocalPointUnitTestCase::$container protected property Drupal container.
FocalPointUnitTestCase::$focalPointManager protected property Focal point manager.
FocalPointUnitTestCase::getTestEffect protected function Get the test effects.
FocalPointUnitTestCase::getTestImage protected function Get the test image.
FocalPointUnitTestCase::setUp protected function Overrides UnitTestCase::setUp 1
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.