/** * Tests for the get_matching_tourdata function. * * @dataProvider get_matching_tourdata_provider * @param array $tourconfigs The configuration for the tours to create * @param string $targetmatch The match to be tested * @param array $expected An array containing the ordered names of the expected tours */ public function test_get_matching_tourdata($tourconfigs, $targetmatch, $expected) { $this->resetAfterTest(); foreach ($tourconfigs as $tourconfig) { $tour = $this->helper_create_tour($tourconfig); $this->helper_create_step((object) ['tourid' => $tour->get_id()]); } $matches = \tool_usertours\cache::get_matching_tourdata((new moodle_url($targetmatch))->out_as_local_url()); $this->assertCount(count($expected), $matches); for ($i = 0; $i < count($matches); $i++) { $match = array_shift($matches); $this->assertEquals($expected[$i], $match->name); } }
/** * Get the first tour matching the specified URL. * * @param moodle_url $pageurl The URL to match. * @return tour */ public static function get_matching_tours(\moodle_url $pageurl) { global $PAGE; $tours = cache::get_matching_tourdata($pageurl); foreach ($tours as $record) { $tour = tour::load_from_record($record); if ($tour->is_enabled() && $tour->matches_all_filters($PAGE->context)) { return $tour; } } return null; }