MDL-15666 - fixed up the dup test and changed setup to mock the user

This commit is contained in:
mjollnir_
2008-08-19 16:14:17 +00:00
parent 29de31324e
commit cc8696b2ef
3 changed files with 15 additions and 1 deletions
+1
View File
@@ -48,6 +48,7 @@ $string['invaliduserproperty'] = 'Could not find that user config property ($a->
$string['invalidconfigproperty'] = 'Could not find that config property ($a->property of $a->class)';
$string['manageportfolios'] = 'Manage portfolios';
$string['manageyourportfolios'] = 'Manage your portfolios';
$string['multipledisallowed'] = 'Trying to create another instance of a plugin that has disallowed multiple instances ($a)';
$string['noavailableplugins'] = 'Sorry, but there are no available portfolios for you to export to';
$string['nocallbackfile'] = 'Something in the module you\'re trying to export from is broken - couldn\'t find a required file ($a)';
$string['nocommonformats'] = 'No common formats between any available portfolio plugin and the calling location $a';
+10
View File
@@ -1272,6 +1272,10 @@ abstract class portfolio_plugin_base {
* you shouldn't need to override it
* unless you're doing something really funky
*
* @param string $plugin portfolio plugin to create
* @param string $name name of new instance
* @param array $config what the admin config form returned
*
* @return object subclass of portfolio_plugin_base
*/
public static function create_instance($plugin, $name, $config) {
@@ -1280,6 +1284,12 @@ abstract class portfolio_plugin_base {
'plugin' => $plugin,
'name' => $name,
);
if (!portfolio_static_function($plugin, 'allows_multiple')) {
// check we don't have one already
if ($DB->record_exists('portfolio_instance', array('plugin' => $plugin))) {
throw new portfolio_exception('multipledisallowed', 'portfolio', $plugin);
}
}
$newid = $DB->insert_record('portfolio_instance', $new);
require_once($CFG->dirroot . '/portfolio/type/' . $plugin . '/lib.php');
$classname = 'portfolio_plugin_' . $plugin;
+4 -1
View File
@@ -111,9 +111,12 @@ class portfoliolib_test extends UnitTestCase {
public $exporter;
function setUp() {
$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
@@ -134,7 +137,7 @@ class portfoliolib_test extends UnitTestCase {
portfolio_plugin_base::create_instance('download', 'download1', array());
portfolio_plugin_base::create_instance('download', 'download2', array());
} catch (portfolio_exception $e) {
$this->assertEqual('invalidinstance', $e->errorcode);
$this->assertEqual('multipledisallowed', $e->errorcode);
$gotexception = true;
}
$this->assertTrue($gotexception);