MDL-77690 core: New activity_header method get_heading_level()

Add a new method for activity_header that determines the heading level
depending on whether the theme displays a heading for the activity
header (usually a h2 heading with the activity name).

E.g. in Boost, the activity name is already being displayed in a
heading. So page headings can be rendered as h2. However, on Classic,
the activity name is being displayed as a h2 heading. So headings need
to be adjusted for the activity pages.
This commit is contained in:
Jun Pataleta
2023-06-30 17:00:33 +08:00
parent ca07598c6f
commit a587bcc4a2
3 changed files with 53 additions and 0 deletions
+33
View File
@@ -123,4 +123,37 @@ class activity_header_test extends \advanced_testcase {
$PAGE->activityheader->set_attrs(['unknown' => true]);
$this->assertDebuggingCalledCount(1, ['Invalid class member variable: unknown']);
}
/**
* Data provider for {@see test_get_heading_level()}.
*
* @return array[]
*/
public function get_heading_level_provider(): array {
return [
'Title not allowed' => [false, '', 2],
'Title allowed, no title' => [true, '', 2],
'Title allowed, empty string title' => [true, ' ', 2],
'Title allowed, non-empty string title' => [true, 'Cool', 3],
];
}
/**
* Test the heading level getter
*
* @dataProvider get_heading_level_provider
* @covers ::get_heading_level
* @param bool $allowtitle Whether the title is allowed.
* @param string $title The activity heading.
* @param int $expectedheadinglevel The expected heading level.
*/
public function test_get_heading_level(bool $allowtitle, string $title, int $expectedheadinglevel): void {
$activityheaderstub = $this->getMockBuilder(activity_header::class)
->disableOriginalConstructor()
->onlyMethods(['is_title_allowed'])
->getMock();
$activityheaderstub->method('is_title_allowed')->willReturn($allowtitle);
$activityheaderstub->set_title($title);
$this->assertEquals($expectedheadinglevel, $activityheaderstub->get_heading_level());
}
}