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 {
}
}
+/**
+ * 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;
$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() {
--- /dev/null
+<?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());
+ }
+}
+?>