....................................../////.===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/blocklib_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;

defined('MOODLE_INTERNAL') || die();

global $CFG;
require_once($CFG->libdir . '/pagelib.php');
require_once($CFG->libdir . '/blocklib.php');
require_once($CFG->dirroot . '/blocks/moodleblock.class.php');
require_once(__DIR__ . '/fixtures/block_ablocktype.php');
require_once(__DIR__ . '/fixtures/testable_block_manager.php');

/**
 * Tests for the block_manager class in ../blocklib.php.
 *
 * @package   core
 * @category  test
 * @copyright 2009 Tim Hunt
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
final class blocklib_test extends \advanced_testcase {
    protected $testpage;
    protected $blockmanager;
    protected $isediting = null;

    protected function setUp(): void {
        parent::setUp();
        $this->testpage = new \moodle_page();
        $this->testpage->set_context(\context_system::instance());
        $this->testpage->set_pagetype('phpunit-block-test');
        $this->blockmanager = new \testable_block_manager($this->testpage);
    }

    protected function tearDown(): void {
        $this->testpage = null;
        $this->blockmanager = null;
        parent::tearDown();
    }

    protected function purge_blocks() {
        global $DB;
        $this->resetAfterTest();

        $bis = $DB->get_records('block_instances');
        foreach ($bis as $instance) {
            blocks_delete_instance($instance);
        }
    }

    /**
     * Gets the last block created.
     *
     * @return stdClass a record from block_instances
     */
    protected function get_last_created_block() {
        global $DB;
        // The newest block should be the record with the highest id.
        $records = $DB->get_records('block_instances', [], 'id DESC', '*', 0, 1);
        $return = null;
        foreach ($records as $record) {
            // There should only be one.
            $return = $record;
        }
        return $return;
    }

    public function test_no_regions_initially(): void {
        // Exercise SUT & Validate.
        $this->assertEquals(array(), $this->blockmanager->get_regions());
    }

    public function test_add_region(): void {
        // Exercise SUT.
        $this->blockmanager->add_region('a-region-name', false);
        // Validate.
        $this->assertEquals(array('a-region-name'), $this->blockmanager->get_regions());
    }

    public function test_add_regions(): void {
        // Set up fixture.
        $regions = array('a-region', 'another-region');
        // Exercise SUT.
        $this->blockmanager->add_regions($regions, false);
        // Validate.
        $this->assertEqualsCanonicalizing($regions, $this->blockmanager->get_regions());
    }

    public function test_add_region_twice(): void {
        // Exercise SUT.
        $this->blockmanager->add_region('a-region-name', false);
        $this->blockmanager->add_region('another-region', false);
        // Validate.
        $this->assertEqualsCanonicalizing(array('a-region-name', 'another-region'), $this->blockmanager->get_regions());
    }

    public function test_cannot_add_region_after_loaded(): void {
        // Set up fixture.
        $this->blockmanager->mark_loaded();
        // Exercise SUT.
        $this->expectException(\coding_exception::class);
        $this->blockmanager->add_region('too-late', false);
    }

    /**
     * Testing adding a custom region.
     */
    public function test_add_custom_region(): void {
        global $SESSION;
        // Exercise SUT.
        $this->blockmanager->add_region('a-custom-region-name');
        // Validate.
        $this->assertEquals(array('a-custom-region-name'), $this->blockmanager->get_regions());
        $this->assertTrue(isset($SESSION->custom_block_regions));
        $this->assertArrayHasKey('phpunit-block-test', $SESSION->custom_block_regions);
        $this->assertTrue(in_array('a-custom-region-name', $SESSION->custom_block_regions['phpunit-block-test']));

    }

    /**
     * Test adding two custom regions using add_regions method.
     */
    public function test_add_custom_regions(): void {
        global $SESSION;
        // Set up fixture.
        $regions = array('a-region', 'another-custom-region');
        // Exercise SUT.
        $this->blockmanager->add_regions($regions);
        // Validate.
        $this->assertEqualsCanonicalizing($regions, $this->blockmanager->get_regions());
        $this->assertTrue(isset($SESSION->custom_block_regions));
        $this->assertArrayHasKey('phpunit-block-test', $SESSION->custom_block_regions);
        $this->assertTrue(in_array('another-custom-region', $SESSION->custom_block_regions['phpunit-block-test']));
    }

    /**
     * Test adding two custom block regions.
     */
    public function test_add_custom_region_twice(): void {
        // Exercise SUT.
        $this->blockmanager->add_region('a-custom-region-name');
        $this->blockmanager->add_region('another-custom-region');
        // Validate.
        $this->assertEqualsCanonicalizing(
            array('a-custom-region-name', 'another-custom-region'),
            $this->blockmanager->get_regions());
    }

    /**
     * Test to ensure that we cannot add a region after the blocks have been loaded.
     */
    public function test_cannot_add_custom_region_after_loaded(): void {
        // Set up fixture.
        $this->blockmanager->mark_loaded();
        // Exercise SUT.
        $this->expectException(\coding_exception::class);
        $this->blockmanager->add_region('too-late');
    }

    public function test_set_default_region(): void {
        // Set up fixture.
        $this->blockmanager->add_region('a-region-name', false);
        // Exercise SUT.
        $this->blockmanager->set_default_region('a-region-name');
        // Validate.
        $this->assertEquals('a-region-name', $this->blockmanager->get_default_region());
    }

    public function test_cannot_set_unknown_region_as_default(): void {
        // Exercise SUT.
        $this->expectException(\coding_exception::class);
        $this->blockmanager->set_default_region('a-region-name');
    }

    public function test_cannot_change_default_region_after_loaded(): void {
        // Set up fixture.
        $this->blockmanager->mark_loaded();
        // Exercise SUT.
        $this->expectException(\coding_exception::class);
        $this->blockmanager->set_default_region('too-late');
    }

    public function test_matching_page_type_patterns(): void {
        $this->assertEqualsCanonicalizing(array('site-index', 'site-index-*', 'site-*', '*'),
            matching_page_type_patterns('site-index'));

        $this->assertEqualsCanonicalizing(array('mod-quiz-report-overview', 'mod-quiz-report-overview-*', 'mod-quiz-report-*', 'mod-quiz-*', 'mod-*', '*'),
            matching_page_type_patterns('mod-quiz-report-overview'));

        $this->assertEqualsCanonicalizing(array('mod-forum-view', 'mod-*-view', 'mod-forum-view-*', 'mod-forum-*', 'mod-*', '*'),
            matching_page_type_patterns('mod-forum-view'));

        $this->assertEqualsCanonicalizing(array('mod-forum-index', 'mod-*-index', 'mod-forum-index-*', 'mod-forum-*', 'mod-*', '*'),
            matching_page_type_patterns('mod-forum-index'));
    }

    protected function get_a_page_and_block_manager($regions, $context, $pagetype, $subpage = '') {
        $page = new \moodle_page;
        $page->set_context($context);
        $page->set_pagetype($pagetype);
        $page->set_subpage($subpage);
        $page->set_url(new \moodle_url('/'));

        $blockmanager = new \testable_block_manager($page);
        $blockmanager->add_regions($regions, false);
        $blockmanager->set_default_region($regions[0]);

        return array($page, $blockmanager);
    }

    protected function get_a_known_block_type() {
        global $DB;
        $block = new \stdClass;
        $block->name = 'ablocktype';
        $DB->insert_record('block', $block);
        return $block->name;
    }

    protected function assertContainsBlocksOfType($typearray, $blockarray) {
        if (!$this->assertEquals(count($typearray), count($blockarray), "Blocks array contains the wrong number of elements %s.")) {
            return;
        }
        $types = array_values($typearray);
        $i = 0;
        foreach ($blockarray as $block) {
            $blocktype = $types[$i];
            $this->assertEquals($blocktype, $block->name(), "Block types do not match at postition $i %s.");
            $i++;
        }
    }

    public function test_empty_initially(): void {
        $this->purge_blocks();

        // Set up fixture.
        list($page, $blockmanager) = $this->get_a_page_and_block_manager(array('a-region'),
            \context_system::instance(), 'page-type');
        // Exercise SUT.
        $blockmanager->load_blocks();
        // Validate.
        $blocks = $blockmanager->get_loaded_blocks();
        $this->assertEquals(array('a-region' => array()), $blocks);
    }

    public function test_adding_and_retrieving_one_block(): void {
        $this->purge_blocks();

        // Set up fixture.
        $regionname = 'a-region';
        $blockname = $this->get_a_known_block_type();
        $context = \context_system::instance();

        list($page, $blockmanager) = $this->get_a_page_and_block_manager(array($regionname),
            $context, 'page-type');

        // Exercise SUT.
        $blockmanager->add_block($blockname, $regionname, 0, false);
        $blockmanager->load_blocks();
        // Validate.
        $blocks = $blockmanager->get_blocks_for_region($regionname);
        $this->assertContainsBlocksOfType(array($blockname), $blocks);
    }

    public function test_adding_and_retrieving_two_blocks(): void {
        $this->purge_blocks();

        // Set up fixture.
        $regionname = 'a-region';
        $blockname = $this->get_a_known_block_type();
        $context = \context_system::instance();

        list($page, $blockmanager) = $this->get_a_page_and_block_manager(array($regionname),
            $context, 'page-type');

        // Exercise SUT.
        $blockmanager->add_block($blockname, $regionname, 0, false);
        $blockmanager->add_block($blockname, $regionname, 1, false);
        $blockmanager->load_blocks();
        // Validate.
        $blocks = $blockmanager->get_blocks_for_region($regionname);
        $this->assertContainsBlocksOfType(array($blockname, $blockname), $blocks);
    }

    public function test_adding_blocks(): void {
        $this->purge_blocks();

        // Set up fixture.
        $regionname = 'a-region';
        $blockname = $this->get_a_known_block_type();
        $context = \context_system::instance();

        list($page, $blockmanager) = $this->get_a_page_and_block_manager(array($regionname),
            $context, 'page-type');

        $blockmanager->add_blocks(array($regionname => array($blockname, $blockname)), null, null, false, 3);
        $blockmanager->load_blocks();

        $blocks = $blockmanager->get_blocks_for_region($regionname);

        $this->assertEquals('3', $blocks[0]->instance->weight);
        $this->assertEquals('4', $blocks[1]->instance->weight);
    }

    /**
     * Test block instances.
     *
     * @return null
     */
    public function test_block_instances(): void {
        $this->purge_blocks();

        // Set up fixture.
        $regionname = 'a-region';
        $blockname = $this->get_a_known_block_type();
        $context = \context_system::instance();

        list($page, $blockmanager) = $this->get_a_page_and_block_manager(array($regionname),
            $context, 'page-type');

        $blockmanager->add_blocks(array($regionname => array($blockname, $blockname)), null, null, false, 3);
        $blockmanager->load_blocks();

        $blocks = $blockmanager->get_blocks_for_region($regionname);

        $this->assertInstanceOf('\block_base', block_instance($blockname, $blocks[0]->instance));
        $this->assertInstanceOf('\block_base', block_instance_by_id($blocks[0]->instance->id));
    }

    public function test_block_not_included_in_different_context(): void {
        $this->purge_blocks();

        // Set up fixture.
        $syscontext = \context_system::instance();
        $cat = $this->getDataGenerator()->create_category(array('name' => 'testcategory'));
        $fakecontext = \context_coursecat::instance($cat->id);
        $regionname = 'a-region';
        $blockname = $this->get_a_known_block_type();

        list($addpage, $addbm) = $this->get_a_page_and_block_manager(array($regionname), $fakecontext, 'page-type');
        list($viewpage, $viewbm) = $this->get_a_page_and_block_manager(array($regionname), $syscontext, 'page-type');

        $addbm->add_block($blockname, $regionname, 0, false);

        // Exercise SUT.
        $viewbm->load_blocks();
        // Validate.
        $blocks = $viewbm->get_blocks_for_region($regionname);
        $this->assertContainsBlocksOfType(array(), $blocks);
    }

    public function test_block_included_in_sub_context(): void {
        $this->purge_blocks();

        // Set up fixture.
        $syscontext = \context_system::instance();
        $childcontext = \context_coursecat::instance(1);
        $regionname = 'a-region';
        $blockname = $this->get_a_known_block_type();

        list($addpage, $addbm) = $this->get_a_page_and_block_manager(array($regionname), $syscontext, 'page-type');
        list($viewpage, $viewbm) = $this->get_a_page_and_block_manager(array($regionname), $childcontext, 'page-type');

        $addbm->add_block($blockname, $regionname, 0, true);

        // Exercise SUT.
        $viewbm->load_blocks();
        // Validate.
        $blocks = $viewbm->get_blocks_for_region($regionname);
        $this->assertContainsBlocksOfType(array($blockname), $blocks);
    }

    public function test_block_not_included_on_different_page_type(): void {
        $this->purge_blocks();

        // Set up fixture.
        $syscontext = \context_system::instance();
        $regionname = 'a-region';
        $blockname = $this->get_a_known_block_type();

        list($addpage, $addbm) = $this->get_a_page_and_block_manager(array($regionname), $syscontext, 'page-type');
        list($viewpage, $viewbm) = $this->get_a_page_and_block_manager(array($regionname), $syscontext, 'other-page-type');

        $addbm->add_block($blockname, $regionname, 0, true);

        // Exercise SUT.
        $viewbm->load_blocks();
        // Validate.
        $blocks = $viewbm->get_blocks_for_region($regionname);
        $this->assertContainsBlocksOfType(array(), $blocks);
    }

    public function test_block_not_included_on_different_sub_page(): void {
        $this->purge_blocks();

        // Set up fixture.
        $regionname = 'a-region';
        $blockname = $this->get_a_known_block_type();
        $syscontext = \context_system::instance();

        list($page, $blockmanager) = $this->get_a_page_and_block_manager(array($regionname),
            $syscontext, 'page-type', 'sub-page');

        $blockmanager->add_block($blockname, $regionname, 0, true, $page->pagetype, 'other-sub-page');

        // Exercise SUT.
        $blockmanager->load_blocks();
        // Validate.
        $blocks = $blockmanager->get_blocks_for_region($regionname);
        $this->assertContainsBlocksOfType(array(), $blocks);
    }

    public function test_block_included_with_explicit_sub_page(): void {
        $this->purge_blocks();

        // Set up fixture.
        $regionname = 'a-region';
        $blockname = $this->get_a_known_block_type();
        $syscontext = \context_system::instance();

        list($page, $blockmanager) = $this->get_a_page_and_block_manager(array($regionname),
            $syscontext, 'page-type', 'sub-page');

        $blockmanager->add_block($blockname, $regionname, 0, true, $page->pagetype, $page->subpage);

        // Exercise SUT.
        $blockmanager->load_blocks();
        // Validate.
        $blocks = $blockmanager->get_blocks_for_region($regionname);
        $this->assertContainsBlocksOfType(array($blockname), $blocks);
    }

    public function test_block_included_with_page_type_pattern(): void {
        $this->purge_blocks();

        // Set up fixture.
        $regionname = 'a-region';
        $blockname = $this->get_a_known_block_type();
        $syscontext = \context_system::instance();

        list($page, $blockmanager) = $this->get_a_page_and_block_manager(array($regionname),
            $syscontext, 'page-type', 'sub-page');

        $blockmanager->add_block($blockname, $regionname, 0, true, 'page-*', $page->subpage);

        // Exercise SUT.
        $blockmanager->load_blocks();
        // Validate.
        $blocks = $blockmanager->get_blocks_for_region($regionname);
        $this->assertContainsBlocksOfType(array($blockname), $blocks);
    }

    public function test_matching_page_type_patterns_from_pattern(): void {
        $pattern = '*';
        $expected = array('*');
        $this->assertEquals($expected, array_values(matching_page_type_patterns_from_pattern($pattern)));

        $pattern = 'admin-*';
        $expected = array('admin-*', 'admin', '*');
        $this->assertEquals($expected, array_values(matching_page_type_patterns_from_pattern($pattern)));

        $pattern = 'blog-index';
        $expected = array('blog-index', 'blog-index-*', 'blog-*', '*');
        $this->assertEquals($expected, array_values(matching_page_type_patterns_from_pattern($pattern)));

        $pattern = 'course-index-*';
        $expected = array('course-index-*', 'course-index', 'course-*', '*');
        $this->assertEquals($expected, array_values(matching_page_type_patterns_from_pattern($pattern)));

        $pattern = 'course-index-category';
        $expected = array('course-index-category', 'course-index-category-*', 'course-index-*', 'course-*', '*');
        $this->assertEquals($expected, array_values(matching_page_type_patterns_from_pattern($pattern)));

        $pattern = 'mod-assign-view';
        $expected = array('mod-assign-view', 'mod-*-view', 'mod-assign-view-*', 'mod-assign-*', 'mod-*', '*');
        $this->assertEquals($expected, array_values(matching_page_type_patterns_from_pattern($pattern)));

        $pattern = 'mod-assign-index';
        $expected = array('mod-assign-index', 'mod-*-index', 'mod-assign-index-*', 'mod-assign-*', 'mod-*', '*');
        $this->assertEquals($expected, array_values(matching_page_type_patterns_from_pattern($pattern)));

        $pattern = 'mod-forum-*';
        $expected = array('mod-forum-*', 'mod-forum', 'mod-*', '*');
        $this->assertEquals($expected, array_values(matching_page_type_patterns_from_pattern($pattern)));

        $pattern = 'mod-*-view';
        $expected = array('mod-*-view', 'mod', 'mod-*', '*');
        $this->assertEquals($expected, array_values(matching_page_type_patterns_from_pattern($pattern)));

        $pattern = 'mod-*-index';
        $expected = array('mod-*-index', 'mod', 'mod-*', '*');
        $this->assertEquals($expected, array_values(matching_page_type_patterns_from_pattern($pattern)));

        $pattern = 'my-index';
        $expected = array('my-index', 'my-index-*', 'my-*', '*');
        $this->assertEquals($expected, array_values(matching_page_type_patterns_from_pattern($pattern)));

        $pattern = 'user-profile';
        $expected = array('user-profile', 'user-profile-*', 'user-*', '*');
        $this->assertEquals($expected, array_values(matching_page_type_patterns_from_pattern($pattern)));
    }

    public function test_delete_instances(): void {
        global $DB;
        $this->purge_blocks();
        $this->setAdminUser();

        $regionname = 'a-region';
        $blockname = $this->get_a_known_block_type();
        $context = \context_system::instance();

        list($page, $blockmanager) = $this->get_a_page_and_block_manager(array($regionname),
            $context, 'page-type');

        $blockmanager->add_blocks(array($regionname => array($blockname, $blockname, $blockname)), null, null, false, 3);
        $blockmanager->load_blocks();

        $blocks = $blockmanager->get_blocks_for_region($regionname);
        $blockids = array();
        $preferences = array();

        // Create block related data.
        foreach ($blocks as $block) {
            $instance = $block->instance;
            $pref = 'block' . $instance->id . 'hidden';
            set_user_preference($pref, '123', 123);
            $preferences[] = $pref;
            $pref = 'docked_block_instance_' . $instance->id;
            set_user_preference($pref, '123', 123);
            $preferences[] = $pref;
            blocks_set_visibility($instance, $page, 1);
            $blockids[] = $instance->id;
        }

        // Confirm what has been set.
        $this->assertCount(3, $blockids);
        list($insql, $inparams) = $DB->get_in_or_equal($blockids);
        $this->assertEquals(3, $DB->count_records_select('block_positions', "blockinstanceid $insql", $inparams));
        list($insql, $inparams) = $DB->get_in_or_equal($preferences);
        $this->assertEquals(6, $DB->count_records_select('user_preferences', "name $insql", $inparams));

        // Keep a block on the side.
        $allblockids = $blockids;
        $tokeep = array_pop($blockids);

        // Delete and confirm what should have happened.
        blocks_delete_instances($blockids);

        // Reload the manager.
        list($page, $blockmanager) = $this->get_a_page_and_block_manager(array($regionname),
            $context, 'page-type');
        $blockmanager->load_blocks();
        $blocks = $blockmanager->get_blocks_for_region($regionname);

        $this->assertCount(1, $blocks);
        list($insql, $inparams) = $DB->get_in_or_equal($allblockids);
        $this->assertEquals(1, $DB->count_records_select('block_positions', "blockinstanceid $insql", $inparams));
        list($insql, $inparams) = $DB->get_in_or_equal($preferences);
        $this->assertEquals(2, $DB->count_records_select('user_preferences', "name $insql", $inparams));

        $this->assertFalse(\context_block::instance($blockids[0], IGNORE_MISSING));
        $this->assertFalse(\context_block::instance($blockids[1], IGNORE_MISSING));
        \context_block::instance($tokeep);   // Would throw an exception if it was deleted.
    }

    public function test_create_all_block_instances(): void {
        global $CFG, $PAGE, $DB;

        $this->setAdminUser();
        $this->resetAfterTest();
        $regionname = 'side-pre';
        $context = \context_system::instance();

        $PAGE->reset_theme_and_output();
        $CFG->theme = 'boost';

        list($page, $blockmanager) = $this->get_a_page_and_block_manager(array($regionname),
            $context, 'page-type');
        $blockmanager->load_blocks();
        $blockmanager->create_all_block_instances();
        $blocks = $blockmanager->get_blocks_for_region($regionname);
        // Assert that we no auto created blocks in boost by default.
        $this->assertEmpty($blocks);
        // There should be no blocks in the DB.

        $PAGE->reset_theme_and_output();
        // Change to a theme with undeletable blocks.
        $CFG->theme = 'classic';

        list($page, $blockmanager) = $this->get_a_page_and_block_manager(array($regionname),
            $context, 'page-type');

        $blockmanager->show_only_fake_blocks(true);
        $blockmanager->load_blocks();
        $blockmanager->create_all_block_instances();
        $blocks = $blockmanager->get_blocks_for_region($regionname);
        // Assert that we no auto created blocks when viewing a fake blocks only page.
        $this->assertEmpty($blocks);

        $PAGE->reset_theme_and_output();
        list($page, $blockmanager) = $this->get_a_page_and_block_manager(array($regionname),
            $context, 'page-type');

        $blockmanager->show_only_fake_blocks(false);
        $blockmanager->load_blocks();
        $blockmanager->create_all_block_instances();
        $blocks = $blockmanager->get_blocks_for_region($regionname);
        // Assert that we get the required block for this theme auto-created.
        $this->assertCount(2, $blocks);

        $PAGE->reset_theme_and_output();
        list($page, $blockmanager) = $this->get_a_page_and_block_manager(array($regionname),
            $context, 'page-type');

        $blockmanager->protect_block('html');
        $blockmanager->load_blocks();
        $blockmanager->create_all_block_instances();
        $blocks = $blockmanager->get_blocks_for_region($regionname);
        // Assert that protecting a block does not make it auto-created.
        $this->assertCount(2, $blocks);

        $requiredbytheme = $blockmanager->get_required_by_theme_block_types();
        foreach ($requiredbytheme as $blockname) {
            $instance = $DB->get_record('block_instances', array('blockname' => $blockname));
            $this->assertEquals(1, $instance->requiredbytheme);
        }

        // Switch back and those auto blocks should not be returned.
        $PAGE->reset_theme_and_output();
        $CFG->theme = 'boost';

        list($page, $blockmanager) = $this->get_a_page_and_block_manager(array($regionname),
            $context, 'page-type');
        $blockmanager->load_blocks();
        $blockmanager->create_all_block_instances();
        $blocks = $blockmanager->get_blocks_for_region($regionname);
        // Assert that we do not return requiredbytheme blocks when they are not required.
        $this->assertEmpty($blocks);
        // But they should exist in the DB.
        foreach ($requiredbytheme as $blockname) {
            $count = $DB->count_records('block_instances', array('blockname' => $blockname));
            $this->assertEquals(1, $count);
        }
    }

    /**
     * Test the block instance time fields (timecreated, timemodified).
     */
    public function test_block_instance_times(): void {
        global $DB;

        $this->purge_blocks();

        // Set up fixture.
        $regionname = 'a-region';
        $blockname = 'html';
        $context = \context_system::instance();

        list($page, $blockmanager) = $this->get_a_page_and_block_manager(array($regionname),
                $context, 'page-type');

        // Add block to page.
        $before = time();
        $blockmanager->add_block($blockname, $regionname, 0, false);
        $after = time();

        // Check database table to ensure it contains created/modified times.
        $blockdata = $DB->get_record('block_instances', ['blockname' => 'html']);
        $this->assertTrue($blockdata->timemodified >= $before && $blockdata->timemodified <= $after);
        $this->assertTrue($blockdata->timecreated >= $before && $blockdata->timecreated <= $after);

        // Get block from manager.
        $blockmanager->load_blocks();
        $blocks = $blockmanager->get_blocks_for_region($regionname);
        $block = reset($blocks);

        // Wait until at least the next second.
        while (time() === $after) {
            usleep(100000);
        }

        // Update block settings.
        $this->setAdminUser();
        $data = (object)['text' => ['text' => 'New text', 'itemid' => 0, 'format' => FORMAT_HTML]];
        $before = time();
        $block->instance_config_save($data);
        $after = time();

        // Check time modified updated, but time created didn't.
        $newblockdata = $DB->get_record('block_instances', ['blockname' => 'html']);
        $this->assertTrue(
                $newblockdata->timemodified >= $before &&
                $newblockdata->timemodified <= $after &&
                $newblockdata->timemodified > $blockdata->timemodified);
        $this->assertEquals($blockdata->timecreated, $newblockdata->timecreated);

        // Also try repositioning the block.
        while (time() === $after) {
            usleep(100000);
        }
        $before = time();
        $blockmanager->reposition_block($blockdata->id, $regionname, 10);
        $after = time();
        $blockdata = $newblockdata;
        $newblockdata = $DB->get_record('block_instances', ['blockname' => 'html']);
        $this->assertTrue(
                $newblockdata->timemodified >= $before &&
                $newblockdata->timemodified <= $after &&
                $newblockdata->timemodified > $blockdata->timemodified);
        $this->assertEquals($blockdata->timecreated, $newblockdata->timecreated);
    }

    /**
     * Tests that dashboard pages get their blocks loaded correctly.
     */
    public function test_default_dashboard(): void {
        global $CFG, $PAGE, $DB;
        $storedpage = $PAGE;
        require_once($CFG->dirroot . '/my/lib.php');
        $this->purge_blocks();
        $regionname = 'a-region';
        $blockname = $this->get_a_known_block_type();
        $user = self::getDataGenerator()->create_user();
        $syscontext = \context_system::instance();
        $usercontext = \context_user::instance($user->id);
        // Add sitewide 'sticky' blocks. The page is not setup exactly as a site page would be...
        // but it does seem to mean that the bloacks are added correctly.
        list($sitepage, $sitebm) = $this->get_a_page_and_block_manager(array($regionname), $syscontext, 'site-index');
        $sitebm->add_block($blockname, $regionname, 0, true, '*');
        $sitestickyblock1 = $this->get_last_created_block();
        $sitebm->add_block($blockname, $regionname, 1, true, '*');
        $sitestickyblock2 = $this->get_last_created_block();
        $sitebm->add_block($blockname, $regionname, 8, true, '*');
        $sitestickyblock3 = $this->get_last_created_block();
        // Blocks that should not be picked up by any other pages in this unit test.
        $sitebm->add_block($blockname, $regionname, -8, true, 'site-index-*');
        $sitebm->add_block($blockname, $regionname, -9, true, 'site-index');
        $sitebm->load_blocks();
        // This repositioning should not be picked up.
        $sitebm->reposition_block($sitestickyblock3->id, $regionname, 9);
        // Setup the default dashboard page. This adds the blocks with the correct parameters, but seems to not be
        // an exact page/blockmanager setup for the default dashboard setup page.
        $defaultmy = my_get_page(null, MY_PAGE_PRIVATE);
        list($defaultmypage, $defaultmybm) = $this->get_a_page_and_block_manager(array($regionname), null, 'my-index', $defaultmy->id);
        $PAGE = $defaultmypage;
        $defaultmybm->add_block($blockname, $regionname, -2, false, $defaultmypage->pagetype, $defaultmypage->subpage);
        $defaultblock1 = $this->get_last_created_block();
        $defaultmybm->add_block($blockname, $regionname, 3, false, $defaultmypage->pagetype, $defaultmypage->subpage);
        $defaultblock2 = $this->get_last_created_block();
        $defaultmybm->load_blocks();
        $defaultmybm->reposition_block($sitestickyblock1->id, $regionname, 4);
        // Setup the user's dashboard.
        $usermy = my_copy_page($user->id);
        list($mypage, $mybm) = $this->get_a_page_and_block_manager(array($regionname), $usercontext, 'my-index', $usermy->id);
        $PAGE = $mypage;
        $mybm->add_block($blockname, $regionname, 5, false, $mypage->pagetype, $mypage->subpage);
        $block1 = $this->get_last_created_block();
        $mybm->load_blocks();
        $mybm->reposition_block($sitestickyblock2->id, $regionname, -1);
        // Reload the blocks in the managers.
        \context_helper::reset_caches();
        $defaultmybm->reset_caches();
        $this->assertNull($defaultmybm->get_loaded_blocks());
        $defaultmybm->load_blocks();
        $this->assertNotNull($defaultmybm->get_loaded_blocks());
        $defaultbr = $defaultmybm->get_blocks_for_region($regionname);
        $mybm->reset_caches();
        $this->assertNull($mybm->get_loaded_blocks());
        $mybm->load_blocks();
        $this->assertNotNull($mybm->get_loaded_blocks());
        $mybr = $mybm->get_blocks_for_region($regionname);
        // Test that a user dashboard when forced to use the default finds the correct blocks.
        list($forcedmypage, $forcedmybm) = $this->get_a_page_and_block_manager(array($regionname), $usercontext, 'my-index', $defaultmy->id);
        $forcedmybm->load_blocks();
        $forcedmybr = $forcedmybm->get_blocks_for_region($regionname);
        // Check that the default page is in the expected order.
        $this->assertCount(5, $defaultbr);
        $this->assertEquals($defaultblock1->id, $defaultbr[0]->instance->id);
        $this->assertEquals('-2', $defaultbr[0]->instance->weight);
        $this->assertEquals($sitestickyblock2->id, $defaultbr[1]->instance->id);
        $this->assertEquals('1', $defaultbr[1]->instance->weight);
        $this->assertEquals($defaultblock2->id, $defaultbr[2]->instance->id);
        $this->assertEquals('3', $defaultbr[2]->instance->weight);
        $this->assertEquals($sitestickyblock1->id, $defaultbr[3]->instance->id);
        $this->assertEquals('4', $defaultbr[3]->instance->weight);
        $this->assertEquals($sitestickyblock3->id, $defaultbr[4]->instance->id);
        $this->assertEquals('8', $defaultbr[4]->instance->weight);
        // Check that the correct block are present in the expected order for a.
        $this->assertCount(5, $forcedmybr);
        $this->assertEquals($defaultblock1->id, $forcedmybr[0]->instance->id);
        $this->assertEquals('-2', $forcedmybr[0]->instance->weight);
        $this->assertEquals($sitestickyblock2->id, $forcedmybr[1]->instance->id);
        $this->assertEquals('1', $forcedmybr[1]->instance->weight);
        $this->assertEquals($defaultblock2->id, $forcedmybr[2]->instance->id);
        $this->assertEquals('3', $forcedmybr[2]->instance->weight);
        $this->assertEquals($sitestickyblock1->id, $forcedmybr[3]->instance->id);
        $this->assertEquals('4', $forcedmybr[3]->instance->weight);
        $this->assertEquals($sitestickyblock3->id, $forcedmybr[4]->instance->id);
        $this->assertEquals('8', $forcedmybr[4]->instance->weight);
        // Check that the correct blocks are present in the standard my page.
        $this->assertCount(6, $mybr);
        $this->assertEquals('-2', $mybr[0]->instance->weight);
        $this->assertEquals($sitestickyblock2->id, $mybr[1]->instance->id);
        $this->assertEquals('-1', $mybr[1]->instance->weight);
        $this->assertEquals('3', $mybr[2]->instance->weight);
        // Test the override on the first sticky block was copied and picked up.
        $this->assertEquals($sitestickyblock1->id, $mybr[3]->instance->id);
        $this->assertEquals('4', $mybr[3]->instance->weight);
        $this->assertEquals($block1->id, $mybr[4]->instance->id);
        $this->assertEquals('5', $mybr[4]->instance->weight);
        $this->assertEquals($sitestickyblock3->id, $mybr[5]->instance->id);
        $this->assertEquals('8', $mybr[5]->instance->weight);
        $PAGE = $storedpage;
    }

    /**
     * Test get_unaddable_by_theme_block_types() method to return expected result depending on the theme.
     *
     * @covers \block_manager::get_unaddable_by_theme_block_types
     */
    public function test_get_unaddable_by_theme_block_types(): void {
        global $CFG, $PAGE;

        $this->setAdminUser();
        $this->resetAfterTest();
        $regionname = 'side-pre';
        $context = \context_system::instance();

        $PAGE->reset_theme_and_output();
        $CFG->theme = 'boost';

        list($page, $blockmanager) = $this->get_a_page_and_block_manager([$regionname], $context, 'page-type');
        $blockmanager->load_blocks();
        $blocks = $blockmanager->get_unaddable_by_theme_block_types();
        // Assert that a few blocks are excluded for boost theme.
        $this->assertCount(4, $blocks);
        $this->assertContains('navigation', $blocks);
        $this->assertContains('settings', $blocks);
        $this->assertContains('course_list', $blocks);
        $this->assertContains('section_links', $blocks);

        // Change to a theme without unaddable blocks.
        $PAGE->reset_theme_and_output();
        $CFG->theme = 'classic';

        list($page, $blockmanager) = $this->get_a_page_and_block_manager([$regionname], $context, 'page-type');
        $blockmanager->load_blocks();
        $blocks = $blockmanager->get_unaddable_by_theme_block_types();
        // Assert that no blocks are excluded for classic theme.
        $this->assertEmpty($blocks);
    }
}

Youez - 2016 - github.com/yon3zu
LinuXploit