diff --git a/user/profile/field/text/classes/privacy/provider.php b/user/profile/field/text/classes/privacy/provider.php index ae2b0bfaa60..778a2142f54 100644 --- a/user/profile/field/text/classes/privacy/provider.php +++ b/user/profile/field/text/classes/privacy/provider.php @@ -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; diff --git a/user/profile/field/text/define.class.php b/user/profile/field/text/define.class.php index 3e861955573..e578e8cdad7 100644 --- a/user/profile/field/text/define.class.php +++ b/user/profile/field/text/define.class.php @@ -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); } -} \ No newline at end of file +} diff --git a/user/profile/field/text/field.class.php b/user/profile/field/text/field.class.php index 3ac0fc20839..6841cdce3ce 100644 --- a/user/profile/field/text/field.class.php +++ b/user/profile/field/text/field.class.php @@ -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 = ''.htmlspecialchars($data).''; + $data = ''.htmlspecialchars($data).''; } 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); } diff --git a/user/profile/field/text/tests/field_class_test.php b/user/profile/field/text/tests/field_class_test.php new file mode 100644 index 00000000000..bdde7f88d65 --- /dev/null +++ b/user/profile/field/text/tests/field_class_test.php @@ -0,0 +1,73 @@ +. + +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' => + ['EnglishFrench', 'English'], + 'emoticons_filter' => ['No emoticons filter :-(', 'No emoticons filter :-('] + ]; + } +} + diff --git a/user/profile/field/text/tests/privacy/provider_test.php b/user/profile/field/text/tests/privacy/provider_test.php index 8b85f37cdc3..d32ec1711eb 100644 --- a/user/profile/field/text/tests/privacy/provider_test.php +++ b/user/profile/field/text/tests/privacy/provider_test.php @@ -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; diff --git a/user/profile/field/text/version.php b/user/profile/field/text/version.php index 4a26b5d8a02..34f4ce250b2 100644 --- a/user/profile/field/text/version.php +++ b/user/profile/field/text/version.php @@ -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).