ÿØÿà JFIF    ÿÛ „  ( %!1"%)+...383-7(-.+  -%%--------+------------/----------------------------ÿÀ  ¶" ÿÄ     ÿÄ @    !1AQaq‘¡"±ÁÑð2’BRráS‚ñ3b¢CT²Ò #cÿÄ    ÿÄ '   1!AQ2a"‘±#ÿÚ   ? ò(/p‘—–¢·,M|¯G»R£üešT. ôŸEoCFñ‡ 4ÔkåóxR|µÁ¨ÓDà!Ç´µ˜‡p ÍQ‹§!þž^õWsŒy  åÁ§$á«%ºq˜™JyyË0y«^Ϗ -3ÃÏËÈ£Æ\P’ä„s&•‹Üs üô'àWt¹pñCp$bÚF`·7.^)¾!)ÒÙ˜–ÅÏš^h¾ø³·ìe±ŒaeÖ—Í,e=B}Jéߦ$$½—šÙÜCC¯¶è8β–Åkèwx LÉngT±æ¹£Ócœ¿Í/©Éÿ ‰ÚCÒ­mq;Tt¶–}0"zÖPcd1š­¤tˆ„ÐÓâqú[™öUCŠ2޿د­É(¸ßúçšmW,Ò ºf‹Ån™ÄLêÁ8üÁkÁ€L¥ÍuJ1œôrÂSŒÓöt!7EUíïb)AËi¬â-ÙHk8òÁiXYwÅ)O^"ÇØriÛô{»wRUKÙÏÚlÓ¬€‚’שT ] ªb—ÊîKC^×M“xùäñz¬zJ× {4[¹M'IÆeH1LCWÕ]œûº WDæà°OÅ‚¹c²ÞuA–rL`HšpCez‡V’— Ž‚Ë„–ñ­'µR0ÕÖ=À:±G»C\nÆÉ5*¢ †3šhQ4ýÒi$Õ1"Ü]¢p-q3zcQ$ªö¨¥æf›‘»´ÝÚHá„e²JÇ–iÊ:·à¬Øc5Åk»Laª*wi [0Ówk ¦a¦0Õ²ÅÅ‚T¸’³q:Æ<¹ú Ò˜Æ}2VE•Ѐp¡Ô3Úº …h³^LJºçì¥Ánó|˜ÖˆÎˆ+« ¦dø‘Mº–d\ªDðÛ„Ì×LÝ——Ð9Ç|•FèçVm™¨€™3õS–9Äå¢<̉Ìm¢±`·º˜&Z²ž Ë®D«¶»6™‰©­HÈ Àá«h­i³04æ’hxœi3ï¨(ÓL·†‹¶ËpŒ ƒÜÒ? :õdsÀ –3æÓ·Üjâ¬9—]8n¼&]I F£¼…ì–—Œ0v°LǐÅfÛ2TÖ’aµ˜N@ÖBSÏ^à´4-±°b×nÈÈœÆD=KdŒø…ÄÈK,›ÖR§fjü$^ÔÎ!„6^ s:Üun\ôkCÞò÷<—Lúl Í›G¹ÀPá¼Nc¡šÒ…ÙWͳœ±vÊáЄ×9‹P‰cEØ‘™›µŸP<×g1 º©Ø¬wiÁ^l5× I/';Ë+´Z‡ÓÄFÕp[Èð’ HÄ ó 9¬Dl4“é±Ï”V=^Hð;žLädÉa‚°Ë,#/Ž~²BÔÛ QãñQtIeórVB,ÏÂf‹4#Μc‹É3ZIÖ Œ¢¥·üxa‡Ãçè„jŠ[5 Ä!U?,3žÎ×…ðdÓ÷háŠA‰ìÄ4÷ÃÜZÃE{‰®+W\ZÍE[‰»µk»MÝ­`¢©†˜ÃV‹-f¢¡†¢a«eŠ%«Y¨©q%jâd,Ôq`) ¤¦…šˆ ¦E>0Ùb²t–Ÿ  ÷jsςҒKÈcø(é›;k(’#ôŒQ ™C> õ³M9óºÆµ¤çâ;uÀ)5>RÔ¸fÓ~Ȧ—’-$fe«"FâUˆÊwµPÏu w+"åÉó¨6s™Û9(À¨ù©hE°½†n`m~“@©›p!Vkhµ Á1šbEqqÊ@ºèl›2 –Yã%‘‚hÛ{a¶‡ÅÞM²¬çL34®Çl]®‹ŽØŒm'RÜe35æöˆ­Á­ cP9šeÁköo´L³Ì=p8]”‡B¶,šº|ɏdzXˆØk*ÇÚ{#ñ‰pã(€¶‡9ý'šÜ³½¯kƒ†Â’ëSOƒ•Å®H6+a¢µˆ‹Y¨b˜b+XˆÖ!°u!¢"µˆˆn2ˆ Å0Ä`Å Ô®c(ÓÜGº•Ä»Œ âWî%q.áÐÄ÷î%umÍ£+ÜQ,Vn¦-GphU¸¢X­&,Gt ·K¢ÅÅ·¥RÄÊÉbKn N­R2g$VµÕó Qr#–ÓZUÏð0ÎtÙÀœz ëöo“Îk¯n„T°"SÞ+³/…€½"ižãO%Í%&Δâ‘ËØ´IˆÓ°Ë‰ÞM3.™yçÁzit›`4C`k¢¼á!álÄï sÂ[×!¤l¾æo"ƒIÔ'@ªu)3›ô®“@Z à¾] üœ'‡4¸PÞkÁ-qÄH‰ÓÍBd´ÿ —¹°ÄA&ÊUC„öz‚‚RæŠtf¬>˜ÑidšEçÑL÷áý¡V±h§­c¿¥¨ƒ@g¼…Ýö^ÞËc.ž„æ“I[ ª+·zÐÒÚ,½Ð»¶€C›7jk$๖€Ž¾ÅÙpp¶ÍþéΤ ½ØÎŒq ñpæžÅ¥#Øâ49ÃÂK^MYV“,¶Éz_òæ:…;Õ«¦I3âJ£¤û5$7Èxün\â]Êe¯(Ÿ&Ž‹¶2<6Ćf× æ¢ƱqWı[(ÙÂŽç‚T7¨@ÈÉÍß‚ïÙ"&3TYlGށ†)†#5ŠA©^T2ÆÁ†)©†©†¤yGXÁ†©"†)©¼ÅV WS†#©]R–r‹q5ÕbâWþBh¯u+ªÅÄ×ü„nÑ^êkªÁj‰jeœWˆÕÕ`µDµ2Ì+Ä µDµµ5Ô{¤Þ0RF’H÷AÛ<ÊÁ§ ƈæ0Ñ£ê4 öÚµ[¬/1²€â<-¬šö²r×0o×w ´xÐÒË„ g01¬„åEM蛇Ã\6µE›‘fÙO k÷CºnÓ1`iîÒ² áÂ!ÑLÄÿ ³¬\õ*:M=Ç»c‹2[‰ØsÕLò\ŒK L^™üÄN\¶#» Ç\……ßïIœÉ$¸ÎñÍ®ÔHÇ Ûí/´>Li”„†g^$ 7NÍÑÑ2M2ªNg=k½Ð}Ÿl6‡ —JWˆ”ÞéT·+µ¦üÂFè¢Vs6ýÆ4»2+2IÝ9ô9®ÇGÙÇ1+Ä8;*Õ§ž½D*îÑWÚçá3Ma¤·ˆ¥t}š²Ü…Q+Æüµ8HíS”üxGéÁˆ¦Ël„éÈ 5 µÄƒ6äÜ(kIš¯S†fÖ&¸®×v|Äyˆ*禌Éù@7-®Ä[]ÎÖ¿ê`º…=:…žJVnݳvðÖKE¼‚ »mà ÷f®:Ë ™–4rð¡4` ܹçž~‹C=œ…¾Ïj|VDtK.ƒ"9 Ï ­–éXá³6WÒïIL-Ї Ç home/smkb8269/public_html/lms.smk-almanshuriyah.sch.id/files/tests/conversion_test.php000064400000043242152266420150025072 0ustar00. namespace core_files; /** * PHPUnit tests for conversion persistent. * * @package core_files * @copyright 2017 Andrew nicols * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ final class conversion_test extends \advanced_testcase { /** * Helper to create a stored file object with the given supplied content. * * @param string $filecontent The content of the mocked file * @param string $filename The file name to use in the stored_file * @param string $filerecord Any overrides to the filerecord * @return \stored_file */ protected function create_stored_file($filecontent = 'content', $filename = 'testfile.txt', $filerecord = []) { $filerecord = array_merge([ 'contextid' => \context_system::instance()->id, 'component' => 'core', 'filearea' => 'unittest', 'itemid' => 0, 'filepath' => '/', 'filename' => $filename, ], $filerecord); $fs = get_file_storage(); $file = $fs->create_file_from_string($filerecord, $filecontent); return $file; } /** * Ensure that get_conversions_for_file returns an existing conversion * record with matching sourcefileid and targetformat. */ public function test_get_conversions_for_file_existing_conversion_incomplete(): void { $this->resetAfterTest(); $sourcefile = $this->create_stored_file(); $existing = new conversion(0, (object) [ 'sourcefileid' => $sourcefile->get_id(), 'targetformat' => 'pdf', ]); $existing->create(); $conversions = conversion::get_conversions_for_file($sourcefile, 'pdf'); $this->assertCount(1, $conversions); $conversion = array_shift($conversions); $conversionfile = $conversion->get_sourcefile(); $this->assertEquals($sourcefile->get_id(), $conversionfile->get_id()); $this->assertFalse($conversion->get_destfile()); } /** * Ensure that get_conversions_for_file returns an existing conversion * record with matching sourcefileid and targetformat when a file with the same * contenthash is uploaded several times. * * @covers \core_files\conversion::get_conversions_for_file */ public function test_get_conversions_for_multiple_files_existing_conversion_incomplete(): void { $this->resetAfterTest(); // Create a bunch of files with the same content. for ($i = 0; $i < 5; $i++) { $sourcefiles[] = $this->create_stored_file('test content', 'testfile' . $i . '.txt'); } // Use only one file for the conversion. // Pick some file in the middle. $sourcefile = $sourcefiles[count($sourcefiles) - 2]; $existing = new conversion(0, (object) [ 'sourcefileid' => $sourcefile->get_id(), 'targetformat' => 'pdf', ]); $existing->create(); $conversions = conversion::get_conversions_for_file($sourcefile, 'pdf'); $this->assertCount(1, $conversions); $conversion = array_shift($conversions); $conversionfile = $conversion->get_sourcefile(); $this->assertEquals($sourcefile->get_id(), $conversionfile->get_id()); $this->assertFalse($conversion->get_destfile()); // Check that getting the conversion for a different file record with the same contenthash // returns the same conversion as above. $conversions = conversion::get_conversions_for_file($sourcefiles[count($sourcefiles) - 1], 'pdf'); $this->assertCount(1, $conversions); $conversion = array_shift($conversions); $conversionfile = $conversion->get_sourcefile(); $this->assertEquals($existing->get('id'), $conversion->get('id')); $this->assertEquals($sourcefile->get_id(), $conversionfile->get_id()); $this->assertFalse($conversion->get_destfile()); } /** * Ensure that get_conversions_for_file returns an existing conversion * record with matching sourcefileid and targetformat when a second * conversion to a different format exists. */ public function test_get_conversions_for_file_existing_conversion_multiple_formats_incomplete(): void { $this->resetAfterTest(); $sourcefile = $this->create_stored_file(); $existing = new conversion(0, (object) [ 'sourcefileid' => $sourcefile->get_id(), 'targetformat' => 'pdf', ]); $existing->create(); $second = new conversion(0, (object) [ 'sourcefileid' => $sourcefile->get_id(), 'targetformat' => 'doc', ]); $second->create(); $conversions = conversion::get_conversions_for_file($sourcefile, 'pdf'); $this->assertCount(1, $conversions); $conversion = array_shift($conversions); $conversionfile = $conversion->get_sourcefile(); $this->assertEquals($sourcefile->get_id(), $conversionfile->get_id()); $this->assertFalse($conversion->get_destfile()); } /** * Ensure that get_conversions_for_file returns an existing conversion * record with matching sourcefileid and targetformat. */ public function test_get_conversions_for_file_existing_conversion_complete(): void { $this->resetAfterTest(); $sourcefile = $this->create_stored_file(); $destfile = $this->create_stored_file( 'example content', $sourcefile->get_contenthash(), [ 'component' => 'core', 'filearea' => 'documentconversion', 'filepath' => '/pdf/', ]); $existing = new conversion(0, (object) [ 'sourcefileid' => $sourcefile->get_id(), 'targetformat' => 'pdf', 'destfileid' => $destfile->get_id(), ]); $existing->create(); $conversions = conversion::get_conversions_for_file($sourcefile, 'pdf'); // Only one file should be returned. $this->assertCount(1, $conversions); $conversion = array_shift($conversions); $this->assertEquals($existing->get('id'), $conversion->get('id')); $this->assertEquals($sourcefile->get_id(), $conversion->get_sourcefile()->get_id()); $this->assertEquals($destfile->get_id(), $conversion->get_destfile()->get_id()); } /** * Ensure that get_conversions_for_file returns an existing conversion * record with matching sourcefileid and targetformat. */ public function test_get_conversions_for_file_existing_conversion_multiple_formats_complete(): void { $this->resetAfterTest(); $sourcefile = $this->create_stored_file(); $destfile = $this->create_stored_file( 'example content', $sourcefile->get_contenthash(), [ 'component' => 'core', 'filearea' => 'documentconversion', 'filepath' => '/pdf/', ]); $existing = new conversion(0, (object) [ 'sourcefileid' => $sourcefile->get_id(), 'targetformat' => 'pdf', 'destfileid' => $destfile->get_id(), ]); $existing->create(); $second = new conversion(0, (object) [ 'sourcefileid' => $sourcefile->get_id(), 'targetformat' => 'doc', ]); $second->create(); $conversions = conversion::get_conversions_for_file($sourcefile, 'pdf'); // Only one file should be returned. $this->assertCount(1, $conversions); $conversion = array_shift($conversions); $this->assertEquals($sourcefile->get_id(), $conversion->get_sourcefile()->get_id()); $this->assertEquals($destfile->get_id(), $conversion->get_destfile()->get_id()); } /** * Ensure that get_conversions_for_file returns an existing conversion * record does not exist, but the file has previously been converted. */ public function test_get_conversions_for_file_existing_target(): void { $this->resetAfterTest(); $sourcefile = $this->create_stored_file(); $destfile = $this->create_stored_file( 'example content', $sourcefile->get_contenthash(), [ 'component' => 'core', 'filearea' => 'documentconversion', 'filepath' => '/pdf/', ]); $conversions = conversion::get_conversions_for_file($sourcefile, 'pdf'); $this->assertCount(1, $conversions); $conversion = array_shift($conversions); $conversionsource = $conversion->get_sourcefile(); $this->assertEquals($sourcefile->get_id(), $conversionsource->get_id()); $conversiondest = $conversion->get_destfile(); $this->assertEquals($destfile->get_id(), $conversiondest->get_id()); } /** * Ensure that set_sourcefile sets the correct fileid. */ public function test_set_sourcefile(): void { $this->resetAfterTest(); $sourcefile = $this->create_stored_file(); $conversion = new conversion(0, (object) []); $conversion->set_sourcefile($sourcefile); $this->assertEquals($sourcefile->get_id(), $conversion->get('sourcefileid')); $this->assertNull($conversion->get('destfileid')); } /** * Ensure that store_destfile_from_path stores the file as expected. */ public function test_store_destfile_from_path(): void { $this->resetAfterTest(); $sourcefile = $this->create_stored_file(); $conversion = new conversion(0, (object) [ 'sourcefileid' => $sourcefile->get_id(), 'targetformat' => 'pdf', ]); $fixture = __FILE__; $conversion->store_destfile_from_path($fixture); $destfile = $conversion->get_destfile(); $this->assertEquals(file_get_contents($fixture), $destfile->get_content()); } /** * Ensure that store_destfile_from_path stores the file as expected. */ public function test_store_destfile_from_path_delete_existing(): void { $this->resetAfterTest(); $sourcefile = $this->create_stored_file(); $conversion = new conversion(0, (object) [ 'sourcefileid' => $sourcefile->get_id(), 'targetformat' => 'pdf', ]); $record = [ 'contextid' => \context_system::instance()->id, 'component' => 'core', 'filearea' => 'documentconversion', 'itemid' => 0, 'filepath' => '/pdf/', ]; $existingfile = $this->create_stored_file('foo', $sourcefile->get_contenthash(), $record); $fixture = __FILE__; $conversion->store_destfile_from_path($fixture); $destfile = $conversion->get_destfile(); $this->assertEquals(file_get_contents($fixture), $destfile->get_content()); } /** * Ensure that store_destfile_from_path stores the file as expected. */ public function test_store_destfile_from_string(): void { $this->resetAfterTest(); $sourcefile = $this->create_stored_file(); $conversion = new conversion(0, (object) [ 'sourcefileid' => $sourcefile->get_id(), 'targetformat' => 'pdf', ]); $fixture = 'Example content'; $conversion->store_destfile_from_string($fixture); $destfile = $conversion->get_destfile(); $this->assertEquals($fixture, $destfile->get_content()); } /** * Ensure that store_destfile_from_string stores the file as expected when * an existing destfile is found. */ public function test_store_destfile_from_string_delete_existing(): void { $this->resetAfterTest(); $sourcefile = $this->create_stored_file(); $conversion = new conversion(0, (object) [ 'sourcefileid' => $sourcefile->get_id(), 'targetformat' => 'pdf', ]); $record = [ 'contextid' => \context_system::instance()->id, 'component' => 'core', 'filearea' => 'documentconversion', 'itemid' => 0, 'filepath' => '/pdf/', ]; $existingfile = $this->create_stored_file('foo', $sourcefile->get_contenthash(), $record); $fixture = 'Example content'; $conversion->store_destfile_from_string($fixture); $destfile = $conversion->get_destfile(); $this->assertEquals($fixture, $destfile->get_content()); } /** * Ensure that the get_status functions cast the status to integer correctly. */ public function test_get_status(): void { $conversion = new conversion(0, (object) [ 'status' => (string) 1, ]); $this->assertIsInt($conversion->get('status')); } /** * Ensure that get_converter_instance returns false when no converter is set. */ public function test_get_converter_instance_none_set(): void { $conversion = new conversion(0, (object) []); $this->assertFalse($conversion->get_converter_instance()); } /** * Ensure that get_converter_instance returns false when no valid converter is set. */ public function test_get_converter_instance_invalid_set(): void { $conversion = new conversion(0, (object) [ 'converter' => '\\fileconverter_not_a_valid_converter\\converter', ]); $this->assertFalse($conversion->get_converter_instance()); } /** * Ensure that get_converter_instance returns an instance when a valid converter is set. */ public function test_get_converter_instance_valid_set(): void { $conversion = new conversion(0, (object) [ 'converter' => \fileconverter_unoconv\converter::class, ]); $this->assertInstanceOf(\fileconverter_unoconv\converter::class, $conversion->get_converter_instance()); } /** * Test that all old conversion records are removed periodically. */ public function test_remove_old_conversion_records_old(): void { $this->resetAfterTest(); global $DB; $sourcefile = $this->create_stored_file(); $conversion = new conversion(0, (object) [ 'sourcefileid' => $sourcefile->get_id(), 'targetformat' => 'pdf', ]); $conversion->create(); $DB->set_field(conversion::TABLE, 'timemodified', time() - YEARSECS); conversion::remove_old_conversion_records(); $this->assertEquals(0, $DB->count_records(conversion::TABLE)); } /** * Test that all old conversion records are removed periodically. */ public function test_remove_old_conversion_records_young(): void { $this->resetAfterTest(); global $DB; $sourcefile = $this->create_stored_file(); $conversion = new conversion(0, (object) [ 'sourcefileid' => $sourcefile->get_id(), 'targetformat' => 'pdf', ]); $conversion->create(); $DB->set_field(conversion::TABLE, 'timemodified', time() - DAYSECS); conversion::remove_old_conversion_records(); $this->assertEquals(1, $DB->count_records(conversion::TABLE)); } /** * Test orphan records are removed. */ public function test_remove_orphan_records(): void { global $DB; $this->resetAfterTest(); $sf1 = $this->create_stored_file('1', '1'); $sf2 = $this->create_stored_file('2', '2'); $sf3 = $this->create_stored_file('3', '3'); $c1 = new conversion(0, (object) ['sourcefileid' => $sf1->get_id(), 'targetformat' => 'pdf']); $c1->create(); $c2 = new conversion(0, (object) ['sourcefileid' => $sf2->get_id(), 'targetformat' => 'pdf']); $c2->create(); $c3 = new conversion(0, (object) ['sourcefileid' => $sf3->get_id(), 'targetformat' => 'pdf']); $c3->create(); $this->assertTrue(conversion::record_exists($c1->get('id'))); $this->assertTrue(conversion::record_exists($c2->get('id'))); $this->assertTrue(conversion::record_exists($c3->get('id'))); // Nothing should happen here. conversion::remove_orphan_records(); $this->assertTrue(conversion::record_exists($c1->get('id'))); $this->assertTrue(conversion::record_exists($c2->get('id'))); $this->assertTrue(conversion::record_exists($c3->get('id'))); // Delete file #2. $sf2->delete(); conversion::remove_orphan_records(); $this->assertTrue(conversion::record_exists($c1->get('id'))); $this->assertFalse(conversion::record_exists($c2->get('id'))); $this->assertTrue(conversion::record_exists($c3->get('id'))); // Delete file #1, #3. $sf1->delete(); $sf3->delete(); conversion::remove_orphan_records(); $this->assertFalse(conversion::record_exists($c1->get('id'))); $this->assertFalse(conversion::record_exists($c2->get('id'))); $this->assertFalse(conversion::record_exists($c3->get('id'))); } }