]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-15666 - fixed up the dup test and changed setup to mock the user
authormjollnir_ <mjollnir_>
Tue, 19 Aug 2008 16:14:17 +0000 (16:14 +0000)
committermjollnir_ <mjollnir_>
Tue, 19 Aug 2008 16:14:17 +0000 (16:14 +0000)
lang/en_utf8/portfolio.php
lib/portfoliolib.php
lib/simpletest/testportfoliolib.php

index f4aa2f6c42c11f29725fc38d31d77c43771519b7..d43ccaf9e99b724cff69d030ca4c97d6b7adb7d5 100644 (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';
index 566a888b49074f86c937f8ff06a0fe19fa082922..09923654ecf870fb1905fa7084bf8a44a7fceb6e 100644 (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;
index 1350350beb9ea8951ce46bb909aee6557b69a3c0..20636c7b9ebf7d40414d4ac1c42e9d5f75da766c 100755 (executable)
@@ -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);