[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Test gd functionality. 19 * 20 * @package core 21 * @category phpunit 22 * @copyright 2015 Andrew Nicols <andrew@nicols.co.uk> 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 defined('MOODLE_INTERNAL') || die(); 27 28 29 /** 30 * A set of tests for some of the gd functionality within Moodle. 31 * 32 * @package core 33 * @category phpunit 34 * @copyright 2015 Andrew Nicols <andrew@nicols.co.uk> 35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 36 */ 37 class core_gdlib_testcase extends basic_testcase { 38 39 private $fixturepath = null; 40 41 public function setUp() { 42 $this->fixturepath = __DIR__ . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR; 43 } 44 45 public function test_generate_image_thumbnail() { 46 global $CFG; 47 require_once($CFG->libdir . '/gdlib.php'); 48 49 // Test with meaningless data. 50 51 // Now use a fixture. 52 $pngpath = $this->fixturepath . 'gd-logo.png'; 53 $pngthumb = generate_image_thumbnail($pngpath, 24, 24); 54 $this->assertTrue(is_string($pngthumb)); 55 56 // And check that the generated image was of the correct proportions and mimetype. 57 $imageinfo = getimagesizefromstring($pngthumb); 58 $this->assertEquals(24, $imageinfo[0]); 59 $this->assertEquals(24, $imageinfo[1]); 60 $this->assertEquals('image/png', $imageinfo['mime']); 61 } 62 63 public function test_generate_image_thumbnail_from_string() { 64 global $CFG; 65 require_once($CFG->libdir . '/gdlib.php'); 66 67 // Test with meaningless data. 68 69 // First empty values. 70 $this->assertFalse(generate_image_thumbnail_from_string('', 24, 24)); 71 $this->assertFalse(generate_image_thumbnail_from_string('invalid', 0, 24)); 72 $this->assertFalse(generate_image_thumbnail_from_string('invalid', 24, 0)); 73 74 // Now an invalid string. 75 $this->assertFalse(generate_image_thumbnail_from_string('invalid', 24, 24)); 76 77 // Now use a fixture. 78 $pngpath = $this->fixturepath . 'gd-logo.png'; 79 $pngdata = file_get_contents($pngpath); 80 $pngthumb = generate_image_thumbnail_from_string($pngdata, 24, 24); 81 $this->assertTrue(is_string($pngthumb)); 82 83 // And check that the generated image was of the correct proportions and mimetype. 84 $imageinfo = getimagesizefromstring($pngthumb); 85 $this->assertEquals(24, $imageinfo[0]); 86 $this->assertEquals(24, $imageinfo[1]); 87 $this->assertEquals('image/png', $imageinfo['mime']); 88 } 89 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |