diff --git a/tests/src/Unit/FocalPointTest.php b/tests/src/Unit/FocalPointTest.php index bef47f7..565366b 100644 --- a/tests/src/Unit/FocalPointTest.php +++ b/tests/src/Unit/FocalPointTest.php @@ -7,11 +7,15 @@ namespace Drupal\Tests\focal_point\Unit; +use Drupal\crop\CropStorageInterface; +use Drupal\Core\Entity\EntityTypeManager; +use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\focal_point\FocalPointManager; use Drupal\Tests\UnitTestCase; /** * @coversDefaultClass \Drupal\focal_point\FocalPointManager + * * @group Focal Point */ class FocalPointTest extends UnitTestCase { @@ -28,30 +32,21 @@ class FocalPointTest extends UnitTestCase { */ protected function setUp() { parent::setUp(); - $crop_storage = $this->getMockBuilder('Drupal\crop\CropStorage') - ->disableOriginalConstructor() - ->getMock(); - $entity_type_manager = $this->getMockBuilder('Drupal\Core\Entity\EntityTypeManager') - ->disableOriginalConstructor() - ->getMock(); - $entity_type_manager->expects($this->any()) - ->method('getStorage') - ->with('crop') - ->will($this->returnValue($crop_storage)); - - $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); - $container->expects($this->any()) - ->method('get') - ->with('entity_type.manager') - ->will($this->returnValue($entity_type_manager)); - - \Drupal::setContainer($container); + $crop_storage = $this->prophesize(CropStorageInterface::class); + + $entity_type_manager = $this->prophesize(EntityTypeManager::class); + $entity_type_manager->getStorage('crop')->willReturn($crop_storage); + + $container = $this->prophesize(ContainerInterface::class); + $container->get('entity_type.manager')->willReturn($entity_type_manager); + + \Drupal::setContainer($container->reveal()); $this->focalPointManager = new FocalPointManager(\Drupal::service('entity_type.manager')); } /** - * Tests the validateFocalPoint() method. + * @covers ::validateFocalPoint * * @dataProvider providerValidateFocalPoint */ @@ -63,25 +58,27 @@ class FocalPointTest extends UnitTestCase { * Data provider for testFocalPoint(). */ public function providerValidateFocalPoint() { - return [ - ['50,50', TRUE], - ['75,25', TRUE], - ['3,50', TRUE], - ['83,6', TRUE], - ['2,9', TRUE], - ['100,100', TRUE], - ['0,0', TRUE], - ['100,0', TRUE], - ['-20,50', FALSE], - ['18,-3', FALSE], - ['44,101', FALSE], - ['', FALSE], - ['invalid', FALSE], - ]; + $data = []; + $data['default_focal_point_position'] = ['50,50', TRUE]; + $data['basic_focal_point_position_1'] = ['75,25', TRUE]; + $data['basic_focal_point_position_2'] = ['3,50', TRUE]; + $data['basic_focal_point_position_3'] = ['83,6', TRUE]; + $data['basic_focal_point_position_4'] = ['2,9', TRUE]; + $data['extreme_focal_point_position_top_right'] = ['100,0', TRUE]; + $data['extreme_focal_point_position_top_left'] = ['0,0', TRUE]; + $data['extreme_focal_point_position_bottom_right'] = ['100,100', TRUE]; + $data['extreme_focal_point_position_bottom_left'] = ['0,100', TRUE]; + $data['invalid_focal_point_position_negative_x'] = ['-20,50', FALSE]; + $data['invalid_focal_point_position_negative_y'] = ['18,-3', FALSE]; + $data['invalid_focal_point_position_out_of_bounds'] = ['44,101', FALSE]; + $data['invalid_focal_point_position_empty'] = ['', FALSE]; + $data['invalid_focal_point_position_incorrect_format'] = ['invalid', FALSE]; + + return $data; } /** - * Tests the relativeToAbsolute() method. + * @covers ::relativeToAbsolute * * @dataProvider providerCoordinates */ @@ -94,7 +91,7 @@ class FocalPointTest extends UnitTestCase { } /** - * Tests the absoluteToRelative() method. + * @covers ::absoluteToRelative * * @dataProvider providerCoordinates */ @@ -110,43 +107,44 @@ class FocalPointTest extends UnitTestCase { * Data provider for testRelativeToAbsolute() and absoluteToRelative(). */ public function providerCoordinates() { - return [ - [ - ['x' => 0, 'y' => 0], - ['width' => 1000, 'height' => 2000], - ['x' => 0, 'y' => 0] - ], - [ - ['x' => 25, 'y' => 50], - ['width' => 1000, 'height' => 2000], - ['x' => 250, 'y' => 1000] - ], - [ - ['x' => 50, 'y' => 25], - ['width' => 1000, 'height' => 2000], - ['x' => 500, 'y' => 500] - ], - [ - ['x' => 50, 'y' => 50], - ['width' => 1000, 'height' => 2000], - ['x' => 500, 'y' => 1000] - ], - [ - ['x' => 75, 'y' => 50], - ['width' => 1000, 'height' => 2000], - ['x' => 750, 'y' => 1000] - ], - [ - ['x' => 100, 'y' => 75], - ['width' => 1000, 'height' => 2000], - ['x' => 1000, 'y' => 1500] - ], - [ - ['x' => 100, 'y' => 100], - ['width' => 1000, 'height' => 2000], - ['x' => 1000, 'y' => 2000] - ], + $data = []; + $data['top_left'] = [ + ['x' => 0, 'y' => 0], + ['width' => 1000, 'height' => 2000], + ['x' => 0, 'y' => 0], + ]; + $data['basic_case_1'] = [ + ['x' => 25, 'y' => 50], + ['width' => 1000, 'height' => 2000], + ['x' => 250, 'y' => 1000] ]; + $data['basic_case_2'] = [ + ['x' => 50, 'y' => 25], + ['width' => 1000, 'height' => 2000], + ['x' => 500, 'y' => 500], + ]; + $data['basic_case_3'] = [ + ['x' => 50, 'y' => 50], + ['width' => 1000, 'height' => 2000], + ['x' => 500, 'y' => 1000], + ]; + $data['basic_case_4'] = [ + ['x' => 75, 'y' => 50], + ['width' => 1000, 'height' => 2000], + ['x' => 750, 'y' => 1000], + ]; + $data['basic_case_5'] = [ + ['x' => 100, 'y' => 75], + ['width' => 1000, 'height' => 2000], + ['x' => 1000, 'y' => 1500], + ]; + $data['bottom_right'] = [ + ['x' => 100, 'y' => 100], + ['width' => 1000, 'height' => 2000], + ['x' => 1000, 'y' => 2000], + ]; + + return $data; } }