MDL-15666 chat module caller tests and generation
This commit is contained in:
+56
-14
@@ -9,20 +9,21 @@ require_once($CFG->dirroot .'/mod/resource/lib.php');
|
||||
class generator {
|
||||
public $modules_to_ignore = array('hotpot', 'lams', 'journal', 'scorm', 'exercise', 'dialogue');
|
||||
public $modules_list = array('forum' => 'forum',
|
||||
'assignment' => 'assignment',
|
||||
'data' => 'data',
|
||||
'glossary' => 'glossary',
|
||||
'quiz' => 'quiz',
|
||||
'comments' => 'comments',
|
||||
'feedback' => 'feedback',
|
||||
'label' => 'label',
|
||||
'lesson' => 'lesson',
|
||||
'chat' => 'chat',
|
||||
'choice' => 'choice',
|
||||
'resource' => 'resource',
|
||||
'survey' => 'survey',
|
||||
'wiki' => 'wiki',
|
||||
'workshop' => 'workshop');
|
||||
'assignment' => 'assignment',
|
||||
'chat' => 'chat',
|
||||
'data' => 'data',
|
||||
'glossary' => 'glossary',
|
||||
'quiz' => 'quiz',
|
||||
'comments' => 'comments',
|
||||
'feedback' => 'feedback',
|
||||
'label' => 'label',
|
||||
'lesson' => 'lesson',
|
||||
'chat' => 'chat',
|
||||
'choice' => 'choice',
|
||||
'resource' => 'resource',
|
||||
'survey' => 'survey',
|
||||
'wiki' => 'wiki',
|
||||
'workshop' => 'workshop');
|
||||
|
||||
public $tables = array('assignment' => array('required' => false, 'toclean' => true),
|
||||
'block' => array('required' => true, 'toclean' => false),
|
||||
@@ -30,6 +31,8 @@ class generator {
|
||||
'block_pinned' => array('required' => true, 'toclean' => true),
|
||||
'capabilities' => array('required' => true, 'toclean' => false),
|
||||
'chat' => array('required' => false, 'toclean' => true),
|
||||
'chat_messages' => array('required' => false, 'toclean' => true),
|
||||
'chat_users' => array('required' => false, 'toclean' => true),
|
||||
'choice' => array('required' => false, 'toclean' => true),
|
||||
'config' => array('required' => true, 'toclean' => false),
|
||||
'config_plugins' => array('required' => true, 'toclean' => false),
|
||||
@@ -154,6 +157,9 @@ class generator {
|
||||
array('short'=>'drs', 'long' => 'database_records_per_student',
|
||||
'help' => 'The number of records to generate for each student/database tuple. Default=1',
|
||||
'type'=>'NUMBER', 'default' => 1),
|
||||
array('short'=>'mc', 'long' => 'messages_per_chat',
|
||||
'help' => 'The number of messages to generate for each chat module. Default=10',
|
||||
'type'=>'NUMBER', 'default' => 10),
|
||||
);
|
||||
|
||||
foreach ($arguments as $args_array) {
|
||||
@@ -974,6 +980,42 @@ class generator {
|
||||
$result = true;
|
||||
}
|
||||
|
||||
$messages_count = 0;
|
||||
if (!empty($modules['chat']) && $this->get('messages_per_chat')) {
|
||||
|
||||
// Insert all users into chat_users table, then a message from each user
|
||||
foreach ($modules['chat'] as $chat) {
|
||||
|
||||
foreach ($course_users as $courseid => $users_array) {
|
||||
|
||||
foreach ($users_array as $userid) {
|
||||
if ($messages_count < $this->get('messages_per_chat')) {
|
||||
$chat_user = new stdClass();
|
||||
$chat_user->chatid = $chat->id;
|
||||
$chat_user->userid = $userid;
|
||||
$chat_user->course = $courseid;
|
||||
$DB->insert_record('chat_users', $chat_user);
|
||||
|
||||
$chat_message = new stdClass();
|
||||
$chat_message->chatid = $chat->id;
|
||||
$chat_message->userid = $userid;
|
||||
$chat_message->message = "Hi, everyone!";
|
||||
$DB->insert_record('chat_messages', $chat_message);
|
||||
|
||||
$messages_count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($messages_count > 0 && !$this->get('quiet')) {
|
||||
$datacount = count($modules['chat']);
|
||||
echo "$messages_count messages have been generated for each of the "
|
||||
. "$datacount generated chats.{$this->eolchar}";
|
||||
}
|
||||
$result = true;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php // $Id$
|
||||
require_once($CFG->libdir.'/simpletest/testportfoliolib.php');
|
||||
require_once($CFG->dirroot.'/mod/chat/lib.php');
|
||||
require_once($CFG->dirroot.'/admin/generator.php');
|
||||
|
||||
Mock::generate('chat_portfolio_caller', 'mock_caller');
|
||||
Mock::generate('portfolio_exporter', 'mock_exporter');
|
||||
|
||||
class testChatPortfolioCallers extends portfoliolib_test {
|
||||
public $module_type = 'chat';
|
||||
public $modules = array();
|
||||
public $entries = array();
|
||||
public $caller;
|
||||
|
||||
public function setUp() {
|
||||
global $DB, $USER;
|
||||
|
||||
parent::setUp();
|
||||
|
||||
$settings = array('quiet' => 1, 'database_prefix' => 'tst_', 'pre_cleanup' => 1,
|
||||
'modules_list' => array($this->module_type),
|
||||
'number_of_students' => 15, 'students_per_course' => 15, 'number_of_sections' => 1,
|
||||
'number_of_modules' => 1, 'messages_per_chat' => 15);
|
||||
|
||||
generator_generate_data($settings);
|
||||
|
||||
$this->modules = $DB->get_records($this->module_type);
|
||||
$first_module = reset($this->modules);
|
||||
$cm = get_coursemodule_from_instance($this->module_type, $first_module->id);
|
||||
$userid = $DB->get_field('chat_users', 'userid', array('chatid' => $first_module->id));
|
||||
|
||||
$callbackargs = array('id' => $cm->id);
|
||||
$this->caller = new chat_portfolio_caller($callbackargs);
|
||||
$this->caller->set('exporter', new mock_exporter());
|
||||
|
||||
$user = $DB->get_record('user', array('id' => $userid));
|
||||
$this->caller->set('user', $user);
|
||||
}
|
||||
|
||||
public function tearDown() {
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function test_caller_sha1() {
|
||||
$sha1 = $this->caller->get_sha1();
|
||||
$this->caller->prepare_package();
|
||||
$this->assertEqual($sha1, $this->caller->get_sha1());
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user