[ 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 unoconv functionality. 19 * 20 * @package core 21 * @copyright 2016 Damyon Wiese 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 defined('MOODLE_INTERNAL') || die(); 26 27 28 /** 29 * A set of tests for some of the unoconv functionality within Moodle. 30 * 31 * @package core 32 * @copyright 2016 Damyon Wiese 33 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 34 */ 35 class core_unoconv_testcase extends advanced_testcase { 36 37 /** @var $testfile1 */ 38 private $testfile1 = null; 39 /** @var $testfile2 */ 40 private $testfile2 = null; 41 42 public function setUp() { 43 $this->fixturepath = __DIR__ . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR; 44 45 $fs = get_file_storage(); 46 $filerecord = array( 47 'contextid' => context_system::instance()->id, 48 'component' => 'test', 49 'filearea' => 'unittest', 50 'itemid' => 0, 51 'filepath' => '/', 52 'filename' => 'test.html' 53 ); 54 $teststring = file_get_contents($this->fixturepath . DIRECTORY_SEPARATOR . 'unoconv-source.html'); 55 $this->testfile1 = $fs->create_file_from_string($filerecord, $teststring); 56 57 $filerecord = array( 58 'contextid' => context_system::instance()->id, 59 'component' => 'test', 60 'filearea' => 'unittest', 61 'itemid' => 0, 62 'filepath' => '/', 63 'filename' => 'test.docx' 64 ); 65 $teststring = file_get_contents($this->fixturepath . DIRECTORY_SEPARATOR . 'unoconv-source.docx'); 66 $this->testfile2 = $fs->create_file_from_string($filerecord, $teststring); 67 68 $this->resetAfterTest(); 69 } 70 71 public function test_generate_pdf() { 72 global $CFG; 73 74 if (empty($CFG->pathtounoconv) || !file_is_executable(trim($CFG->pathtounoconv))) { 75 // No conversions are possible, sorry. 76 return $this->markTestSkipped(); 77 } 78 $fs = get_file_storage(); 79 80 $result = $fs->get_converted_document($this->testfile1, 'pdf'); 81 $this->assertNotFalse($result); 82 $this->assertSame($result->get_mimetype(), 'application/pdf'); 83 $this->assertGreaterThan(0, $result->get_filesize()); 84 $result = $fs->get_converted_document($this->testfile2, 'pdf'); 85 $this->assertNotFalse($result); 86 $this->assertSame($result->get_mimetype(), 'application/pdf'); 87 $this->assertGreaterThan(0, $result->get_filesize()); 88 } 89 90 public function test_generate_markdown() { 91 global $CFG; 92 93 if (empty($CFG->pathtounoconv) || !file_is_executable(trim($CFG->pathtounoconv))) { 94 // No conversions are possible, sorry. 95 return $this->markTestSkipped(); 96 } 97 $fs = get_file_storage(); 98 99 $result = $fs->get_converted_document($this->testfile1, 'txt'); 100 $this->assertNotFalse($result); 101 $this->assertSame($result->get_mimetype(), 'text/plain'); 102 $this->assertGreaterThan(0, $result->get_filesize()); 103 $result = $fs->get_converted_document($this->testfile2, 'txt'); 104 $this->assertNotFalse($result); 105 $this->assertSame($result->get_mimetype(), 'text/plain'); 106 $this->assertGreaterThan(0, $result->get_filesize()); 107 } 108 }
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 |