| Línea 23... |
Línea 23... |
| 23 |
* @category test
|
23 |
* @category test
|
| 24 |
* @coversDefaultClass \core\output\activity_header
|
24 |
* @coversDefaultClass \core\output\activity_header
|
| 25 |
* @copyright 2021 Peter
|
25 |
* @copyright 2021 Peter
|
| 26 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
26 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
| 27 |
*/
|
27 |
*/
|
| 28 |
class activity_header_test extends \advanced_testcase {
|
28 |
final class activity_header_test extends \advanced_testcase {
|
| Línea 29... |
Línea 29... |
| 29 |
|
29 |
|
| 30 |
/**
|
30 |
/**
|
| 31 |
* Test the title setter
|
31 |
* Test the title setter
|
| 32 |
*
|
32 |
*
|
| Línea 58... |
Línea 58... |
| 58 |
|
58 |
|
| 59 |
/**
|
59 |
/**
|
| 60 |
* Provider for the test_set_title unit test.
|
60 |
* Provider for the test_set_title unit test.
|
| 61 |
* @return array
|
61 |
* @return array
|
| 62 |
*/
|
62 |
*/
|
| 63 |
public function set_title_provider(): array {
|
63 |
public static function set_title_provider(): array {
|
| 64 |
return [
|
64 |
return [
|
| 65 |
"Set the title with a plain text" => [
|
65 |
"Set the title with a plain text" => [
|
| 66 |
"Activity title", "Activity title"
|
66 |
"Activity title", "Activity title"
|
| 67 |
],
|
67 |
],
|
| Línea 127... |
Línea 127... |
| 127 |
/**
|
127 |
/**
|
| 128 |
* Data provider for {@see test_get_heading_level()}.
|
128 |
* Data provider for {@see test_get_heading_level()}.
|
| 129 |
*
|
129 |
*
|
| 130 |
* @return array[]
|
130 |
* @return array[]
|
| 131 |
*/
|
131 |
*/
|
| 132 |
public function get_heading_level_provider(): array {
|
132 |
public static function get_heading_level_provider(): array {
|
| 133 |
return [
|
133 |
return [
|
| 134 |
'Title not allowed' => [false, '', 2],
|
134 |
'Title not allowed' => [false, '', 2],
|
| 135 |
'Title allowed, no title' => [true, '', 2],
|
135 |
'Title allowed, no title' => [true, '', 2],
|
| 136 |
'Title allowed, empty string title' => [true, ' ', 2],
|
136 |
'Title allowed, empty string title' => [true, ' ', 2],
|
| 137 |
'Title allowed, non-empty string title' => [true, 'Cool', 3],
|
137 |
'Title allowed, non-empty string title' => [true, 'Cool', 3],
|
| Línea 154... |
Línea 154... |
| 154 |
->getMock();
|
154 |
->getMock();
|
| 155 |
$activityheaderstub->method('is_title_allowed')->willReturn($allowtitle);
|
155 |
$activityheaderstub->method('is_title_allowed')->willReturn($allowtitle);
|
| 156 |
$activityheaderstub->set_title($title);
|
156 |
$activityheaderstub->set_title($title);
|
| 157 |
$this->assertEquals($expectedheadinglevel, $activityheaderstub->get_heading_level());
|
157 |
$this->assertEquals($expectedheadinglevel, $activityheaderstub->get_heading_level());
|
| 158 |
}
|
158 |
}
|
| - |
|
159 |
|
| - |
|
160 |
/**
|
| - |
|
161 |
* Tests that is_title_allowed returns correctly based on the theme default and current layout options.
|
| - |
|
162 |
*
|
| - |
|
163 |
* The current layout has precedence, if the notitle option is set, otherwise the theme default is used if set.
|
| - |
|
164 |
*
|
| - |
|
165 |
* @param array $themeoptions The activityheader options array set in the theme.
|
| - |
|
166 |
* @param array $layoutoptions The activitityheader options array set in the layout.
|
| - |
|
167 |
* @param bool $allowed The expected return value of is_title_allowed.
|
| - |
|
168 |
* @covers ::is_title_allowed
|
| - |
|
169 |
* @dataProvider get_title_options
|
| - |
|
170 |
* @return void
|
| - |
|
171 |
*/
|
| - |
|
172 |
public function test_is_title_allowed(array $themeoptions, array $layoutoptions, bool $allowed): void {
|
| - |
|
173 |
$themeconfig = $this->getMockBuilder(\theme_config::class)
|
| - |
|
174 |
->disableOriginalConstructor()
|
| - |
|
175 |
->getMock();
|
| - |
|
176 |
$themeconfig->activityheaderconfig = $themeoptions;
|
| - |
|
177 |
$page = $this->getMockBuilder(\moodle_page::class)
|
| - |
|
178 |
->getMock();
|
| - |
|
179 |
// Mocking the magic_get_layout_options() and magic_get_theme() methods directly doesn't work,
|
| - |
|
180 |
// so mock the whole magic __get() method and just return the test values for those properties.
|
| - |
|
181 |
$page->expects($this->any())->method('__get')->willReturnCallback(fn($name) => match($name) {
|
| - |
|
182 |
'layout_options' => ['activityheader' => $layoutoptions],
|
| - |
|
183 |
'theme' => $themeconfig,
|
| - |
|
184 |
default => null
|
| - |
|
185 |
});
|
| - |
|
186 |
$user = new \stdClass();
|
| - |
|
187 |
|
| - |
|
188 |
$activityheader = new activity_header($page, $user);
|
| - |
|
189 |
$this->assertEquals($allowed, $activityheader->is_title_allowed());
|
| - |
|
190 |
}
|
| - |
|
191 |
|
| - |
|
192 |
/**
|
| - |
|
193 |
* Return scenarios for test_is_title_allowed.
|
| - |
|
194 |
*
|
| - |
|
195 |
* Test each combination of the 'notitle' option being unset, true and false in each of the theme and layout options.
|
| - |
|
196 |
*
|
| - |
|
197 |
* @return array[]
|
| - |
|
198 |
*/
|
| - |
|
199 |
public static function get_title_options(): array {
|
| - |
|
200 |
return [
|
| - |
|
201 |
'Undefined in theme, undefined in layout' => [[], [], true],
|
| - |
|
202 |
'Undefined in theme, disallowed in layout' => [[], ['notitle' => true], false],
|
| - |
|
203 |
'Undefined in theme, allowed in layout' => [[], ['notitle' => false], true],
|
| - |
|
204 |
'Disallowed in theme, undefined in layout' => [['notitle' => true], [], false],
|
| - |
|
205 |
'Disallowed in theme, disallowed in layout' => [['notitle' => true], ['notitle' => true], false],
|
| - |
|
206 |
'Disallowed in theme, allowed in layout' => [['notitle' => true], ['notitle' => false], true],
|
| - |
|
207 |
'Allowed in theme, undefined in layout' => [['notitle' => false], [], true],
|
| - |
|
208 |
'Allowed in theme, disallowed in layout' => [['notitle' => false], ['notitle' => true], false],
|
| - |
|
209 |
'Allowed in theme, allowed in layout' => [['notitle' => false], ['notitle' => false], true],
|
| - |
|
210 |
];
|
| - |
|
211 |
}
|
| 159 |
}
|
212 |
}
|