Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are 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   * Behat steps definitions for Language import tool
  19   *
  20   * @package   tool_langimport
  21   * @category  test
  22   * @copyright 2014 Dan Poltawski <dan@moodle.com>
  23   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  // NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
  27  
  28  require_once (__DIR__ . '/../../../../../lib/behat/behat_base.php');
  29  
  30  use Moodle\BehatExtension\Exception\SkippedException;
  31  
  32  /**
  33   * Steps definitions related with the Language import tool
  34   *
  35   * @package   tool_langimport
  36   * @category  test
  37   * @copyright 2014 Dan Poltawski <dan@moodle.com>
  38   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  39   */
  40  class behat_tool_langimport extends behat_base {
  41  
  42      /**
  43       * This step looks to see if the remote language import tests should be run (indicated by
  44       * setting TOOL_LANGIMPORT_REMOTE_TESTS in config.php.
  45       *
  46       * @Given /^remote langimport tests are enabled$/
  47       */
  48      public function remote_langimport_tests_are_enabled() {
  49          if (!defined('TOOL_LANGIMPORT_REMOTE_TESTS')) {
  50              throw new SkippedException('To run the remote langimport tests you must '.
  51                  'define TOOL_LANGIMPORT_REMOTE_TESTS in config.php');
  52          }
  53      }
  54  
  55      /**
  56       * Downloads a langpack and fakes it being outdated
  57       *
  58       * @param string $langcode The language code (e.g. en)
  59       * @Given /^outdated langpack \'([^\']*)\' is installed$/
  60       */
  61      public function outdated_langpack_is_installed($langcode) {
  62          global $CFG;
  63          require_once($CFG->libdir.'/componentlib.class.php');
  64  
  65          // Download the langpack.
  66          $dir = make_upload_directory('lang');
  67          $installer = new lang_installer($langcode);
  68          $result = $installer->run();
  69  
  70          if ($result[$langcode] !== lang_installer::RESULT_INSTALLED) {
  71              throw new coding_exception("Failed to install langpack '$langcode'");
  72          }
  73  
  74          $path = "$dir/$langcode/$langcode.md5";
  75  
  76          if (!file_exists($path)) {
  77              throw new coding_exception("Failed to find '$langcode' checksum");
  78          }
  79          file_put_contents($path, '000000');
  80      }
  81  }