ÿØÿà 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/user/tests/profilelib_test.php000064400000035647152266357740024740 0ustar00. namespace core_user; /** * Unit tests for user/profile/lib.php. * * @package core_user * @copyright 2014 The Open University * @licensehttp://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ final class profilelib_test extends \advanced_testcase { /** * Load required test libraries */ public static function setUpBeforeClass(): void { global $CFG; require_once("{$CFG->dirroot}/user/profile/lib.php"); parent::setUpBeforeClass(); } /** * Tests profile_get_custom_fields function and checks it is consistent * with profile_user_record. */ public function test_get_custom_fields(): void { $this->resetAfterTest(); $user = $this->getDataGenerator()->create_user(); // Add a custom field of textarea type. $id1 = $this->getDataGenerator()->create_custom_profile_field([ 'shortname' => 'frogdesc', 'name' => 'Description of frog', 'datatype' => 'textarea'])->id; // Check the field is returned. $result = profile_get_custom_fields(); $this->assertArrayHasKey($id1, $result); $this->assertEquals('frogdesc', $result[$id1]->shortname); // Textarea types are not included in user data though, so if we // use the 'only in user data' parameter, there is still nothing. $this->assertArrayNotHasKey($id1, profile_get_custom_fields(true)); // Check that profile_user_record returns same (no) fields. $this->assertObjectNotHasProperty('frogdesc', profile_user_record($user->id)); // Check that profile_user_record returns all the fields when requested. $this->assertObjectHasProperty('frogdesc', profile_user_record($user->id, false)); // Add another custom field, this time of normal text type. $id2 = $this->getDataGenerator()->create_custom_profile_field(array( 'shortname' => 'frogname', 'name' => 'Name of frog', 'datatype' => 'text'))->id; // Check both are returned using normal option. $result = profile_get_custom_fields(); $this->assertArrayHasKey($id2, $result); $this->assertEquals('frogname', $result[$id2]->shortname); // And check that only the one is returned the other way. $this->assertArrayHasKey($id2, profile_get_custom_fields(true)); // Check profile_user_record returns same field. $this->assertObjectHasProperty('frogname', profile_user_record($user->id)); // Check that profile_user_record returns all the fields when requested. $this->assertObjectHasProperty('frogname', profile_user_record($user->id, false)); } /** * Make sure that all profile fields can be initialised without arguments. */ public function test_default_constructor(): void { global $DB, $CFG; require_once($CFG->dirroot . '/user/profile/definelib.php'); $datatypes = profile_list_datatypes(); foreach ($datatypes as $datatype => $datatypename) { require_once($CFG->dirroot . '/user/profile/field/' . $datatype . '/field.class.php'); $newfield = 'profile_field_' . $datatype; $formfield = new $newfield(); $this->assertNotNull($formfield); } } /** * Test profile_view function */ public function test_profile_view(): void { global $USER; $this->resetAfterTest(); // Course without sections. $course = $this->getDataGenerator()->create_course(); $context = \context_course::instance($course->id); $user = $this->getDataGenerator()->create_user(); $usercontext = \context_user::instance($user->id); $this->setUser($user); // Redirect events to the sink, so we can recover them later. $sink = $this->redirectEvents(); profile_view($user, $context, $course); $events = $sink->get_events(); $event = reset($events); // Check the event details are correct. $this->assertInstanceOf('\core\event\user_profile_viewed', $event); $this->assertEquals($context, $event->get_context()); $this->assertEquals($user->id, $event->relateduserid); $this->assertEquals($course->id, $event->other['courseid']); $this->assertEquals($course->shortname, $event->other['courseshortname']); $this->assertEquals($course->fullname, $event->other['coursefullname']); profile_view($user, $usercontext); $events = $sink->get_events(); $event = array_pop($events); $sink->close(); $this->assertInstanceOf('\core\event\user_profile_viewed', $event); $this->assertEquals($usercontext, $event->get_context()); $this->assertEquals($user->id, $event->relateduserid); } /** * Test that {@link user_not_fully_set_up()} takes required custom fields into account. */ public function test_profile_has_required_custom_fields_set(): void { global $CFG; require_once($CFG->dirroot.'/mnet/lib.php'); $this->resetAfterTest(); // Add a required, visible, unlocked custom field. $this->getDataGenerator()->create_custom_profile_field(['shortname' => 'house', 'name' => 'House', 'required' => 1, 'visible' => 1, 'locked' => 0, 'datatype' => 'text']); // Add an optional, visible, unlocked custom field. $this->getDataGenerator()->create_custom_profile_field(['shortname' => 'pet', 'name' => 'Pet', 'required' => 0, 'visible' => 1, 'locked' => 0, 'datatype' => 'text']); // Add required but invisible custom field. $this->getDataGenerator()->create_custom_profile_field(['shortname' => 'secretid', 'name' => 'Secret ID', 'required' => 1, 'visible' => 0, 'locked' => 0, 'datatype' => 'text']); // Add required but locked custom field. $this->getDataGenerator()->create_custom_profile_field(['shortname' => 'muggleborn', 'name' => 'Muggle-born', 'required' => 1, 'visible' => 1, 'locked' => 1, 'datatype' => 'checkbox']); // Create some student accounts. $hermione = $this->getDataGenerator()->create_user(); $harry = $this->getDataGenerator()->create_user(); $ron = $this->getDataGenerator()->create_user(); $draco = $this->getDataGenerator()->create_user(); // Hermione has all available custom fields filled (of course she has). profile_save_data((object)['id' => $hermione->id, 'profile_field_house' => 'Gryffindor']); profile_save_data((object)['id' => $hermione->id, 'profile_field_pet' => 'Crookshanks']); // Harry has only the optional field filled. profile_save_data((object)['id' => $harry->id, 'profile_field_pet' => 'Hedwig']); // Draco has only the required field filled. profile_save_data((object)['id' => $draco->id, 'profile_field_house' => 'Slytherin']); // Only students with required fields filled should be considered as fully set up in the default (strict) mode. $this->assertFalse(user_not_fully_set_up($hermione)); $this->assertFalse(user_not_fully_set_up($draco)); $this->assertTrue(user_not_fully_set_up($harry)); $this->assertTrue(user_not_fully_set_up($ron)); // In the lax mode, students do not need to have required fields filled. $this->assertFalse(user_not_fully_set_up($hermione, false)); $this->assertFalse(user_not_fully_set_up($draco, false)); $this->assertFalse(user_not_fully_set_up($harry, false)); $this->assertFalse(user_not_fully_set_up($ron, false)); // Lack of required core field is seen as a problem in either mode. unset($hermione->email); $this->assertTrue(user_not_fully_set_up($hermione, true)); $this->assertTrue(user_not_fully_set_up($hermione, false)); // When confirming remote MNet users, we do not have custom fields available. $roamingharry = mnet_strip_user($harry, ['firstname', 'lastname', 'email']); $roaminghermione = mnet_strip_user($hermione, ['firstname', 'lastname', 'email']); $this->assertTrue(user_not_fully_set_up($roamingharry, true)); $this->assertFalse(user_not_fully_set_up($roamingharry, false)); $this->assertTrue(user_not_fully_set_up($roaminghermione, true)); $this->assertTrue(user_not_fully_set_up($roaminghermione, false)); } /** * Test that user generator sets the custom profile fields */ public function test_profile_fields_in_generator(): void { global $CFG; require_once($CFG->dirroot.'/mnet/lib.php'); $this->resetAfterTest(); // Add a required, visible, unlocked custom field. $this->getDataGenerator()->create_custom_profile_field(['shortname' => 'house', 'name' => 'House', 'required' => 1, 'visible' => 1, 'locked' => 0, 'datatype' => 'text', 'defaultdata' => null]); // Create some student accounts. $hermione = $this->getDataGenerator()->create_user(['profile_field_house' => 'Gryffindor']); $harry = $this->getDataGenerator()->create_user(); // Only students with required fields filled should be considered as fully set up. $this->assertFalse(user_not_fully_set_up($hermione)); $this->assertTrue(user_not_fully_set_up($harry)); // Test that the profile fields were actually set. $profilefields1 = profile_user_record($hermione->id); $this->assertEquals('Gryffindor', $profilefields1->house); $profilefields2 = profile_user_record($harry->id); $this->assertObjectHasProperty('house', $profilefields2); $this->assertNull($profilefields2->house); } /** * Tests the profile_get_custom_field_data_by_shortname function when working normally. */ public function test_profile_get_custom_field_data_by_shortname_normal(): void { global $DB; $this->resetAfterTest(); // Create 3 profile fields. $generator = $this->getDataGenerator(); $field1 = $generator->create_custom_profile_field(['datatype' => 'text', 'shortname' => 'speciality', 'name' => 'Speciality', 'visible' => PROFILE_VISIBLE_ALL]); $field2 = $generator->create_custom_profile_field(['datatype' => 'menu', 'shortname' => 'veggie', 'name' => 'Vegetarian', 'visible' => PROFILE_VISIBLE_PRIVATE]); // Get the first field data and check it is correct. $data = profile_get_custom_field_data_by_shortname('speciality'); $this->assertEquals('Speciality', $data->name); $this->assertEquals(PROFILE_VISIBLE_ALL, $data->visible); $this->assertEquals($field1->id, $data->id); // Get the second field data, checking there is no database query this time. $before = $DB->perf_get_queries(); $data = profile_get_custom_field_data_by_shortname('veggie'); $this->assertEquals($before, $DB->perf_get_queries()); $this->assertEquals('Vegetarian', $data->name); $this->assertEquals(PROFILE_VISIBLE_PRIVATE, $data->visible); $this->assertEquals($field2->id, $data->id); } /** * Tests the profile_get_custom_field_data_by_shortname function with a field that doesn't exist. */ public function test_profile_get_custom_field_data_by_shortname_missing(): void { $this->assertNull(profile_get_custom_field_data_by_shortname('speciality')); } /** * Data provider for {@see test_profile_get_custom_field_data_by_shortname_case_sensitivity} * * @return array[] */ public static function profile_get_custom_field_data_by_shortname_case_sensitivity_provider(): array { return [ 'Matching case, case-sensitive search' => ['hello', 'hello', true, true], 'Matching case, case-insensitive search' => ['hello', 'hello', false, true], 'Non-matching case, case-sensitive search' => ['hello', 'Hello', true, false], 'Non-matching case, case-insensitive search' => ['hello', 'Hello', false, true], 'Non-matching, case-sensitive search' => ['hello', 'hola', true, false], 'Non-matching, case-insensitive search' => ['hello', 'hola', false, false], ]; } /** * Test retrieving custom field by shortname, specifying case-sensitivity when matching * * @param string $shortname * @param string $shortnamesearch * @param bool $casesensitive * @param bool $expectmatch * * @dataProvider profile_get_custom_field_data_by_shortname_case_sensitivity_provider */ public function test_profile_get_custom_field_data_by_shortname_case_sensitivity( string $shortname, string $shortnamesearch, bool $casesensitive, bool $expectmatch ): void { $this->resetAfterTest(); $this->getDataGenerator()->create_custom_profile_field([ 'datatype' => 'text', 'shortname' => $shortname, 'name' => 'My field', ]); $customfield = profile_get_custom_field_data_by_shortname($shortnamesearch, $casesensitive); if ($expectmatch) { $this->assertInstanceOf(\stdClass::class, $customfield); $this->assertEquals('text', $customfield->datatype); $this->assertEquals($shortname, $customfield->shortname); $this->assertEquals('My field', $customfield->name); } else { $this->assertNull($customfield); } } /** * Test profile field loading via profile_get_user_field helper * * @covers ::profile_get_user_field */ public function test_profile_get_user_field(): void { $this->resetAfterTest(); $profilefield = $this->getDataGenerator()->create_custom_profile_field([ 'shortname' => 'fruit', 'name' => 'Fruit', 'datatype' => 'text', ]); $user = $this->getDataGenerator()->create_user(['profile_field_fruit' => 'Apple']); $fieldinstance = profile_get_user_field('text', $profilefield->id, $user->id); $this->assertInstanceOf(\profile_field_text::class, $fieldinstance); $this->assertEquals($profilefield->id, $fieldinstance->fieldid); $this->assertEquals($user->id, $fieldinstance->userid); $this->assertEquals('Apple', $fieldinstance->data); } }