Exemple #1
0
 /**
  * Test that notify_step_change clears the cache.
  */
 public function test_notify_step_change()
 {
     global $DB;
     $this->resetAfterTest();
     $tour = $this->helper_create_tour();
     $this->helper_create_step((object) ['tourid' => $tour->get_id()]);
     // Only one read for the first call.
     $startreads = $DB->perf_get_reads();
     $matches = \tool_usertours\cache::get_stepdata($tour->get_id());
     $this->assertEquals(1, $DB->perf_get_reads() - $startreads);
     // No subsequent reads for any further calls.
     $matches = \tool_usertours\cache::get_stepdata($tour->get_id());
     $this->assertEquals(1, $DB->perf_get_reads() - $startreads);
     // Reset.
     \tool_usertours\cache::notify_step_change($tour->get_id());
     // An additional DB read now.
     $startreads = $DB->perf_get_reads();
     $matches = \tool_usertours\cache::get_stepdata($tour->get_id());
     $this->assertEquals(1, $DB->perf_get_reads() - $startreads);
 }
 /**
  * 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;
 }