1<?php 2 3namespace dokuwiki\test\File; 4 5use dokuwiki\File\MediaFile; 6 7/** 8 * Tests for dokuwiki\File\MediaFile display-dimension helpers. 9 * 10 * The fixture wiki:exif-orient-6.jpg is a 20x30 raw JPEG carrying EXIF 11 * orientation 6, so its display orientation is 30x20 (portrait -> landscape swap). 12 */ 13class MediaFileTest extends \DokuWikiTest 14{ 15 /** @var string */ 16 private $rotated = 'wiki:exif-orient-6.jpg'; 17 18 /** @var string */ 19 private $unrotated = 'wiki:dokuwiki-128.png'; 20 21 public function testDisplayDimsForNonImageReturnsZero() 22 { 23 $mf = new MediaFile('nonexistent:file.jpg'); 24 $this->assertSame([0, 0], $mf->getDisplayDimensions(500, 500)); 25 } 26 27 public function testGetDisplayDimensionsBboxFitRotated() 28 { 29 $mf = new MediaFile($this->rotated); 30 // raw 20x30 -> rotated 30x20 -> fit into 500x500 preserves aspect, 31 // max dimension scales from 30 to 500 => 500 x round(500 * 20/30) = 500 x 333 32 $this->assertSame([500, 333], $mf->getDisplayDimensions(500, 500, false)); 33 } 34 35 public function testGetDisplayDimensionsCropPassthrough() 36 { 37 $mf = new MediaFile($this->rotated); 38 $this->assertSame([100, 100], $mf->getDisplayDimensions(100, 100, true)); 39 } 40 41 public function testGetDisplayDimensionsNativeWhenNoRequest() 42 { 43 $mf = new MediaFile($this->rotated); 44 $this->assertSame([30, 20], $mf->getDisplayDimensions(0, 0, false)); 45 } 46 47 public function testGetDisplayDimensionsUnrotatedImage() 48 { 49 $mf = new MediaFile($this->unrotated); 50 // non-JPEG: display dims equal raw dims 51 $this->assertSame([$mf->getWidth(), $mf->getHeight()], $mf->getDisplayDimensions(0, 0, false)); 52 } 53} 54