Línea 27... |
Línea 27... |
27 |
* @package block_recentlyaccesseditems
|
27 |
* @package block_recentlyaccesseditems
|
28 |
* @copyright 2018 Victor Deniz <victor@moodle.com>
|
28 |
* @copyright 2018 Victor Deniz <victor@moodle.com>
|
29 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
29 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
30 |
* @since Moodle 3.6
|
30 |
* @since Moodle 3.6
|
31 |
*/
|
31 |
*/
|
32 |
class observer_test extends \advanced_testcase {
|
32 |
final class observer_test extends \advanced_testcase {
|
33 |
use \mod_assign_test_generator;
|
33 |
use \mod_assign_test_generator;
|
Línea 34... |
Línea 34... |
34 |
|
34 |
|
35 |
/** @var string Table name. */
|
35 |
/** @var string Table name. */
|
Línea 54... |
Línea 54... |
54 |
protected $forum;
|
54 |
protected $forum;
|
Línea 55... |
Línea 55... |
55 |
|
55 |
|
56 |
/** @var \stdClass course glossary. */
|
56 |
/** @var \stdClass course glossary. */
|
Línea 57... |
Línea 57... |
57 |
protected $glossary;
|
57 |
protected $glossary;
|
58 |
|
58 |
|
Línea 59... |
Línea 59... |
59 |
/** @var \stdClass course chat. */
|
59 |
/** @var \stdClass course assignment. */
|
60 |
protected $chat;
|
60 |
protected $assign;
|
61 |
|
61 |
|
62 |
/**
|
62 |
/**
|
63 |
* Set up for every test
|
63 |
* Set up for every test
|
- |
|
64 |
*/
|
Línea 64... |
Línea 65... |
64 |
*/
|
65 |
public function setUp(): void {
|
65 |
public function setUp(): void {
|
66 |
global $DB;
|
Línea 66... |
Línea 67... |
66 |
global $DB;
|
67 |
parent::setUp();
|
Línea 85... |
Línea 86... |
85 |
$this->getDataGenerator()->enrol_user($this->teacher->id, $this->course->id, $this->teacherrole->id, 'manual');
|
86 |
$this->getDataGenerator()->enrol_user($this->teacher->id, $this->course->id, $this->teacherrole->id, 'manual');
|
Línea 86... |
Línea 87... |
86 |
|
87 |
|
87 |
// Create items.
|
88 |
// Create items.
|
88 |
$this->forum = $this->getDataGenerator()->create_module('forum', array('course' => $this->course));
|
89 |
$this->forum = $this->getDataGenerator()->create_module('forum', array('course' => $this->course));
|
89 |
$this->glossary = $this->getDataGenerator()->create_module('glossary', array('course' => $this->course));
|
90 |
$this->glossary = $this->getDataGenerator()->create_module('glossary', array('course' => $this->course));
|
90 |
$this->chat = $this->getDataGenerator()->create_module('chat', array('course' => $this->course));
|
91 |
$this->assign = $this->getDataGenerator()->create_module('assign', ['course' => $this->course]);
|
Línea 91... |
Línea 92... |
91 |
}
|
92 |
}
|
92 |
|
93 |
|
93 |
/**
|
94 |
/**
|
Línea 106... |
Línea 107... |
106 |
$this->setUser($this->teacher);
|
107 |
$this->setUser($this->teacher);
|
107 |
$event = \mod_forum\event\course_module_viewed::create(array('context' => \context_module::instance($this->forum->cmid),
|
108 |
$event = \mod_forum\event\course_module_viewed::create(array('context' => \context_module::instance($this->forum->cmid),
|
108 |
'objectid' => $this->forum->id));
|
109 |
'objectid' => $this->forum->id));
|
109 |
$event->trigger();
|
110 |
$event->trigger();
|
Línea 110... |
Línea 111... |
110 |
|
111 |
|
111 |
// Student access chat activity.
|
112 |
// Student access assignment activity.
|
112 |
$this->setUser($this->student);
|
113 |
$this->setUser($this->student);
|
113 |
$event1 = \mod_chat\event\course_module_viewed::create(array('context' => \context_module::instance($this->chat->cmid),
|
114 |
$event1 = \mod_assign\event\course_module_viewed::create(['context' => \context_module::instance($this->assign->cmid),
|
114 |
'objectid' => $this->chat->id));
|
115 |
'objectid' => $this->assign->id]);
|
Línea 115... |
Línea 116... |
115 |
$event1->trigger();
|
116 |
$event1->trigger();
|
116 |
|
117 |
|
117 |
$records = $DB->count_records($this->table, array('userid' => $this->teacher->id, 'courseid' => $this->course->id,
|
118 |
$records = $DB->count_records($this->table, array('userid' => $this->teacher->id, 'courseid' => $this->course->id,
|
Línea 118... |
Línea 119... |
118 |
'cmid' => $this->forum->cmid));
|
119 |
'cmid' => $this->forum->cmid));
|
119 |
$this->assertEquals(1, $records);
|
120 |
$this->assertEquals(1, $records);
|
120 |
|
121 |
|
Línea 121... |
Línea 122... |
121 |
$records = $DB->count_records($this->table, array('userid' => $this->student->id, 'courseid' => $this->course->id, 'cmid' =>
|
122 |
$records = $DB->count_records($this->table, ['userid' => $this->student->id, 'courseid' => $this->course->id, 'cmid' =>
|
122 |
$this->chat->cmid));
|
123 |
$this->assign->cmid]);
|
123 |
$this->assertEquals(1, $records);
|
124 |
$this->assertEquals(1, $records);
|
124 |
|
125 |
|
125 |
$this->waitForSecond();
|
126 |
$this->waitForSecond();
|
Línea 126... |
Línea 127... |
126 |
// Student access chat activity again after 1 second (no new record created, timeaccess updated).
|
127 |
// Student access assignment activity again after 1 second (no new record created, timeaccess updated).
|
127 |
$event2 = \mod_chat\event\course_module_viewed::create(array('context' => \context_module::instance($this->chat->cmid),
|
128 |
$event2 = \mod_assign\event\course_module_viewed::create(['context' => \context_module::instance($this->assign->cmid),
|
128 |
'objectid' => $this->chat->id));
|
129 |
'objectid' => $this->assign->id]);
|
129 |
$event2->trigger();
|
130 |
$event2->trigger();
|
Línea 130... |
Línea 131... |
130 |
|
131 |
|
Línea 151... |
Línea 152... |
151 |
$this->setUser($this->teacher);
|
152 |
$this->setUser($this->teacher);
|
152 |
$event = \mod_forum\event\course_module_viewed::create(array('context' => \context_module::instance($this->forum->cmid),
|
153 |
$event = \mod_forum\event\course_module_viewed::create(array('context' => \context_module::instance($this->forum->cmid),
|
153 |
'objectid' => $this->forum->id));
|
154 |
'objectid' => $this->forum->id));
|
154 |
$event->trigger();
|
155 |
$event->trigger();
|
Línea 155... |
Línea 156... |
155 |
|
156 |
|
156 |
// Teacher access chat activity.
|
157 |
// Teacher access assignment activity.
|
157 |
$event = \mod_chat\event\course_module_viewed::create(array('context' => \context_module::instance($this->chat->cmid),
|
158 |
$event = \mod_assign\event\course_module_viewed::create(['context' => \context_module::instance($this->assign->cmid),
|
158 |
'objectid' => $this->chat->id));
|
159 |
'objectid' => $this->assign->id]);
|
Línea 159... |
Línea 160... |
159 |
$event->trigger();
|
160 |
$event->trigger();
|
160 |
|
161 |
|
161 |
// Student access chat activity.
|
162 |
// Student access assignment activity.
|
162 |
$this->setUser($this->student);
|
163 |
$this->setUser($this->student);
|
163 |
$event = \mod_chat\event\course_module_viewed::create(array('context' => \context_module::instance($this->chat->cmid),
|
164 |
$event = \mod_assign\event\course_module_viewed::create(['context' => \context_module::instance($this->assign->cmid),
|
Línea 164... |
Línea 165... |
164 |
'objectid' => $this->chat->id));
|
165 |
'objectid' => $this->assign->id]);
|
165 |
$event->trigger();
|
166 |
$event->trigger();
|
166 |
|
167 |
|
Línea 172... |
Línea 173... |
172 |
$records = $DB->count_records($this->table, array('cmid' => $this->forum->cmid));
|
173 |
$records = $DB->count_records($this->table, array('cmid' => $this->forum->cmid));
|
173 |
$this->assertEquals(2, $records);
|
174 |
$this->assertEquals(2, $records);
|
174 |
course_delete_module($this->forum->cmid);
|
175 |
course_delete_module($this->forum->cmid);
|
175 |
$records = $DB->count_records($this->table, array('cmid' => $this->forum->cmid));
|
176 |
$records = $DB->count_records($this->table, array('cmid' => $this->forum->cmid));
|
176 |
$this->assertEquals(0, $records);
|
177 |
$this->assertEquals(0, $records);
|
177 |
$records = $DB->count_records($this->table, array('cmid' => $this->chat->cmid));
|
178 |
$records = $DB->count_records($this->table, ['cmid' => $this->assign->cmid]);
|
178 |
$this->assertEquals(2, $records);
|
179 |
$this->assertEquals(2, $records);
|
179 |
}
|
180 |
}
|
180 |
}
|
181 |
}
|