3 namespace Drupal\Tests\Component\Utility;
5 use Drupal\Component\Utility\Image;
6 use PHPUnit\Framework\TestCase;
9 * @coversDefaultClass \Drupal\Component\Utility\Image
12 class ImageTest extends TestCase {
15 * Tests all control flow branches in image_dimensions_scale().
17 * @dataProvider providerTestScaleDimensions
19 public function testScaleDimensions($input, $output) {
20 // Process the test dataset.
21 $return_value = Image::scaleDimensions($input['dimensions'], $input['width'], $input['height'], $input['upscale']);
24 $this->assertEquals($output['dimensions']['width'], $input['dimensions']['width'], sprintf('Computed width (%s) does not equal expected width (%s)', $output['dimensions']['width'], $input['dimensions']['width']));
27 $this->assertEquals($output['dimensions']['height'], $input['dimensions']['height'], sprintf('Computed height (%s) does not equal expected height (%s)', $output['dimensions']['height'], $input['dimensions']['height']));
29 // Check the return value.
30 $this->assertEquals($output['return_value'], $return_value, 'Incorrect return value.');
34 * Provides data for image dimension scale tests.
37 * Keyed array containing:
38 * - 'input' - Array which contains input for Image::scaleDimensions().
39 * - 'output' - Array which contains expected output after passing
40 * through Image::scaleDimensions. Also contains a boolean
41 * 'return_value' which should match the expected return value.
43 * @see testScaleDimensions()
45 public function providerTestScaleDimensions() {
46 // Define input / output datasets to test different branch conditions.
49 // Test branch conditions:
51 // - Upscale, don't need to upscale.
67 'return_value' => TRUE,
71 // Test branch conditions:
73 // - Don't upscale, don't need to upscale.
89 'return_value' => TRUE,
93 // Test branch conditions:
94 // - Source aspect ratio greater than target.
95 // - Upscale, need to upscale.
111 'return_value' => TRUE,
115 // Test branch condition: target aspect ratio greater than source.
131 'return_value' => TRUE,
135 // Test branch condition: don't upscale, need to upscale.
151 'return_value' => FALSE,