MDL-15666 - changes to the portfolio caller tests

now that i changed the api again (adding load_data), rather than add a call to it to
all the callers, i abstracted the caller setup into the parent class (portfoliolib_test)
This commit is contained in:
mjollnir_
2008-09-11 13:47:40 +00:00
parent 0d06b6fda7
commit 27dda89ffe
6 changed files with 41 additions and 27 deletions
+32
View File
@@ -95,6 +95,14 @@ class portfolio_caller_test extends portfolio_caller_base {
public static function display_name() {
return "Test caller subclass";
}
public function load_data() {
}
public static function expected_callbackargs() {
return array();
}
}
/**
@@ -162,6 +170,30 @@ class portfoliolib_test extends UnitTestCase {
}
$this->assertTrue($gotexception);
}
/**
* does everything we need to set up a new caller
* so each subclass doesn't have to implement this
*
* @param string $class name of caller class to generate (this class def must be already loaded)
* @param array $callbackargs the arguments to pass the constructor of the caller
* @param int $userid a userid the subclass has generated
*
* @return portfolio_caller_base subclass
*/
protected function setup_caller($class, $callbackargs, $user=null) {
global $DB;
$caller = new $class($callbackargs);
$caller->set('exporter', new mock_exporter());
if (is_numeric($user)) {
$user = $DB->get_record('user', array('id' => $user));
}
if (is_object($user)) {
$caller->set('user', $user);
}
$caller->load_data();
return $caller;
}
}
// Load tests for various modules
@@ -30,11 +30,8 @@ class testAssignmentPortfolioCallers extends portfoliolib_test {
$submissions = $DB->get_records('assignment_submissions', array('assignment' => $first_module->id));
$first_submission = reset($submissions);
$callbackargs = array('assignmentid' => $cm->id, 'userid' => $USER->id);
$this->caller = new assignment_portfolio_caller($callbackargs);
$this->caller->set('exporter', new mock_exporter());
$user = $DB->get_record('user', array('id' => $first_submission->userid));
$this->caller->set('user', $user);
$callbackargs = array('id' => $cm->id);
$this->caller = parent::setup_caller('assignment_portfolio_caller', array('id' => $cm->id), $first_submission->userid);
}
public function tearDown() {
@@ -29,12 +29,7 @@ class testChatPortfolioCallers extends portfoliolib_test {
$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);
$this->caller = parent::setup_caller('chat_portfolio_caller', array('id' => $cm->id), $userid);
}
public function tearDown() {
@@ -46,14 +46,8 @@ class testDataPortfolioCallers extends portfoliolib_test {
}
// Callback args required: id, record, delimiter_name, exporttype
$callbackargs = array('id' => $cm->id, 'record' => $recordid);
$this->caller_single = new data_portfolio_caller($callbackargs);
$this->caller_single->set('exporter', new mock_exporter());
unset($callbackargs['record']);
$this->caller = new data_portfolio_caller($callbackargs);
$this->caller->set('exporter', new mock_exporter());
$this->caller_single = parent::setup_caller('data_portfolio_caller', array('id' => $cm->id, 'record' => $recordid));
$this->caller = parent::setup_caller('data_portfolio_caller', array('id' => $cm->id));
}
public function tearDown() {
@@ -44,10 +44,7 @@ class testForumPortfolioCallers extends portfoliolib_test {
$first_post = reset($posts);
$callbackargs = array('postid' => $first_post->id, 'discussionid' => $first_discussion->id);
$this->caller = new forum_portfolio_caller($callbackargs);
$this->caller->set('exporter', new mock_exporter());
$user = $DB->get_record('user', array('id' => $first_post->userid));
$this->caller->set('user', $user);
$this->caller = parent::setup_caller('forum_portfolio_caller', $callbackargs, $first_post->userid);
}
public function tearDown() {
@@ -33,10 +33,9 @@ class testGlossaryPortfolioCallers extends portfoliolib_test {
$first_entry = reset($this->entries);
$callbackargs = array('id' => $cm->id, 'entryid' => $first_entry->id);
$this->entry_caller = new glossary_entry_portfolio_caller($callbackargs);
$this->entry_caller->set('exporter', new mock_exporter());
$this->csv_caller = new glossary_csv_portfolio_caller($callbackargs);
$this->csv_caller->set('exporter', new mock_exporter());
$this->entry_caller = parent::setup_caller('glossary_entry_portfolio_caller', $callbackargs);
$this->csv_caller = parent::setup_caller('glossary_csv_portfolio_caller', $callbackargs);
}
public function tearDown() {