Merge branch 'MDL-83094-404' of https://github.com/paulholden/moodle into MOODLE_404_STABLE

This commit is contained in:
Andrew Nicols 2024-09-27 11:05:55 +08:00
commit 9f3174a32d
No known key found for this signature in database
GPG Key ID: 6D1E3157C8CFBF14
4 changed files with 60 additions and 27 deletions

View File

@ -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,
],
);
}

View File

@ -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

View File

@ -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
*/

View File

@ -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
*/