Proyectos de Subversion Moodle

Rev

| 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
 * Unit tests for generating instances.
19
 *
20
 * @package     mod_unilabel
21
 * @category    test
22
 * @author      Andreas Grabs <info@grabs-edv.de>
23
 * @copyright   2018 onwards Grabs EDV {@link https://www.grabs-edv.de}
24
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25
 */
26
 
27
namespace mod_unilabel;
28
 
29
/**
30
 * Unit tests for generating instances.
31
 *
32
 * @package     mod_unilabel
33
 * @category    test
34
 * @author      Andreas Grabs <info@grabs-edv.de>
35
 * @copyright   2018 onwards Grabs EDV {@link https://www.grabs-edv.de}
36
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37
 */
38
final class generator_test extends \advanced_testcase {
39
    /**
40
     * Test create an instance.
41
     *
42
     * @covers ::unilabel_add_instance()
43
     * @return void
44
     */
45
    public function test_create_instance(): void {
46
        global $DB;
47
        $this->resetAfterTest();
48
        $this->setAdminUser();
49
 
50
        $course = $this->getDataGenerator()->create_course();
51
 
52
        $this->assertFalse($DB->record_exists('unilabel', ['course' => $course->id]));
53
        $unilabel = $this->getDataGenerator()->create_module(
54
            'unilabel',
55
            [
56
                'course'       => $course,
57
                'idnumber'     => 'mh1',
58
                'name'         => 'testlabel',
59
                'intro'        => 'Hello label',
60
                'unilabeltype' => 'simpletext',
61
            ]
62
        );
63
        $records = $DB->get_records('unilabel', ['course' => $course->id], 'id');
64
        $this->assertEquals(1, count($records));
65
        $this->assertTrue(array_key_exists($unilabel->id, $records));
66
 
67
        $params = [
68
            'course'       => $course->id,
69
            'idnumber'     => 'mh2',
70
            'name'         => 'testlabel2',
71
            'intro'        => 'Hello label-2',
72
            'unilabeltype' => 'simpletext',
73
        ];
74
        $unilabel = $this->getDataGenerator()->create_module('unilabel', $params);
75
        $records  = $DB->get_records('unilabel', ['course' => $course->id], 'id');
76
        $this->assertEquals(2, count($records));
77
        $this->assertEquals('testlabel2', $records[$unilabel->id]->name);
78
    }
79
}