From 795ad63034b8daecd84add1a560d28ba11e0271f Mon Sep 17 00:00:00 2001 From: nicolasconnault Date: Mon, 15 Sep 2008 13:18:44 +0000 Subject: [PATCH] MDL-15666 Testing a matrix of portfolio caller/plugin. Starting the new cleanup method in unit tests (max id) --- admin/generator.php | 171 +------------ lib/portfolio/exporter.php | 2 +- lib/simpletest/portfolio_testclass.php | 231 ++++++++++++++++++ lib/simpletest/testportfoliolib.php | 161 +----------- .../test_assignment_portfolio_callers.php | 8 +- .../test_chat_portfolio_callers.php | 7 +- .../test_data_portfolio_callers.php | 7 +- .../test_forum_portfolio_callers.php | 7 +- .../test_glossary_portfolio_callers.php | 8 +- .../test_resource_portfolio_callers.php | 45 ++++ 10 files changed, 317 insertions(+), 330 deletions(-) create mode 100644 lib/simpletest/portfolio_testclass.php create mode 100644 mod/resource/simpletest/test_resource_portfolio_callers.php diff --git a/admin/generator.php b/admin/generator.php index b42a43f03c..d49639a82e 100755 --- a/admin/generator.php +++ b/admin/generator.php @@ -25,56 +25,6 @@ class generator { '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), - 'context' => array('required' => true, 'toclean' => true), - 'course' => array('required' => true, 'toclean' => true, 'wheresql' => 'sortorder > 1'), - 'course_categories' => array('required' => true, 'toclean' => true, 'wheresql' => 'id > 1'), - 'course_modules' => array('required' => true, 'toclean' => true), - 'course_sections' => array('required' => true, 'toclean' => true), - 'data' => array('required' => false, 'toclean' => true), - 'data_content' => array('required' => false, 'toclean' => true), - 'data_fields' => array('required' => false, 'toclean' => true), - 'data_records' => array('required' => false, 'toclean' => true), - 'event' => array('required' => true, 'toclean' => true), - 'forum' => array('required' => false, 'toclean' => true), - 'forum_discussions' => array('required' => false, 'toclean' => true), - 'forum_posts' => array('required' => false, 'toclean' => true), - 'glossary' => array('required' => false, 'toclean' => true), - 'glossary_formats' => array('required' => false, 'toclean' => false), - 'grade_categories' => array('required' => true, 'toclean' => true), - 'grade_items' => array('required' => true, 'toclean' => true), - 'groups' => array('required' => true, 'toclean' => true), - 'label' => array('required' => false, 'toclean' => true), - 'lesson' => array('required' => false, 'toclean' => true), - 'lesson_default' => array('required' => false, 'toclean' => true), - 'log' => array('required' => true, 'toclean' => true), - 'log_display' => array('required' => true, 'toclean' => true), - 'message' => array('required' => false, 'toclean' => true), - 'modules' => array('required' => true, 'toclean' => true), - 'question' => array('required' => false, 'toclean' => true), - 'quiz' => array('required' => false, 'toclean' => true), - 'resource' => array('required' => true, 'toclean' => true), - 'role' => array('required' => true, 'toclean' => false), - 'role_allow_assign' => array('required' => true, 'toclean' => false), - 'role_allow_override' => array('required' => true, 'toclean' => false), - 'role_assignments' => array('required' => true, 'toclean' => true), - 'role_capabilities' => array('required' => true, 'toclean' => true), - 'survey' => array('required' => false, 'toclean' => true), - 'user' => array('required' => true, 'toclean' => true, 'wheresql' => 'id > 2'), - 'wiki' => array('required' => false, 'toclean' => true) - ); - public $missing_tables = array(); - public $settings = array(); public $eolchar = '
'; public $do_generation = false; @@ -91,9 +41,6 @@ class generator { 'help' => 'Your moodle username', 'type'=>'STRING', 'default' => ''), array('short'=>'pw', 'long'=>'password', 'help' => 'Your moodle password', 'type'=>'STRING', 'default' => ''), - array('short'=>'p', 'long'=>'data_prefix', - 'help' => 'An optional prefix prepended to the unique identifiers of the generated data. Default=test_', - 'type'=>'STRING', 'default' => 'test_'), array('short'=>'P', 'long' => 'database_prefix', 'help' => 'Database prefix to use: tables must already exist or the script will abort!', 'type'=>'STRING', 'default' => 'tst_'), @@ -244,8 +191,7 @@ class generator { $user = new stdClass(); $user->firstname = trim(ucfirst(strtolower($firstname))); - $user->username = $this->get('data_prefix') . strtolower(substr($firstname, 0, 7) - . substr($lastname, 0, 7)) . $next_user_id++; + $user->username = strtolower(substr($firstname, 0, 7) . substr($lastname, 0, 7)) . $next_user_id++; $user->lastname = $lastname; $user->email = $user->username . '@example.com'; $user->mnethostid = 1; @@ -362,7 +308,7 @@ class generator { $newcourse = fullclone($base_course); $newcourse->fullname = "Test course $next_course_id"; $newcourse->shortname = "Test $next_course_id"; - $newcourse->idnumber = $this->get('data_prefix') . $next_course_id; + $newcourse->idnumber = $next_course_id; if (!$course = create_course($newcourse)) { $this->verbose("Error inserting a new course in the database!"); if (!$this->get('ignore_errors')) { @@ -564,7 +510,7 @@ class generator { break; } - $module->name = $this->get('data_prefix') . ucfirst($moduledata->name) . ' ' . $moduledata->count++; + $module->name = ucfirst($moduledata->name) . ' ' . $moduledata->count++; $module->course = $courseid; $module->section = $i; @@ -940,7 +886,8 @@ class generator { $type = $database_field_types[array_rand($database_field_types)]; require_once($CFG->dirroot.'/mod/data/field/'.$type.'/field.class.php'); $newfield = 'data_field_'.$type; - $newfield = new $newfield(0, $data, true); + $cm = get_coursemodule_from_instance('data', $data->id); + $newfield = new $newfield(0, $data, $cm); $fields[$data->id][] = $newfield; $newfield->insert_field(); } @@ -1002,45 +949,6 @@ class generator { return $result; } - /** - * If an alternate DB prefix was given, we need to check that the appropriate tables - * exist. - */ - public function check_test_tables() { - global $CFG, $DB; - - ksort($this->tables); - // Check that all required tables exist - - $table_errors = array(); - - foreach ($this->tables as $table => $tabledata) { - require_once($CFG->libdir . '/ddllib.php'); - $dbman = $DB->get_manager(); - $xmltable = new XMLDBTable($table); - if (!$dbman->table_exists($xmltable)) { - if ($tabledata['required']) { - $table_errors[] = $this->get('database_prefix') . $table; - } - $this->missing_tables[] = $table; - } - } - - if (!empty($table_errors) && !$this->get('quiet')) { - if (!$this->get('quiet')) { - echo "The following required tables do not exist in the database:" . $this->eolchar; - foreach ($table_errors as $table) { - echo " $table" . $this->eolchar; - } - echo "Please create these tables or choose a different database prefix before running " - ."this script with these parameters again." . $this->eolchar; - } - if (!$this->get('ignore_errors')) { - die(); - } - } - - } /** * If verbose is switched on, prints a string terminated by the global eolchar string. @@ -1052,11 +960,10 @@ class generator { } } + /** - * Attempts to delete all generated test data. A few conditions are required for this to be successful: - * 1. If a database-prefix has been given, tables with this prefix must exist - * 2. If a data prefix has been given (e.g. test_), test data must contain this prefix in their unique identifiers (not PKs) - * The first method is safest, because it will not interfere with existing tables, but you have to create all the tables yourself. + * Attempts to delete all generated test data. + * WARNING: THIS WILL COMPLETELY MESS UP A "REAL" SITE, AND IS INTENDED ONLY FOR DEVELOPMENT PURPOSES */ function data_cleanup() { global $DB; @@ -1065,63 +972,7 @@ class generator { ob_start(); } - // Truncate test tables if a specific db prefix was given - if (!is_null($this->get('database_prefix')) && isset($this->tables)) { - foreach ($this->tables as $table_name => $tabledata) { - // Don't empty a few tables - if (!in_array($table_name, array('modules', 'block')) && - $tabledata['toclean'] && - !in_array($table_name, $this->missing_tables)) { - // Leave the frontpage course - $conditions = 'id > 0'; - if (!empty($tabledata['wheresql'])) { - $conditions .= " AND {$tabledata['wheresql']} "; - } - - if ($DB->delete_records_select($table_name, $conditions)) { - $this->verbose("Truncated table $table_name"); - } else { - $this->verbose("Could not truncate table $table_name"); - if (!$this->get('ignore_errors')) { - die(); - } - } - } - } - - } else { - echo "BOOH"; - } - /** Following code has been commented for security reasons - - else { // Delete records in normal tables if no specific db prefix was given - $courses = $DB->get_records_select('course', "idnumber LIKE ?", - array($this->get('data_prefix').'%'), null, 'id'); - - if (is_array($courses) && count($courses) > 0) { - foreach ($courses as $course) { - if (!delete_course($course->id, false)) { - $this->verbose("Could not delete course $course->id or some of " - ."its associated records from the database."); - if (!$this->get('ignore_errors')) { - die(); - } - } else { - $this->verbose("Deleted course $course->id and all associated records from the database."); - } - } - } - - $this->verbose("Deleting test users (permanently)..."); - if (!$DB->delete_records_select('user', "username LIKE ?", array($this->get('data_prefix').'%'))) { - $this->verbose("Error deleting users from the database"); - if (!$this->get('ignore_errors')) { - die(); - } - } - } - - */ + // TODO Cleanup code if ($this->get('quiet')) { ob_end_clean(); @@ -1169,6 +1020,7 @@ class generator_cli extends generator { // Building the USAGE output of the command line version $help = "Moodle Data Generator. Generates Data for Moodle sites. Good for benchmarking and other tests.\n\n" + . "FOR DEVELOPMENT PURPOSES ONLY! DO NOT USE ON A PRODUCTION SITE!\n\n" . "Usage: {$settings[0]}; [OPTION] ...\n" . "Options:\n" . " -h, -?, -help, --help This output\n"; @@ -1283,6 +1135,9 @@ class generator_web extends generator { public function display() { print_header("Data generator"); print_heading("Data generator: web interface"); + print_heading("FOR DEVELOPMENT PURPOSES ONLY. DO NOT USE ON A PRODUCTION SITE!", '', 3); + print_heading("Your database contents will probably be massacred. You have been warned", '', 5); + $mform = new generator_form(); $this->do_generation = optional_param('do_generation', false, PARAM_BOOL); diff --git a/lib/portfolio/exporter.php b/lib/portfolio/exporter.php index 0b782653cb..3728a41cde 100644 --- a/lib/portfolio/exporter.php +++ b/lib/portfolio/exporter.php @@ -702,7 +702,7 @@ class portfolio_exporter { $zipper = new zip_packer(); list ($contextid, $filearea, $itemid) = array_values($this->get_base_filearea()); - if ($newfile = $zipper->archive_to_storage($files, $contextid, $filearea, $itemid, $filepath, $filename, $this->user->id)) { + if ($newfile = $zipper->archive_to_storage($this->get_tempfiles(), $contextid, $filearea, $itemid, $filepath, $filename, $this->user->id)) { return $newfile; } return false; diff --git a/lib/simpletest/portfolio_testclass.php b/lib/simpletest/portfolio_testclass.php new file mode 100644 index 0000000000..3964e85aaf --- /dev/null +++ b/lib/simpletest/portfolio_testclass.php @@ -0,0 +1,231 @@ +libdir . '/portfoliolib.php'); +require_once($CFG->dirroot . '/admin/generator.php'); + +class portfolio_plugin_test extends portfolio_plugin_push_base { + public function expected_time($callertime){ + return $callertime; + } + + public function prepare_package() { + return true; + } + + public function send_package() { + return true; + } + + public function get_continue_url() { + return ''; + } + + public static function get_name() { + return ''; + } +} + +class portfolio_caller_test extends portfolio_caller_base { + private $content; + + public function __construct($content) { + $this->content = $content; + } + + public function expected_time() { + return PORTFOLIO_TIME_LOW; + } + + public function get_navigation() { + $extranav = array('name' => 'Test caller class', 'link' => $this->get_return_url()); + return array($extranav, 'test'); + } + + public function get_sha1(){ + return sha1($this->content); + } + + public function prepare_package() { + + } + + public function get_return_url() { + return ''; + } + + public function check_permissions() { + return true; + } + + public static function display_name() { + return "Test caller subclass"; + } + + public function load_data() { + + } + + public static function expected_callbackargs() { + return array(); + } +} + +/** + * The following two classes are full mocks: none of their methods do anything, including their constructor. + * They can be instantiated directly with no params (new portfolio_caller_test()) + */ +Mock::generate('portfolio_caller_test', 'mock_caller'); +Mock::generate('portfolio_plugin_test', 'mock_plugin'); + +/** + * Partial mocks work as normal except the methods listed in the 3rd param, which are mocked. + * They are instantiated by passing $this to the constructor within the test case class. + */ +Mock::generatePartial('portfolio_plugin_test', 'partialmock_plugin', array('send_package')); +Mock::generatePartial('portfolio_exporter', 'partialmock_exporter', array('process_stage_confirm', + 'process_stage_cleanup', + 'log_transfer', + 'save', + 'rewaken_object')); + + +// Generate a mock class for each plugin subclass present +$portfolio_plugins = get_list_of_plugins('portfolio/type'); +foreach ($portfolio_plugins as $plugin) { + require_once($CFG->dirroot . "/portfolio/type/$plugin/lib.php"); + Mock::generatePartial("portfolio_plugin_$plugin", "partialmock_plugin_$plugin", array('send_package')); +} + +require_once($CFG->libdir . '/portfoliolib.php'); +require_once($CFG->dirroot . '/admin/generator.php'); + +class portfoliolib_test extends UnitTestCase { + public $tables = array(); + + function setUp() { + global $DB, $CFG; + + $this->tables = $DB->get_tables(); + + foreach ($this->tables as $key => $table) { + if ($table == 'sessions2') { + unset($this->tables[$key]); + continue; + } + + if ($max_id = $DB->get_field_sql("SELECT MAX(id) FROM {$CFG->prefix}{$table}")) { + $this->tables[$table] = $max_id; + } else { + $this->tables[$table] = 0; + } + } + } + + function tearDown() { + global $DB; + + // Truncate all data created during unit tests + foreach ($this->tables as $table => $max_pk) { + $DB->delete_records_select($table, "id > $max_pk"); + } + } + + function test_construct_dupe_instance() { + $gotexception = false; + try { + $plugin1 = portfolio_plugin_base::create_instance('download', 'download1', array()); + $plugin2 = portfolio_plugin_base::create_instance('download', 'download2', array()); + $test1 = new portfolio_plugin_download($plugin1->get('id')); + } catch (portfolio_exception $e) { + $this->assertEqual('multipledisallowed', $e->errorcode); + $gotexception = true; + } + $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; + } + + public function test_caller_with_plugins() { + if (!empty($this->caller)) { + $plugins = get_list_of_plugins('portfolio/type'); + + foreach ($plugins as $plugin) { + // Instantiate a fake plugin instance + $plugin_class = "partialmock_plugin_$plugin"; + $plugin = new $plugin_class(&$this); + + // Create a new fake exporter + $exporter = new partialmock_exporter(&$this); + $exporter->set('caller', $this->caller); + $exporter->set('instance', $plugin); + + $exception = false; + try { + $exporter->process_stage_package(); + } catch (Exception $e) { + $exception = $e->getMessage(); + } + + $this->assertFalse($exception, "Unwanted exception: $exception"); + } + } + } +} +?> diff --git a/lib/simpletest/testportfoliolib.php b/lib/simpletest/testportfoliolib.php index cd72e849bb..b76879f655 100755 --- a/lib/simpletest/testportfoliolib.php +++ b/lib/simpletest/testportfoliolib.php @@ -35,166 +35,7 @@ if (!defined('MOODLE_INTERNAL')) { die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page } -require_once($CFG->libdir . '/portfoliolib.php'); -require_once($CFG->dirroot . '/admin/generator.php'); - -class portfolio_plugin_test extends portfolio_plugin_push_base { - public function expected_time($callertime){ - return $callertime; - } - - public function prepare_package() { - return true; - } - - public function send_package() { - return true; - } - - public function get_continue_url() { - return ''; - } - - public static function get_name() { - return ''; - } -} - -class portfolio_caller_test extends portfolio_caller_base { - private $content; - - public function __construct($content) { - $this->content = $content; - } - - public function expected_time() { - return PORTFOLIO_TIME_LOW; - } - - public function get_navigation() { - $extranav = array('name' => 'Test caller class', 'link' => $this->get_return_url()); - return array($extranav, 'test'); - } - - public function get_sha1(){ - return sha1($this->content); - } - - public function prepare_package() { - - } - - public function get_return_url() { - return ''; - } - - public function check_permissions() { - return true; - } - - public static function display_name() { - return "Test caller subclass"; - } - - public function load_data() { - - } - - public static function expected_callbackargs() { - return array(); - } -} - -/** - * The following two classes are full mocks: none of their methods do anything, including their constructor. - * They can be instantiated directly with no params (new portfolio_caller_test()) - */ -Mock::generate('portfolio_caller_test', 'mock_caller'); -Mock::generate('portfolio_plugin_test', 'mock_plugin'); - -/** - * Partial mocks work as normal except the methods listed in the 3rd param, which are mocked. - * They are instantiated by passing $this to the constructor within the test case class. - */ -Mock::generatePartial('portfolio_plugin_test', 'partialmock_plugin', array('send_package')); - -class portfoliolib_test extends UnitTestCase { - public $caller; - public $plugin; - public $exporter; - public $original_db; - - function setUp() { - global $DB, $CFG; - $this->original_db = clone($DB); - - $class = get_class($DB); - $DB = new $class(); - $DB->connect($CFG->dbhost, $CFG->dbuser, $CFG->dbpass, $CFG->dbname, true, 'tst_'); - - $u = new StdClass; - $u->id = 100000000000; - $this->plugin = new mock_plugin(); - $this->caller = new mock_caller(); - $this->exporter = new portfolio_exporter(&$this->plugin, &$this->caller, '', array()); - $this->exporter->set('user', $u); - $partialplugin = &new partialmock_plugin($this); - - // Write a new text file - $this->exporter->save(); - $this->exporter->write_new_file('Test text', 'test.txt'); - } - - function tearDown() { - global $DB; - $DB->delete_records('portfolio_tempdata', array('id' => $this->exporter->get('id'))); - $fs = get_file_storage(); - $fs->delete_area_files(SYSCONTEXTID, 'portfolio_exporter', $this->exporter->get('id')); - - $settings = array('no_data' => 1, 'post_cleanup' => 1, 'database_prefix' => 'tst_', 'quiet' => 1); - generator_generate_data($settings); - - // Restore original DB - $DB = $this->original_db; - } - - function test_construct_dupe_instance() { - $gotexception = false; - try { - $plugin1 = portfolio_plugin_base::create_instance('download', 'download1', array()); - $plugin2 = portfolio_plugin_base::create_instance('download', 'download2', array()); - $test1 = new portfolio_plugin_download($plugin1->get('id')); - } catch (portfolio_exception $e) { - $this->assertEqual('multipledisallowed', $e->errorcode); - $gotexception = true; - } - $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; - } -} +require_once($CFG->libdir . '/simpletest/portfolio_testclass.php'); // Load tests for various modules foreach (get_list_of_plugins('mod') as $module) { diff --git a/mod/assignment/simpletest/test_assignment_portfolio_callers.php b/mod/assignment/simpletest/test_assignment_portfolio_callers.php index 9269d4b309..bb47d8cd59 100644 --- a/mod/assignment/simpletest/test_assignment_portfolio_callers.php +++ b/mod/assignment/simpletest/test_assignment_portfolio_callers.php @@ -1,5 +1,5 @@ libdir.'/simpletest/testportfoliolib.php'); +require_once($CFG->libdir.'/simpletest/portfolio_testclass.php'); require_once($CFG->dirroot.'/mod/assignment/lib.php'); require_once($CFG->dirroot.'/admin/generator.php'); @@ -17,7 +17,7 @@ class testAssignmentPortfolioCallers extends portfoliolib_test { parent::setUp(); - $settings = array('quiet' => 1, 'database_prefix' => 'tst_', 'pre_cleanup' => 1, + $settings = array('quiet' => 1, 'pre_cleanup' => 1, 'modules_list' => array($this->module_type), 'assignment_grades' => true, 'assignment_type' => 'online', 'number_of_students' => 5, 'students_per_course' => 5, 'number_of_sections' => 1, @@ -30,7 +30,6 @@ class testAssignmentPortfolioCallers extends portfoliolib_test { $submissions = $DB->get_records('assignment_submissions', array('assignment' => $first_module->id)); $first_submission = reset($submissions); - $callbackargs = array('id' => $cm->id); $this->caller = parent::setup_caller('assignment_portfolio_caller', array('id' => $cm->id), $first_submission->userid); } @@ -44,5 +43,8 @@ class testAssignmentPortfolioCallers extends portfoliolib_test { $this->assertEqual($sha1, $this->caller->get_sha1()); } + public function test_caller_with_plugins() { + parent::test_caller_with_plugins(); + } } ?> diff --git a/mod/chat/simpletest/test_chat_portfolio_callers.php b/mod/chat/simpletest/test_chat_portfolio_callers.php index 56d2ce2487..48333c4a47 100644 --- a/mod/chat/simpletest/test_chat_portfolio_callers.php +++ b/mod/chat/simpletest/test_chat_portfolio_callers.php @@ -1,5 +1,5 @@ libdir.'/simpletest/testportfoliolib.php'); +require_once($CFG->libdir.'/simpletest/portfolio_testclass.php'); require_once($CFG->dirroot.'/mod/chat/lib.php'); require_once($CFG->dirroot.'/admin/generator.php'); @@ -17,7 +17,7 @@ class testChatPortfolioCallers extends portfoliolib_test { parent::setUp(); - $settings = array('quiet' => 1, 'database_prefix' => 'tst_', 'pre_cleanup' => 1, + $settings = array('quiet' => 1, '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); @@ -42,5 +42,8 @@ class testChatPortfolioCallers extends portfoliolib_test { $this->assertEqual($sha1, $this->caller->get_sha1()); } + public function test_caller_with_plugins() { + parent::test_caller_with_plugins(); + } } ?> diff --git a/mod/data/simpletest/test_data_portfolio_callers.php b/mod/data/simpletest/test_data_portfolio_callers.php index 42af481c2e..5e4954e9e0 100644 --- a/mod/data/simpletest/test_data_portfolio_callers.php +++ b/mod/data/simpletest/test_data_portfolio_callers.php @@ -1,5 +1,5 @@ libdir.'/simpletest/testportfoliolib.php'); +require_once($CFG->libdir.'/simpletest/portfolio_testclass.php'); require_once($CFG->dirroot.'/mod/data/lib.php'); require_once($CFG->dirroot.'/admin/generator.php'); @@ -19,7 +19,7 @@ class testDataPortfolioCallers extends portfoliolib_test { parent::setUp(); $settings = array('quiet' => 1, - 'database_prefix' => 'tst_', + 'pre_cleanup' => 0, 'modules_list' => array($this->module_type), 'number_of_students' => 5, @@ -64,5 +64,8 @@ class testDataPortfolioCallers extends portfoliolib_test { $this->assertEqual($sha1, $this->caller_single->get_sha1()); } + public function test_caller_with_plugins() { + parent::test_caller_with_plugins(); + } } ?> diff --git a/mod/forum/simpletest/test_forum_portfolio_callers.php b/mod/forum/simpletest/test_forum_portfolio_callers.php index 7a6aca5c40..e741313c60 100644 --- a/mod/forum/simpletest/test_forum_portfolio_callers.php +++ b/mod/forum/simpletest/test_forum_portfolio_callers.php @@ -1,5 +1,5 @@ libdir.'/simpletest/testportfoliolib.php'); +require_once($CFG->libdir.'/simpletest/portfolio_testclass.php'); require_once($CFG->dirroot.'/mod/forum/lib.php'); require_once($CFG->dirroot.'/admin/generator.php'); @@ -20,7 +20,7 @@ class testForumPortfolioCallers extends portfoliolib_test { $settings = array('quiet' => 1, 'verbose' => 0, - 'database_prefix' => 'tst_', + 'pre_cleanup' => 0, 'post_cleanup' => 0, 'modules_list' => array($this->module_type), @@ -66,5 +66,8 @@ class testForumPortfolioCallers extends portfoliolib_test { $this->assertEqual($sha1, $this->discussioncaller->get_sha1()); } + public function test_caller_with_plugins() { + parent::test_caller_with_plugins(); + } } ?> diff --git a/mod/glossary/simpletest/test_glossary_portfolio_callers.php b/mod/glossary/simpletest/test_glossary_portfolio_callers.php index 658b0f5ddf..01e4423085 100644 --- a/mod/glossary/simpletest/test_glossary_portfolio_callers.php +++ b/mod/glossary/simpletest/test_glossary_portfolio_callers.php @@ -1,5 +1,5 @@ libdir.'/simpletest/testportfoliolib.php'); +require_once($CFG->libdir.'/simpletest/portfolio_testclass.php'); require_once($CFG->dirroot.'/mod/glossary/lib.php'); require_once($CFG->dirroot.'/admin/generator.php'); @@ -19,7 +19,7 @@ class testGlossaryPortfolioCallers extends portfoliolib_test { parent::setUp(); - $settings = array('tiny' => 1, 'quiet' => 1, 'database_prefix' => 'tst_', 'pre_cleanup' => 1, + $settings = array('tiny' => 1, 'quiet' => 1, 'pre_cleanup' => 1, 'modules_list' => array('glossary'), 'entries_per_glossary' => 20, 'number_of_students' => 5, 'students_per_course' => 5, 'number_of_sections' => 1, 'number_of_modules' => 1, 'questions_per_course' => 0); @@ -53,5 +53,9 @@ class testGlossaryPortfolioCallers extends portfoliolib_test { $this->csv_caller->prepare_package(); $this->assertEqual($csv_sha1, $this->csv_caller->get_sha1()); } + + public function test_caller_with_plugins() { + parent::test_caller_with_plugins(); + } } ?> diff --git a/mod/resource/simpletest/test_resource_portfolio_callers.php b/mod/resource/simpletest/test_resource_portfolio_callers.php new file mode 100644 index 0000000000..b0f109edb9 --- /dev/null +++ b/mod/resource/simpletest/test_resource_portfolio_callers.php @@ -0,0 +1,45 @@ +libdir.'/simpletest/testportfoliolib.php'); +require_once($CFG->dirroot.'/mod/resource/lib.php'); +require_once($CFG->dirroot.'/admin/generator.php'); + +Mock::generate('resource_portfolio_caller', 'mock_caller'); +Mock::generate('portfolio_exporter', 'mock_exporter'); + +class testResourcePortfolioCallers extends portfoliolib_test { + public $module_type = 'resource'; + public $modules = array(); + public $entries = array(); + public $caller; + + public function setUp() { + global $DB, $USER; + + parent::setUp(); + + $settings = array('quiet' => 1, '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_resource' => 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); + + $this->caller = parent::setup_caller('resource_portfolio_caller', array('id' => $cm->id)); + } + + 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()); + } + +} +?> -- 2.39.5