mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 13:38:32 +01:00
Merge branch 'MDL-83094-404' of https://github.com/paulholden/moodle into MOODLE_404_STABLE
This commit is contained in:
commit
9f3174a32d
@ -14,24 +14,14 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Customfield category persistent class
|
||||
*
|
||||
* @package core_customfield
|
||||
* @copyright 2018 Toni Barbera <toni@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace core_customfield;
|
||||
|
||||
use core\persistent;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
/**
|
||||
* Class category
|
||||
* Customfield category persistent class
|
||||
*
|
||||
* @package core_customfield
|
||||
* @package core_customfield
|
||||
* @copyright 2018 Toni Barbera <toni@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
@ -60,7 +50,8 @@ class category extends persistent {
|
||||
'descriptionformat' => [
|
||||
'type' => PARAM_INT,
|
||||
'default' => FORMAT_MOODLE,
|
||||
'optional' => true
|
||||
'optional' => true,
|
||||
'null' => NULL_ALLOWED,
|
||||
],
|
||||
'component' => [
|
||||
'type' => PARAM_COMPONENT
|
||||
@ -80,7 +71,8 @@ class category extends persistent {
|
||||
'sortorder' => [
|
||||
'type' => PARAM_INT,
|
||||
'optional' => true,
|
||||
'default' => -1
|
||||
'default' => -1,
|
||||
'null' => NULL_ALLOWED,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
@ -14,24 +14,14 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Field persistent class
|
||||
*
|
||||
* @package core_customfield
|
||||
* @copyright 2018 Toni Barbera <toni@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace core_customfield;
|
||||
|
||||
use core\persistent;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
/**
|
||||
* Class field
|
||||
* Customfield field persistent class
|
||||
*
|
||||
* @package core_customfield
|
||||
* @package core_customfield
|
||||
* @copyright 2018 Toni Barbera <toni@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
@ -67,12 +57,14 @@ class field extends persistent {
|
||||
'descriptionformat' => [
|
||||
'type' => PARAM_INT,
|
||||
'default' => FORMAT_MOODLE,
|
||||
'optional' => true
|
||||
'optional' => true,
|
||||
'null' => NULL_ALLOWED,
|
||||
],
|
||||
'sortorder' => [
|
||||
'type' => PARAM_INT,
|
||||
'optional' => true,
|
||||
'default' => -1,
|
||||
'null' => NULL_ALLOWED,
|
||||
],
|
||||
'categoryid' => [
|
||||
'type' => PARAM_INT
|
||||
|
@ -25,6 +25,7 @@ use core_customfield_generator;
|
||||
* @category test
|
||||
* @copyright 2018 Toni Barbera <toni@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @covers \core_customfield\category_controller
|
||||
*/
|
||||
class category_controller_test extends \advanced_testcase {
|
||||
|
||||
@ -61,6 +62,29 @@ class category_controller_test extends \advanced_testcase {
|
||||
$this->assertTrue($c instanceof category_controller);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test creation of category instance from pre-defined object
|
||||
*/
|
||||
public function test_constructor_from_record(): void {
|
||||
$this->resetAfterTest();
|
||||
|
||||
// Create field object that matches the persistent/schema definition.
|
||||
$category = category_controller::create(0, (object) [
|
||||
'name' => 'Test',
|
||||
'description' => null,
|
||||
'descriptionformat' => null,
|
||||
'component' => 'core_course',
|
||||
'area' => 'course',
|
||||
'itemid' => 0,
|
||||
'sortorder' => null,
|
||||
]);
|
||||
|
||||
// Saving the category will validate the persistent internally.
|
||||
$category->save();
|
||||
|
||||
$this->assertInstanceOf(category_controller::class, $category);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for function \core_customfield\field_controller::create() in case of wrong parameters
|
||||
*/
|
||||
|
@ -30,6 +30,7 @@ use customfield_textarea;
|
||||
* @category test
|
||||
* @copyright 2018 Ruslan Kabalin
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @covers \core_customfield\field_controller
|
||||
*/
|
||||
class field_controller_test extends \advanced_testcase {
|
||||
|
||||
@ -89,6 +90,30 @@ class field_controller_test extends \advanced_testcase {
|
||||
field_controller::create(0, $fieldrecord, $category0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test creation of field instance from pre-defined object
|
||||
*/
|
||||
public function test_constructor_from_record(): void {
|
||||
$this->resetAfterTest();
|
||||
|
||||
// Create field object that matches the persistent/schema definition.
|
||||
$category = $this->get_generator()->create_category();
|
||||
$field = field_controller::create(0, (object) [
|
||||
'name' => 'Test',
|
||||
'shortname' => 'test',
|
||||
'type' => 'text',
|
||||
'description' => null,
|
||||
'descriptionformat' => null,
|
||||
'sortorder' => null,
|
||||
'configdata' => null,
|
||||
], $category);
|
||||
|
||||
// Saving the field will validate the persistent internally.
|
||||
$field->save();
|
||||
|
||||
$this->assertInstanceOf(\customfield_text\field_controller::class, $field);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for function \core_customfield\field_controller::create() in case of wrong parameters
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user