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 |
final class observer_test extends \advanced_testcase {
|
32 |
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 assignment. */
|
59 |
/** @var \stdClass course chat. */
|
60 |
protected $assign;
|
60 |
protected $chat;
|
61 |
|
61 |
|
62 |
/**
|
62 |
/**
|
63 |
* Set up for every test
|
63 |
* Set up for every test
|
64 |
*/
|
- |
|
Línea 65... |
Línea 64... |
65 |
public function setUp(): void {
|
64 |
*/
|
66 |
global $DB;
|
65 |
public function setUp(): void {
|
Línea 67... |
Línea 66... |
67 |
parent::setUp();
|
66 |
global $DB;
|
Línea 86... |
Línea 85... |
86 |
$this->getDataGenerator()->enrol_user($this->teacher->id, $this->course->id, $this->teacherrole->id, 'manual');
|
85 |
$this->getDataGenerator()->enrol_user($this->teacher->id, $this->course->id, $this->teacherrole->id, 'manual');
|
Línea 87... |
Línea 86... |
87 |
|
86 |
|
88 |
// Create items.
|
87 |
// Create items.
|
89 |
$this->forum = $this->getDataGenerator()->create_module('forum', array('course' => $this->course));
|
88 |
$this->forum = $this->getDataGenerator()->create_module('forum', array('course' => $this->course));
|
90 |
$this->glossary = $this->getDataGenerator()->create_module('glossary', array('course' => $this->course));
|
89 |
$this->glossary = $this->getDataGenerator()->create_module('glossary', array('course' => $this->course));
|
91 |
$this->assign = $this->getDataGenerator()->create_module('assign', ['course' => $this->course]);
|
90 |
$this->chat = $this->getDataGenerator()->create_module('chat', array('course' => $this->course));
|
Línea 92... |
Línea 91... |
92 |
}
|
91 |
}
|
93 |
|
92 |
|
94 |
/**
|
93 |
/**
|
Línea 107... |
Línea 106... |
107 |
$this->setUser($this->teacher);
|
106 |
$this->setUser($this->teacher);
|
108 |
$event = \mod_forum\event\course_module_viewed::create(array('context' => \context_module::instance($this->forum->cmid),
|
107 |
$event = \mod_forum\event\course_module_viewed::create(array('context' => \context_module::instance($this->forum->cmid),
|
109 |
'objectid' => $this->forum->id));
|
108 |
'objectid' => $this->forum->id));
|
110 |
$event->trigger();
|
109 |
$event->trigger();
|
Línea 111... |
Línea 110... |
111 |
|
110 |
|
112 |
// Student access assignment activity.
|
111 |
// Student access chat activity.
|
113 |
$this->setUser($this->student);
|
112 |
$this->setUser($this->student);
|
114 |
$event1 = \mod_assign\event\course_module_viewed::create(['context' => \context_module::instance($this->assign->cmid),
|
113 |
$event1 = \mod_chat\event\course_module_viewed::create(array('context' => \context_module::instance($this->chat->cmid),
|
115 |
'objectid' => $this->assign->id]);
|
114 |
'objectid' => $this->chat->id));
|
Línea 116... |
Línea 115... |
116 |
$event1->trigger();
|
115 |
$event1->trigger();
|
117 |
|
116 |
|
118 |
$records = $DB->count_records($this->table, array('userid' => $this->teacher->id, 'courseid' => $this->course->id,
|
117 |
$records = $DB->count_records($this->table, array('userid' => $this->teacher->id, 'courseid' => $this->course->id,
|
Línea 119... |
Línea 118... |
119 |
'cmid' => $this->forum->cmid));
|
118 |
'cmid' => $this->forum->cmid));
|
120 |
$this->assertEquals(1, $records);
|
119 |
$this->assertEquals(1, $records);
|
121 |
|
120 |
|
Línea 122... |
Línea 121... |
122 |
$records = $DB->count_records($this->table, ['userid' => $this->student->id, 'courseid' => $this->course->id, 'cmid' =>
|
121 |
$records = $DB->count_records($this->table, array('userid' => $this->student->id, 'courseid' => $this->course->id, 'cmid' =>
|
123 |
$this->assign->cmid]);
|
122 |
$this->chat->cmid));
|
124 |
$this->assertEquals(1, $records);
|
123 |
$this->assertEquals(1, $records);
|
125 |
|
124 |
|
126 |
$this->waitForSecond();
|
125 |
$this->waitForSecond();
|
Línea 127... |
Línea 126... |
127 |
// Student access assignment activity again after 1 second (no new record created, timeaccess updated).
|
126 |
// Student access chat activity again after 1 second (no new record created, timeaccess updated).
|
128 |
$event2 = \mod_assign\event\course_module_viewed::create(['context' => \context_module::instance($this->assign->cmid),
|
127 |
$event2 = \mod_chat\event\course_module_viewed::create(array('context' => \context_module::instance($this->chat->cmid),
|
129 |
'objectid' => $this->assign->id]);
|
128 |
'objectid' => $this->chat->id));
|
130 |
$event2->trigger();
|
129 |
$event2->trigger();
|
Línea 131... |
Línea 130... |
131 |
|
130 |
|
Línea 152... |
Línea 151... |
152 |
$this->setUser($this->teacher);
|
151 |
$this->setUser($this->teacher);
|
153 |
$event = \mod_forum\event\course_module_viewed::create(array('context' => \context_module::instance($this->forum->cmid),
|
152 |
$event = \mod_forum\event\course_module_viewed::create(array('context' => \context_module::instance($this->forum->cmid),
|
154 |
'objectid' => $this->forum->id));
|
153 |
'objectid' => $this->forum->id));
|
155 |
$event->trigger();
|
154 |
$event->trigger();
|
Línea 156... |
Línea 155... |
156 |
|
155 |
|
157 |
// Teacher access assignment activity.
|
156 |
// Teacher access chat activity.
|
158 |
$event = \mod_assign\event\course_module_viewed::create(['context' => \context_module::instance($this->assign->cmid),
|
157 |
$event = \mod_chat\event\course_module_viewed::create(array('context' => \context_module::instance($this->chat->cmid),
|
159 |
'objectid' => $this->assign->id]);
|
158 |
'objectid' => $this->chat->id));
|
Línea 160... |
Línea 159... |
160 |
$event->trigger();
|
159 |
$event->trigger();
|
161 |
|
160 |
|
162 |
// Student access assignment activity.
|
161 |
// Student access chat activity.
|
163 |
$this->setUser($this->student);
|
162 |
$this->setUser($this->student);
|
164 |
$event = \mod_assign\event\course_module_viewed::create(['context' => \context_module::instance($this->assign->cmid),
|
163 |
$event = \mod_chat\event\course_module_viewed::create(array('context' => \context_module::instance($this->chat->cmid),
|
Línea 165... |
Línea 164... |
165 |
'objectid' => $this->assign->id]);
|
164 |
'objectid' => $this->chat->id));
|
166 |
$event->trigger();
|
165 |
$event->trigger();
|
167 |
|
166 |
|
Línea 173... |
Línea 172... |
173 |
$records = $DB->count_records($this->table, array('cmid' => $this->forum->cmid));
|
172 |
$records = $DB->count_records($this->table, array('cmid' => $this->forum->cmid));
|
174 |
$this->assertEquals(2, $records);
|
173 |
$this->assertEquals(2, $records);
|
175 |
course_delete_module($this->forum->cmid);
|
174 |
course_delete_module($this->forum->cmid);
|
176 |
$records = $DB->count_records($this->table, array('cmid' => $this->forum->cmid));
|
175 |
$records = $DB->count_records($this->table, array('cmid' => $this->forum->cmid));
|
177 |
$this->assertEquals(0, $records);
|
176 |
$this->assertEquals(0, $records);
|
178 |
$records = $DB->count_records($this->table, ['cmid' => $this->assign->cmid]);
|
177 |
$records = $DB->count_records($this->table, array('cmid' => $this->chat->cmid));
|
179 |
$this->assertEquals(2, $records);
|
178 |
$this->assertEquals(2, $records);
|
180 |
}
|
179 |
}
|
181 |
}
|
180 |
}
|