@@ -76,6 +76,19 @@ public function __construct($questiontext, $specificfeedback, $quizmoduleid) {
7676 parent ::__construct (new \moodle_url ('/ ' ), $ fakequestion , $ category , $ contexts );
7777 }
7878
79+ /**
80+ * Public override of parent function to allow access.
81+ * @param mixed $field
82+ * @param mixed $text
83+ * @param mixed $format
84+ * @param mixed $itemid
85+ * @param mixed $filearea
86+ * @return array
87+ */
88+ public function prepare_text_field ($ field , $ text , $ format , $ itemid , $ filearea = '' ) {
89+ return parent ::prepare_text_field ($ field , $ text , $ format , $ itemid , $ filearea );
90+ }
91+
7992}
8093
8194/**
@@ -101,7 +114,7 @@ protected function get_form($questiontext, $specificfeedback) {
101114 return new editform_test_class ($ questiontext , $ specificfeedback , $ quizmoduleid );
102115 }
103116
104- public function test_get_input_names_from_question_text_default (): void {
117+ public function x_test_get_input_names_from_question_text_default (): void {
105118
106119 $ form = $ this ->get_form (\qtype_stack_edit_form::DEFAULT_QUESTION_TEXT ,
107120 \qtype_stack_edit_form::DEFAULT_SPECIFIC_FEEDBACK );
@@ -111,7 +124,7 @@ public function test_get_input_names_from_question_text_default(): void {
111124 $ qtype ->get_input_names_from_question_text (\qtype_stack_edit_form::DEFAULT_QUESTION_TEXT ));
112125 }
113126
114- public function test_get_prt_names_from_question_default (): void {
127+ public function x_test_get_prt_names_from_question_default (): void {
115128
116129 $ form = $ this ->get_form (\qtype_stack_edit_form::DEFAULT_QUESTION_TEXT ,
117130 \qtype_stack_edit_form::DEFAULT_SPECIFIC_FEEDBACK );
@@ -121,4 +134,43 @@ public function test_get_prt_names_from_question_default(): void {
121134 $ qtype ->get_prt_names_from_question (\qtype_stack_edit_form::DEFAULT_QUESTION_TEXT ,
122135 \qtype_stack_edit_form::DEFAULT_SPECIFIC_FEEDBACK ));
123136 }
137+
138+ public function test_text_format (): void {
139+ $ form = $ this ->get_form (\qtype_stack_edit_form::DEFAULT_QUESTION_TEXT ,
140+ \qtype_stack_edit_form::DEFAULT_SPECIFIC_FEEDBACK );
141+ // No script. Leave format alone.
142+ $ data = $ form ->prepare_text_field ('questiontext ' , 'hello ' , FORMAT_HTML , 1 );
143+ $ this ->assertEquals (FORMAT_HTML , $ data ['format ' ]);
144+ // Scripts of different types. Set input to plain.
145+ $ data = $ form ->prepare_text_field ('questiontext ' , 'hello<script>there</script> ' , FORMAT_HTML , 1 );
146+ $ this ->assertEquals (FORMAT_PLAIN , $ data ['format ' ]);
147+ $ data = $ form ->prepare_text_field ('questiontext ' , 'hello[[javascript]]there[[/javascript]] ' , FORMAT_HTML , 1 );
148+ $ this ->assertEquals (FORMAT_PLAIN , $ data ['format ' ]);
149+ $ data = $ form ->prepare_text_field ('questiontext ' , 'hello[[geogebra]]there[[/geogebra]] ' , FORMAT_HTML , 1 );
150+ $ this ->assertEquals (FORMAT_PLAIN , $ data ['format ' ]);
151+ $ data = $ form ->prepare_text_field ('questiontext ' , 'hello<jsxgraph>there</jsxgraph> ' , FORMAT_HTML , 1 );
152+ $ this ->assertEquals (FORMAT_PLAIN , $ data ['format ' ]);
153+ $ data = $ form ->prepare_text_field ('questiontext ' , 'hello[[jsxgraph]]there[[/jsxgraph]] ' , FORMAT_HTML , 1 );
154+ $ this ->assertEquals (FORMAT_PLAIN , $ data ['format ' ]);
155+ $ data = $ form ->prepare_text_field ('questiontext ' , 'hello<geogebra>there</geogebra> ' , FORMAT_HTML , 1 );
156+ $ this ->assertEquals (FORMAT_PLAIN , $ data ['format ' ]);
157+ $ data = $ form ->prepare_text_field ('questiontext ' , 'hello[[script]]there[[/script]] ' , FORMAT_HTML , 1 );
158+ $ this ->assertEquals (FORMAT_PLAIN , $ data ['format ' ]);
159+ $ data = $ form ->prepare_text_field ('questiontext ' , 'hello<=there ' , FORMAT_HTML , 1 );
160+ $ this ->assertEquals (FORMAT_PLAIN , $ data ['format ' ]);
161+ $ data = $ form ->prepare_text_field ('questiontext ' , 'hello=>there ' , FORMAT_HTML , 1 );
162+ $ this ->assertEquals (FORMAT_PLAIN , $ data ['format ' ]);
163+ // No script. Leave format alone.
164+ $ data = $ form ->prepare_text_field ('questiontext ' , '=hello> ' , FORMAT_HTML , 1 );
165+ $ this ->assertEquals (FORMAT_HTML , $ data ['format ' ]);
166+ $ data = $ form ->prepare_text_field ('questiontext ' , 'script ' , FORMAT_HTML , 1 );
167+ $ this ->assertEquals (FORMAT_HTML , $ data ['format ' ]);
168+ // Format already set to something other than HTML. Leave alone.
169+ $ data = $ form ->prepare_text_field ('questiontext ' , 'hello<=there ' , FORMAT_MARKDOWN , 1 );
170+ $ this ->assertEquals (FORMAT_MARKDOWN , $ data ['format ' ]);
171+ // User editor preference set. Leave format alone.
172+ set_user_preference ('htmleditor ' , 'bob ' , null );
173+ $ data = $ form ->prepare_text_field ('questiontext ' , 'hello<=there ' , FORMAT_HTML , 1 );
174+ $ this ->assertEquals (FORMAT_HTML , $ data ['format ' ]);
175+ }
124176}
0 commit comments