Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 310 and 400] [Versions 39 and 400]

   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  namespace tool_usertours;
  18  
  19  /**
  20   * Tests for theme filter.
  21   *
  22   * @package    tool_usertours
  23   * @copyright  2016 Andrew Nicols <andrew@nicols.co.uk>
  24   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  25   */
  26  class theme_filter_test extends \advanced_testcase {
  27  
  28      /**
  29       * Data Provider for filter_matches function.
  30       *
  31       * @return array
  32       */
  33      public function filter_matches_provider() {
  34          return [
  35              'No config set; Matches' => [
  36                  null,
  37                  'boost',
  38                  true,
  39              ],
  40              'Empty config set; Matches' => [
  41                  [],
  42                  'boost',
  43                  true,
  44              ],
  45              'Single matching value set; Matches' => [
  46                  ['boost'],
  47                  'boost',
  48                  true,
  49              ],
  50              'Multiple values set including matching; Matches' => [
  51                  ['boost', 'classic'],
  52                  'boost',
  53                  true,
  54              ],
  55              'Single value set; No match' => [
  56                  ['classic'],
  57                  'boost',
  58                  false,
  59              ],
  60              'Multiple values set; No match' => [
  61                  ['classic', 'artificial'],
  62                  'boost',
  63                  false,
  64              ],
  65          ];
  66      }
  67  
  68      /**
  69       * Test the filter_matches function.
  70       *
  71       * @dataProvider    filter_matches_provider
  72       * @param   array       $filtervalues   The filter values
  73       * @param   string      $currenttheme   The name of the current theme
  74       * @param   boolean     $expected       Whether the tour is expected to match
  75       */
  76      public function test_filter_matches($filtervalues, $currenttheme, $expected) {
  77          global $PAGE;
  78  
  79          $filtername = \tool_usertours\local\filter\theme::class;
  80  
  81          // Note: No need to persist this tour.
  82          $tour = new \tool_usertours\tour();
  83          if ($filtervalues !== null) {
  84              $tour->set_filter_values('theme', $filtervalues);
  85          }
  86  
  87          $PAGE->theme->name = $currenttheme;
  88  
  89          // Note: The theme filter does not use the context.
  90          $this->assertEquals($expected, $filtername::filter_matches($tour, \context_system::instance()));
  91      }
  92  }