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