mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 16:32:18 +02:00
MDL-67585 core_course: Added legacyitem to exporter.
Legacy items have no id and so can not be favourited nor recommended. We needed a way to easily determine whether to show these features in the templates.
This commit is contained in:
parent
54561c885e
commit
a7b2378d72
@ -77,7 +77,13 @@ class course_content_item_exporter extends exporter {
|
||||
*/
|
||||
protected static function define_other_properties() {
|
||||
// This will hold user-dependant properties such as whether the item is starred or recommended.
|
||||
return ['favourite' => ['type' => PARAM_BOOL, 'description' => 'Has the user favourited the content item']];
|
||||
return [
|
||||
'favourite' => ['type' => PARAM_BOOL, 'description' => 'Has the user favourited the content item'],
|
||||
'legacyitem' => [
|
||||
'type' => PARAM_BOOL,
|
||||
'description' => 'If this item was pulled from the old callback and has no item id.'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -116,7 +122,8 @@ class course_content_item_exporter extends exporter {
|
||||
'help' => $this->contentitem->get_help(),
|
||||
'archetype' => $this->contentitem->get_archetype(),
|
||||
'componentname' => $this->contentitem->get_component_name(),
|
||||
'favourite' => $favourite
|
||||
'favourite' => $favourite,
|
||||
'legacyitem' => ($this->contentitem->get_id() == -1)
|
||||
];
|
||||
|
||||
return $properties;
|
||||
|
@ -70,5 +70,52 @@ class exporters_course_content_item_testcase extends \advanced_testcase {
|
||||
$this->assertEquals($exporteditem->archetype, $contentitem->get_archetype());
|
||||
$this->assertObjectHasAttribute('componentname', $exporteditem);
|
||||
$this->assertEquals($exporteditem->componentname, $contentitem->get_component_name());
|
||||
$this->assertObjectHasAttribute('legacyitem', $exporteditem);
|
||||
$this->assertFalse($exporteditem->legacyitem);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that legacy items (with id of -1) are exported correctly.
|
||||
*/
|
||||
public function test_export_course_content_item_legacy() {
|
||||
$this->resetAfterTest();
|
||||
global $PAGE;
|
||||
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
|
||||
$contentitem = new \core_course\local\entity\content_item(
|
||||
-1,
|
||||
'test_name',
|
||||
new \core_course\local\entity\string_title('test_title'),
|
||||
new \moodle_url(''),
|
||||
'',
|
||||
'',
|
||||
MOD_ARCHETYPE_OTHER,
|
||||
'core_test'
|
||||
);
|
||||
|
||||
$ciexporter = new course_content_item_exporter($contentitem, ['context' => \context_course::instance($course->id)]);
|
||||
$renderer = $PAGE->get_renderer('core');
|
||||
$exporteditem = $ciexporter->export($renderer);
|
||||
|
||||
$this->assertObjectHasAttribute('id', $exporteditem);
|
||||
$this->assertEquals($exporteditem->id, $contentitem->get_id());
|
||||
$this->assertObjectHasAttribute('name', $exporteditem);
|
||||
$this->assertEquals($exporteditem->name, $contentitem->get_name());
|
||||
$this->assertObjectHasAttribute('title', $exporteditem);
|
||||
$this->assertEquals($exporteditem->title, $contentitem->get_title()->get_value());
|
||||
$this->assertObjectHasAttribute('link', $exporteditem);
|
||||
$this->assertEquals($exporteditem->link, $contentitem->get_link()->out(false));
|
||||
$this->assertObjectHasAttribute('icon', $exporteditem);
|
||||
$this->assertEquals($exporteditem->icon, $contentitem->get_icon());
|
||||
$this->assertObjectHasAttribute('help', $exporteditem);
|
||||
$this->assertEquals($exporteditem->help, $contentitem->get_help());
|
||||
$this->assertObjectHasAttribute('archetype', $exporteditem);
|
||||
$this->assertEquals($exporteditem->archetype, $contentitem->get_archetype());
|
||||
$this->assertObjectHasAttribute('componentname', $exporteditem);
|
||||
$this->assertEquals($exporteditem->componentname, $contentitem->get_component_name());
|
||||
// Most important, is this a legacy item?
|
||||
$this->assertObjectHasAttribute('legacyitem', $exporteditem);
|
||||
$this->assertTrue($exporteditem->legacyitem);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user