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