mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 22:08:20 +01:00
Merge branch 'MDL-75380' of https://github.com/AnupamaSarjoshi/moodle
This commit is contained in:
commit
273e9a4447
@ -24,8 +24,6 @@
|
||||
|
||||
namespace profilefield_text\privacy;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
use \core_privacy\local\metadata\collection;
|
||||
use \core_privacy\local\request\contextlist;
|
||||
use \core_privacy\local\request\approved_contextlist;
|
||||
|
@ -70,4 +70,4 @@ class profile_define_text extends profile_define_base {
|
||||
$form->addElement('select', 'param5', get_string('profilefieldlinktarget', 'admin'), $targetoptions);
|
||||
$form->setType('param5', PARAM_RAW);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -35,10 +35,10 @@ class profile_field_text extends profile_field_base {
|
||||
*/
|
||||
public function display_data() {
|
||||
// Default formatting.
|
||||
$data = parent::display_data();
|
||||
$data = format_string($this->data);
|
||||
|
||||
// Are we creating a link?
|
||||
if (!empty($this->field->param4) and !empty($data)) {
|
||||
if (!empty($this->field->param4) && !empty($data)) {
|
||||
|
||||
// Define the target.
|
||||
if (! empty($this->field->param5)) {
|
||||
@ -48,7 +48,8 @@ class profile_field_text extends profile_field_base {
|
||||
}
|
||||
|
||||
// Create the link.
|
||||
$data = '<a href="'.str_replace('$$', urlencode($data), $this->field->param4).'" '.$target.'>'.htmlspecialchars($data).'</a>';
|
||||
$data = '<a href="'.str_replace('$$', urlencode($data),
|
||||
$this->field->param4).'" '.$target.'>'.htmlspecialchars($data).'</a>';
|
||||
}
|
||||
|
||||
return $data;
|
||||
@ -64,7 +65,8 @@ class profile_field_text extends profile_field_base {
|
||||
$fieldtype = ($this->field->param3 == 1 ? 'password' : 'text');
|
||||
|
||||
// Create the form field.
|
||||
$mform->addElement($fieldtype, $this->inputname, format_string($this->field->name), 'maxlength="'.$maxlength.'" size="'.$size.'" ');
|
||||
$mform->addElement($fieldtype, $this->inputname, format_string($this->field->name),
|
||||
'maxlength="'.$maxlength.'" size="'.$size.'" ');
|
||||
$mform->setType($this->inputname, PARAM_TEXT);
|
||||
}
|
||||
|
||||
|
73
user/profile/field/text/tests/field_class_test.php
Normal file
73
user/profile/field/text/tests/field_class_test.php
Normal file
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
namespace profilefield_text;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
|
||||
require_once($CFG->dirroot.'/user/profile/lib.php');
|
||||
require_once($CFG->dirroot.'/user/profile/field/text/field.class.php');
|
||||
|
||||
use profile_field_text;
|
||||
|
||||
/**
|
||||
* Unit tests for the profilefield_text.
|
||||
*
|
||||
* @package profilefield_text
|
||||
* @copyright 2022 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @covers \profilefield_text\profile_field_text
|
||||
*/
|
||||
class field_class_test extends \advanced_testcase {
|
||||
/**
|
||||
* Test that the profile text data is formatted and required filters applied
|
||||
*
|
||||
* @covers \profile_field_text::display_data
|
||||
* @dataProvider filter_profile_field_text_provider
|
||||
* @param string $input
|
||||
* @param string $expected
|
||||
*/
|
||||
public function test_filter_display_data(string $input, string $expected): void {
|
||||
$this->resetAfterTest();
|
||||
$field = new profile_field_text();
|
||||
$field->data = $input;
|
||||
|
||||
filter_set_global_state('multilang', TEXTFILTER_ON);
|
||||
filter_set_global_state('emoticon', TEXTFILTER_ON);
|
||||
filter_set_applies_to_strings('multilang', true);
|
||||
|
||||
$actual = $field->display_data();
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for {@see test_filter_display_data}
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function filter_profile_field_text_provider(): array {
|
||||
return [
|
||||
'simple_string' => ['Simple string', 'Simple string'],
|
||||
'format_string' => ['HTML & is escaped', 'HTML & is escaped'],
|
||||
'multilang_filter' =>
|
||||
['<span class="multilang" lang="en">English</span><span class="multilang" lang="fr">French</span>', 'English'],
|
||||
'emoticons_filter' => ['No emoticons filter :-(', 'No emoticons filter :-(']
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -23,8 +23,6 @@
|
||||
*/
|
||||
namespace profilefield_text\privacy;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
use core_privacy\tests\provider_testcase;
|
||||
use profilefield_text\privacy\provider;
|
||||
use core_privacy\local\request\approved_userlist;
|
||||
|
@ -26,4 +26,4 @@ defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->version = 2022041900; // The current plugin version (Date: YYYYMMDDXX).
|
||||
$plugin->requires = 2022041200; // Requires this Moodle version.
|
||||
$plugin->component = 'profilefield_text'; // Full name of the plugin (used for diagnostics)
|
||||
$plugin->component = 'profilefield_text'; // Full name of the plugin (used for diagnostics).
|
||||
|
Loading…
x
Reference in New Issue
Block a user