[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/search/tests/ -> engine_test.php (source)

   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   * Search engine base unit tests.
  19   *
  20   * @package     core_search
  21   * @category    phpunit
  22   * @copyright   2015 David Monllao {@link http://www.davidmonllao.com}
  23   * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  require_once (__DIR__ . '/fixtures/testable_core_search.php');
  29  
  30  /**
  31   * Search engine base unit tests.
  32   *
  33   * @package     core_search
  34   * @category    phpunit
  35   * @copyright   2015 David Monllao {@link http://www.davidmonllao.com}
  36   * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  37   */
  38  class search_engine_testcase extends advanced_testcase {
  39  
  40      public function setUp() {
  41          $this->resetAfterTest();
  42          set_config('enableglobalsearch', true);
  43  
  44          // Set \core_search::instance to the mock_search_engine as we don't require the search engine to be working to test this.
  45          $search = testable_core_search::instance();
  46      }
  47  
  48      /**
  49       * Engine basic info.
  50       *
  51       * @return void
  52       */
  53      public function test_engine_info() {
  54          $engine = new \mock_search\engine();
  55  
  56          $this->assertEquals('mock_search', $engine->get_plugin_name());
  57  
  58          // Resolves to the default one.
  59          $this->assertEquals('\\core_search\\document', $engine->get_document_classname());
  60      }
  61  
  62      /**
  63       * Test engine caches.
  64       *
  65       * @return void
  66       */
  67      public function test_engine_caches() {
  68          global $DB;
  69  
  70          $engine = new \mock_search\engine();
  71  
  72          $course1 = self::getDataGenerator()->create_course();
  73  
  74          $this->assertEquals($course1->id, $engine->get_course($course1->id)->id);
  75          $dbreads = $DB->perf_get_reads();
  76          $engine->get_course($course1->id);
  77          $this->assertEquals($dbreads, $DB->perf_get_reads());
  78          $fakearea1 = \core_search\manager::generate_areaid('plugintype_unexisting', 'fakearea');
  79          $fakearea2 = \core_search\manager::generate_areaid('mod_unexisting', 'morefake');
  80          $this->assertFalse($engine->get_search_area($fakearea1));
  81          $this->assertFalse($engine->get_search_area($fakearea2));
  82          $this->assertFalse($engine->get_search_area($fakearea2));
  83  
  84          $areaid = \core_search\manager::generate_areaid('mod_forum', 'post');
  85          $this->assertInstanceOf('\\mod_forum\\search\\post', $engine->get_search_area($areaid));
  86          $dbreads = $DB->perf_get_reads();
  87          $this->assertInstanceOf('\\mod_forum\\search\\post', $engine->get_search_area($areaid));
  88          $this->assertEquals($dbreads, $DB->perf_get_reads());
  89  
  90      }
  91  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1