From 0fd2fb2c10d497fa645b34dad3fea9e2809d698a Mon Sep 17 00:00:00 2001 From: Nathan Nguyen Date: Fri, 19 Jan 2024 13:07:37 +1100 Subject: [PATCH] Fix issue with type extension --- classes/converter.php | 4 ++++ tests/converter_test.php | 45 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/classes/converter.php b/classes/converter.php index 7fa89fa..5ce9a09 100644 --- a/classes/converter.php +++ b/classes/converter.php @@ -418,6 +418,10 @@ public function poll_conversion_status(conversion $conversion) { * @return bool */ public static function supports($from, $to) { + // Make sure we receive the extensions in lowercase. + $from = strtolower($from); + $to = strtolower($to); + // This is not a one-liner because of php 5.6. $imports = self::$imports; $exports = self::$exports; diff --git a/tests/converter_test.php b/tests/converter_test.php index 7d0ef10..c610122 100644 --- a/tests/converter_test.php +++ b/tests/converter_test.php @@ -546,4 +546,49 @@ public function test_conversion_record_deduplication() { $task->execute(); $this->assertEquals(2, $DB->count_records('file_conversion')); } + + /** + * Data provider for test_supports + * Supported formats: 'doc', 'docx', 'rtf', 'xls', 'xlsx', 'ppt', 'pptx', 'html', 'odt', + * 'ods', 'txt', 'png', 'jpg', 'gif', 'pdf' + * + * @return array + */ + public function supports_provider() { + return [ + ['doc', true], ['DOC', true], + ['docx', true], ['DOCX', true], + ['rtf', true], ['RTF', true], + ['xls', true], ['XLS', true], + ['xlsx', true], ['XLSX', true], + ['ppt', true], ['PPT', true], + ['pptx', true], ['PPTX', true], + ['html', true], ['HTML', true], + ['odt', true], ['ODT', true], + ['ods', true], ['ODS', true], + ['txt', true], ['TXT', true], + ['png', true], ['PNG', true], + ['jpg', true], ['JPG', true], + ['gif', true], ['GIF', true], + ['pdf', false], ['PDF', false], + ['mp3', false], ['MP3', false], + ['mp4', false], ['mp4', false], + ]; + } + + /** + * Test supports method of converter class. + * + * @covers converter::supports + * @dataProvider supports_provider + * + * @param string $format The format to test. + * @param bool $expected The expected result. + * + */ + public function test_supports($format, $expected) { + // Check supported format. + $this->assertEquals($expected, \fileconverter_librelambda\converter::supports($format, 'pdf')); + $this->assertEquals($expected, \fileconverter_librelambda\converter::supports($format, 'PDF')); + } }