Skip to content

Commit

Permalink
MDL-15666 MDL-16177
Browse files Browse the repository at this point in the history
Refactored the generator script into proper Object Oriented code. It can now be used as a CLI tool, as a web form or as an included library with a function call. Stub implementation is demonstrated in portfolio unit tests.
  • Loading branch information
nicolasconnault committed Aug 29, 2008
1 parent d3919c2 commit 7e95408
Show file tree
Hide file tree
Showing 7 changed files with 721 additions and 538 deletions.
1,176 changes: 641 additions & 535 deletions admin/generator.php

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions lib/simpletest/testportfoliolib.php
Expand Up @@ -129,13 +129,17 @@ function tearDown() {
$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'));

$settings = array('no_data' => 1, 'post_cleanup' => 1, 'database_prefix' => 'tst_', 'quiet' => 1);
generator_generate_data($settings);
}

function test_construct_dupe_instance() {
$gotexception = false;
try {
portfolio_plugin_base::create_instance('download', 'download1', array());
portfolio_plugin_base::create_instance('download', 'download2', array());
$plugin1 = portfolio_plugin_base::create_instance('download', 'download1', array());
$plugin2 = portfolio_plugin_base::create_instance('download', 'download2', array());
$test1 = new portfolio_plugin_download($plugin1->get('id'));
} catch (portfolio_exception $e) {
$this->assertEqual('multipledisallowed', $e->errorcode);
$gotexception = true;
Expand Down
2 changes: 1 addition & 1 deletion portfolio/type/boxnet/lib.php
Expand Up @@ -4,7 +4,7 @@

class portfolio_plugin_boxnet extends portfolio_plugin_push_base {

private $boxclient;
public $boxclient;
private $ticket;
private $authtoken;
private $folders;
Expand Down
@@ -1,6 +1,7 @@
<?php // $Id$
require_once($CFG->libdir.'/simpletest/testportfoliolib.php');
require_once($CFG->dirroot.'/portfolio/type/boxnet/lib.php');
require_once($CFG->dirroot.'/admin/generator.php');

Mock::generate('boxclient', 'mock_boxclient');
Mock::generatePartial('portfolio_plugin_boxnet', 'mock_boxnetplugin', array('ensure_ticket', 'ensure_account_tree'));
Expand All @@ -10,6 +11,8 @@ public function setUp() {
parent::setUp();
$this->plugin = &new mock_boxnetplugin($this);
$this->plugin->boxclient = new mock_boxclient();
$settings = array('tiny' => 1, 'quiet' => 1, 'database_prefix' => 'tst_', 'pre_cleanup' => 1);
generator_generate_data($settings);
}

public function tearDown() {
Expand Down
21 changes: 21 additions & 0 deletions portfolio/type/download/simpletest/testportfolioplugindownload.php
@@ -0,0 +1,21 @@
<?php // $Id$
require_once($CFG->libdir.'/simpletest/testportfoliolib.php');
require_once($CFG->dirroot.'/portfolio/type/download/lib.php');

Mock::generate('boxclient', 'mock_boxclient');
Mock::generatePartial('portfolio_plugin_download', 'mock_downloadplugin', array('ensure_ticket', 'ensure_account_tree'));


class testPortfolioPluginDownload 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();
}

}
?>
42 changes: 42 additions & 0 deletions portfolio/type/flickr/lib.php
@@ -0,0 +1,42 @@
<?php
require_once($CFG->libdir.'/filelib.php');
require_once($CFG->dirroot.'/repository/flickr/phpFlickr.php');

class portfolio_plugin_flickr extends portfolio_plugin_push_base {

private $flickr;

public function prepare_package() {
$this->flickr = new phpFlickr($this->get_config('apikey'), $this->get_config('sharedsecret'));
return true; // don't do anything else for this plugin, we want to send all files as they are.
}

public function send_package() {

}

public function get_continue_url() {
return 'http://www.flickr.com/files#0:f:' . $this->get_export_config('folder');
}

public function expected_time($callertime) {
return $callertime;
}

public static function get_allowed_config() {
return array('apikey', 'sharedsecret');
}

public static function has_admin_config() {
return true;
}

public function admin_config_form(&$mform) {
$strrequired = get_string('required');
$mform->addElement('text', 'apikey', get_string('apikey', 'portfolio_flickr'));
$mform->addRule('apikey', $strrequired, 'required', null, 'client');
$mform->addElement('text', 'sharedsecret', get_string('sharedsecret', 'portfolio_flickr'));
$mform->addRule('sharedsecret', $strrequired, 'required', null, 'client');
}

}
7 changes: 7 additions & 0 deletions portfolio/type/flickr/version.php
@@ -0,0 +1,7 @@
<?php

$plugin->version = 2008072500;
$plugin->requires = 2008072500;
$plugin->cron = 0;

?>

0 comments on commit 7e95408

Please sign in to comment.