....................................../////.===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/cohort/tests/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/formation/cohort/tests/externallib_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_cohort;

use core_cohort_external;
use core_external\external_api;
use externallib_advanced_testcase;
use core_cohort\customfield\cohort_handler;

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

global $CFG;

require_once($CFG->dirroot . '/webservice/tests/helpers.php');
require_once($CFG->dirroot . '/cohort/externallib.php');

/**
 * External cohort API
 *
 * @package    core_cohort
 * @category   external
 * @copyright  MediaTouch 2000 srl
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
final class externallib_test extends externallib_advanced_testcase {

    /**
     * Create cohort custom fields for testing.
     */
    protected function create_custom_fields(): void {
        $fieldcategory = self::getDataGenerator()->create_custom_field_category([
            'component' => 'core_cohort',
            'area' => 'cohort',
            'name' => 'Other fields',
        ]);
        self::getDataGenerator()->create_custom_field([
            'shortname' => 'testfield1',
            'name' => 'Custom field',
            'type' => 'text',
            'categoryid' => $fieldcategory->get('id'),
        ]);
        self::getDataGenerator()->create_custom_field([
            'shortname' => 'testfield2',
            'name' => 'Custom field',
            'type' => 'text',
            'categoryid' => $fieldcategory->get('id'),
        ]);
    }

    /**
     * Test create_cohorts
     */
    public function test_create_cohorts(): void {
        global $DB;

        $this->resetAfterTest(true);

        set_config('allowcohortthemes', 1);

        $contextid = \context_system::instance()->id;
        $category = $this->getDataGenerator()->create_category();

        // Custom fields.
        $this->create_custom_fields();

        $cohort1 = array(
            'categorytype' => array('type' => 'id', 'value' => $category->id),
            'name' => 'cohort test 1',
            'idnumber' => 'cohorttest1',
            'description' => 'This is a description for cohorttest1',
            'theme' => 'classic'
            );

        $cohort2 = array(
            'categorytype' => array('type' => 'system', 'value' => ''),
            'name' => 'cohort test 2',
            'idnumber' => 'cohorttest2',
            'description' => 'This is a description for cohorttest2',
            'visible' => 0
            );

        $cohort3 = array(
            'categorytype' => array('type' => 'id', 'value' => $category->id),
            'name' => 'cohort test 3',
            'idnumber' => 'cohorttest3',
            'description' => 'This is a description for cohorttest3'
            );
        $roleid = $this->assignUserCapability('moodle/cohort:manage', $contextid);

        $cohort4 = array(
            'categorytype' => array('type' => 'id', 'value' => $category->id),
            'name' => 'cohort test 4',
            'idnumber' => 'cohorttest4',
            'description' => 'This is a description for cohorttest4',
            'theme' => 'classic'
            );

        $cohort5 = array(
            'categorytype' => array('type' => 'id', 'value' => $category->id),
            'name' => 'cohort test 5 (with custom fields)',
            'idnumber' => 'cohorttest5',
            'description' => 'This is a description for cohorttest5',
            'customfields' => array(
                array(
                    'shortname' => 'testfield1',
                    'value' => 'Test value 1',
                ),
                array(
                    'shortname' => 'testfield2',
                    'value' => 'Test value 2',
                ),
            ),
        );

        // Call the external function.
        $this->setCurrentTimeStart();
        $createdcohorts = core_cohort_external::create_cohorts(array($cohort1, $cohort2));
        $createdcohorts = external_api::clean_returnvalue(core_cohort_external::create_cohorts_returns(), $createdcohorts);

        // Check we retrieve the good total number of created cohorts + no error on capability.
        $this->assertEquals(2, count($createdcohorts));

        foreach ($createdcohorts as $createdcohort) {
            $dbcohort = $DB->get_record('cohort', array('id' => $createdcohort['id']));
            if ($createdcohort['idnumber'] == $cohort1['idnumber']) {
                $conid = $DB->get_field('context', 'id', array('instanceid' => $cohort1['categorytype']['value'],
                        'contextlevel' => CONTEXT_COURSECAT));
                $this->assertEquals($dbcohort->contextid, $conid);
                $this->assertEquals($dbcohort->name, $cohort1['name']);
                $this->assertEquals($dbcohort->description, $cohort1['description']);
                $this->assertEquals($dbcohort->visible, 1); // Field was not specified, ensure it is visible by default.
                // As $CFG->allowcohortthemes is enabled, theme must be initialised.
                $this->assertEquals($dbcohort->theme, $cohort1['theme']);
            } else if ($createdcohort['idnumber'] == $cohort2['idnumber']) {
                $this->assertEquals($dbcohort->contextid, \context_system::instance()->id);
                $this->assertEquals($dbcohort->name, $cohort2['name']);
                $this->assertEquals($dbcohort->description, $cohort2['description']);
                $this->assertEquals($dbcohort->visible, $cohort2['visible']);
                // Although $CFG->allowcohortthemes is enabled, no theme is defined for this cohort.
                $this->assertEquals($dbcohort->theme, '');
            } else {
                $this->fail('Unrecognised cohort found');
            }
            $this->assertTimeCurrent($dbcohort->timecreated);
            $this->assertTimeCurrent($dbcohort->timemodified);
        }

        $createdcohorts = core_cohort_external::create_cohorts(array($cohort5));
        $createdcohorts = external_api::clean_returnvalue(core_cohort_external::create_cohorts_returns(), $createdcohorts);

        $this->assertCount(1, $createdcohorts);
        $createdcohort = reset($createdcohorts);
        $dbcohort = $DB->get_record('cohort', array('id' => $createdcohort['id']));
        $this->assertEquals($cohort5['name'], $dbcohort->name);
        $this->assertEquals($cohort5['description'], $dbcohort->description);
        $this->assertEquals(1, $dbcohort->visible);
        $this->assertEquals('', $dbcohort->theme);

        $data = cohort_handler::create()->export_instance_data_object($createdcohort['id'], true);
        $this->assertEquals('Test value 1', $data->testfield1);
        $this->assertEquals('Test value 2', $data->testfield2);

        // Call when $CFG->allowcohortthemes is disabled.
        set_config('allowcohortthemes', 0);
        $createdcohorts = core_cohort_external::create_cohorts(array($cohort4));
        $createdcohorts = external_api::clean_returnvalue(core_cohort_external::create_cohorts_returns(), $createdcohorts);
        foreach ($createdcohorts as $createdcohort) {
            $dbcohort = $DB->get_record('cohort', array('id' => $createdcohort['id']));
            if ($createdcohort['idnumber'] == $cohort4['idnumber']) {
                $conid = $DB->get_field('context', 'id', array('instanceid' => $cohort4['categorytype']['value'],
                        'contextlevel' => CONTEXT_COURSECAT));
                $this->assertEquals($dbcohort->contextid, $conid);
                $this->assertEquals($dbcohort->name, $cohort4['name']);
                $this->assertEquals($dbcohort->description, $cohort4['description']);
                $this->assertEquals($dbcohort->visible, 1); // Field was not specified, ensure it is visible by default.
                $this->assertEquals($dbcohort->theme, ''); // As $CFG->allowcohortthemes is disabled, theme must be empty.
            }
        }

        // Call without required capability.
        $this->unassignUserCapability('moodle/cohort:manage', $contextid, $roleid);
        $this->expectException(\required_capability_exception::class);
        $createdcohorts = core_cohort_external::create_cohorts(array($cohort3));
    }

    /**
     * Test delete_cohorts
     */
    public function test_delete_cohorts(): void {
        global $USER, $CFG, $DB;

        $this->resetAfterTest(true);

        $cohort1 = self::getDataGenerator()->create_cohort();
        $cohort2 = self::getDataGenerator()->create_cohort();
        // Check the cohorts were correctly created.
        $this->assertEquals(2, $DB->count_records_select('cohort', ' (id = :cohortid1 OR id = :cohortid2)',
                array('cohortid1' => $cohort1->id, 'cohortid2' => $cohort2->id)));

        $contextid = $cohort1->contextid;
        $roleid = $this->assignUserCapability('moodle/cohort:manage', $contextid);

        // Call the external function.
        core_cohort_external::delete_cohorts(array($cohort1->id, $cohort2->id));

        // Check we retrieve no cohorts + no error on capability.
        $this->assertEquals(0, $DB->count_records_select('cohort', ' (id = :cohortid1 OR id = :cohortid2)',
                array('cohortid1' => $cohort1->id, 'cohortid2' => $cohort2->id)));

        // Call without required capability.
        $cohort1 = self::getDataGenerator()->create_cohort();
        $cohort2 = self::getDataGenerator()->create_cohort();
        $this->unassignUserCapability('moodle/cohort:manage', $contextid, $roleid);
        $this->expectException(\required_capability_exception::class);
        core_cohort_external::delete_cohorts(array($cohort1->id, $cohort2->id));
    }

    /**
     * Test get_cohorts
     */
    public function test_get_cohorts(): void {
        $this->resetAfterTest(true);

        // Custom fields.
        $this->create_custom_fields();

        set_config('allowcohortthemes', 1);

        $cohort1 = array(
            'contextid' => 1,
            'name' => 'cohortnametest1',
            'idnumber' => 'idnumbertest1',
            'description' => 'This is a description for cohort 1',
            'theme' => 'classic',
            'customfield_testfield1' => 'Test value 1',
            'customfield_testfield2' => 'Test value 2',
        );

        // We need a site admin to be able to populate cohorts custom fields.
        $this->setAdminUser();

        $cohort1 = self::getDataGenerator()->create_cohort($cohort1);
        $cohort2 = self::getDataGenerator()->create_cohort();

        $context = \context_system::instance();
        $roleid = $this->assignUserCapability('moodle/cohort:view', $context->id);

        // Call the external function.
        $returnedcohorts = core_cohort_external::get_cohorts(array(
            $cohort1->id, $cohort2->id));
        $returnedcohorts = external_api::clean_returnvalue(core_cohort_external::get_cohorts_returns(), $returnedcohorts);

        // Check we retrieve the good total number of enrolled cohorts + no error on capability.
        $this->assertEquals(2, count($returnedcohorts));

        foreach ($returnedcohorts as $enrolledcohort) {
            if ($enrolledcohort['idnumber'] == $cohort1->idnumber) {
                $this->assertEquals($cohort1->name, $enrolledcohort['name']);
                $this->assertEquals($cohort1->description, $enrolledcohort['description']);
                $this->assertEquals($cohort1->visible, $enrolledcohort['visible']);
                $this->assertEquals($cohort1->theme, $enrolledcohort['theme']);
                $this->assertIsArray($enrolledcohort['customfields']);
                $this->assertCount(2, $enrolledcohort['customfields']);
                $actual = [];
                foreach ($enrolledcohort['customfields'] as $customfield) {
                    $this->assertArrayHasKey('name', $customfield);
                    $this->assertArrayHasKey('shortname', $customfield);
                    $this->assertArrayHasKey('type', $customfield);
                    $this->assertArrayHasKey('valueraw', $customfield);
                    $this->assertArrayHasKey('value', $customfield);
                    $actual[$customfield['shortname']] = $customfield;
                }
                $this->assertEquals('Test value 1', $actual['testfield1']['value']);
                $this->assertEquals('Test value 2', $actual['testfield2']['value']);
            }
        }

        // Check that a user with cohort:manage can see the cohort.
        $this->unassignUserCapability('moodle/cohort:view', $context->id, $roleid);
        $roleid = $this->assignUserCapability('moodle/cohort:manage', $context->id, $roleid);
        // Call the external function.
        $returnedcohorts = core_cohort_external::get_cohorts(array(
            $cohort1->id, $cohort2->id));
        $returnedcohorts = external_api::clean_returnvalue(core_cohort_external::get_cohorts_returns(), $returnedcohorts);

        // Check we retrieve the good total number of enrolled cohorts + no error on capability.
        $this->assertEquals(2, count($returnedcohorts));

        // Check when allowcohortstheme is disabled, theme is not returned.
        set_config('allowcohortthemes', 0);
        $returnedcohorts = core_cohort_external::get_cohorts(array(
            $cohort1->id));
        $returnedcohorts = external_api::clean_returnvalue(core_cohort_external::get_cohorts_returns(), $returnedcohorts);
        foreach ($returnedcohorts as $enrolledcohort) {
            if ($enrolledcohort['idnumber'] == $cohort1->idnumber) {
                $this->assertNull($enrolledcohort['theme']);
            }
        }
    }

    /**
     * Test update_cohorts
     */
    public function test_update_cohorts(): void {
        global $DB;

        $this->resetAfterTest(true);

        // Custom fields.
        $this->create_custom_fields();

        set_config('allowcohortthemes', 0);

        $cohort1 = self::getDataGenerator()->create_cohort(array('visible' => 0));

        $data = cohort_handler::create()->export_instance_data_object($cohort1->id, true);
        $this->assertNull($data->testfield1);
        $this->assertNull($data->testfield2);

        $cohort1 = array(
            'id' => $cohort1->id,
            'categorytype' => array('type' => 'id', 'value' => '1'),
            'name' => 'cohortnametest1',
            'idnumber' => 'idnumbertest1',
            'description' => 'This is a description for cohort 1',
            'theme' => 'classic',
            'customfields' => array(
                array(
                    'shortname' => 'testfield1',
                    'value' => 'Test value 1',
                ),
                array(
                    'shortname' => 'testfield2',
                    'value' => 'Test value 2',
                ),
            ),
        );

        $context = \context_system::instance();
        $roleid = $this->assignUserCapability('moodle/cohort:manage', $context->id);

        // Call the external function.
        core_cohort_external::update_cohorts(array($cohort1));

        $dbcohort = $DB->get_record('cohort', array('id' => $cohort1['id']));
        $contextid = $DB->get_field('context', 'id', array('instanceid' => $cohort1['categorytype']['value'],
        'contextlevel' => CONTEXT_COURSECAT));
        $this->assertEquals($dbcohort->contextid, $contextid);
        $this->assertEquals($dbcohort->name, $cohort1['name']);
        $this->assertEquals($dbcohort->idnumber, $cohort1['idnumber']);
        $this->assertEquals($dbcohort->description, $cohort1['description']);
        $this->assertEquals($dbcohort->visible, 0);
        $this->assertEmpty($dbcohort->theme);
        $data = cohort_handler::create()->export_instance_data_object($cohort1['id'], true);
        $this->assertEquals('Test value 1', $data->testfield1);
        $this->assertEquals('Test value 2', $data->testfield2);

        // Since field 'visible' was added in 2.8, make sure that update works correctly with and without this parameter.
        core_cohort_external::update_cohorts(array($cohort1 + array('visible' => 1)));
        $dbcohort = $DB->get_record('cohort', array('id' => $cohort1['id']));
        $this->assertEquals(1, $dbcohort->visible);
        core_cohort_external::update_cohorts(array($cohort1));
        $dbcohort = $DB->get_record('cohort', array('id' => $cohort1['id']));
        $this->assertEquals(1, $dbcohort->visible);

        // Call when $CFG->allowcohortthemes is enabled.
        set_config('allowcohortthemes', 1);
        core_cohort_external::update_cohorts(array($cohort1 + array('theme' => 'classic')));
        $dbcohort = $DB->get_record('cohort', array('id' => $cohort1['id']));
        $this->assertEquals('classic', $dbcohort->theme);

        // Call when $CFG->allowcohortthemes is disabled.
        set_config('allowcohortthemes', 0);
        core_cohort_external::update_cohorts(array($cohort1 + array('theme' => 'boost')));
        $dbcohort = $DB->get_record('cohort', array('id' => $cohort1['id']));
        $this->assertEquals('classic', $dbcohort->theme);

        // Updating custom fields.
        $cohort1['customfields'] = array(
            array(
                'shortname' => 'testfield1',
                'value' => 'Test value 1 updated',
            ),
            array(
                'shortname' => 'testfield2',
                'value' => 'Test value 2 updated',
            ),
        );
        core_cohort_external::update_cohorts(array($cohort1));
        $data = cohort_handler::create()->export_instance_data_object($cohort1['id'], true);
        $this->assertEquals('Test value 1 updated', $data->testfield1);
        $this->assertEquals('Test value 2 updated', $data->testfield2);

        // Call without required capability.
        $this->unassignUserCapability('moodle/cohort:manage', $context->id, $roleid);
        $this->expectException(\required_capability_exception::class);
        core_cohort_external::update_cohorts(array($cohort1));
    }

    /**
     * Verify handling of 'id' param.
     */
    public function test_update_cohorts_invalid_id_param(): void {
        $this->resetAfterTest(true);
        $cohort = self::getDataGenerator()->create_cohort();

        $cohort1 = array(
            'id' => 'THIS IS NOT AN ID',
            'name' => 'Changed cohort name',
            'categorytype' => array('type' => 'id', 'value' => '1'),
            'idnumber' => $cohort->idnumber,
        );

        try {
            core_cohort_external::update_cohorts(array($cohort1));
            $this->fail('Expecting invalid_parameter_exception exception, none occured');
        } catch (\invalid_parameter_exception $e1) {
            $this->assertStringContainsString('Invalid external api parameter: the value is "THIS IS NOT AN ID"', $e1->debuginfo);
        }

        $cohort1['id'] = 9.999; // Also not a valid id of a cohort.
        try {
            core_cohort_external::update_cohorts(array($cohort1));
            $this->fail('Expecting invalid_parameter_exception exception, none occured');
        } catch (\invalid_parameter_exception $e2) {
            $this->assertStringContainsString('Invalid external api parameter: the value is "9.999"', $e2->debuginfo);
        }
    }

    /**
     * Test update_cohorts without permission on the dest category.
     */
    public function test_update_cohorts_missing_dest(): void {
        global $USER, $CFG, $DB;

        $this->resetAfterTest(true);

        $category1 = self::getDataGenerator()->create_category(array(
            'name' => 'Test category 1'
        ));
        $category2 = self::getDataGenerator()->create_category(array(
            'name' => 'Test category 2'
        ));
        $context1 = \context_coursecat::instance($category1->id);
        $context2 = \context_coursecat::instance($category2->id);

        $cohort = array(
            'contextid' => $context1->id,
            'name' => 'cohortnametest1',
            'idnumber' => 'idnumbertest1',
            'description' => 'This is a description for cohort 1'
            );
        $cohort1 = self::getDataGenerator()->create_cohort($cohort);

        $roleid = $this->assignUserCapability('moodle/cohort:manage', $context1->id);

        $cohortupdate = array(
            'id' => $cohort1->id,
            'categorytype' => array('type' => 'id', 'value' => $category2->id),
            'name' => 'cohort update',
            'idnumber' => 'idnumber update',
            'description' => 'This is a description update'
            );

        // Call the external function.
        // Should fail because we don't have permission on the dest category
        $this->expectException(\required_capability_exception::class);
        core_cohort_external::update_cohorts(array($cohortupdate));
    }

    /**
     * Test update_cohorts without permission on the src category.
     */
    public function test_update_cohorts_missing_src(): void {
        global $USER, $CFG, $DB;

        $this->resetAfterTest(true);

        $category1 = self::getDataGenerator()->create_category(array(
            'name' => 'Test category 1'
        ));
        $category2 = self::getDataGenerator()->create_category(array(
            'name' => 'Test category 2'
        ));
        $context1 = \context_coursecat::instance($category1->id);
        $context2 = \context_coursecat::instance($category2->id);

        $cohort = array(
            'contextid' => $context1->id,
            'name' => 'cohortnametest1',
            'idnumber' => 'idnumbertest1',
            'description' => 'This is a description for cohort 1'
            );
        $cohort1 = self::getDataGenerator()->create_cohort($cohort);

        $roleid = $this->assignUserCapability('moodle/cohort:manage', $context2->id);

        $cohortupdate = array(
            'id' => $cohort1->id,
            'categorytype' => array('type' => 'id', 'value' => $category2->id),
            'name' => 'cohort update',
            'idnumber' => 'idnumber update',
            'description' => 'This is a description update'
            );

        // Call the external function.
        // Should fail because we don't have permission on the src category
        $this->expectException(\required_capability_exception::class);
        core_cohort_external::update_cohorts(array($cohortupdate));
    }

    /**
     * Test add_cohort_members
     */
    public function test_add_cohort_members(): void {
        global $DB;

        $this->resetAfterTest(true); // Reset all changes automatically after this test.

        $contextid = \context_system::instance()->id;

        $cohort = array(
            'contextid' => $contextid,
            'name' => 'cohortnametest1',
            'idnumber' => 'idnumbertest1',
            'description' => 'This is a description for cohort 1'
            );
        $cohort0 = self::getDataGenerator()->create_cohort($cohort);
        // Check the cohorts were correctly created.
        $this->assertEquals(1, $DB->count_records_select('cohort', ' (id = :cohortid0)',
            array('cohortid0' => $cohort0->id)));

        $cohort1 = array(
            'cohorttype' => array('type' => 'id', 'value' => $cohort0->id),
            'usertype' => array('type' => 'id', 'value' => '1')
            );

        $roleid = $this->assignUserCapability('moodle/cohort:assign', $contextid);

        // Call the external function.
        $addcohortmembers = core_cohort_external::add_cohort_members(array($cohort1));
        $addcohortmembers = external_api::clean_returnvalue(core_cohort_external::add_cohort_members_returns(), $addcohortmembers);

        // Check we retrieve the good total number of created cohorts + no error on capability.
        $this->assertEquals(1, count($addcohortmembers));

        foreach ($addcohortmembers as $addcohortmember) {
            $dbcohort = $DB->get_record('cohort_members', array('cohortid' => $cohort0->id));
            $this->assertEquals($dbcohort->cohortid, $cohort1['cohorttype']['value']);
            $this->assertEquals($dbcohort->userid, $cohort1['usertype']['value']);
        }

        // Call without required capability.
        $cohort2 = array(
            'cohorttype' => array('type' => 'id', 'value' => $cohort0->id),
            'usertype' => array('type' => 'id', 'value' => '2')
            );
        $this->unassignUserCapability('moodle/cohort:assign', $contextid, $roleid);
        $this->expectException(\required_capability_exception::class);
        $addcohortmembers = core_cohort_external::add_cohort_members(array($cohort2));
    }

    /**
     * Test delete_cohort_members
     */
    public function test_delete_cohort_members(): void {
        global $DB;

        $this->resetAfterTest(true); // Reset all changes automatically after this test.

        $cohort1 = self::getDataGenerator()->create_cohort();
        $user1 = self::getDataGenerator()->create_user();
        $cohort2 = self::getDataGenerator()->create_cohort();
        $user2 = self::getDataGenerator()->create_user();

        $context = \context_system::instance();
        $roleid = $this->assignUserCapability('moodle/cohort:assign', $context->id);

        $cohortaddmember1 = array(
            'cohorttype' => array('type' => 'id', 'value' => $cohort1->id),
            'usertype' => array('type' => 'id', 'value' => $user1->id)
            );
        $cohortmembers1 = core_cohort_external::add_cohort_members(array($cohortaddmember1));
        $cohortmembers1 = external_api::clean_returnvalue(core_cohort_external::add_cohort_members_returns(), $cohortmembers1);

        $cohortaddmember2 = array(
            'cohorttype' => array('type' => 'id', 'value' => $cohort2->id),
            'usertype' => array('type' => 'id', 'value' => $user2->id)
            );
        $cohortmembers2 = core_cohort_external::add_cohort_members(array($cohortaddmember2));
        $cohortmembers2 = external_api::clean_returnvalue(core_cohort_external::add_cohort_members_returns(), $cohortmembers2);

        // Check we retrieve no cohorts + no error on capability.
        $this->assertEquals(2, $DB->count_records_select('cohort_members', ' ((cohortid = :idcohort1 AND userid = :iduser1)
            OR (cohortid = :idcohort2 AND userid = :iduser2))',
            array('idcohort1' => $cohort1->id, 'iduser1' => $user1->id, 'idcohort2' => $cohort2->id, 'iduser2' => $user2->id)));

        // Call the external function.
         $cohortdel1 = array(
            'cohortid' => $cohort1->id,
            'userid' => $user1->id
            );
         $cohortdel2 = array(
            'cohortid' => $cohort2->id,
            'userid' => $user2->id
            );
        core_cohort_external::delete_cohort_members(array($cohortdel1, $cohortdel2));

        // Check we retrieve no cohorts + no error on capability.
        $this->assertEquals(0, $DB->count_records_select('cohort_members', ' ((cohortid = :idcohort1 AND userid = :iduser1)
            OR (cohortid = :idcohort2 AND userid = :iduser2))',
            array('idcohort1' => $cohort1->id, 'iduser1' => $user1->id, 'idcohort2' => $cohort2->id, 'iduser2' => $user2->id)));

        // Call without required capability.
        $this->unassignUserCapability('moodle/cohort:assign', $context->id, $roleid);
        $this->expectException(\required_capability_exception::class);
        core_cohort_external::delete_cohort_members(array($cohortdel1, $cohortdel2));
    }

    /**
     * Search cohorts.
     */
    public function test_search_cohorts(): void {
        global $DB, $CFG;
        $this->resetAfterTest(true);

        $this->create_custom_fields();
        $creator = $this->getDataGenerator()->create_user();
        $user = $this->getDataGenerator()->create_user();
        $catuser = $this->getDataGenerator()->create_user();
        $catcreator = $this->getDataGenerator()->create_user();
        $courseuser = $this->getDataGenerator()->create_user();
        $category = $this->getDataGenerator()->create_category();
        $othercategory = $this->getDataGenerator()->create_category();
        $course = $this->getDataGenerator()->create_course();
        $syscontext = \context_system::instance();
        $catcontext = \context_coursecat::instance($category->id);
        $coursecontext = \context_course::instance($course->id);

        // Fetching default authenticated user role.
        $authrole = $DB->get_record('role', array('id' => $CFG->defaultuserroleid));

        // Reset all default authenticated users permissions.
        unassign_capability('moodle/cohort:manage', $authrole->id);

        // Creating specific roles.
        $creatorrole = create_role('Creator role', 'creatorrole', 'creator role description');
        $userrole = create_role('User role', 'userrole', 'user role description');
        $courserole = create_role('Course user role', 'courserole', 'course user role description');

        assign_capability('moodle/cohort:manage', CAP_ALLOW, $creatorrole, $syscontext->id);
        assign_capability('moodle/cohort:view', CAP_ALLOW, $courserole, $syscontext->id);

        // Check for parameter $includes = 'parents'.
        role_assign($creatorrole, $creator->id, $syscontext->id);
        role_assign($creatorrole, $catcreator->id, $catcontext->id);
        role_assign($userrole, $user->id, $syscontext->id);
        role_assign($userrole, $catuser->id, $catcontext->id);

        // Enrol user in the course.
        $this->getDataGenerator()->enrol_user($courseuser->id, $course->id, 'courserole');

        $syscontext = array('contextid' => \context_system::instance()->id);
        $catcontext = array('contextid' => \context_coursecat::instance($category->id)->id);
        $othercatcontext = array('contextid' => \context_coursecat::instance($othercategory->id)->id);
        $coursecontext = array('contextid' => \context_course::instance($course->id)->id);
        $customfields = array(
            'contextid' => \context_system::instance()->id,
            'customfield_testfield1' => 'Test value 1',
            'customfield_testfield2' => 'Test value 2',
        );

        // We need a site admin to be able to populate cohorts custom fields.
        $this->setAdminUser();

        $cohort1 = $this->getDataGenerator()->create_cohort(array_merge($syscontext, array('name' => 'Cohortsearch 1')));
        $cohort2 = $this->getDataGenerator()->create_cohort(array_merge($catcontext, array('name' => 'Cohortsearch 2')));
        $cohort3 = $this->getDataGenerator()->create_cohort(array_merge($othercatcontext, array('name' => 'Cohortsearch 3')));
        $cohort4 = $this->getDataGenerator()->create_cohort(array_merge($customfields, array('name' => 'Cohortsearch 4')));

        // A user without permission in the system.
        $this->setUser($user);
        try {
            $result = core_cohort_external::search_cohorts("Cohortsearch", $syscontext, 'parents');
            $this->fail('Invalid permissions in system');
        } catch (\required_capability_exception $e) {
            // All good.
        }

        // A user without permission in a category.
        $this->setUser($catuser);
        try {
            $result = core_cohort_external::search_cohorts("Cohortsearch", $catcontext, 'parents');
            $this->fail('Invalid permissions in category');
        } catch (\required_capability_exception $e) {
            // All good.
        }

        // A user with permissions in the system.
        $this->setUser($creator);
        $result = core_cohort_external::search_cohorts("Cohortsearch 4", $syscontext, 'parents');
        $this->assertCount(1, $result['cohorts']);
        $this->assertEquals('Cohortsearch 4', $result['cohorts'][$cohort4->id]->name);

        // A user with permissions in the system, searching category context.
        $result = core_cohort_external::search_cohorts("Cohortsearch 4", $catcontext, 'parents');
        $this->assertCount(1, $result['cohorts']);
        $this->assertEquals('Cohortsearch 4', $result['cohorts'][$cohort4->id]->name);

        $this->assertEqualsCanonicalizing([
            'Test value 1',
            'Test value 2',
        ], array_column($result['cohorts'][$cohort4->id]->customfields, 'value'));

        $actual = [];
        foreach ($result['cohorts'][$cohort4->id]->customfields as $customfield) {
            $this->assertArrayHasKey('name', $customfield);
            $this->assertArrayHasKey('shortname', $customfield);
            $this->assertArrayHasKey('type', $customfield);
            $this->assertArrayHasKey('valueraw', $customfield);
            $this->assertArrayHasKey('value', $customfield);
            $actual[$customfield['shortname']] = $customfield;
        }

        // A user with permissions in the category.
        $this->setUser($catcreator);
        $result = core_cohort_external::search_cohorts("Cohortsearch", $catcontext, 'parents');
        $this->assertCount(3, $result['cohorts']);
        $cohorts = array();
        foreach ($result['cohorts'] as $cohort) {
            $cohorts[] = $cohort->name;
        }
        $this->assertTrue(in_array('Cohortsearch 1', $cohorts));

        // Check for parameter $includes = 'self'.
        $this->setUser($creator);
        $result = core_cohort_external::search_cohorts("Cohortsearch", $othercatcontext, 'self');
        $this->assertCount(1, $result['cohorts']);
        $this->assertEquals('Cohortsearch 3', $result['cohorts'][$cohort3->id]->name);

        // Check for parameter $includes = 'all'.
        $this->setUser($creator);
        $result = core_cohort_external::search_cohorts("Cohortsearch", $syscontext, 'all');
        $this->assertCount(4, $result['cohorts']);

        // A user in the course context with the system cohort:view capability. Check that all the system cohorts are returned.
        $this->setUser($courseuser);
        $result = core_cohort_external::search_cohorts("Cohortsearch", $coursecontext, 'all');
        $this->assertCount(2, $result['cohorts']);
        $this->assertEquals('Cohortsearch 1', $result['cohorts'][$cohort1->id]->name);

        // Detect invalid parameter $includes.
        $this->setUser($creator);
        try {
            $result = core_cohort_external::search_cohorts("Cohortsearch", $syscontext, 'invalid');
            $this->fail('Invalid parameter includes');
        } catch (\coding_exception $e) {
            // All good.
        }
    }
}

Youez - 2016 - github.com/yon3zu
LinuXploit