1*c3a14f67SAndreas Gohr<?php 2*c3a14f67SAndreas Gohr 3*c3a14f67SAndreas Gohr/** 4*c3a14f67SAndreas Gohr * Tests for the $upscale option of the image resize helpers. 5*c3a14f67SAndreas Gohr * 6*c3a14f67SAndreas Gohr * Fixture wiki:dokuwiki-128.png is a 128x128 PNG. 7*c3a14f67SAndreas Gohr */ 8*c3a14f67SAndreas Gohrclass media_resize_test extends DokuWikiTest { 9*c3a14f67SAndreas Gohr 10*c3a14f67SAndreas Gohr /** @var string */ 11*c3a14f67SAndreas Gohr protected $img = 'wiki:dokuwiki-128.png'; 12*c3a14f67SAndreas Gohr 13*c3a14f67SAndreas Gohr public function test_resize_no_upscale_keeps_original_size() { 14*c3a14f67SAndreas Gohr $file = mediaFN($this->img); 15*c3a14f67SAndreas Gohr // 128x128 fit into a 500x500 box with upscaling disabled -> stays 128x128 16*c3a14f67SAndreas Gohr $out = media_resize_image($file, 'png', 500, 500, false); 17*c3a14f67SAndreas Gohr $this->assertNotEquals($file, $out, 'a cache file should have been produced'); 18*c3a14f67SAndreas Gohr $this->assertFileExists($out); 19*c3a14f67SAndreas Gohr [$w, $h] = getimagesize($out); 20*c3a14f67SAndreas Gohr $this->assertSame(128, $w); 21*c3a14f67SAndreas Gohr $this->assertSame(128, $h); 22*c3a14f67SAndreas Gohr } 23*c3a14f67SAndreas Gohr 24*c3a14f67SAndreas Gohr public function test_resize_default_still_upscales() { 25*c3a14f67SAndreas Gohr $file = mediaFN($this->img); 26*c3a14f67SAndreas Gohr // default behaviour (in-page images) still enlarges as before 27*c3a14f67SAndreas Gohr $out = media_resize_image($file, 'png', 500, 500); 28*c3a14f67SAndreas Gohr $this->assertFileExists($out); 29*c3a14f67SAndreas Gohr [$w, $h] = getimagesize($out); 30*c3a14f67SAndreas Gohr $this->assertSame(500, $w); 31*c3a14f67SAndreas Gohr $this->assertSame(500, $h); 32*c3a14f67SAndreas Gohr } 33*c3a14f67SAndreas Gohr 34*c3a14f67SAndreas Gohr public function test_upscale_and_no_upscale_use_separate_caches() { 35*c3a14f67SAndreas Gohr $file = mediaFN($this->img); 36*c3a14f67SAndreas Gohr $up = media_resize_image($file, 'png', 500, 500); 37*c3a14f67SAndreas Gohr $noup = media_resize_image($file, 'png', 500, 500, false); 38*c3a14f67SAndreas Gohr $this->assertNotEquals($up, $noup, 'the two variants must not share a cache file'); 39*c3a14f67SAndreas Gohr } 40*c3a14f67SAndreas Gohr} 41