@@ -311,26 +311,42 @@ public function test_render_mc_question(): void {
311
311
$ this ->get_contains_num_parts_correct (1 )
312
312
);
313
313
$ this ->check_current_mark (0.7 );
314
+
315
+ // Restart with immediate feedback to check the radio box is disabled when showing the feedback.
316
+ $ this ->start_attempt_at_question ($ q , 'immediatefeedback ' , 1 );
317
+ $ this ->process_submission (['0_0 ' => '1 ' , '-submit ' => 1 ]);
318
+ $ this ->check_current_output (
319
+ $ this ->get_contains_radio_expectation (['id ' => $ this ->quba ->get_field_prefix ($ this ->slot ) . '0_0_0 ' ], false , false ),
320
+ $ this ->get_contains_radio_expectation (['id ' => $ this ->quba ->get_field_prefix ($ this ->slot ) . '0_0_1 ' ], false , true ),
321
+ $ this ->get_contains_radio_expectation (['id ' => $ this ->quba ->get_field_prefix ($ this ->slot ) . '0_0_2 ' ], false , false ),
322
+ $ this ->get_contains_radio_expectation (['id ' => $ this ->quba ->get_field_prefix ($ this ->slot ) . '0_0_3 ' ], false , false ),
323
+ );
314
324
}
315
325
316
326
public function test_render_mce_question (): void {
317
- // Create a single part multiple choice (radio ) question.
327
+ // Create a single part multiple choice (dropdown ) question.
318
328
$ q = $ this ->get_test_formulas_question ('testmce ' );
319
329
$ this ->start_attempt_at_question ($ q , 'immediatefeedback ' , 1 );
320
330
321
331
$ this ->render ();
322
- $ this -> check_output_contains_selectoptions (
323
- $ this -> get_contains_select_expectation ( ' 0_0 ' , [ ' Dog ' , ' Cat ' , ' Bird ' , ' Fish ' ])
324
- );
332
+ // Using check_current_output to make sure that the <select> is actually there. Using
333
+ // check_output_contains_selectoptions only makes sure that the options are there
334
+ // *among* existing <select>s; if no <select> is there, the options do not need to exist.
325
335
$ this ->check_current_output (
326
- $ this ->get_does_not_contain_specific_feedback_expectation ()
336
+ new \question_contains_tag_with_attribute ('select ' , 'name ' , $ this ->quba ->get_field_prefix ($ this ->slot ) . '0_0 ' ),
337
+ $ this ->get_does_not_contain_specific_feedback_expectation (),
338
+ new \question_contains_tag_with_contents ('label ' , 'Answer ' ),
339
+ new \question_contains_tag_with_attribute ('label ' , 'class ' , 'subq accesshide ' ),
340
+ );
341
+ $ this ->check_output_contains_selectoptions (
342
+ $ this ->get_contains_select_expectation ('0_0 ' , ['Dog ' , 'Cat ' , 'Bird ' , 'Fish ' ], 0 )
327
343
);
328
344
329
345
// Submit wrong answer.
330
346
$ this ->process_submission (['0_0 ' => '0 ' , '-submit ' => 1 ]);
331
347
$ this ->check_current_state (question_state::$ gradedwrong );
332
348
$ this ->check_output_contains_selectoptions (
333
- $ this ->get_contains_select_expectation ('0_0 ' , ['Dog ' , 'Cat ' , 'Bird ' , 'Fish ' ], 0 )
349
+ $ this ->get_contains_select_expectation ('0_0 ' , ['Dog ' , 'Cat ' , 'Bird ' , 'Fish ' ], 0 )
334
350
);
335
351
$ this ->check_current_mark (0 );
336
352
$ this ->check_output_contains_lang_string ('correctansweris ' , 'qtype_formulas ' , 'Cat ' );
@@ -340,12 +356,91 @@ public function test_render_mce_question(): void {
340
356
$ this ->process_submission (['0_0 ' => '1 ' , '-submit ' => 1 ]);
341
357
$ this ->check_current_state (question_state::$ gradedright );
342
358
$ this ->check_output_contains_selectoptions (
343
- $ this ->get_contains_select_expectation ('0_0 ' , ['Dog ' , 'Cat ' , 'Bird ' , 'Fish ' ], 1 )
359
+ $ this ->get_contains_select_expectation ('0_0 ' , ['Dog ' , 'Cat ' , 'Bird ' , 'Fish ' ], 1 , false )
344
360
);
345
361
$ this ->check_current_mark (1 );
346
362
$ this ->check_output_contains_lang_string ('correctansweris ' , 'qtype_formulas ' , 'Cat ' );
347
363
}
348
364
365
+ public function test_render_mc_question_with_missing_options (): void {
366
+ // Create a single part multiple choice (dropdown) question.
367
+ $ q = $ this ->get_test_formulas_question ('testmce ' );
368
+ $ q ->parts [0 ]->subqtext = '{_0:xxxx} ' ;
369
+ $ this ->start_attempt_at_question ($ q , 'immediatefeedback ' , 1 );
370
+
371
+ $ this ->render ();
372
+ // The options are not available, so a text box should be rendered instead.
373
+ $ this ->check_output_contains_text_input ('0_0 ' , '' , true );
374
+ $ this ->check_current_output (
375
+ new \question_contains_tag_with_contents ('label ' , 'Answer ' ),
376
+ );
377
+
378
+ // Create a single part multiple choice (radio) question.
379
+ $ q = $ this ->get_test_formulas_question ('testmc ' );
380
+ $ q ->parts [0 ]->subqtext = '{_0:xxxx} ' ;
381
+ $ this ->start_attempt_at_question ($ q , 'immediatefeedback ' , 1 );
382
+
383
+ $ this ->render ();
384
+ // The options are not available, so a text box should be rendered instead.
385
+ $ this ->check_output_contains_text_input ('0_0 ' , '' , true );
386
+ $ this ->check_current_output (
387
+ new \question_contains_tag_with_contents ('label ' , 'Answer ' ),
388
+ );
389
+ }
390
+
391
+ public function test_render_mce_accessibility_labels (): void {
392
+ // FIXME: also with no other answer field
393
+ // Create a single part multiple choice (dropdown) question.
394
+ $ q = $ this ->get_test_formulas_question ('testmce ' );
395
+ $ q ->parts [0 ]->numbox = 2 ;
396
+ $ q ->parts [0 ]->answer = '[1, 1] ' ;
397
+
398
+ $ this ->start_attempt_at_question ($ q , 'immediatefeedback ' , 1 );
399
+ $ this ->check_current_output (
400
+ new \question_contains_tag_with_contents ('label ' , 'Answer field 1 ' ),
401
+ new \question_contains_tag_with_contents ('label ' , 'Answer field 2 ' ),
402
+ );
403
+
404
+ // Create a two-part multiple choice (dropdown) question.
405
+ $ q ->numparts = 2 ;
406
+ $ q ->textfragments = [0 => $ q ->parts [0 ]->subqtext , 1 => '' , 2 => '' ];
407
+ $ q ->parts [] = qtype_formulas_test_helper::make_a_formulas_part ();
408
+ $ q ->parts [1 ]->numbox = 2 ;
409
+ $ q ->parts [1 ]->partindex = 1 ;
410
+ $ q ->parts [1 ]->answer = '[1, 1] ' ;
411
+
412
+ $ this ->start_attempt_at_question ($ q , 'immediatefeedback ' , 1 );
413
+ $ this ->check_current_output (
414
+ new \question_contains_tag_with_contents ('label ' , 'Answer field 1 for part 1 ' ),
415
+ new \question_contains_tag_with_contents ('label ' , 'Answer field 2 for part 1 ' ),
416
+ new \question_contains_tag_with_contents ('label ' , 'Answer field 1 for part 2 ' ),
417
+ new \question_contains_tag_with_contents ('label ' , 'Answer field 2 for part 2 ' ),
418
+ );
419
+ }
420
+
421
+ public function test_render_textbox_accessibility_labels (): void {
422
+ // Create a multi-part question with a combined and a separate unit field.
423
+ $ q = $ this ->get_test_formulas_question ('testmethodsinparts ' );
424
+ $ this ->start_attempt_at_question ($ q , 'immediatefeedback ' , 1 );
425
+ $ this ->check_current_output (
426
+ new \question_contains_tag_with_contents ('label ' , 'Answer and unit for part 1 ' ),
427
+ new \question_contains_tag_with_contents ('label ' , 'Answer for part 2 ' ),
428
+ new \question_contains_tag_with_contents ('label ' , 'Unit for part 2 ' ),
429
+ new \question_contains_tag_with_contents ('label ' , 'Answer for part 3 ' ),
430
+ new \question_contains_tag_with_contents ('label ' , 'Answer for part 4 ' ),
431
+ );
432
+
433
+ // Create a multi-part question with a combined and a separate unit field.
434
+ $ q = $ this ->get_test_formulas_question ('testtwoandtwo ' );
435
+ $ this ->start_attempt_at_question ($ q , 'immediatefeedback ' , 1 );
436
+ $ this ->check_current_output (
437
+ new \question_contains_tag_with_contents ('label ' , 'Answer field 1 for part 1 ' ),
438
+ new \question_contains_tag_with_contents ('label ' , 'Answer field 2 for part 1 ' ),
439
+ new \question_contains_tag_with_contents ('label ' , 'Answer field 1 for part 2 ' ),
440
+ new \question_contains_tag_with_contents ('label ' , 'Answer field 2 for part 2 ' ),
441
+ );
442
+ }
443
+
349
444
public function test_question_with_hint (): void {
350
445
// Create a single part multiple choice (radio) question.
351
446
$ q = $ this ->get_test_formulas_question ('testsinglenum ' );
0 commit comments