Proyectos de Subversion Moodle

Rev

Ir a la última revisión | | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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 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_content_item_test 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->assertObjectHasProperty('id', $exporteditem);
58
        $this->assertEquals($exporteditem->id, $contentitem->get_id());
59
        $this->assertObjectHasProperty('name', $exporteditem);
60
        $this->assertEquals($exporteditem->name, $contentitem->get_name());
61
        $this->assertObjectHasProperty('title', $exporteditem);
62
        $this->assertEquals($exporteditem->title, $contentitem->get_title()->get_value());
63
        $this->assertObjectHasProperty('link', $exporteditem);
64
        $this->assertEquals($exporteditem->link, $contentitem->get_link()->out(false));
65
        $this->assertObjectHasProperty('icon', $exporteditem);
66
        $this->assertEquals($exporteditem->icon, $contentitem->get_icon());
67
        $this->assertObjectHasProperty('help', $exporteditem);
68
        $this->assertEquals($exporteditem->help, format_text($contentitem->get_help(), FORMAT_MARKDOWN));
69
        $this->assertObjectHasProperty('archetype', $exporteditem);
70
        $this->assertEquals($exporteditem->archetype, $contentitem->get_archetype());
71
        $this->assertObjectHasProperty('componentname', $exporteditem);
72
        $this->assertEquals($exporteditem->componentname, $contentitem->get_component_name());
73
        $this->assertObjectHasProperty('legacyitem', $exporteditem);
74
        $this->assertFalse($exporteditem->legacyitem);
75
        $this->assertEquals($exporteditem->purpose, $contentitem->get_purpose());
76
        $this->assertEquals($exporteditem->branded, $contentitem->is_branded());
77
    }
78
 
79
    /**
80
     * Test that legacy items (with id of -1) are exported correctly.
81
     */
82
    public function test_export_course_content_item_legacy() {
83
        $this->resetAfterTest();
84
        global $PAGE;
85
 
86
        $course = $this->getDataGenerator()->create_course();
87
 
88
        $contentitem = new \core_course\local\entity\content_item(
89
            -1,
90
            'test_name',
91
            new \core_course\local\entity\string_title('test_title'),
92
            new \moodle_url(''),
93
            '',
94
            '* First point
95
            * Another point',
96
            MOD_ARCHETYPE_OTHER,
97
            'core_test',
98
            MOD_PURPOSE_CONTENT
99
        );
100
 
101
        $ciexporter = new course_content_item_exporter($contentitem, ['context' => \context_course::instance($course->id)]);
102
        $renderer = $PAGE->get_renderer('core');
103
        $exporteditem = $ciexporter->export($renderer);
104
 
105
        $this->assertObjectHasProperty('id', $exporteditem);
106
        $this->assertEquals($exporteditem->id, $contentitem->get_id());
107
        $this->assertObjectHasProperty('name', $exporteditem);
108
        $this->assertEquals($exporteditem->name, $contentitem->get_name());
109
        $this->assertObjectHasProperty('title', $exporteditem);
110
        $this->assertEquals($exporteditem->title, $contentitem->get_title()->get_value());
111
        $this->assertObjectHasProperty('link', $exporteditem);
112
        $this->assertEquals($exporteditem->link, $contentitem->get_link()->out(false));
113
        $this->assertObjectHasProperty('icon', $exporteditem);
114
        $this->assertEquals($exporteditem->icon, $contentitem->get_icon());
115
        $this->assertObjectHasProperty('help', $exporteditem);
116
        $this->assertEquals($exporteditem->help, format_text($contentitem->get_help(), FORMAT_MARKDOWN));
117
        $this->assertObjectHasProperty('archetype', $exporteditem);
118
        $this->assertEquals($exporteditem->archetype, $contentitem->get_archetype());
119
        $this->assertObjectHasProperty('componentname', $exporteditem);
120
        $this->assertEquals($exporteditem->componentname, $contentitem->get_component_name());
121
        // Most important, is this a legacy item?
122
        $this->assertObjectHasProperty('legacyitem', $exporteditem);
123
        $this->assertTrue($exporteditem->legacyitem);
124
    }
125
}