See Release Notes
Long Term Support Release
Differences Between: [Versions 310 and 401] [Versions 39 and 401]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 namespace portfolio_googledocs; 18 19 use portfolio_admin_form; 20 21 defined('MOODLE_INTERNAL') || die(); 22 23 global $CFG; 24 require_once($CFG->libdir . '/portfoliolib.php'); 25 require_once($CFG->libdir . '/portfolio/forms.php'); 26 27 /** 28 * Googledocs portfolio functional test. 29 * 30 * @package portfolio_googledocs 31 * @category tests 32 * @copyright 2016 Marina Glancy 33 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 34 */ 35 class plugin_test extends \advanced_testcase { 36 37 /** @var string name of the portfolio plugin */ 38 protected $pluginname = 'googledocs'; 39 40 /** 41 * Creates a new instance of the portfolio plugin 42 * 43 * @param string $name name of the instance 44 * @param \stdClass $data config data for the instance 45 * @return portfolio_plugin_base 46 */ 47 protected function enable_plugin($name = 'Instance name', $data = null) { 48 $data = $data ?: new \stdClass(); 49 $instance = portfolio_static_function($this->pluginname, 'create_instance', $this->pluginname, $name, $data); 50 \core_plugin_manager::reset_caches(); 51 return $instance; 52 } 53 54 /** 55 * Test for method enable_plugin() 56 */ 57 public function test_enable() { 58 global $DB; 59 $this->resetAfterTest(); 60 $instance = $this->enable_plugin(); 61 $record = $DB->get_record('portfolio_instance', ['plugin' => $this->pluginname]); 62 $this->assertEquals($record->id, $instance->get('id')); 63 $this->assertEquals('portfolio_plugin_' . $this->pluginname, get_class($instance)); 64 $this->assertEquals(1, $instance->get('visible')); 65 } 66 67 /** 68 * Test submitting a form for creating an instance 69 */ 70 public function test_create_form() { 71 $formdata = ['name' => 'Instance name', 'clientid' => 'CLIENT', 'secret' => 'SECRET']; 72 portfolio_admin_form::mock_submit($formdata); 73 74 $form = new portfolio_admin_form('', array('plugin' => $this->pluginname, 75 'instance' => null, 'portfolio' => null, 76 'action' => 'new', 'visible' => 1)); 77 $data = $form->get_data(); 78 $this->assertEquals('new', $data->action); 79 $this->assertEquals(1, $data->visible); 80 $this->assertEquals($this->pluginname, $data->plugin); 81 foreach ($formdata as $key => $value) { 82 $this->assertEquals($value, $data->$key); 83 } 84 } 85 86 /** 87 * Test submitting a form for editing an instance 88 */ 89 public function test_edit_form() { 90 $this->resetAfterTest(); 91 $instance = $this->enable_plugin(); 92 93 $formdata = ['name' => 'New name', 'clientid' => 'CLIENT', 'secret' => 'SECRET']; 94 portfolio_admin_form::mock_submit($formdata); 95 96 $form = new portfolio_admin_form('', array('plugin' => $this->pluginname, 97 'instance' => $instance, 'portfolio' => $instance->get('id'), 98 'action' => 'edit', 'visible' => $instance->get('visible'))); 99 $this->assertTrue($form->is_validated()); 100 $this->assertTrue($form->is_submitted()); 101 $data = $form->get_data(); 102 $this->assertEquals('edit', $data->action); 103 $this->assertEquals($instance->get('visible'), $data->visible); 104 $this->assertEquals($this->pluginname, $data->plugin); 105 foreach ($formdata as $key => $value) { 106 $this->assertEquals($value, $data->$key); 107 } 108 } 109 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body