ÿØÿà JFIF    ÿÛ „  ( %"1!%)+...383,7(-.+  -+++--++++---+-+-----+---------------+---+-++7-----ÿÀ  ß â" ÿÄ     ÿÄ H    !1AQaq"‘¡2B±ÁÑð#R“Ò Tbr‚²á3csƒ’ÂñDS¢³$CÿÄ   ÿÄ %  !1AQa"23‘ÿÚ   ? ôÿ ¨pŸªáÿ —åYõõ\?àÒü©ŠÄï¨pŸªáÿ —åYõõ\?àÓü©ŠÄá 0Ÿªáÿ Ÿå[úƒ ú®ði~TÁbqÐ8OÕpÿ ƒOò¤Oè`–RÂáœá™êi€ßÉ< FtŸI“öÌ8úDf´°å}“¾œ6  öFá°y¥jñÇh†ˆ¢ã/ÃÐ:ªcÈ "Y¡ðÑl>ÿ ”ÏËte:qž\oäŠe÷󲍷˜HT4&ÿ ÓÐü6ö®¿øþßèô Ÿ•7Ñi’•j|“ñì>b…þS?*Óôÿ ÓÐü*h¥£ír¶ü UãS炟[AÐaè[ûª•õ&õj?†Éö+EzP—WeÒírJFt ‘BŒ†Ï‡%#tE Øz ¥OÛ«!1›üä±Í™%ºÍãö]°î(–:@<‹ŒÊö×òÆt¦ãº+‡¦%ÌÁ²h´OƒJŒtMÜ>ÀÜÊw3Y´•牋4ǍýʏTì>œú=Íwhyë,¾Ôò×õ¿ßÊa»«þˆѪQ|%6ž™A õ%:øj<>É—ÿ Å_ˆCbõ¥š±ý¯Ýƒï…¶|RëócÍf溪“t.СøTÿ *Ä¿-{†çàczůŽ_–^XþŒ±miB[X±d 1,é”zEù»& î9gœf™9Ð'.;—™i}!ôšåîqêÛ٤ёý£½ÆA–àôe"A$˝Úsäÿ ÷Û #°xŸëí(l »ý3—¥5m! rt`†0~'j2(]S¦¦kv,ÚÇ l¦øJA£Šƒ J3E8ÙiŽ:cÉžúeZ°€¯\®kÖ(79«Ž:¯X”¾³Š&¡* ….‰Ž(ÜíŸ2¥ª‡×Hi²TF¤ò[¨íÈRëÉ䢍mgÑ.Ÿ<öäS0í„ǹÁU´f#Vß;Õ–…P@3ío<ä-±»Ž.L|kªÀê›fÂ6@»eu‚|ÓaÞÆŸ…¨ááå>åŠ?cKü6ùTÍÆ”†sĤÚ;H2RÚ†õ\Ö·Ÿn'¾ ñ#ºI¤Å´%çÁ­‚â7›‹qT3Iï¨ÖÚ5I7Ë!ÅOóŸ¶øÝñØôת¦$Tcö‘[«Ö³šÒ';Aþ ¸èíg A2Z"i¸vdÄ÷.iõ®§)¿]¤À†–‡É&ä{V¶iŽ”.Ó×Õÿ û?h¬Mt–íª[ÿ Ñÿ ÌV(í}=ibÔ¡›¥¢±b Lô¥‡piη_Z<‡z§èŒ)iÖwiÇ 2hÙ3·=’d÷8éŽ1¦¸c¤µ€7›7Ø ð\á)} ¹fËí›pAÃL%âc2 í§æQz¿;T8sæ°qø)QFMð‰XŒÂ±N¢aF¨…8¯!U  Z©RÊ ÖPVÄÀÍin™Ì-GˆªÅËŠ›•zË}º±ŽÍFò¹}Uw×#ä5B¤{î}Ð<ÙD é©¤&‡ïDbàÁôMÁ.. namespace core; use core_filetypes; defined('MOODLE_INTERNAL') || die(); global $CFG; require_once($CFG->libdir . '/filelib.php'); /** * Unit tests for /lib/classes/filetypes.php. * * @package core * @copyright 2014 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class filetypes_test extends \advanced_testcase { public function test_add_type() { $this->resetAfterTest(); // Check the filetypes to be added do not exist yet (basically this // ensures we're testing the cache clear). $types = get_mimetypes_array(); $this->assertArrayNotHasKey('frog', $types); $this->assertArrayNotHasKey('zombie', $types); // Add two filetypes (minimal, then all options). core_filetypes::add_type('frog', 'application/x-frog', 'document'); core_filetypes::add_type('zombie', 'application/x-zombie', 'document', array('document', 'image'), 'image', 'A zombie', true); // Check they now exist, and check data. $types = get_mimetypes_array(); $this->assertEquals('application/x-frog', $types['frog']['type']); $this->assertEquals('document', $types['frog']['icon']); $this->assertEquals(array('document', 'image'), $types['zombie']['groups']); $this->assertEquals('image', $types['zombie']['string']); $this->assertEquals(true, $types['zombie']['defaulticon']); $this->assertEquals('A zombie', $types['zombie']['customdescription']); // Test adding again causes exception. try { core_filetypes::add_type('frog', 'application/x-frog', 'document'); $this->fail(); } catch (\coding_exception $e) { $this->assertStringContainsString('already exists', $e->getMessage()); $this->assertStringContainsString('frog', $e->getMessage()); } // Test bogus extension causes exception. try { core_filetypes::add_type('.frog', 'application/x-frog', 'document'); $this->fail(); } catch (\coding_exception $e) { $this->assertStringContainsString('Invalid extension', $e->getMessage()); $this->assertStringContainsString('..frog', $e->getMessage()); } try { core_filetypes::add_type('', 'application/x-frog', 'document'); $this->fail(); } catch (\coding_exception $e) { $this->assertStringContainsString('Invalid extension', $e->getMessage()); } // Test there is an exception if you add something with defaulticon when // there is already a type that has it. try { core_filetypes::add_type('gecko', 'text/plain', 'document', array(), '', '', true); $this->fail(); } catch (\coding_exception $e) { $this->assertStringContainsString('default icon set', $e->getMessage()); $this->assertStringContainsString('text/plain', $e->getMessage()); } } public function test_update_type() { $this->resetAfterTest(); // Check previous value for the MIME type of Word documents. $types = get_mimetypes_array(); $this->assertEquals('application/msword', $types['doc']['type']); // Change it. core_filetypes::update_type('doc', 'doc', 'application/x-frog', 'document'); // Check the MIME type is now set and also the other (not specified) // options, like groups, were removed. $types = get_mimetypes_array(); $this->assertEquals('application/x-frog', $types['doc']['type']); $this->assertArrayNotHasKey('groups', $types['doc']); // This time change the extension. core_filetypes::update_type('doc', 'docccc', 'application/x-frog', 'document'); $types = get_mimetypes_array(); $this->assertEquals('application/x-frog', $types['docccc']['type']); $this->assertArrayNotHasKey('doc', $types); // Test unknown extension. try { core_filetypes::update_type('doc', 'doc', 'application/x-frog', 'document'); $this->fail(); } catch (\coding_exception $e) { $this->assertStringContainsString('not found', $e->getMessage()); $this->assertStringContainsString('doc', $e->getMessage()); } // Test bogus extension causes exception. try { core_filetypes::update_type('docccc', '.frog', 'application/x-frog', 'document'); $this->fail(); } catch (\coding_exception $e) { $this->assertStringContainsString('Invalid extension', $e->getMessage()); $this->assertStringContainsString('.frog', $e->getMessage()); } try { core_filetypes::update_type('docccc', '', 'application/x-frog', 'document'); $this->fail(); } catch (\coding_exception $e) { $this->assertStringContainsString('Invalid extension', $e->getMessage()); } // Test defaulticon changes. try { core_filetypes::update_type('docccc', 'docccc', 'text/plain', 'document', array(), '', '', true); $this->fail(); } catch (\coding_exception $e) { $this->assertStringContainsString('default icon set', $e->getMessage()); $this->assertStringContainsString('text/plain', $e->getMessage()); } } public function test_delete_type() { $this->resetAfterTest(); // Filetype exists. $types = get_mimetypes_array(); $this->assertArrayHasKey('doc', $types); // Remove it. core_filetypes::delete_type('doc'); $types = get_mimetypes_array(); $this->assertArrayNotHasKey('doc', $types); // Test removing one that doesn't exist causes exception. try { core_filetypes::delete_type('doc'); $this->fail(); } catch (\coding_exception $e) { $this->assertStringContainsString('not found', $e->getMessage()); $this->assertStringContainsString('doc', $e->getMessage()); } // Try a custom type (slightly different). core_filetypes::add_type('frog', 'application/x-frog', 'document'); $types = get_mimetypes_array(); $this->assertArrayHasKey('frog', $types); core_filetypes::delete_type('frog'); $types = get_mimetypes_array(); $this->assertArrayNotHasKey('frog', $types); } public function test_revert_type_to_default() { $this->resetAfterTest(); // Delete and then revert. core_filetypes::delete_type('doc'); $this->assertArrayNotHasKey('doc', get_mimetypes_array()); core_filetypes::revert_type_to_default('doc'); $this->assertArrayHasKey('doc', get_mimetypes_array()); // Update and then revert. core_filetypes::update_type('asm', 'asm', 'text/plain', 'sourcecode', array(), '', 'An asm file'); $types = get_mimetypes_array(); $this->assertEquals('An asm file', $types['asm']['customdescription']); core_filetypes::revert_type_to_default('asm'); $types = get_mimetypes_array(); $this->assertArrayNotHasKey('customdescription', $types['asm']); // Test reverting a non-default type causes exception. try { core_filetypes::revert_type_to_default('frog'); $this->fail(); } catch (\coding_exception $e) { $this->assertStringContainsString('not a default type', $e->getMessage()); $this->assertStringContainsString('frog', $e->getMessage()); } } /** * Check that the logic cleans up the variable by deleting parts that are * no longer needed. */ public function test_cleanup() { global $CFG; $this->resetAfterTest(); // The custom filetypes setting is empty to start with. $this->assertObjectNotHasAttribute('customfiletypes', $CFG); // Add a custom filetype, then delete it. core_filetypes::add_type('frog', 'application/x-frog', 'document'); $this->assertObjectHasAttribute('customfiletypes', $CFG); core_filetypes::delete_type('frog'); $this->assertObjectNotHasAttribute('customfiletypes', $CFG); // Change a standard filetype, then change it back. core_filetypes::update_type('asm', 'asm', 'text/plain', 'document'); $this->assertObjectHasAttribute('customfiletypes', $CFG); core_filetypes::update_type('asm', 'asm', 'text/plain', 'sourcecode'); $this->assertObjectNotHasAttribute('customfiletypes', $CFG); // Delete a standard filetype, then add it back (the same). core_filetypes::delete_type('asm'); $this->assertObjectHasAttribute('customfiletypes', $CFG); core_filetypes::add_type('asm', 'text/plain', 'sourcecode'); $this->assertObjectNotHasAttribute('customfiletypes', $CFG); // Revert a changed type. core_filetypes::update_type('asm', 'asm', 'text/plain', 'document'); $this->assertObjectHasAttribute('customfiletypes', $CFG); core_filetypes::revert_type_to_default('asm'); $this->assertObjectNotHasAttribute('customfiletypes', $CFG); // Revert a deleted type. core_filetypes::delete_type('asm'); $this->assertObjectHasAttribute('customfiletypes', $CFG); core_filetypes::revert_type_to_default('asm'); $this->assertObjectNotHasAttribute('customfiletypes', $CFG); } }