1<?php 2 3namespace dokuwiki\test\Ui\Media; 4 5use dokuwiki\File\MediaFile; 6use dokuwiki\Ui\Media\Display; 7 8/** 9 * Tests for dokuwiki\Ui\Media\Display::getDetailHtml(). 10 * 11 * Fixture wiki:exif-orient-6.jpg is a 20x30 JPEG carrying EXIF orientation 6, 12 * so its rotated display orientation is 30x20. 13 */ 14class DisplayTest extends \DokuWikiTest 15{ 16 /** @var string */ 17 private $rotated = 'wiki:exif-orient-6.jpg'; 18 19 public function testGetDetailHtmlEmitsBboxFittedRotatedDims() 20 { 21 $display = new Display(new MediaFile($this->rotated)); 22 $html = $display->getDetailHtml(500, 500); 23 24 // rotated 30x20 fit into 500x500 bbox -> 500x333 (matches MediaFileTest) 25 $this->assertStringContainsString('width="500"', $html); 26 $this->assertStringContainsString('height="333"', $html); 27 } 28 29 public function testGetDetailHtmlStructure() 30 { 31 $display = new Display(new MediaFile($this->rotated)); 32 $html = $display->getDetailHtml(); 33 34 $this->assertStringContainsString('<div class="image">', $html); 35 $this->assertStringContainsString('target="_blank"', $html); 36 $this->assertStringContainsString('fit=1', $html); 37 $this->assertStringContainsString('<img ', $html); 38 } 39 40 public function testGetDetailHtmlReturnsEmptyForNonImage() 41 { 42 $display = new Display(new MediaFile('nonexistent:file.jpg')); 43 $this->assertSame('', $display->getDetailHtml()); 44 } 45 46 public function testGetDetailHtmlUsesRevParamWhenRevIsSet() 47 { 48 $rev = 1700000000; 49 $atticPath = mediaFN($this->rotated, $rev); 50 if (!is_dir(dirname($atticPath))) mkdir(dirname($atticPath), 0777, true); 51 copy(mediaFN($this->rotated), $atticPath); 52 try { 53 $html = (new Display(new MediaFile($this->rotated, $rev)))->getDetailHtml(); 54 $this->assertMatchesRegularExpression('/[?&][^f]*?rev=' . $rev . '/', $html); 55 $this->assertDoesNotMatchRegularExpression('/[?&](?:amp;)*t=\d/', $html); 56 } finally { 57 unlink($atticPath); 58 } 59 } 60 61 public function testGetDetailHtmlUsesTimestampWhenNoRev() 62 { 63 $html = (new Display(new MediaFile($this->rotated)))->getDetailHtml(); 64 $this->assertMatchesRegularExpression('/[?&](?:amp;)*t=\d/', $html); 65 $this->assertStringNotContainsString('rev=', $html); 66 } 67} 68