Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | 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
namespace core_calendar;
18
 
19
use core_calendar\local\event\entities\event;
20
use core_calendar\local\event\proxies\std_proxy;
21
use core_calendar\local\event\proxies\coursecat_proxy;
22
use core_calendar\local\event\value_objects\event_description;
23
use core_calendar\local\event\value_objects\event_times;
24
use core_calendar\local\event\entities\event_collection_interface;
25
 
26
defined('MOODLE_INTERNAL') || die();
27
 
28
/**
29
 * Calendar event tests..
30
 *
31
 * @package    core_calendar
32
 * @copyright 2017 Cameron Ball <cameron@cameron1729.xyz>
33
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34
 */
35
class event_test extends \advanced_testcase {
36
    /**
37
     * Test event class getters.
38
     *
39
     * @dataProvider getters_testcases()
40
     * @param array $constructorparams Associative array of constructor parameters.
41
     */
11 efrain 42
    public function test_getters($constructorparams): void {
1 efrain 43
        $event = new event(
44
            $constructorparams['id'],
45
            $constructorparams['name'],
46
            $constructorparams['description'],
47
            $constructorparams['category'],
48
            $constructorparams['course'],
49
            $constructorparams['group'],
50
            $constructorparams['user'],
51
            $constructorparams['repeats'],
52
            $constructorparams['course_module'],
53
            $constructorparams['type'],
54
            $constructorparams['times'],
55
            $constructorparams['visible'],
56
            $constructorparams['subscription'],
57
            $constructorparams['location'],
58
            $constructorparams['component']
59
        );
60
 
61
        foreach ($constructorparams as $name => $value) {
62
            if ($name !== 'visible' && $name !== 'component') {
63
                $this->assertEquals($event->{'get_' . $name}(), $value);
64
            }
65
        }
66
 
67
        $this->assertEquals($event->is_visible(), $constructorparams['visible']);
68
        $this->assertEquals('mod_' . $event->get_course_module()->get('modname'), $event->get_component());
69
    }
70
 
71
    /**
72
     * Test cases for getters test.
73
     */
74
    public function getters_testcases() {
75
        $lamecallable = function($id) {
76
            return (object)['id' => $id, 'modname' => 'assign'];
77
        };
78
 
79
        return [
80
            'Dataset 1' => [
81
                'constructorparams' => [
82
                    'id' => 1,
83
                    'name' => 'Test event 1',
84
                    'description' => new event_description('asdf', 1),
85
                    'category' => new coursecat_proxy(0),
86
                    'course' => new std_proxy(1, $lamecallable),
87
                    'group' => new std_proxy(1, $lamecallable),
88
                    'user' => new std_proxy(1, $lamecallable),
89
                    'repeats' => new core_calendar_event_test_event_collection(),
90
                    'course_module' => new std_proxy(1, $lamecallable),
91
                    'type' => 'dunno what this actually is meant to be',
92
                    'times' => new event_times(
93
                        (new \DateTimeImmutable())->setTimestamp(-386380800),
94
                        (new \DateTimeImmutable())->setTimestamp(115776000),
95
                        (new \DateTimeImmutable())->setTimestamp(115776000),
96
                        (new \DateTimeImmutable())->setTimestamp(time()),
97
                        (new \DateTimeImmutable())->setTimestamp(115776000)
98
                    ),
99
                    'visible' => true,
100
                    'subscription' => new std_proxy(1, $lamecallable),
101
                    'location' => 'Test',
102
                    'component' => null
103
                ]
104
            ],
105
        ];
106
    }
107
}
108
 
109
/**
110
 * Test event class.
111
 *
112
 * @copyright 2017 Cameron Ball <cameron@cameron1729.xyz>
113
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
114
 */
115
class core_calendar_event_test_event_collection implements event_collection_interface {
116
    /**
117
     * @var array $events Array of events.
118
     */
119
    protected $events;
120
 
121
    /**
122
     * Constructor.
123
     */
124
    public function __construct() {
125
        $this->events = [
126
            'not really an event hahaha',
127
            'also not really. gottem.'
128
        ];
129
    }
130
 
131
    public function get_id() {
132
        return 1729;
133
    }
134
 
135
    public function get_num() {
136
        return 2;
137
    }
138
 
139
    public function getIterator(): \Traversable {
140
        foreach ($this->events as $event) {
141
            yield $event;
142
        }
143
    }
144
}