Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.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   * Tests for helper.
  19   *
  20   * @package    tool_usertours
  21   * @copyright  2022 Huong Nguyen <huongnv13@gmail.com>
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  namespace tool_usertours;
  26  
  27  use advanced_testcase;
  28  
  29  defined('MOODLE_INTERNAL') || die();
  30  
  31  /**
  32   * Tests for helper.
  33   *
  34   * @package    tool_usertours
  35   * @copyright  2022 Huong Nguyen <huongnv13@gmail.com>
  36   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  37   */
  38  class helper_test extends advanced_testcase {
  39  
  40      /**
  41       * Data Provider for get_string_from_input.
  42       *
  43       * @return array
  44       */
  45      public function get_string_from_input_provider(): array {
  46          return [
  47              'Text'  => [
  48                  'example',
  49                  'example',
  50              ],
  51              'Text which looks like a langstring' => [
  52                  'example,fakecomponent',
  53                  'example,fakecomponent',
  54              ],
  55              'Text which is a langstring' => [
  56                  'administration,core',
  57                  'Administration',
  58              ],
  59              'Text which is a langstring but uses "moodle" instead of "core"' => [
  60                  'administration,moodle',
  61                  'Administration',
  62              ],
  63              'Text which is a langstring, but with extra whitespace' => [
  64                  '  administration,moodle  ',
  65                  'Administration',
  66              ],
  67              'Looks like a langstring, but has incorrect space around comma' => [
  68                  'administration , moodle',
  69                  'administration , moodle',
  70              ],
  71          ];
  72      }
  73  
  74      /**
  75       * Ensure that the get_string_from_input function returns langstring strings correctly.
  76       *
  77       * @dataProvider get_string_from_input_provider
  78       * @param string $string The string to test
  79       * @param string $expected The expected result
  80       */
  81      public function test_get_string_from_input($string, $expected) {
  82          $this->assertEquals($expected, helper::get_string_from_input($string));
  83      }
  84  }