See Release Notes
Long Term Support Release
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 core_question; 18 19 /** 20 * Unit tests for {@see \question_display_options}. 21 * 22 * @coversDefaultClass \question_display_options 23 * @package core_question 24 * @category test 25 * @copyright 2023 Jun Pataleta 26 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 27 */ 28 class question_display_options_test extends \advanced_testcase { 29 30 /** 31 * Data provider for {@see self::test_has_question_identifier()} 32 * 33 * @return array[] 34 */ 35 public function has_question_identifier_provider(): array { 36 return [ 37 'Empty string' => ['', false], 38 'Empty space' => [' ', false], 39 'Null' => [null, false], 40 'Non-empty string' => ["Hello!", true], 41 ]; 42 } 43 44 /** 45 * Tests for {@see \question_display_options::has_question_identifier} 46 * 47 * @covers ::has_question_identifier 48 * @dataProvider has_question_identifier_provider 49 * @param string|null $identifier The question identifier 50 * @param bool $expected The expected return value 51 * @return void 52 */ 53 public function test_has_question_identifier(?string $identifier, bool $expected): void { 54 $options = new \question_display_options(); 55 $options->questionidentifier = $identifier; 56 $this->assertEquals($expected, $options->has_question_identifier()); 57 } 58 59 /** 60 * Data provider for {@see self::test_add_question_identifier_to_label() 61 * 62 * @return array[] 63 */ 64 public function add_question_identifier_to_label_provider(): array { 65 return [ 66 'Empty string identifier' => ['Hello', '', false, false, "Hello"], 67 'Null identifier' => ['Hello', null, false, false, "Hello"], 68 'With identifier' => ['Hello', 'World', false, false, "Hello World"], 69 'With identifier, sr-only' => ['Hello', 'World', true, false, 'Hello <span class="sr-only">World</span>'], 70 'With identifier, prepend' => ['Hello', 'World', false, true, "World Hello"], 71 ]; 72 } 73 74 /** 75 * Tests for {@see \question_display_options::add_question_identifier_to_label()} 76 * 77 * @covers ::add_question_identifier_to_label 78 * @dataProvider add_question_identifier_to_label_provider 79 * @param string $label The label string. 80 * @param string|null $identifier The question identifier. 81 * @param bool $sronly Whether to render the question identifier in a sr-only container 82 * @param bool $addbefore Whether to render the question identifier before the label. 83 * @param string $expected The expected return value. 84 * @return void 85 */ 86 public function test_add_question_identifier_to_label( 87 string $label, 88 ?string $identifier, 89 bool $sronly, 90 bool $addbefore, 91 string $expected 92 ): void { 93 $options = new \question_display_options(); 94 $options->questionidentifier = $identifier; 95 $this->assertEquals($expected, $options->add_question_identifier_to_label($label, $sronly, $addbefore)); 96 } 97 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body