Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.
   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   * Unit test for mod_survey searching.
  19   *
  20   * This is needed because the activity.php class overrides default behaviour.
  21   *
  22   * @package mod_survey
  23   * @category test
  24   * @copyright 2017 The Open University
  25   * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  26   */
  27  
  28  namespace mod_survey\search;
  29  
  30  /**
  31   * Unit test for mod_survey searching.
  32   *
  33   * This is needed because the activity.php class overrides default behaviour.
  34   *
  35   * @package mod_survey
  36   * @category test
  37   * @copyright 2017 The Open University
  38   * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  39   */
  40  class search_test extends \advanced_testcase {
  41  
  42      /**
  43       * Test survey_view
  44       * @return void
  45       */
  46      public function test_survey_indexing() {
  47          global $CFG;
  48  
  49          $this->resetAfterTest();
  50  
  51          require_once($CFG->dirroot . '/search/tests/fixtures/testable_core_search.php');
  52          \testable_core_search::instance();
  53          $area = \core_search\manager::get_search_area('mod_survey-activity');
  54  
  55          // Setup test data.
  56          $generator = $this->getDataGenerator();
  57          $course = $generator->create_course();
  58          $survey1 = $generator->create_module('survey', ['course' => $course->id]);
  59          $survey2 = $generator->create_module('survey', ['course' => $course->id]);
  60  
  61          // Get all surveys for indexing - note that there are special entries in the table with
  62          // course zero which should not be returned.
  63          $rs = $area->get_document_recordset();
  64          $this->assertEquals(2, iterator_count($rs));
  65          $rs->close();
  66  
  67          // Test specific context and course context.
  68          $rs = $area->get_document_recordset(0, \context_module::instance($survey1->cmid));
  69          $this->assertEquals(1, iterator_count($rs));
  70          $rs->close();
  71          $rs = $area->get_document_recordset(0, \context_course::instance($course->id));
  72          $this->assertEquals(2, iterator_count($rs));
  73          $rs->close();
  74      }
  75  }