You are here

public function ImageTest::providerTestScaleDimensions in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/tests/Drupal/Tests/Component/Utility/ImageTest.php \Drupal\Tests\Component\Utility\ImageTest::providerTestScaleDimensions()

Provides data for image dimension scale tests.

Return value

array Keyed array containing:

  • 'input' - Array which contains input for Image::scaleDimensions().
  • 'output' - Array which contains expected output after passing through Image::scaleDimensions. Also contains a boolean 'return_value' which should match the expected return value.

See also

testScaleDimensions()

File

core/tests/Drupal/Tests/Component/Utility/ImageTest.php, line 51
Contains \Drupal\Tests\Component\Utility\ImageTest.

Class

ImageTest
@coversDefaultClass \Drupal\Component\Utility\Image @group Image

Namespace

Drupal\Tests\Component\Utility

Code

public function providerTestScaleDimensions() {

  // Define input / output datasets to test different branch conditions.
  $tests = array();

  // Test branch conditions:
  // - No height.
  // - Upscale, don't need to upscale.
  $tests[] = array(
    'input' => array(
      'dimensions' => array(
        'width' => 1000,
        'height' => 2000,
      ),
      'width' => 200,
      'height' => NULL,
      'upscale' => TRUE,
    ),
    'output' => array(
      'dimensions' => array(
        'width' => 200,
        'height' => 400,
      ),
      'return_value' => TRUE,
    ),
  );

  // Test branch conditions:
  // - No width.
  // - Don't upscale, don't need to upscale.
  $tests[] = array(
    'input' => array(
      'dimensions' => array(
        'width' => 1000,
        'height' => 800,
      ),
      'width' => NULL,
      'height' => 140,
      'upscale' => FALSE,
    ),
    'output' => array(
      'dimensions' => array(
        'width' => 175,
        'height' => 140,
      ),
      'return_value' => TRUE,
    ),
  );

  // Test branch conditions:
  // - Source aspect ratio greater than target.
  // - Upscale, need to upscale.
  $tests[] = array(
    'input' => array(
      'dimensions' => array(
        'width' => 8,
        'height' => 20,
      ),
      'width' => 200,
      'height' => 140,
      'upscale' => TRUE,
    ),
    'output' => array(
      'dimensions' => array(
        'width' => 56,
        'height' => 140,
      ),
      'return_value' => TRUE,
    ),
  );

  // Test branch condition: target aspect ratio greater than source.
  $tests[] = array(
    'input' => array(
      'dimensions' => array(
        'width' => 2000,
        'height' => 800,
      ),
      'width' => 200,
      'height' => 140,
      'upscale' => FALSE,
    ),
    'output' => array(
      'dimensions' => array(
        'width' => 200,
        'height' => 80,
      ),
      'return_value' => TRUE,
    ),
  );

  // Test branch condition: don't upscale, need to upscale.
  $tests[] = array(
    'input' => array(
      'dimensions' => array(
        'width' => 100,
        'height' => 50,
      ),
      'width' => 200,
      'height' => 140,
      'upscale' => FALSE,
    ),
    'output' => array(
      'dimensions' => array(
        'width' => 100,
        'height' => 50,
      ),
      'return_value' => FALSE,
    ),
  );
  return $tests;
}