Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]
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 /** 18 * Contains the tests for the course_content_item_exporter class. 19 * 20 * @package core 21 * @subpackage course 22 * @copyright 2020 Jake Dallimore <jrhdallimore@gmail.com> 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 namespace tests\core_course; 26 27 defined('MOODLE_INTERNAL') || die(); 28 29 use core_course\local\exporters\course_content_item_exporter; 30 use core_course\local\repository\content_item_readonly_repository; 31 32 /** 33 * The tests for the course_content_item_exporter class. 34 * 35 * @copyright 2020 Jake Dallimore <jrhdallimore@gmail.com> 36 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 37 */ 38 class exporters_course_content_item_testcase extends \advanced_testcase { 39 40 /** 41 * Test confirming a content_item can be exported for a course. 42 */ 43 public function test_export_course_content_item() { 44 $this->resetAfterTest(); 45 global $PAGE; 46 47 $course = $this->getDataGenerator()->create_course(); 48 $user = $this->getDataGenerator()->create_and_enrol($course, 'editingteacher'); 49 $cir = new content_item_readonly_repository(); 50 $contentitems = $cir->find_all_for_course($course, $user); 51 $contentitem = array_shift($contentitems); 52 53 $ciexporter = new course_content_item_exporter($contentitem, ['context' => \context_course::instance($course->id)]); 54 $renderer = $PAGE->get_renderer('core'); 55 $exporteditem = $ciexporter->export($renderer); 56 57 $this->assertObjectHasAttribute('id', $exporteditem); 58 $this->assertEquals($exporteditem->id, $contentitem->get_id()); 59 $this->assertObjectHasAttribute('name', $exporteditem); 60 $this->assertEquals($exporteditem->name, $contentitem->get_name()); 61 $this->assertObjectHasAttribute('title', $exporteditem); 62 $this->assertEquals($exporteditem->title, $contentitem->get_title()->get_value()); 63 $this->assertObjectHasAttribute('link', $exporteditem); 64 $this->assertEquals($exporteditem->link, $contentitem->get_link()->out(false)); 65 $this->assertObjectHasAttribute('icon', $exporteditem); 66 $this->assertEquals($exporteditem->icon, $contentitem->get_icon()); 67 $this->assertObjectHasAttribute('help', $exporteditem); 68 $this->assertEquals($exporteditem->help, format_text($contentitem->get_help(), FORMAT_MARKDOWN)); 69 $this->assertObjectHasAttribute('archetype', $exporteditem); 70 $this->assertEquals($exporteditem->archetype, $contentitem->get_archetype()); 71 $this->assertObjectHasAttribute('componentname', $exporteditem); 72 $this->assertEquals($exporteditem->componentname, $contentitem->get_component_name()); 73 $this->assertObjectHasAttribute('legacyitem', $exporteditem); 74 $this->assertFalse($exporteditem->legacyitem); 75 } 76 77 /** 78 * Test that legacy items (with id of -1) are exported correctly. 79 */ 80 public function test_export_course_content_item_legacy() { 81 $this->resetAfterTest(); 82 global $PAGE; 83 84 $course = $this->getDataGenerator()->create_course(); 85 86 $contentitem = new \core_course\local\entity\content_item( 87 -1, 88 'test_name', 89 new \core_course\local\entity\string_title('test_title'), 90 new \moodle_url(''), 91 '', 92 '* First point 93 * Another point', 94 MOD_ARCHETYPE_OTHER, 95 'core_test' 96 ); 97 98 $ciexporter = new course_content_item_exporter($contentitem, ['context' => \context_course::instance($course->id)]); 99 $renderer = $PAGE->get_renderer('core'); 100 $exporteditem = $ciexporter->export($renderer); 101 102 $this->assertObjectHasAttribute('id', $exporteditem); 103 $this->assertEquals($exporteditem->id, $contentitem->get_id()); 104 $this->assertObjectHasAttribute('name', $exporteditem); 105 $this->assertEquals($exporteditem->name, $contentitem->get_name()); 106 $this->assertObjectHasAttribute('title', $exporteditem); 107 $this->assertEquals($exporteditem->title, $contentitem->get_title()->get_value()); 108 $this->assertObjectHasAttribute('link', $exporteditem); 109 $this->assertEquals($exporteditem->link, $contentitem->get_link()->out(false)); 110 $this->assertObjectHasAttribute('icon', $exporteditem); 111 $this->assertEquals($exporteditem->icon, $contentitem->get_icon()); 112 $this->assertObjectHasAttribute('help', $exporteditem); 113 $this->assertEquals($exporteditem->help, format_text($contentitem->get_help(), FORMAT_MARKDOWN)); 114 $this->assertObjectHasAttribute('archetype', $exporteditem); 115 $this->assertEquals($exporteditem->archetype, $contentitem->get_archetype()); 116 $this->assertObjectHasAttribute('componentname', $exporteditem); 117 $this->assertEquals($exporteditem->componentname, $contentitem->get_component_name()); 118 // Most important, is this a legacy item? 119 $this->assertObjectHasAttribute('legacyitem', $exporteditem); 120 $this->assertTrue($exporteditem->legacyitem); 121 } 122 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body