Index: trunk/phase3/tests/phpunit/includes/media/ExifRotationTest.php |
— | — | @@ -32,27 +32,45 @@ |
33 | 33 | */ |
34 | 34 | function testMetadata( $name, $type, $info ) { |
35 | 35 | $file = UnregisteredLocalFile::newFromPath( $this->filePath . $name, $type ); |
36 | | - $this->assertEquals( $file->getWidth(), $info['width'], "$name: width check" ); |
37 | | - $this->assertEquals( $file->getHeight(), $info['height'], "$name: height check" ); |
| 36 | + $this->assertEquals( $info['width'], $file->getWidth(), "$name: width check" ); |
| 37 | + $this->assertEquals( $info['height'], $file->getHeight(), "$name: height check" ); |
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
41 | 41 | * |
42 | 42 | * @dataProvider providerFiles |
43 | 43 | */ |
44 | | - function testRotationRendering( $name, $type, $info ) { |
45 | | - $file = $this->localFile( $name, $type ); |
46 | | - $thumb = $file->transform( array( |
47 | | - 'width' => 800, |
48 | | - 'height' => 600, |
49 | | - ), File::RENDER_NOW ); |
| 44 | + function testRotationRendering( $name, $type, $info, $thumbs ) { |
| 45 | + foreach( $thumbs as $size => $out ) { |
| 46 | + if( preg_match('/^(\d+)px$/', $size, $matches ) ) { |
| 47 | + $params = array( |
| 48 | + 'width' => $matches[1], |
| 49 | + ); |
| 50 | + } elseif ( preg_match( '/^(\d+)x(\d+)px$/', $size, $matches ) ) { |
| 51 | + $params = array( |
| 52 | + 'width' => $matches[1], |
| 53 | + 'height' => $matches[2] |
| 54 | + ); |
| 55 | + } else { |
| 56 | + throw new MWException('bogus test data format ' . $size); |
| 57 | + } |
50 | 58 | |
51 | | - $this->assertEquals( $thumb->getWidth(), $info['thumbWidth'], "$name: thumb reported width check" ); |
52 | | - $this->assertEquals( $thumb->getHeight(), $info['thumbHeight'], "$name: thumb reported height check" ); |
| 59 | + $file = $this->localFile( $name, $type ); |
| 60 | + $thumb = $file->transform( $params, File::RENDER_NOW ); |
53 | 61 | |
54 | | - $gis = getimagesize( $thumb->getPath() ); |
55 | | - $this->assertEquals( $gis[0], $info['thumbWidth'], "$name: thumb actual width check"); |
56 | | - $this->assertEquals( $gis[0], $info['thumbWidth'], "$name: thumb actual height check"); |
| 62 | + $this->assertEquals( $out[0], $thumb->getWidth(), "$name: thumb reported width check for $size" ); |
| 63 | + $this->assertEquals( $out[1], $thumb->getHeight(), "$name: thumb reported height check for $size" ); |
| 64 | + |
| 65 | + $gis = getimagesize( $thumb->getPath() ); |
| 66 | + if ($out[0] > $info['width']) { |
| 67 | + // Physical image won't be scaled bigger than the original. |
| 68 | + $this->assertEquals( $info['width'], $gis[0], "$name: thumb actual width check for $size"); |
| 69 | + $this->assertEquals( $info['height'], $gis[1], "$name: thumb actual height check for $size"); |
| 70 | + } else { |
| 71 | + $this->assertEquals( $out[0], $gis[0], "$name: thumb actual width check for $size"); |
| 72 | + $this->assertEquals( $out[1], $gis[1], "$name: thumb actual height check for $size"); |
| 73 | + } |
| 74 | + } |
57 | 75 | } |
58 | 76 | |
59 | 77 | private function localFile( $name, $type ) { |
— | — | @@ -67,8 +85,12 @@ |
68 | 86 | array( |
69 | 87 | 'width' => 1024, |
70 | 88 | 'height' => 768, |
71 | | - 'thumbWidth' => 800, |
72 | | - 'thumbHeight' => 600, |
| 89 | + ), |
| 90 | + array( |
| 91 | + '800x600px' => array( 800, 600 ), |
| 92 | + '9999x800px' => array( 1067, 800 ), |
| 93 | + '800px' => array( 800, 600 ), |
| 94 | + '600px' => array( 600, 450 ), |
73 | 95 | ) |
74 | 96 | ), |
75 | 97 | array( |
— | — | @@ -77,8 +99,12 @@ |
78 | 100 | array( |
79 | 101 | 'width' => 768, // as rotated |
80 | 102 | 'height' => 1024, // as rotated |
81 | | - 'thumbWidth' => 450, |
82 | | - 'thumbHeight' => 600, |
| 103 | + ), |
| 104 | + array( |
| 105 | + '800x600px' => array( 450, 600 ), |
| 106 | + '9999x800px' => array( 600, 800 ), |
| 107 | + '800px' => array( 800, 1067 ), |
| 108 | + '600px' => array( 600, 800 ), |
83 | 109 | ) |
84 | 110 | ) |
85 | 111 | ); |