Differences Between: [Versions 400 and 401] [Versions 400 and 402] [Versions 400 and 403]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Behat custom steps and configuration for mod_bigbluebuttonbn. 19 * 20 * @package mod_bigbluebuttonbn 21 * @category test 22 * @copyright 2021 Andrew Lyons <andrew@nicols.co.uk> 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 require_once (__DIR__ . '/../../../../lib/behat/behat_base.php'); 27 28 use Behat\Behat\Hook\Scope\BeforeScenarioScope; 29 use Behat\Gherkin\Node\TableNode; 30 use Moodle\BehatExtension\Exception\SkippedException; 31 32 /** 33 * Behat custom steps and configuration for mod_bigbluebuttonbn. 34 * 35 * @package mod_bigbluebuttonbn 36 * @copyright 2021 Andrew Lyons <andrew@nicols.co.uk> 37 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 38 */ 39 class behat_mod_bigbluebuttonbn extends behat_base { 40 41 /** 42 * BeforeScenario hook to reset the remote testpoint. 43 * 44 * @BeforeScenario @mod_bigbluebuttonbn 45 * 46 * @param BeforeScenarioScope $scope 47 */ 48 public function before_scenario(BeforeScenarioScope $scope) { 49 if (defined('TEST_MOD_BIGBLUEBUTTONBN_MOCK_SERVER')) { 50 $this->send_mock_request('backoffice/reset'); 51 } 52 } 53 54 /** 55 * Accept dpa and enable bigbluebuttonbn plugin. 56 * 57 * @When /^I accept dpa and enable bigbluebuttonbn plugin$/ 58 */ 59 public function i_accept_dpa_and_enable_bigbluebuttonbn_plugin(): void { 60 set_config('bigbluebuttonbn_default_dpa_accepted', true); 61 $this->execute('behat_general::i_enable_plugin', ['bigbluebuttonbn', 'mod']); 62 } 63 64 /** 65 * Check that the TEST_MOD_BIGBLUEBUTTONBN_MOCK_SERVER is defined, so we can connect to the mock server. 66 * 67 * @Given /^a BigBlueButton mock server is configured$/ 68 */ 69 public function mock_is_configured(): void { 70 if (!defined('TEST_MOD_BIGBLUEBUTTONBN_MOCK_SERVER')) { 71 throw new SkippedException( 72 'The TEST_MOD_BIGBLUEBUTTONBN_MOCK_SERVER constant must be defined to run mod_bigbluebuttonbn tests' 73 ); 74 } 75 76 set_config('bigbluebuttonbn_server_url', TEST_MOD_BIGBLUEBUTTONBN_MOCK_SERVER); 77 } 78 79 /** 80 * Return the list of exact named selectors. 81 * 82 * @return array 83 */ 84 public static function get_exact_named_selectors(): array { 85 return [ 86 new behat_component_named_selector('Meeting field', [ 87 <<<XPATH 88 .//*[@data-identifier=%locator%] 89 XPATH 90 ], false), 91 ]; 92 } 93 94 /** 95 * Retrieve the mock server URL from the TEST_MOD_BIGBLUEBUTTONBN_MOCK_SERVER definition 96 * 97 * @param string $endpoint 98 * @param array $params 99 * @return moodle_url 100 */ 101 public static function get_mocked_server_url(string $endpoint = '', array $params = []): moodle_url { 102 return new moodle_url(TEST_MOD_BIGBLUEBUTTONBN_MOCK_SERVER . '/' . $endpoint, $params); 103 } 104 105 /** 106 * Send a query to the mock server 107 * 108 * @param string $endpoint 109 * @param array $params 110 */ 111 protected function send_mock_request(string $endpoint, array $params = []): void { 112 $url = $this->get_mocked_server_url($endpoint, $params); 113 114 $curl = new \curl(); 115 $curl->get($url->out_omit_querystring(), $url->params()); 116 } 117 118 /** 119 * Convert page names to URLs for steps like 'When I am on the "[page name]" page'. 120 * 121 * Recognised page names are: 122 * | None so far! | | 123 * 124 * @param string $page name of the page, with the component name removed e.g. 'Admin notification'. 125 * @return moodle_url the corresponding URL. 126 * @throws Exception with a meaningful error message if the specified page cannot be found. 127 */ 128 protected function resolve_page_url(string $page): moodle_url { 129 throw new Exception("Unrecognised page type '{$page}'."); 130 } 131 132 /** 133 * Convert page names to URLs for steps like 'When I am on the "[identifier]" "[page type]" page'. 134 * 135 * Recognised page names are: 136 * | pagetype | name meaning | description | 137 * | Index | BBB Course Index | The bbb index page (index.php) | 138 * 139 * @param string $type identifies which type of page this is, e.g. 'Indez'. 140 * @param string $identifier identifies the particular page, e.g. 'Mathematics 101'. 141 * @return moodle_url the corresponding URL. 142 * @throws Exception with a meaningful error message if the specified page cannot be found. 143 */ 144 protected function resolve_page_instance_url(string $type, string $identifier): moodle_url { 145 switch ($type) { 146 case 'Index': 147 $this->get_course_id($identifier); 148 return new moodle_url('/mod/bigbluebuttonbn/index.php', [ 149 'id' => $this->get_course_id($identifier), 150 ]); 151 152 default: 153 throw new Exception("Unrecognised page type '{$type}'."); 154 } 155 } 156 157 /** 158 * Get course id from its identifier (shortname or fullname or idnumber) 159 * 160 * @param string $identifier 161 * @return int 162 */ 163 protected function get_course_id(string $identifier): int { 164 global $DB; 165 166 return $DB->get_field_select( 167 'course', 168 'id', 169 "shortname = :shortname OR fullname = :fullname OR idnumber = :idnumber", 170 [ 171 'shortname' => $identifier, 172 'fullname' => $identifier, 173 'idnumber' => $identifier, 174 ], 175 MUST_EXIST 176 ); 177 } 178 179 /** 180 * Trigger a recording ready notification on BBB side 181 * 182 * @Given the BigBlueButtonBN server has sent recording ready notifications 183 */ 184 public function trigger_recording_ready_notification(): void { 185 $this->send_mock_request('backoffice/sendRecordingReadyNotifications', [ 186 'secret' => \mod_bigbluebuttonbn\local\config::DEFAULT_SHARED_SECRET, 187 ] 188 ); 189 } 190 191 /** 192 * Trigger a meeting event on BBB side 193 * 194 * @Given /^the BigBlueButtonBN server has received the following events from user "(?P<element_string>(?:[^"]|\\")*)":$/ 195 * @param string $username 196 * @param TableNode $data 197 */ 198 public function trigger_meeting_event(string $username, TableNode $data): void { 199 global $DB; 200 $user = core_user::get_user_by_username($username); 201 $rows = $data->getHash(); 202 foreach ($rows as $elementdata) { 203 $instanceid = $DB->get_field('bigbluebuttonbn', 'id', [ 204 'name' => $elementdata['instancename'], 205 ]); 206 $instance = \mod_bigbluebuttonbn\instance::get_from_instanceid($instanceid); 207 $this->send_mock_request('backoffice/addMeetingEvent', [ 208 'secret' => \mod_bigbluebuttonbn\local\config::DEFAULT_SHARED_SECRET, 209 'meetingID' => $instance->get_meeting_id(), 210 'attendeeID' => $user->id, 211 'attendeeName' => fullname($user), 212 'eventType' => $elementdata['eventtype'], 213 'eventData' => $elementdata['eventdata'] ?? '', 214 ] 215 ); 216 } 217 } 218 /** 219 * Send all events received for this meeting back to moodle 220 * 221 * @Given /^the BigBlueButtonBN activity "(?P<element_string>(?:[^"]|\\")*)" has sent recording all its events$/ 222 * @param string $instancename 223 */ 224 public function trigger_all_events(string $instancename): void { 225 global $DB; 226 227 $instanceid = $DB->get_field('bigbluebuttonbn', 'id', [ 228 'name' => $instancename, 229 ]); 230 $instance = \mod_bigbluebuttonbn\instance::get_from_instanceid($instanceid); 231 $this->send_mock_request('backoffice/sendAllEvents', [ 232 'meetingID' => $instance->get_meeting_id(), 233 'sendQuery' => true 234 ] 235 ); 236 } 237 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body