Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 400 and 401] [Versions 400 and 402] [Versions 400 and 403]

   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  namespace profilefield_text;
  18  
  19  defined('MOODLE_INTERNAL') || die();
  20  
  21  global $CFG;
  22  
  23  require_once($CFG->dirroot.'/user/profile/lib.php');
  24  require_once($CFG->dirroot.'/user/profile/field/text/field.class.php');
  25  
  26  use profile_field_text;
  27  
  28  /**
  29   * Unit tests for the profilefield_text.
  30   *
  31   * @package    profilefield_text
  32   * @copyright  2022 The Open University
  33   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  34   * @covers     \profilefield_text\profile_field_text
  35   */
  36  class field_class_test extends \advanced_testcase {
  37      /**
  38       * Test that the profile text data is formatted and required filters applied
  39       *
  40       * @covers \profile_field_text::display_data
  41       * @dataProvider filter_profile_field_text_provider
  42       * @param string $input
  43       * @param string $expected
  44       */
  45      public function test_filter_display_data(string $input, string $expected): void {
  46          $this->resetAfterTest();
  47          $field = new profile_field_text();
  48          $field->data = $input;
  49  
  50          filter_set_global_state('multilang', TEXTFILTER_ON);
  51          filter_set_global_state('emoticon', TEXTFILTER_ON);
  52          filter_set_applies_to_strings('multilang', true);
  53  
  54          $actual = $field->display_data();
  55          $this->assertEquals($expected, $actual);
  56      }
  57  
  58      /**
  59       * Data provider for {@see test_filter_display_data}
  60       *
  61       * @return string[]
  62       */
  63      public function filter_profile_field_text_provider(): array {
  64          return [
  65                  'simple_string' => ['Simple string', 'Simple string'],
  66                  'format_string' => ['HTML & is escaped', 'HTML &amp; is escaped'],
  67                  'multilang_filter' =>
  68                      ['<span class="multilang" lang="en">English</span><span class="multilang" lang="fr">French</span>', 'English'],
  69                  'emoticons_filter' => ['No emoticons filter :-(', 'No emoticons filter :-(']
  70          ];
  71      }
  72  }