From: mjollnir_ Date: Tue, 19 Aug 2008 16:14:17 +0000 (+0000) Subject: MDL-15666 - fixed up the dup test and changed setup to mock the user X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=cc8696b2ef6f892bfd33be2053735f5d11f74011;p=moodle.git MDL-15666 - fixed up the dup test and changed setup to mock the user --- diff --git a/lang/en_utf8/portfolio.php b/lang/en_utf8/portfolio.php index f4aa2f6c42..d43ccaf9e9 100644 --- a/lang/en_utf8/portfolio.php +++ b/lang/en_utf8/portfolio.php @@ -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'; diff --git a/lib/portfoliolib.php b/lib/portfoliolib.php index 566a888b49..09923654ec 100644 --- a/lib/portfoliolib.php +++ b/lib/portfoliolib.php @@ -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; diff --git a/lib/simpletest/testportfoliolib.php b/lib/simpletest/testportfoliolib.php index 1350350beb..20636c7b9e 100755 --- a/lib/simpletest/testportfoliolib.php +++ b/lib/simpletest/testportfoliolib.php @@ -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);