ÿØÿà 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/lib/form/tests/duration_test.php000064400000021101152267541160025135 0ustar00. namespace core_form; use moodleform; use MoodleQuickForm; defined('MOODLE_INTERNAL') || die(); global $CFG; require_once($CFG->libdir . '/form/duration.php'); /** * Unit tests for MoodleQuickForm_duration * * Contains test cases for testing MoodleQuickForm_duration * * @package core_form * @category test * @copyright 2009 Tim Hunt * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @covers \MoodleQuickForm_duration */ final class duration_test extends \basic_testcase { /** * Get a form that can be used for testing. * * @return MoodleQuickForm */ protected function get_test_form(): MoodleQuickForm { $form = new temp_form_duration(); return $form->get_form(); } /** * Get a form with a duration element that can be used for testing. * * @return array with two elements, a MoodleQuickForm and a MoodleQuickForm_duration. */ protected function get_test_form_and_element(): array { $mform = $this->get_test_form(); $element = $mform->addElement('duration', 'duration'); return [$mform, $element]; } /** * Test the constructor error handling. */ public function test_constructor_rejects_invalid_unit(): void { // Test trying to create with an invalid unit. $mform = $this->get_test_form(); $this->expectException(\coding_exception::class); $mform->addElement('duration', 'testel', null, ['defaultunit' => 123, 'optional' => false]); } /** * Test constructor only some units. */ public function test_constructor_limited_units(): void { $mform = $this->get_test_form(); $mform->addElement('duration', 'testel', null, ['units' => [MINSECS, 1], 'optional' => false]); $html = $mform->toHtml(); $html = preg_replace('~ +>~', '>', $html); // Clean HTML to avoid spurious errors. $this->assertStringContainsString('', $html); $this->assertStringContainsString('', $html); $this->assertStringNotContainsString('value="3600"', $html); } /** * Testcase for testing units (seconds, minutes, hours and days) */ public function test_get_units(): void { [$mform, $element] = $this->get_test_form_and_element(); $units = $element->get_units(); $this->assertEquals($units, [1 => get_string('seconds'), 60 => get_string('minutes'), 3600 => get_string('hours'), 86400 => get_string('days'), 604800 => get_string('weeks')]); } /** * Data provider for {@see test_seconds_to_unit()}. * * @return array test cases. */ public static function seconds_to_unit_cases(): array { return [ [[0, MINSECS], 0], // Zero minutes, for a nice default unit. [[1, 1], 1], [[3601, 1], 3601], [[1, MINSECS], 60], [[3, MINSECS], 180], [[1, HOURSECS], 3600], [[2, HOURSECS], 7200], [[1, DAYSECS], 86400], [[25, HOURSECS], 90000], ]; } /** * Testcase for testing conversion of seconds to the best possible unit. * * @dataProvider seconds_to_unit_cases * @param array $expected expected return value from seconds_to_unit * @param int $seconds value to pass to seconds_to_unit */ public function test_seconds_to_unit(array $expected, int $seconds): void { [, $element] = $this->get_test_form_and_element(); $this->assertEquals($expected, $element->seconds_to_unit($seconds)); } /** * Testcase for testing conversion of seconds to the best possible unit with a non-default default unit. */ public function test_seconds_to_unit_different_default_unit(): void { $mform = $this->get_test_form(); $element = $mform->addElement('duration', 'testel', null, ['defaultunit' => DAYSECS, 'optional' => false]); $this->assertEquals([0, DAYSECS], $element->seconds_to_unit(0)); } /** * Data provider for {@see test_export_value()}. * * @return array test cases. */ public static function export_value_cases(): array { return [ [10, '10', 1], [9, '9.3', 1], [10, '9.5', 1], [180, '3', MINSECS], [90, '1.5', MINSECS], [7200, '2', HOURSECS], [86400, '1', DAYSECS], [0, '0', HOURSECS], [0, '10', 1, 0, true], [20, '20', 1, 1, true], [0, '10', 1, 0, true, ''], [20, '20', 1, 1, true, ''], ]; } /** * Testcase to check generated timestamp * * @dataProvider export_value_cases * @param int $expected Expected value returned by the element. * @param string $number Number entered into the element. * @param int $unit Unit selected in the element. * @param int $enabled Whether the enabled checkbox on the form was selected. (Only used if $optional is true.) * @param bool $optional Whether the element has the optional option on. * @param string|null $label The element's label. */ public function test_export_value(int $expected, string $number, int $unit, int $enabled = 0, bool $optional = false, ?string $label = null): void { // Create the test element. $mform = $this->get_test_form(); $el = $mform->addElement('duration', 'testel', $label, $optional ? ['optional' => true] : []); // Prepare the submitted values. $values = ['testel' => ['number' => $number, 'timeunit' => $unit]]; if ($optional) { $values['testel']['enabled'] = $enabled; } // Test. $this->assertEquals(['testel' => $expected], $el->exportValue($values, true)); $this->assertEquals($expected, $el->exportValue($values)); } /** * Test cases for {@see test_validate_submit_value_negative_blocked()}. * @return array[] test cases. */ public static function validate_submit_value_cases(): array { return [ [false, -10, MINSECS, false], [false, 10, MINSECS, true], [false, 0, MINSECS, true], [true, -10, MINSECS, true], [true, 10, MINSECS, true], [true, 0, MINSECS, true], ]; } /** * Test for {@see MoodleQuickForm_duration::validateSubmitValue()}. * * @dataProvider validate_submit_value_cases * @param bool $allownegative whether the element should be created to allow negative values. * @param int $number the number submitted. * @param int $unit the unit submitted. * @param bool $isvalid whether this submission is valid. */ public function test_validate_submit_value(bool $allownegative, int $number, int $unit, bool $isvalid): void { $form = new temp_form_duration(null, null, 'post', '', null, true); /** @var \MoodleQuickForm_duration $element */ $element = $form->get_form()->addElement('duration', 'testel', '', ['allownegative' => $allownegative]); $values = ['testel' => ['number' => $number, 'timeunit' => $unit]]; if ($isvalid) { $this->assertNull($element->validateSubmitValue($values)); } else { $this->assertEquals( get_string('err_positiveduration', 'core_form'), $element->validateSubmitValue($values), ); } } } /** * Form object to be used in test case. */ class temp_form_duration extends moodleform { /** * Form definition. */ public function definition() { // No definition required. } /** * Returns form reference * @return MoodleQuickForm */ public function get_form() { $mform = $this->_form; // Set submitted flag, to simulate submission. $mform->_flagSubmitted = true; return $mform; } }