You are here

class ImageUtilityTest in Image Effects 8

Same name and namespace in other branches
  1. 8.3 tests/src/Unit/ImageUtilityTest.php \Drupal\Tests\image_effects\Unit\ImageUtilityTest
  2. 8.2 tests/src/Unit/ImageUtilityTest.php \Drupal\Tests\image_effects\Unit\ImageUtilityTest

Tests the image utility helper methods.

@coversDefaultClass \Drupal\image_effects\Component\ImageUtility

@group Image Effects

Hierarchy

  • class \Drupal\Tests\image_effects\Unit\ImageUtilityTest extends \PHPUnit\Framework\TestCase

Expanded class hierarchy of ImageUtilityTest

File

tests/src/Unit/ImageUtilityTest.php, line 15

Namespace

Drupal\Tests\image_effects\Unit
View source
class ImageUtilityTest extends TestCase {

  /**
   * Data provider for testPercentFilter.
   */
  public function percentFilterProvider() {
    return [
      [
        50,
        400,
        50,
      ],
      [
        '50',
        400,
        50,
      ],
      [
        '50%',
        400,
        200,
      ],
      [
        50,
        NULL,
        50,
      ],
      [
        '50',
        NULL,
        50,
      ],
      [
        '50%',
        NULL,
        NULL,
      ],
      [
        NULL,
        100,
        NULL,
      ],
      [
        NULL,
        NULL,
        NULL,
      ],
      [
        '10%',
        400,
        40,
      ],
      [
        '100%',
        400,
        400,
      ],
      [
        '150%',
        400,
        600,
      ],
    ];
  }

  /**
   * @covers ::percentFilter
   * @dataProvider percentFilterProvider
   */
  public function testPercentFilter($length_specification, $current_length, $expected_result) {
    $this
      ->assertSame($expected_result, ImageUtility::percentFilter($length_specification, $current_length));
  }

  /**
   * Data provider for testResizeDimensions.
   */
  public function resizeDimensionsProvider() {
    return [
      // Square = FALSE.
      [
        NULL,
        100,
        50,
        25,
        FALSE,
        50,
        25,
      ],
      [
        200,
        NULL,
        50,
        25,
        FALSE,
        50,
        25,
      ],
      [
        NULL,
        NULL,
        50,
        25,
        FALSE,
        50,
        25,
      ],
      [
        200,
        100,
        50,
        25,
        FALSE,
        50,
        25,
      ],
      [
        NULL,
        100,
        '50%',
        '25%',
        FALSE,
        NULL,
        NULL,
      ],
      [
        200,
        NULL,
        '50%',
        '25%',
        FALSE,
        NULL,
        NULL,
      ],
      [
        NULL,
        NULL,
        '50%',
        '25%',
        FALSE,
        NULL,
        NULL,
      ],
      [
        200,
        100,
        '50%',
        '25%',
        FALSE,
        100,
        25,
      ],
      [
        200,
        100,
        '50%',
        '150%',
        FALSE,
        100,
        150,
      ],
      [
        200,
        100,
        '150%',
        '10%',
        FALSE,
        300,
        10,
      ],
      [
        NULL,
        100,
        '50',
        '25%',
        FALSE,
        50,
        25,
      ],
      [
        200,
        NULL,
        '50%',
        '25',
        FALSE,
        100,
        25,
      ],
      [
        200,
        100,
        '50%',
        NULL,
        FALSE,
        100,
        50,
      ],
      [
        200,
        100,
        NULL,
        '50%',
        FALSE,
        100,
        50,
      ],
      [
        40,
        20,
        '100%',
        0,
        FALSE,
        40,
        20,
      ],
      [
        40,
        20,
        0,
        '100%',
        FALSE,
        40,
        20,
      ],
      // Square = TRUE.
      [
        200,
        100,
        30,
        NULL,
        TRUE,
        30,
        30,
      ],
      [
        200,
        100,
        NULL,
        35,
        TRUE,
        35,
        35,
      ],
      [
        200,
        100,
        '50%',
        NULL,
        TRUE,
        100,
        100,
      ],
      [
        200,
        100,
        NULL,
        '50%',
        TRUE,
        50,
        50,
      ],
      [
        40,
        20,
        '100%',
        0,
        TRUE,
        40,
        40,
      ],
      [
        40,
        20,
        0,
        '100%',
        TRUE,
        20,
        20,
      ],
    ];
  }

  /**
   * @covers ::resizeDimensions
   * @dataProvider resizeDimensionsProvider
   */
  public function testResizeDimensions($source_width, $source_height, $width_specification, $height_specification, $square, $expected_width, $expected_height) {
    $result = ImageUtility::resizeDimensions($source_width, $source_height, $width_specification, $height_specification, $square);
    $this
      ->assertSame($expected_width, $result['width']);
    $this
      ->assertSame($expected_height, $result['height']);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ImageUtilityTest::percentFilterProvider public function Data provider for testPercentFilter.
ImageUtilityTest::resizeDimensionsProvider public function Data provider for testResizeDimensions.
ImageUtilityTest::testPercentFilter public function @covers ::percentFilter @dataProvider percentFilterProvider
ImageUtilityTest::testResizeDimensions public function @covers ::resizeDimensions @dataProvider resizeDimensionsProvider