From 761ef5d33ac12392e40c757d944af2fecdc5ebcb Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Fri, 28 Oct 2016 11:54:22 +0800 Subject: [PATCH 1/2] MDL-56615 portfolio: fix php 7.0.9 warning --- lib/portfolio/forms.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/portfolio/forms.php b/lib/portfolio/forms.php index 73390c9108e..fe908730228 100644 --- a/lib/portfolio/forms.php +++ b/lib/portfolio/forms.php @@ -202,7 +202,8 @@ final class portfolio_admin_form extends moodleform { if (portfolio_static_function($this->plugin, 'has_admin_config')) { require_once($CFG->libdir . '/portfolio/plugin.php'); require_once($CFG->dirroot . '/portfolio/' . $this->plugin . '/lib.php'); - call_user_func(array('portfolio_plugin_' . $this->plugin, 'admin_config_form'), $mform); + $classname = 'portfolio_plugin_' . $this->plugin; + $classname::admin_config_form($mform); } // and set the data if we have some. From 3abda0332de11fad26e9086ecb5b2b3521b16d95 Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Fri, 28 Oct 2016 11:53:55 +0800 Subject: [PATCH 2/2] MDL-56615 portfolio_googledocs: add basic unittests --- portfolio/googledocs/tests/plugin_test.php | 114 +++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 portfolio/googledocs/tests/plugin_test.php diff --git a/portfolio/googledocs/tests/plugin_test.php b/portfolio/googledocs/tests/plugin_test.php new file mode 100644 index 00000000000..23dac5c2c39 --- /dev/null +++ b/portfolio/googledocs/tests/plugin_test.php @@ -0,0 +1,114 @@ +. + +/** + * Googledocs portfolio functional test. + * + * @package portfolio_googledocs + * @category tests + * @copyright 2016 Marina Glancy + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +global $CFG; +require_once($CFG->libdir . '/portfoliolib.php'); +require_once($CFG->libdir . '/portfolio/forms.php'); + +/** + * Googledocs portfolio functional test. + * + * @package portfolio_googledocs + * @category tests + * @copyright 2016 Marina Glancy + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class portfolio_googledocs_plugin_testcase extends advanced_testcase { + + /** @var string name of the portfolio plugin */ + protected $pluginname = 'googledocs'; + + /** + * Creates a new instance of the portfolio plugin + * + * @param string $name name of the instance + * @param stdClass $data config data for the instance + * @return portfolio_plugin_base + */ + protected function enable_plugin($name = 'Instance name', $data = null) { + $data = $data ?: new stdClass(); + $instance = portfolio_static_function($this->pluginname, 'create_instance', $this->pluginname, $name, $data); + core_plugin_manager::reset_caches(); + return $instance; + } + + /** + * Test for method enable_plugin() + */ + public function test_enable() { + global $DB; + $this->resetAfterTest(); + $instance = $this->enable_plugin(); + $record = $DB->get_record('portfolio_instance', ['plugin' => $this->pluginname]); + $this->assertEquals($record->id, $instance->get('id')); + $this->assertEquals('portfolio_plugin_' . $this->pluginname, get_class($instance)); + $this->assertEquals(1, $instance->get('visible')); + } + + /** + * Test submitting a form for creating an instance + */ + public function test_create_form() { + $formdata = ['name' => 'Instance name', 'clientid' => 'CLIENT', 'secret' => 'SECRET']; + portfolio_admin_form::mock_submit($formdata); + + $form = new portfolio_admin_form('', array('plugin' => $this->pluginname, + 'instance' => null, 'portfolio' => null, + 'action' => 'new', 'visible' => 1)); + $data = $form->get_data(); + $this->assertEquals('new', $data->action); + $this->assertEquals(1, $data->visible); + $this->assertEquals($this->pluginname, $data->plugin); + foreach ($formdata as $key => $value) { + $this->assertEquals($value, $data->$key); + } + } + + /** + * Test submitting a form for editing an instance + */ + public function test_edit_form() { + $this->resetAfterTest(); + $instance = $this->enable_plugin(); + + $formdata = ['name' => 'New name', 'clientid' => 'CLIENT', 'secret' => 'SECRET']; + portfolio_admin_form::mock_submit($formdata); + + $form = new portfolio_admin_form('', array('plugin' => $this->pluginname, + 'instance' => $instance, 'portfolio' => $instance->get('id'), + 'action' => 'edit', 'visible' => $instance->get('visible'))); + $this->assertTrue($form->is_validated()); + $this->assertTrue($form->is_submitted()); + $data = $form->get_data(); + $this->assertEquals('edit', $data->action); + $this->assertEquals($instance->get('visible'), $data->visible); + $this->assertEquals($this->pluginname, $data->plugin); + foreach ($formdata as $key => $value) { + $this->assertEquals($value, $data->$key); + } + } +}