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   * Provides \antivirus_testable class.
  19   *
  20   * @package     core
  21   * @subpackage  fixtures
  22   * @category    test
  23   * @copyright   2016 Ruslan Kabalin, Lancaster University.
  24   * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  25   */
  26  
  27  namespace antivirus_testable;
  28  
  29  defined('MOODLE_INTERNAL') || die();
  30  
  31  /**
  32   * Testable antivirus plugin.
  33   *
  34   * @copyright   2016 Ruslan Kabalin, Lancaster University.
  35   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  36   */
  37  class scanner extends \core\antivirus\scanner {
  38      /**
  39       * Are the necessary antivirus settings configured?
  40       *
  41       * @return bool True if all necessary config settings been entered
  42       */
  43      public function is_configured() {
  44          return true;
  45      }
  46  
  47      /**
  48       * Scan file.
  49       *
  50       * Provides fake responses for testing \core\antivirus\manager.
  51       *
  52       * @param string $file Full path to the file.
  53       * @param string $filename For mocking purposes, filename defines expected response.
  54       * @return int Scanning result constant.
  55       */
  56      public function scan_file($file, $filename) {
  57          switch ($filename) {
  58              case 'OK':
  59                  return self::SCAN_RESULT_OK;
  60              case 'FOUND':
  61                  return self::SCAN_RESULT_FOUND;
  62              case 'ERROR':
  63                  return self::SCAN_RESULT_ERROR;
  64              default:
  65                  debugging('$filename should be either OK, FOUND or ERROR.');
  66                  break;
  67          }
  68      }
  69  
  70      /**
  71       * Scan data.
  72       *
  73       * Provides fake responses for testing \core\antivirus\manager.
  74       *
  75       * @param string $data The variable containing the data to scan.
  76       * @return int Scanning result constant.
  77       */
  78      public function scan_data($data) {
  79          switch ($data) {
  80              case 'OK':
  81                  return self::SCAN_RESULT_OK;
  82              case 'FOUND':
  83                  return self::SCAN_RESULT_FOUND;
  84              case 'ERROR':
  85                  return self::SCAN_RESULT_ERROR;
  86              default:
  87                  debugging('$data should be either OK, FOUND or ERROR.');
  88                  break;
  89          }
  90      }
  91  }