....................................../////.===Shadow-Here===./////................................................ > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < ------------------------------------------------------------------------------------------------------------------- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// RIFF¤ WEBPVP8 ˜ ðÑ *ôô>‘HŸK¥¤"§£±¨àð enü¹%½_F‘åè¿2ºQú³íªú`N¿­3ÿƒügµJžaÿ¯ÿ°~¼ÎùnúîÞÖô•òíôÁÉß®Sm¥Ü/ ‡ó˜f£Ùà<˜„xëJ¢Ù€SO3x<ªÔ©4¿+ç¶A`q@Ì“Úñè™ÍÿJÌ´ª-˜ÆtÊÛL]Ïq*‘Ý”ì#ŸÌÏãY]@ê`¿ /ªfkØB4·®£ó z—Üw¥Pxù–ÞLШKÇN¾AkÙTf½è'‰g gÆv›Øuh~ a˜Z— ïj*á¥t d£“uÒ ¨`K˜¹ßþ]b>˜]_ÏÔ6W—è2r4x•íÖ…"ƒÖNîä!¦å Ú}ýxGøÌ —@ ;ÆÚŠ=ɾ1ý8lªË¥ô ^yf®Œ¢u&2©nÙÇ›ñÂñŒ³ aPo['½»øFùà­+4ê“$!lövlüÞ=;N®3ð‚õ›DÉKòÞ>ÄÍ ¥ˆuߤ#ˆ$6ù™¥îЇy’ÍB¼ çxÛ;X"WL£R÷͝*ó-¶Zu}º.s¸sšXqù–DþÿvªhüïwyŸ ¯é³lÀ:KCûÄ£Ëá\…­ ~—ýóî ¼ûûÜTÓüÇy…ŽÆvc»¾×U ñ¸žþоP÷¦ó:Ò¨¨5;Ð#&#ÖúñläÿÁœ GxÉ­/ñ‡áQðìYÉtÒw޼GÔ´zàÒò ð*ëzƒ•4~H]Ø‹f ñÓÈñ`NåWçs'ÆÏW^ø¹!XžµmQ5ÃËoLœÎ: ÞËÍ¥J ù…î èo£ßPÎñ¶ž8.Œ]ʵ~5›ÙË-ù*8ÙÖß±~ ©¹rÓê‚j¶d¸{^Q'˜±Crß ÚH—#¥¥QlÀ×ëã‡DÜ«èî þ&Çæžî;ŽÏºò6ÒLÃXy&ZŒ'j‚¢Ù€IßÚù+–MGi‰*jE€‘JcÜ ÓÌ EÏÚj]o˜ Þr <¾U ûŪæÍ/šÝH¥˜b”¼ ÁñßX GP›ï2›4WŠÏà×£…íÓk†¦H·ÅíMh–*nó÷à]ÁjCº€b7<ب‹¨5車bp2:Á[UªM„QŒçiNMa#<5›áËó¸HýÊ"…×Éw¹¦ì2º–x<›»a±¸3Weü®FÝ⑱ö–î–³|LPÈ~çð~Çå‡|º kD¢µÏàÆAI %1À% ¹Ò – ”ϝS¦‰4&¶£°à Öý”û_Ò Áw°A«Å€?mÇÛgHÉ/8)á¾ÛìáöŽP í¨PŸNÙµº¦‡§Ùš"ÿ«>+ªÕ`Ê÷‡‚ß Õû˜þãÇ-PÍ.¾XV‘€ dÜ"þ4¹ ±Oú‘©t¥¦FªÄÃÄ•b‚znýu½—#cDs˜ÃiÑOˆñ×QO=*IAÊ,¶ŽZƒ;‡wøXè%EÐk:F±Ú” .Ѽ+Áu&Ç`."pÈÉw o&¿dE6‘’EqTuK@Ì¥ã™À(Êk(h‰,H}RÀIXÛš3µ1©_OqÚÒJAñ$ÊÙÜ;D3çŒ[þùœh¬Ã³™ö6ç†NY".Ú‰ï[ªŸŒ '²Ð öø_¨ÂÉ9ué¶³ÒŠõTàîMØ#û¯gN‡bÙ놚X„ö …ÉeüÌ^J ‹€.œ$Æ)βÄeæW#óüßĺŸ€ ÀzwV 9oä»f4V*uB «Ë†¹ì¯žR霓æHXa=&“I4K;¯ç‹h×·"UŠ~<•╪Vêª&ÍSÃÆÅ?ÔqÎ*mTM ˜›µwêd#[C¡©§‘D<©àb†–ÁœøvH/,í:¯( ²£|4-„Æövv„Yͼ™^Á$ˆ„¢Û[6yB.åH*V¨æ?$=˜Ñ€•ñ·­(VlŸ‘ nÀt8W÷´Bûba?q9ú¶Xƒl«ÿ\ù¶’þòUÐj/õ¢Ìµ³g$ƒÎR!¸»|Oߍë’BhîÚÑ¢ñåŒJ„®„£2Ð3•ô02Nt…!£Í]Ïc½Qÿ?ˆ<&ÃA¾Ú,JˆijÌ#5yz„‰Î|ÊŽ5QÏ:‹ÐaóVÔxW—CpeÏzÐïíçôÿÅ_[hãsÐ_/ŽTÝ?BîˆííV$<¿i>²F¬_Eß¿ †bÊŒº­ÿ®Z H“C}”¬,Mp ý/Bá£w>˜YV°aƒúh+cŠ- r/[%|üUMHäQ°X»|û/@|°¥Ð !BÔ Ç¢Ä©š+Õì D«7ìN¶ŽðÔ " ƶ’ÖçtA‰Û×}{tþz­¾GÍ›k¹OEJR$ Â׃ «ëÁ"oÉôž$oUK(Ä)Ãz³Ê-‹êN[Ò3Œñbï8P 4ƒ×q¢bo|?<ÛX¬òÄͰL–±›(™ûG?ýË©ÚÄ–ÂDØÐ_Ç¡ô ¾–ÄÏø ×e8Ë©$ÄF¹Å‹ì[©óìl:F¾f´‹‹Xì²ï®\¬ôùƒ ÿat¥óèÒùHß0äe‚;ü×h:ÆWðHž=Ã8骣"kœ'Y?³}Tûè€>?0l›e1Lòñ„aæKÆw…hÖŠùW…ÈÆÄ0ši·›[pcwËþñiêíY/~-Á5˜!¿†A›™Mÿþ(±“t@â“ö2­´TG5yé]çå僳 .·ÍïçÝ7UÚ±Ð/Nè»,_Ï ùdj7\ï Wì4›„»c¸àešg#ÒÊ⥭áØo5‘?ÌdÝô¯ ¹kzsƒ=´#ëÉK›Ø´±-¥eW?‡çßtòTã…$Ý+qÿ±ƒ÷_3Ô¥í÷:æ–ž<·Ö‡‰Å¢ š‡%Ô—utÌÈìðžgÖÀz²À—ï÷Óîäõ{K'´È÷³yaÏÁjƒô}ž§®æÊydÕÈë5¯èˆõvÕ©ã*çD„ “z„Ó‡^^xÂ3M§A´JG‚öï 3W'ˆ.OvXè¡ÊÕª?5º7†˜(˜Ç¶#çê’¶!ÌdZK§æ 0fãaN]òY³RV ™î$®K2R¨`W!1Ôó\;Ý ýB%qæK•&ÓÈe9È0êI±žeŸß -ú@žQr¦ ö4»M¼Áè¹µmw 9 EÆE_°2ó„ŸXKWÁ×Hóì^´²GѝF©óäR†¦‰ç"V»eØ<3ùd3ÿÚ¤Žú“Gi" —‘_ÙËÎ~Üö¯¥½Î»üŸEÚŽåmÞþí ;ÞólËΦMzA"Âf(´òá;Éï(/7½ûñÌ­cïÕçлþÝz¾-ÍvÑ“pH­–ðÓj$¸Äû¤‚‘ãUBË-n“2åPkS5&‹Â|+g^œ®Ì͆d!OïäîU«c;{Û!ÅŽ«ëZ9Ókóˆ]¯ƒ›né `ÇÒ+tÆš (ØKá¾—=3œ®•vuMñg²\ï Ec€ 05±d™‡×iÇ×›UúvÌ¢£Èþ¡ÕØô¶ßÎA"ß±#Ö²ˆÊŸ¦*Ä~ij|àø.-¼'»Ú¥£h ofº¦‡VsR=N½„Î v˜Z*SÌ{=jÑB‹tê…;’HžH¯8–îDù8ñ¢|Q•bÛçš–‹m³“ê¨ åÏ^m¬Žãþ©ïêO‡½6] µÆ„Ooòü ²x}N¦Ë3ïé¿»€›HA˜m%çÞ/¿í7Fø“‹léUk)É°Œµ8Q8›:ÀŠeT*šõ~ôڝG6 ¢}`ùH­–”¡k ‰P1>š†®9z11!X wKfmÁ¦xÑ,N1Q”–æB¶M…ÒÃv6SMˆhU¬ÊPŽï‘öj=·CŒ¯u¹ƒVIЃsx4’ömÛýcå¡¶7ßŠß 57^\wÒÐÆ k§h,Œý î«q^R½3]J¸ÇðN ‚çU¬ôº^Áì} ³f©Õœ§ˆã:FÄÈ‚é(€™?àýÓüè1Gô£¼éj‚OÅñ  #>×—ßtà 0G¥Åa뀐kßhc™À_ÉñÞ#±)GD" YîäË-ÿÙ̪ ¹™a¯´¢E\ÝÒö‚;™„ë]_ p8‰o¡ñ+^÷ 3‘'dT4œŽ ðVë½° :¬víÑ«£tßÚS-3¶“þ2 †üüʨòrš¹M{É_¤`Û¨0ìjœøJ‡:÷ÃáZ˜†@GP&œÑDGÏs¡þ¦þDGú‘1Yá9Ôþ¼ ûø…§÷8&–ÜÑnÄ_m®^üÆ`;ÉVÁJ£?â€-ßê}suÍ2sõA NÌúA磸‘îÿÚ»ƒìö·á¿±tÑÐ"Tÿü˜[@/äj¬€uüªìù¥Ý˜á8Ý´sõj 8@rˆð äþZÇD®ÿUÏ2ùôõrBzÆÏÞž>Ì™xœ“ wiÎ×7_… ¸ \#€MɁV¶¥üÕÿPÔ9Z‡ø§É8#H:ƒ5ÀÝå9ÍIŒ5åKÙŠ÷qÄ>1AÈøžj"µÂд/ªnÀ qªã}"iŸBå˜ÓÛŽ¦…&ݧ;G@—³b¯“•"´4í¨ôM¨åñC‹ïùÉó¯ÓsSH2Ý@ßáM‡ˆKÀªÛUeø/4\gnm¥‹ŸŒ qÄ b9ÞwÒNÏ_4Ég³ú=܆‚´ •â¥õeíþkjz>éÚyU«Íӝ݃6"8/ø{=Ô¢»G¥ äUw°W«,ô—¿ãㆅү¢³xŠUû™yŒ (øSópÐ 9\åTâ»—*oG$/×ÍT†Y¿1¤Þ¢_‡ ¼ „±ÍçèSaÓ 3ÛMÁBkxs‰’R/¡¤ˆÙçª(*õ„üXÌ´ƒ E§´¬EF"Ù”R/ÐNyÆÂ^°?™6¡œïJ·±$§?º>ÖüœcNÌù¯G ‹ñ2ЁBB„^·úìaz¨k:#¨Æ¨8LÎõލ£^§S&cŒÐU€ü(‡F±Š¼&P>8ÙÁ ‰ p5?0ÊÆƒZl¸aô š¼¡}gÿ¶zÆC²¹¬ÎÖG*HB¡O<º2#ñŒAƒ–¡B˜´É$¥›É:FÀÔx¾u?XÜÏÓvN©RS{2ʈãk9rmP¼Qq̳ è¼ÐFׄ^¡Öì fE“F4A…!ì/…¦Lƒ… … $%´¾yã@CI¬ á—3PþBÏNÿ<ý°4Ü ËÃ#ØÍ~âW«rEñw‹eùMMHß²`¬Öó½íf³:‹k˜¯÷}Z!ã¿<¥,\#öµÀ¯aÒNÆIé,Ћ–lŽ#Àæ9ÀÒS·I’½-Ïp Äz¤Š Â* ­íÄ9­< h>׍3ZkËU¹§˜ŒŠ±f­’¤º³Q ÏB?‹#µíÃ¥®@(Gs«†vI¥Mµ‹Á©e~2ú³ÁP4ìÕi‚²Ê^ö@-DþÓàlÜOÍ]n"µã:žpsŽ¢:! Aõ.ç~ÓBûH÷JCÌ]õVƒd «ú´QÙEA–¯¯Œ!.ˆˆëQ±ù œ·Ì!Õâ )ùL„ÅÀlÚè5@B…o´Æ¸XÓ&Û…O«˜”_#‡ƒ„ûÈt!¤ÁÏ›ÎÝŠ?c9 â\>lÓÁVÄÑ™£eØY]:fÝ–—ù+p{™ðè û³”g±OƒÚSù£áÁÊ„ä,ï7š²G ÕÌBk)~ÑiCµ|h#u¤¶îK¨² #²vݯGãeÖ϶ú…¾múÀ¶þÔñ‚Š9'^($¤§ò “š½{éúp÷J›ušS¹áªCÂubÃH9™D™/ZöØÁ‡¦ÝÙŸ·kð*_”.C‹{áXó€‡c¡c€§/šò/&éš÷,àéJþ‰X›fµ“C¨œ®r¬"kL‰Â_q…Z–.ÉL~O µ›zn‚¹À¦Öª7\àHµšÖ %»ÇníV[¥*Õ;ƒ#½¾HK-ÖIÊdÏEÚ#=o÷Óò³´Š: Ç?{¾+9›–‘OEáU·S€˜j"ÄaÜ ŒÛWt› á–c#a»pÔZÞdŽtWê=9éöÊ¢µ~ ë ;Öe‡Œ®:bî3±ýê¢wà¼îpêñ¹¾4 zc¾ðÖÿzdêŒÑÒŝÀ‰s6¤í³ÎÙB¿OZ”+F¤á‡3@Ñëäg©·Ž ˆèª<ù@É{&S„œÕúÀA)‰h:YÀ5^ÂÓŒ°õäU\ ùËÍû#²?Xe¬tu‰^zÒÔãë¼ÛWtEtû …‚g¶Úüâî*moGè¨7%u!]PhÏd™Ý%Îx: VÒ¦ôÊD3ÀŽKÛËãvÆî…N¯ä>Eró–ð`5 Œ%u5XkñÌ*NU%¶áœÊ:Qÿú»“úzyÏ6å-၇¾ ´ ÒÊ]y žO‘w2Äøæ…H’²f±ÎÇ.ª|¥'gîV•Ü .̘¯€šòü¤U~Ù†*¢!?ò wý,}´°ÔÞnïoKq5µb!áÓ3"vAßH¡³¡·G(ÐÎ0Îò¼MG!/ài®@—¬04*`…«é8ªøøló“ˆÊ”èù¤…ßÊoÿé'ËuÌÖ5×È¡§ˆˆfŽë9}hìâ_!!¯  B&Ëö¶‰ÀAÙNVŸ Wh›¸®XÑJì¨ú“¿÷3uj²˜¨ÍÎìë±aúŠÝå¯ð*Ó¨ôJ“yºØ)m°WýOè68†ŸÏ2—‰Ïüꪫٚ¥‹l1 ø ÏÄFjêµvÌbü¦èÝx:X±¢H=MÐß—,ˆÉÇ´(9ú¾^ÅÚ4¿m‡$âX‘å%(AlZo@½¨UOÌÕ”1ø¸jÎÀÃÃ_ µ‘Ü.œº¦Ut: Æï’!=¯uwû#,“pþÇúŒø(é@?³ü¥‘Mo §—s@Œ#)§ŒùkL}NOÆêA›¸~r½¼ÙA—HJ«eˆÖ´*¡ÓpÌŸö.m<-"³ûÈ$¬_6­åf£ïÚâj1y§ÕJ½@dÞÁr&Í\Z%D£Íñ·AZ Û³øüd/ªAi†/Й~  ‡âĮҮÏh§°b—›Û«mJžòG'[ÈYýŒ¦9psl ýÁ ®±f¦x,‰½tN ‚Xª9 ÙÖH.«Lo0×?͹m¡å†Ѽ+›2ƒF ±Ê8 7Hցϓ²Æ–m9…òŸï]Â1äN†VLâCˆU .ÿ‰Ts +ÅÎx(%¦u]6AF Š ØF鈄‘ |¢¶c±soŒ/t[a¾–û:s·`i햍ê›ËchÈ…8ßÀUÜewŒðNOƒõD%q#éû\9¤x¹&UE×G¥ Í—™$ð E6-‡¼!ýpãÔM˜ Âsìe¯ñµK¢Ç¡ùôléœ4Ö£”À Š®Ðc ^¨À}ÙËŸ§›ºê{ÊuÉC ×Sr€¤’fÉ*j!úÓ’Gsùìoîßîn%ò· àc Wp÷$¨˜)û»H ×8ŽÒ€Zj¤3ÀÙºY'Ql¦py{-6íÔCeiØp‘‡XÊîÆUߢ܂ž£Xé¼Y8þ©ëgñß}é.ÎógÒ„ÃØËø¯»™§Xýy M%@NŠ À(~áÐvu7&•,Ù˜ó€uP‡^^®=_E„jt’ 403WebShell
403Webshell
Server IP : 41.207.40.59  /  Your IP : 216.73.216.58
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux srv-prod 5.15.0-157-generic #167-Ubuntu SMP Wed Sep 17 21:35:53 UTC 2025 x86_64
User : www-data ( 33)
PHP Version : 8.3.26
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /var/www/html/formation/lib/tests/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/formation/lib/tests/outputcomponents_test.php
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.

namespace core;

use block_contents;
use custom_menu;
use custom_menu_item;
use paging_bar;
use renderer_base;
use single_button;
use single_select;
use theme_config;
use url_select;
use core\output\user_picture;

/**
 * Unit tests for lib/outputcomponents.php.
 *
 * @package   core
 * @category  test
 * @copyright 2011 David Mudrak <david@moodle.com>
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
final class outputcomponents_test extends \advanced_testcase {
    /**
     * Tests user_picture::fields.
     *
     * @deprecated since Moodle 3.11 MDL-45242
     */
    public function test_fields_aliasing(): void {
        $fields = user_picture::fields();
        $fields = array_map('trim', explode(',', $fields));
        $this->assertTrue(in_array('id', $fields));

        $aliased = array();
        foreach ($fields as $field) {
            if ($field === 'id') {
                $aliased['id'] = 'aliasedid';
            } else {
                $aliased[$field] = 'prefix'.$field;
            }
        }

        $returned = user_picture::fields('', array('custom1', 'id'), 'aliasedid', 'prefix');
        $returned = array_map('trim', explode(',', $returned));
        $this->assertEquals(count($returned), count($fields) + 1); // Only one extra field added.

        foreach ($fields as $field) {
            if ($field === 'id') {
                $expected = "id AS aliasedid";
            } else {
                $expected = "$field AS prefix$field";
            }
            $this->assertContains($expected, $returned, "Expected pattern '$expected' not returned");
        }
        $this->assertContains("custom1 AS prefixcustom1", $returned, "Expected pattern 'custom1 AS prefixcustom1' not returned");

        // Deprecation warnings for user_picture::fields.
        $this->assertDebuggingCalledCount(2);
    }

    /**
     * Tests user_picture::unalias.
     */
    public function test_fields_unaliasing(): void {
        $fields = implode(',', \core_user\fields::get_picture_fields());
        $fields = array_map('trim', explode(',', $fields));

        $fakerecord = new \stdClass();
        $fakerecord->aliasedid = 42;
        foreach ($fields as $field) {
            if ($field !== 'id') {
                $fakerecord->{'prefix'.$field} = "Value of $field";
            }
        }
        $fakerecord->prefixcustom1 = 'Value of custom1';

        $returned = user_picture::unalias($fakerecord, array('custom1'), 'aliasedid', 'prefix');

        $this->assertEquals(42, $returned->id);
        foreach ($fields as $field) {
            if ($field !== 'id') {
                $this->assertSame("Value of $field", $returned->{$field});
            }
        }
        $this->assertSame('Value of custom1', $returned->custom1);
    }

    /**
     * Tests user_picture::unalias with null values.
     */
    public function test_fields_unaliasing_null(): void {
        $fields = implode(',', \core_user\fields::get_picture_fields());
        $fields = array_map('trim', explode(',', $fields));

        $fakerecord = new \stdClass();
        $fakerecord->aliasedid = 42;
        foreach ($fields as $field) {
            if ($field !== 'id') {
                $fakerecord->{'prefix'.$field} = "Value of $field";
            }
        }
        $fakerecord->prefixcustom1 = 'Value of custom1';
        $fakerecord->prefiximagealt = null;

        $returned = user_picture::unalias($fakerecord, array('custom1'), 'aliasedid', 'prefix');

        $this->assertEquals(42, $returned->id);
        $this->assertNull($returned->imagealt);
        foreach ($fields as $field) {
            if ($field !== 'id' and $field !== 'imagealt') {
                $this->assertSame("Value of $field", $returned->{$field});
            }
        }
        $this->assertSame('Value of custom1', $returned->custom1);
    }

    public function test_get_url(): void {
        global $DB, $CFG, $USER;

        $this->resetAfterTest();

        // Verify new install contains expected defaults.
        $this->assertSame(theme_config::DEFAULT_THEME, $CFG->theme);
        $this->assertEquals(1, $CFG->slasharguments);
        $this->assertEquals(1, $CFG->themerev);
        $this->assertEquals(0, $CFG->themedesignermode);
        $this->assertSame('https://www.example.com/moodle', $CFG->wwwroot);
        $this->assertEquals(0, $CFG->enablegravatar);
        $this->assertSame('mm', $CFG->gravatardefaulturl);

        // Create some users.
        $page = new \moodle_page();
        $page->set_url('/user/profile.php');
        $page->set_context(\context_system::instance());
        $renderer = $page->get_renderer('core');

        $user1 = $this->getDataGenerator()->create_user(array('picture'=>11, 'email'=>'user1@example.com'));
        $context1 = \context_user::instance($user1->id);
        $user2 = $this->getDataGenerator()->create_user(array('picture'=>0, 'email'=>'user2@example.com'));
        $context2 = \context_user::instance($user2->id);

        // User 3 is deleted.
        $user3 = $this->getDataGenerator()->create_user(array('picture'=>1, 'deleted'=>1, 'email'=>'user3@example.com'));
        $this->assertNotEmpty(\context_user::instance($user3->id));
        $this->assertEquals(0, $user3->picture);
        $this->assertNotEquals('user3@example.com', $user3->email);

        // User 4 is incorrectly deleted with its context deleted as well (testing legacy code).
        $user4 = $this->getDataGenerator()->create_user(['picture' => 1, 'deleted' => 1, 'email' => 'user4@example.com']);
        \context_helper::delete_instance(CONTEXT_USER, $user4->id);
        $this->assertEquals(0, $user4->picture);
        $this->assertNotEquals('user4@example.com', $user4->email);

        // Try legacy picture == 1.
        $user1->picture = 1;
        $up1 = new user_picture($user1);
        $this->assertSame($CFG->wwwroot.'/pluginfile.php/'.$context1->id.'/user/icon/boost/f2?rev=1', $up1->get_url($page, $renderer)->out(false));
        $user1->picture = 11;

        // Try valid user with picture when user context is not cached - 1 query expected.
        \context_helper::reset_caches();
        $reads = $DB->perf_get_reads();
        $up1 = new user_picture($user1);
        $this->assertEquals($reads, $DB->perf_get_reads());
        $this->assertSame($CFG->wwwroot.'/pluginfile.php/'.$context1->id.'/user/icon/boost/f2?rev=11', $up1->get_url($page, $renderer)->out(false));
        $this->assertEquals($reads+1, $DB->perf_get_reads());

        // Try valid user with contextid hint - no queries expected.
        $user1->contextid = $context1->id;
        \context_helper::reset_caches();
        $reads = $DB->perf_get_reads();
        $up1 = new user_picture($user1);
        $this->assertEquals($reads, $DB->perf_get_reads());
        $this->assertSame($CFG->wwwroot.'/pluginfile.php/'.$context1->id.'/user/icon/boost/f2?rev=11', $up1->get_url($page, $renderer)->out(false));
        $this->assertEquals($reads, $DB->perf_get_reads());

        // Try valid user without image - no queries expected.
        \context_helper::reset_caches();
        $reads = $DB->perf_get_reads();
        $up2 = new user_picture($user2);
        $this->assertEquals($reads, $DB->perf_get_reads());
        $this->assertSame($CFG->wwwroot.'/theme/image.php/boost/core/1/u/f2', $up2->get_url($page, $renderer)->out(false));
        $this->assertEquals($reads, $DB->perf_get_reads());

        // Try guessing of deleted users - no queries expected.
        unset($user3->deleted);
        \context_helper::reset_caches();
        $reads = $DB->perf_get_reads();
        $up3 = new user_picture($user3);
        $this->assertEquals($reads, $DB->perf_get_reads());
        $this->assertSame($CFG->wwwroot.'/theme/image.php/boost/core/1/u/f2', $up3->get_url($page, $renderer)->out(false));
        $this->assertEquals($reads, $DB->perf_get_reads());

        // Try incorrectly deleted users (with valid email and picture flag, but user context removed) - some DB reads expected.
        unset($user4->deleted);
        $user4->email = 'user4@example.com';
        $user4->picture = 1;
        $reads = $DB->perf_get_reads();
        $up4 = new user_picture($user4);
        $this->assertEquals($reads, $DB->perf_get_reads());
        $this->assertSame($CFG->wwwroot.'/theme/image.php/boost/core/1/u/f2', $up4->get_url($page, $renderer)->out(false));
        $this->assertGreaterThan($reads, $DB->perf_get_reads());

        // Test gravatar.
        set_config('enablegravatar', 1);

        // Deleted user can not have gravatar.
        $user3->email = 'deleted';
        $user3->picture = 0;
        $up3 = new user_picture($user3);
        $this->assertSame($CFG->wwwroot.'/theme/image.php/boost/core/1/u/f2', $up3->get_url($page, $renderer)->out(false));
        $user4->email = 'deleted';
        $user4->picture = 0;
        $up4 = new user_picture($user4);
        $this->assertSame($CFG->wwwroot.'/theme/image.php/boost/core/1/u/f2', $up4->get_url($page, $renderer)->out(false));

        // Http version.
        $CFG->wwwroot = str_replace('https:', 'http:', $CFG->wwwroot);

        // Verify defaults to misteryman (mm).
        $up2 = new user_picture($user2);
        $this->assertSame('http://www.gravatar.com/avatar/ab53a2911ddf9b4817ac01ddcd3d975f?s=35&d=mm', $up2->get_url($page, $renderer)->out(false));

        // Without gravatardefaulturl, verify we pick own file.
        set_config('gravatardefaulturl', '');
        $up2 = new user_picture($user2);
        $this->assertSame('http://www.gravatar.com/avatar/ab53a2911ddf9b4817ac01ddcd3d975f?s=35&d=http%3A%2F%2Fwww.example.com%2Fmoodle%2Fpix%2Fu%2Ff2.png', $up2->get_url($page, $renderer)->out(false));
        // Uploaded image takes precedence before gravatar.
        $up1 = new user_picture($user1);
        $this->assertSame($CFG->wwwroot.'/pluginfile.php/'.$context1->id.'/user/icon/boost/f2?rev=11', $up1->get_url($page, $renderer)->out(false));

        // Uploaded image with token-based access for current user.
        $up1 = new user_picture($user1);
        $up1->includetoken = true;
        $token = get_user_key('core_files', $USER->id);
        $this->assertSame($CFG->wwwroot.'/tokenpluginfile.php/'.$token.'/'.$context1->id.'/user/icon/boost/f2?rev=11', $up1->get_url($page, $renderer)->out(false));

        // Uploaded image with token-based access for other user.
        $up1 = new user_picture($user1);
        $up1->includetoken = $user2->id;
        $token = get_user_key('core_files', $user2->id);
        $this->assertSame($CFG->wwwroot.'/tokenpluginfile.php/'.$token.'/'.$context1->id.'/user/icon/boost/f2?rev=11', $up1->get_url($page, $renderer)->out(false));

        // Https version.
        $CFG->wwwroot = str_replace('http:', 'https:', $CFG->wwwroot);

        $up1 = new user_picture($user1);
        $this->assertSame($CFG->wwwroot.'/pluginfile.php/'.$context1->id.'/user/icon/boost/f2?rev=11', $up1->get_url($page, $renderer)->out(false));

        $up2 = new user_picture($user2);
        $this->assertSame('https://secure.gravatar.com/avatar/ab53a2911ddf9b4817ac01ddcd3d975f?s=35&d=https%3A%2F%2Fwww.example.com%2Fmoodle%2Fpix%2Fu%2Ff2.png', $up2->get_url($page, $renderer)->out(false));

        $up3 = new user_picture($user3);
        $this->assertSame($CFG->wwwroot.'/theme/image.php/boost/core/1/u/f2', $up3->get_url($page, $renderer)->out(false));

        $up4 = new user_picture($user4);
        $this->assertSame($CFG->wwwroot.'/theme/image.php/boost/core/1/u/f2', $up4->get_url($page, $renderer)->out(false));

        // TODO MDL-44792 Rewrite those tests to use a fixture.
        // Now test gravatar with one theme having own images (afterburner).
        // $this->assertFileExists("$CFG->dirroot/theme/afterburner/config.php");
        // set_config('theme', 'afterburner');
        // $page = new \moodle_page();
        // $page->set_url('/user/profile.php');
        // $page->set_context(\context_system::instance());
        // $renderer = $page->get_renderer('core');

        // $up2 = new user_picture($user2);
        // $this->assertEquals('http://www.gravatar.com/avatar/ab53a2911ddf9b4817ac01ddcd3d975f?s=35&d=http%3A%2F%2Fwww.example.com%2Fmoodle%2Ftheme%2Fafterburner%2Fpix_core%2Fu%2Ff2.png', $up2->get_url($page, $renderer)->out(false));

        // $up2 = new user_picture($user2);
        // $this->assertSame('https://secure.gravatar.com/avatar/ab53a2911ddf9b4817ac01ddcd3d975f?s=35&d=https%3A%2F%2Fwww.example.com%2Fmoodle%2Ftheme%2Fafterburner%2Fpix_core%2Fu%2Ff2.png', $up2->get_url($page, $renderer)->out(false));
        // End of gravatar tests.

        // Test themed images.
        // set_config('enablegravatar', 0);
        // $this->assertFileExists("$CFG->dirroot/theme/formal_white/config.php"); // Use any other theme.
        // set_config('theme', 'formal_white');
        // $page = new \moodle_page();
        // $page->set_url('/user/profile.php');
        // $page->set_context(\context_system::instance());
        // $renderer = $page->get_renderer('core');

        // $up1 = new user_picture($user1);
        // $this->assertSame($CFG->wwwroot.'/pluginfile.php/'.$context1->id.'/user/icon/formal_white/f2?rev=11', $up1->get_url($page, $renderer)->out(false));

        // $up2 = new user_picture($user2);
        // $this->assertSame($CFG->wwwroot.'/theme/image.php/formal_white/core/1/u/f2', $up2->get_url($page, $renderer)->out(false));

        // Test non-slashargument images.
        set_config('theme', 'classic');
        $CFG->wwwroot = str_replace('https:', 'http:', $CFG->wwwroot);
        $CFG->slasharguments = 0;
        $page = new \moodle_page();
        $page->set_url('/user/profile.php');
        $page->set_context(\context_system::instance());
        $renderer = $page->get_renderer('core');

        $up3 = new user_picture($user3);
        $this->assertSame($CFG->wwwroot.'/theme/image.php?theme=classic&component=core&rev=1&image=u%2Ff2', $up3->get_url($page, $renderer)->out(false));
    }

    public function test_empty_menu(): void {
        $emptymenu = new custom_menu();
        $this->assertInstanceOf(custom_menu::class, $emptymenu);
        $this->assertFalse($emptymenu->has_children());
    }

    public function test_basic_syntax(): void {
        $definition = <<<EOF
Moodle community|http://moodle.org
-Moodle free support|http://moodle.org/support
-Moodle development|http://moodle.org/development
--Moodle Tracker|http://tracker.moodle.org
--Moodle Docs|http://docs.moodle.org
-Moodle News|http://moodle.org/news
Moodle company||Moodle trust pty
-Hosting|http://moodle.com/hosting|Commercial hosting
-Support|http://moodle.com/support|Commercial support
EOF;

        $menu = new custom_menu($definition);
        $this->assertInstanceOf('custom_menu', $menu);
        $this->assertTrue($menu->has_children());
        $firstlevel = $menu->get_children();
        $this->assertTrue(is_array($firstlevel));
        $this->assertCount(2, $firstlevel);

        $item = array_shift($firstlevel);
        $this->assertInstanceOf('custom_menu_item', $item);
        $this->assertTrue($item->has_children());
        $this->assertCount(3, $item->get_children());
        $this->assertEquals('Moodle community', $item->get_text());
        $itemurl = $item->get_url();
        $this->assertTrue($itemurl instanceof \moodle_url);
        $this->assertEquals('http://moodle.org', $itemurl->out());
        $this->assertNull($item->get_title()); // Implicit title.

        /** @var custom_menu_item $item */
        $item = array_shift($firstlevel);
        $this->assertTrue($item->has_children());
        $this->assertCount(2, $item->get_children());
        $this->assertSame('Moodle company', $item->get_text());
        $this->assertNull($item->get_url());
        $this->assertSame('Moodle trust pty', $item->get_title());

        $children = $item->get_children();
        $subitem = array_shift($children);
        $this->assertFalse($subitem->has_children());
        $this->assertSame('Hosting', $subitem->get_text());
        $this->assertSame('Commercial hosting', $subitem->get_title());
    }

    public function test_custommenu_mulitlang(): void {
        $definition = <<<EOF
Start|http://school.info
Info
-English|http://school.info/en|Information in English|en
--Nested under English
--I will be lost|||de
-Deutsch|http://school.info/de|Informationen in deutscher Sprache|de,de_du,de_kids
--Nested under Deutsch
--I will be lost|||en
kontaktieren Sie uns|contactus.php||de
Contact us|contactus.php||en
EOF;
        $definitionen = <<<EOF
Start|http://school.info
Info
-English|http://school.info/en|Information in English|en
--Nested under English
Contact us|contactus.php||en
EOF;
        $definitionde = <<<EOF
Start|http://school.info
Info
-Deutsch|http://school.info/de|Informationen in deutscher Sprache|de,de_du,de_kids
--Nested under Deutsch
kontaktieren Sie uns|contactus.php||de
EOF;

        $definitiondedu = <<<EOF
Start|http://school.info
Info
-Deutsch|http://school.info/de|Informationen in deutscher Sprache|de,de_du,de_kids
--Nested under Deutsch
EOF;

        $parsed = $this->custommenu_out(new custom_menu($definition));
        $parseden = $this->custommenu_out(new custom_menu($definition, 'en'));
        $parsedde = $this->custommenu_out(new custom_menu($definition, 'de'));
        $parseddedu = $this->custommenu_out(new custom_menu($definition, 'de_du'));

        $actualen = $this->custommenu_out(new custom_menu($definitionen, 'en'));
        $actualde = $this->custommenu_out(new custom_menu($definitionde, 'de'));
        $actualdedu = $this->custommenu_out(new custom_menu($definitiondedu, 'de_du'));

        $this->assertSame($actualen, $parseden, 'The parsed English menu does not match the expected English menu');
        $this->assertSame($actualde, $parsedde, 'The parsed German menu does not match the expected German menu');
        $this->assertSame($actualdedu, $parseddedu, 'The parsed German [Du] menu does not match the expected German [Du] menu');

        $this->assertNotSame($parsed, $parsedde, 'The menu without language is the same as the German menu. They should differ!');
        $this->assertNotSame($parsed, $parseden, 'The menu without language is the same as the English menu. They should differ!');
        $this->assertNotSame($parsed, $parseddedu, 'The menu without language is the same as the German [Du] menu. They should differ!');
        $this->assertNotSame($parseden, $parsedde, 'The English menu is the same as the German menu. They should differ!');
        $this->assertNotSame($parseden, $parseddedu, 'The English menu is the same as the German [Du] menu. They should differ!');
        $this->assertNotSame($parseddedu, $parsedde, 'The German [Du] menu is the same as the German menu. They should differ!');
    }

    /**
     * Support function that takes a custom_menu_item and converts it to a string.
     *
     * @param custom_menu_item $item
     * @param int $depth
     * @return string
     */
    protected function custommenu_out(custom_menu_item $item, $depth = 0) {
        $str = str_repeat('-', $depth);
        $str .= $item->get_text();
        $str .= '|' . $item->get_url();
        $str .= '|' . $item->get_title();
        if ($item->has_children()) {
            $str .= '|' . count($item->get_children());
            foreach ($item->get_children() as $child) {
                $str .= "\n" . $this->custommenu_out($child, $depth + 1);
            }
        }
        return $str;
    }

    public function test_prepare(): void {
        $expecteda = array('<span class="current-page">1</span>',
            '<a href="index.php?page=1">2</a>',
            '<a href="index.php?page=2">3</a>',
            '<a href="index.php?page=3">4</a>',
            '<a href="index.php?page=4">5</a>',
            '<a href="index.php?page=5">6</a>',
            '<a href="index.php?page=6">7</a>',
            '<a href="index.php?page=7">8</a>',
        );
        $expectedb = array('<a href="page?page=3">4</a>',
            '<a href="page?page=4">5</a>',
            '<span class="current-page">6</span>',
            '<a href="page?page=6">7</a>',
            '<a href="page?page=7">8</a>',
        );

        $mpage = new \moodle_page();
        $rbase = new renderer_base($mpage, "/");
        $pbara = new paging_bar(40, 0, 5, 'index.php');
        $pbara->prepare($rbase, $mpage, "/");
        $pbarb = new paging_bar(100, 5, 5, 'page');
        $pbarb->maxdisplay = 5;
        $pbarb->prepare($rbase, $mpage, "/");

        $this->assertEquals($expecteda, $pbara->pagelinks);
        $this->assertEquals($expectedb, $pbarb->pagelinks);
    }

    public function test_pix_icon(): void {
        $this->resetAfterTest();

        $page = new \moodle_page();

        set_config('theme', 'boost');
        // Need to reset after changing theme.
        $page->reset_theme_and_output();
        $renderer = $page->get_renderer('core');

        $reason = 'An icon with no alt text is hidden from screenreaders.';
        $this->assertStringContainsString('aria-hidden="true"', $renderer->pix_icon('t/print', ''), $reason);

        $reason = 'An icon with alt text is not hidden from screenreaders.';
        $this->assertStringNotContainsString('aria-hidden="true"', $renderer->pix_icon('t/print', 'Print'), $reason);

        // Test another theme with a different icon system.
        set_config('theme', 'classic');
        // Need to reset after changing theme.
        $page->reset_theme_and_output();
        $renderer = $page->get_renderer('core');

        $reason = 'An icon with no alt text is hidden from screenreaders.';
        $this->assertStringContainsString('aria-hidden="true"', $renderer->pix_icon('t/print', ''), $reason);

        $reason = 'An icon with alt text is not hidden from screenreaders.';
        $this->assertStringNotContainsString('aria-hidden="true"', $renderer->pix_icon('t/print', 'Print'), $reason);
    }

    /**
     * Test for checking the template context data for the single_select element.
     */
    public function test_single_select(): void {
        global $PAGE;

        $fakename = 'fakename';
        $fakeclass = 'fakeclass';
        $faketitle = 'faketitle';
        $fakedisabled = true;
        $fakefor = 'fakefor';

        $someid = 'someid';
        $realname = 'realname';
        $realclass = 'realclass';
        $realtitle = 'realtitle';
        $realdisabled = false;
        $reallabel = 'Some cool label';
        $labelclass = 'somelabelclass';
        $labelstyle = 'font-weight: bold';

        $dataaction = 'actiondata';
        $dataother = 'otherdata';

        $attributes = [
            'id' => $someid,
            'class' => $fakeclass,
            'title' => $faketitle,
            'disabled' => $fakedisabled,
            'name' => $fakename,
            'data-action' => $dataaction,
            'data-other' => $dataother,
        ];
        $labelattributes = [
            'for' => $fakefor,
            'class' => $labelclass,
            'style' => $labelstyle
        ];

        $options = [ "Option A", "Option B", "Option C" ];
        $nothing = ['' => 'choosedots'];

        $url = new \moodle_url('/');

        $singleselect = new single_select($url, $realname, $options, null, $nothing, 'someformid');
        $singleselect->class = $realclass;
        $singleselect->tooltip = $realtitle;
        $singleselect->disabled = $realdisabled;
        $singleselect->attributes = $attributes;
        $singleselect->label = $reallabel;
        $singleselect->labelattributes = $labelattributes;

        $renderer = $PAGE->get_renderer('core');
        $data = $singleselect->export_for_template($renderer);

        $this->assertEquals($realtitle, $data->title);
        $this->assertEquals($singleselect->class, $data->classes);
        $this->assertEquals($realname, $data->name);
        $this->assertEquals($reallabel, $data->label);
        $this->assertEquals($realdisabled, $data->disabled);
        $this->assertEquals($someid, $data->id);

        // Validate attributes array.
        // The following should not be included: id, class, name, disabled.
        $this->assertFalse(in_array(['name' => 'id', 'value' => $someid], $data->attributes));
        $this->assertFalse(in_array(['name' => 'class', 'value' => $fakeclass], $data->attributes));
        $this->assertFalse(in_array(['name' => 'name', 'value' => $fakeclass], $data->attributes));
        $this->assertFalse(in_array(['name' => 'disabled', 'value' => $fakedisabled], $data->attributes));
        // The rest should be fine.
        $this->assertTrue(in_array(['name' => 'data-action', 'value' => $dataaction], $data->attributes));
        $this->assertTrue(in_array(['name' => 'data-other', 'value' => $dataother], $data->attributes));

        // Validate label attributes.
        // The for attribute should not be included.
        $this->assertFalse(in_array(['name' => 'for', 'value' => $someid], $data->labelattributes));
        // The rest should be fine.
        $this->assertTrue(in_array(['name' => 'class', 'value' => $labelclass], $data->labelattributes));
        $this->assertTrue(in_array(['name' => 'style', 'value' => $labelstyle], $data->labelattributes));
    }
    /**
     * Test for checking the template context data for the single_select element.
     * @covers \single_button
     */
    public function test_single_button(): void {
        global $PAGE;
        $url = new \moodle_url('/');
        $realname = 'realname';
        $attributes = [
            'data-dummy' => 'dummy',
        ];
        $singlebutton = new single_button($url, $realname, 'post', single_button::BUTTON_SECONDARY, $attributes);
        $renderer = $PAGE->get_renderer('core');
        $data = $singlebutton->export_for_template($renderer);

        $this->assertEquals($realname, $data->label);
        $this->assertEquals('post', $data->method);
        $this->assertEquals('singlebutton', $data->classes);
        $this->assertEquals('secondary', $data->type);
        $this->assertEquals($attributes['data-dummy'], $data->attributes[0]['value']);

        $singlebutton = new single_button($url, $realname, 'post', single_button::BUTTON_PRIMARY, $attributes);
        $renderer = $PAGE->get_renderer('core');
        $data = $singlebutton->export_for_template($renderer);

        $this->assertEquals($realname, $data->label);
        $this->assertEquals('post', $data->method);
        $this->assertEquals('singlebutton', $data->classes);
        $this->assertEquals('primary', $data->type);
        $this->assertEquals($attributes['data-dummy'], $data->attributes[0]['value']);
    }

    /**
     * Test for checking the template context data for the single_select element legacy API.
     * @covers \single_button
     */
    public function test_single_button_deprecated(): void {
        global $PAGE;
        $url = new \moodle_url('/');
        $realname = 'realname';
        $attributes = [
            'data-dummy' => 'dummy',
        ];

        // Test that when we use a true boolean value for the 4th parameter this is set as primary type.
        $singlebutton = new single_button($url, $realname, 'post', single_button::BUTTON_PRIMARY, $attributes);
        $renderer = $PAGE->get_renderer('core');
        $data = $singlebutton->export_for_template($renderer);
        $this->assertEquals($realname, $data->label);
        $this->assertEquals('post', $data->method);
        $this->assertEquals('singlebutton', $data->classes);
        $this->assertEquals('primary', $data->type);
        $this->assertEquals($attributes['data-dummy'], $data->attributes[0]['value']);

        // Test that when we use a false boolean value for the 4th parameter this is set as secondary type.
        $singlebutton = new single_button($url, $realname, 'post', false, $attributes);
        $this->assertDebuggingCalled();
        $renderer = $PAGE->get_renderer('core');
        $data = $singlebutton->export_for_template($renderer);
        $this->assertEquals($realname, $data->label);
        $this->assertEquals('post', $data->method);
        $this->assertEquals('singlebutton', $data->classes);
        $this->assertEquals('secondary', $data->type);
        $this->assertEquals($attributes['data-dummy'], $data->attributes[0]['value']);

        // Test that when we set the primary value, then this is reflected in the type.
        $singlebutton->primary = false;
        $this->assertDebuggingCalled();
        $this->assertEquals(single_button::BUTTON_SECONDARY, $singlebutton->type);
        $singlebutton->primary = true;
        $this->assertDebuggingCalled();
        $this->assertEquals(single_button::BUTTON_PRIMARY, $singlebutton->type);
        // Then set the type directly.

        $singlebutton->type = single_button::BUTTON_DANGER;
        $data = $singlebutton->export_for_template($renderer);
        $this->assertEquals('danger', $data->type);

    }

    /**
     * Test for checking the template context data for the url_select element.
     */
    public function test_url_select(): void {
        global $PAGE;

        $fakename = 'fakename';
        $fakeclass = 'fakeclass';
        $faketitle = 'faketitle';
        $fakedisabled = true;
        $fakefor = 'fakefor';

        $someid = 'someid';
        $realclass = 'realclass';
        $realtitle = 'realtitle';
        $realdisabled = false;
        $reallabel = 'Some cool label';
        $labelclass = 'somelabelclass';
        $labelstyle = 'font-weight: bold';

        $dataaction = 'actiondata';
        $dataother = 'otherdata';

        $attributes = [
            'id' => $someid,
            'class' => $fakeclass,
            'title' => $faketitle,
            'disabled' => $fakedisabled,
            'name' => $fakename,
            'data-action' => $dataaction,
            'data-other' => $dataother,
        ];
        $labelattributes = [
            'for' => $fakefor,
            'class' => $labelclass,
            'style' => $labelstyle
        ];

        $url1 = new \moodle_url("/#a");
        $url2 = new \moodle_url("/#b");
        $url3 = new \moodle_url("/#c");

        $urls = [
            $url1->out() => 'A',
            $url2->out() => 'B',
            $url3->out() => 'C',
        ];
        $nothing = ['' => 'choosedots'];

        $urlselect = new url_select($urls, null, $nothing, 'someformid');
        $urlselect->class = $realclass;
        $urlselect->tooltip = $realtitle;
        $urlselect->disabled = $realdisabled;
        $urlselect->attributes = $attributes;
        $urlselect->label = $reallabel;
        $urlselect->labelattributes = $labelattributes;

        $renderer = $PAGE->get_renderer('core');
        $data = $urlselect->export_for_template($renderer);

        $this->assertEquals($realtitle, $data->title);
        $this->assertEquals($urlselect->class, $data->classes);
        $this->assertEquals($reallabel, $data->label);
        $this->assertEquals($realdisabled, $data->disabled);
        $this->assertEquals($someid, $data->id);

        // Validate attributes array.
        // The following should not be included: id, class, name, disabled.
        $this->assertFalse(in_array(['name' => 'id', 'value' => $someid], $data->attributes));
        $this->assertFalse(in_array(['name' => 'class', 'value' => $fakeclass], $data->attributes));
        $this->assertFalse(in_array(['name' => 'name', 'value' => $fakeclass], $data->attributes));
        $this->assertFalse(in_array(['name' => 'disabled', 'value' => $fakedisabled], $data->attributes));
        // The rest should be fine.
        $this->assertTrue(in_array(['name' => 'data-action', 'value' => $dataaction], $data->attributes));
        $this->assertTrue(in_array(['name' => 'data-other', 'value' => $dataother], $data->attributes));

        // Validate label attributes.
        // The for attribute should not be included.
        $this->assertFalse(in_array(['name' => 'for', 'value' => $someid], $data->labelattributes));
        // The rest should be fine.
        $this->assertTrue(in_array(['name' => 'class', 'value' => $labelclass], $data->labelattributes));
        $this->assertTrue(in_array(['name' => 'style', 'value' => $labelstyle], $data->labelattributes));
    }

    /**
     * Test for checking the template context data for the url_select element.
     * @covers \url_select::disable_option
     * @covers \url_select::enable_option
     */
    public function test_url_select_disabled_options(): void {
        global $PAGE;
        $url1 = new \moodle_url("/#a");
        $url2 = new \moodle_url("/#b");
        $url3 = new \moodle_url("/#c");

        $urls = [
            $url1->out() => 'A',
            $url2->out() => 'B',
            $url3->out() => 'C',
        ];
        $urlselect = new url_select($urls,
            null,
            null,
            'someformid',
            null);
        $renderer = $PAGE->get_renderer('core');
        $urlselect->set_option_disabled($url2->out(), true);
        $data = $urlselect->export_for_template($renderer);
        $this->assertFalse($data->options[0]['disabled']);
        $this->assertTrue($data->options[1]['disabled']);
        $urlselect->set_option_disabled($url2->out(), false);
        $data = $urlselect->export_for_template($renderer);
        $this->assertFalse($data->options[0]['disabled']);
        $this->assertFalse($data->options[1]['disabled']);
    }

    /**
     * Data provider for test_block_contents_is_fake().
     *
     * @return array
     */
    public static function block_contents_is_fake_provider(): array {
        return [
            'Null' => [null, false],
            'Not set' => [false, false],
            'Fake' => ['_fake', true],
            'Real block' => ['activity_modules', false],
        ];
    }

    /**
     * Test block_contents is_fake() method.
     *
     * @dataProvider block_contents_is_fake_provider
     * @param mixed $value Value for the data-block attribute
     * @param boolean $expected The expected result
     */
    public function test_block_contents_is_fake($value, $expected): void {
        $bc = new block_contents(array());
        if ($value !== false) {
            $bc->attributes['data-block'] = $value;
        }
        $this->assertEquals($expected, $bc->is_fake());
    }
}

Youez - 2016 - github.com/yon3zu
LinuXploit