Skip to content

Commit

Permalink
MDL-15666 chat module caller tests and generation
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasconnault committed Sep 9, 2008
1 parent a200c48 commit 74cd7b9
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 14 deletions.
70 changes: 56 additions & 14 deletions admin/generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,30 @@
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),
'block_instance' => array('required' => true, 'toclean' => true),
'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),
Expand Down Expand Up @@ -154,6 +157,9 @@ public function __construct($settings = array(), $generate=false) {
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) {
Expand Down Expand Up @@ -974,6 +980,42 @@ public function generate_module_content($course_users, $courses, $modules) {
$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;
}

Expand Down
51 changes: 51 additions & 0 deletions mod/chat/simpletest/test_chat_portfolio_callers.php
Original file line number Diff line number Diff line change
@@ -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());
}

}
?>

0 comments on commit 74cd7b9

Please sign in to comment.