]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-15666 Adding test file with stub methods.
authornicolasconnault <nicolasconnault>
Tue, 19 Aug 2008 09:21:30 +0000 (09:21 +0000)
committernicolasconnault <nicolasconnault>
Tue, 19 Aug 2008 09:21:30 +0000 (09:21 +0000)
lib/simpletest/testportfoliolib.php
portfolio/type/boxnet/simpletest/testportfoliopluginboxnet.php [new file with mode: 0644]

index afeed65feeff4773d577b84434bef611ee979c5e..bb66ff0d21e9b5b2df263f6205efe549926cfbfa 100755 (executable)
@@ -38,11 +38,21 @@ if (!defined('MOODLE_INTERNAL')) {
 require_once($CFG->libdir . '/portfoliolib.php');
 
 class portfolio_plugin_test extends portfolio_plugin_push_base {
-    public function expected_time($callertime){}
-    public function is_push(){}
-    public function prepare_package(){}
-    public function send_package(){}
-    public function get_continue_url(){}
+    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 '';
+    }
 }
 
 class portfolio_caller_test extends portfolio_caller_base {
@@ -82,9 +92,19 @@ class portfolio_caller_test extends portfolio_caller_base {
     }
 }
 
+/**
+ * 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;
@@ -94,10 +114,18 @@ class portfoliolib_test extends UnitTestCase {
         $this->plugin = new mock_plugin();
         $this->caller = new mock_caller();
         $this->exporter = new portfolio_exporter(&$this->plugin, &$this->caller, '', array());
+        $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'));
     }
 
     function test_construct() {
diff --git a/portfolio/type/boxnet/simpletest/testportfoliopluginboxnet.php b/portfolio/type/boxnet/simpletest/testportfoliopluginboxnet.php
new file mode 100644 (file)
index 0000000..7b79bc1
--- /dev/null
@@ -0,0 +1,41 @@
+<?php // $Id$
+require_once($CFG->libdir.'/simpletest/testportfoliolib.php');
+require_once($CFG->dirroot.'/portfolio/type/boxnet/lib.php');
+
+Mock::generate('boxclient', 'mock_boxclient');
+Mock::generatePartial('portfolio_plugin_boxnet', 'mock_boxnetplugin', array('ensure_ticket', 'ensure_account_tree'));
+
+class testPortfolioPluginBoxnet extends portfoliolib_test {
+    public function setUp() {
+        parent::setUp();
+        $this->plugin = &new mock_boxnetplugin($this);
+        $this->plugin->boxclient = new mock_boxclient();
+    }
+
+    public function tearDown() {
+        parent::tearDown();
+    }
+
+    public function test_something() {
+        $ticket = md5(rand(0,873907));
+        $authtoken = 'ezfoeompplpug3ofii4nud0d8tvg96e0';
+
+        $this->plugin->setReturnValue('ensure_account_tree', true);
+        $this->plugin->setReturnValue('ensure_ticket', $ticket);
+
+        $this->plugin->boxclient->setReturnValue('renameFile', true);
+        $this->plugin->boxclient->setReturnValue('uploadFile', array('status' => 'upload_ok', 'id' => array(1)));
+        $this->plugin->boxclient->setReturnValue('createFolder', array(1 => 'folder 1', 2 => 'folder 2'));
+        $this->plugin->boxclient->setReturnValue('isError', false);
+        $this->plugin->boxclient->authtoken = $authtoken;
+
+        $this->assertTrue($this->plugin->set('exporter', $this->exporter));
+        $this->assertTrue($this->plugin->set('ticket', $ticket));
+        $this->assertTrue($this->plugin->set('authtoken', $authtoken));
+        $this->plugin->set_export_config(array('folder' => 1));
+
+        $this->assertTrue($this->plugin->prepare_package());
+        $this->assertTrue($this->plugin->send_package());
+    }
+}
+?>