class ImageTest in Zircon Profile 8
Same name in this branch
- 8 core/tests/Drupal/Tests/Core/Image/ImageTest.php \Drupal\Tests\Core\Image\ImageTest
- 8 core/tests/Drupal/Tests/Component/Utility/ImageTest.php \Drupal\Tests\Component\Utility\ImageTest
- 8 core/modules/system/src/Tests/Theme/ImageTest.php \Drupal\system\Tests\Theme\ImageTest
Same name and namespace in other branches
- 8.0 core/tests/Drupal/Tests/Component/Utility/ImageTest.php \Drupal\Tests\Component\Utility\ImageTest
@coversDefaultClass \Drupal\Component\Utility\Image @group Image
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \Drupal\Tests\PHPUnit_Framework_TestCase
- class \Drupal\Tests\Component\Utility\ImageTest
Expanded class hierarchy of ImageTest
File
- core/
tests/ Drupal/ Tests/ Component/ Utility/ ImageTest.php, line 17 - Contains \Drupal\Tests\Component\Utility\ImageTest.
Namespace
Drupal\Tests\Component\UtilityView source
class ImageTest extends UnitTestCase {
/**
* Tests all control flow branches in image_dimensions_scale().
*
* @dataProvider providerTestScaleDimensions
*/
public function testScaleDimensions($input, $output) {
// Process the test dataset.
$return_value = Image::scaleDimensions($input['dimensions'], $input['width'], $input['height'], $input['upscale']);
// Check the width.
$this
->assertEquals($output['dimensions']['width'], $input['dimensions']['width'], sprintf('Computed width (%s) does not equal expected width (%s)', $output['dimensions']['width'], $input['dimensions']['width']));
// Check the height.
$this
->assertEquals($output['dimensions']['height'], $input['dimensions']['height'], sprintf('Computed height (%s) does not equal expected height (%s)', $output['dimensions']['height'], $input['dimensions']['height']));
// Check the return value.
$this
->assertEquals($output['return_value'], $return_value, 'Incorrect return value.');
}
/**
* Provides data for image dimension scale tests.
*
* @return 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 testScaleDimensions()
*/
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;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ImageTest:: |
public | function | Provides data for image dimension scale tests. | |
ImageTest:: |
public | function | Tests all control flow branches in image_dimensions_scale(). | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed in 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. | |
UnitTestCase:: |
protected | function | 259 |