mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 05:58:34 +01:00
Merge branch 'MDL-75085-master-4' of https://github.com/junpataleta/moodle
This commit is contained in:
commit
7ceb00f887
@ -345,6 +345,7 @@ class core_completion_external extends external_api {
|
||||
)
|
||||
]
|
||||
),
|
||||
'Completion status details',
|
||||
VALUE_DEFAULT,
|
||||
[]
|
||||
),
|
||||
|
@ -488,6 +488,7 @@ class core_course_external extends external_api {
|
||||
'dataid' => new external_value(PARAM_NOTAGS, 'cm data id', VALUE_OPTIONAL),
|
||||
)
|
||||
),
|
||||
'Course dates',
|
||||
VALUE_DEFAULT,
|
||||
[]
|
||||
),
|
||||
@ -519,7 +520,7 @@ class core_course_external extends external_api {
|
||||
VALUE_OPTIONAL
|
||||
),
|
||||
)
|
||||
), VALUE_DEFAULT, array()
|
||||
), 'Course contents', VALUE_DEFAULT, array()
|
||||
),
|
||||
'contentsinfo' => new external_single_structure(
|
||||
array(
|
||||
@ -1310,7 +1311,7 @@ class core_course_external extends external_api {
|
||||
'value' => new external_value(PARAM_RAW, 'the value for the option 1 (yes) or 0 (no)'
|
||||
)
|
||||
)
|
||||
), VALUE_DEFAULT, array()
|
||||
), 'Course duplication options', VALUE_DEFAULT, array()
|
||||
),
|
||||
)
|
||||
);
|
||||
@ -1537,7 +1538,7 @@ class core_course_external extends external_api {
|
||||
'value' => new external_value(PARAM_RAW, 'the value for the option 1 (yes) or 0 (no)'
|
||||
)
|
||||
)
|
||||
), VALUE_DEFAULT, array()
|
||||
), 'Course import options', VALUE_DEFAULT, array()
|
||||
),
|
||||
)
|
||||
);
|
||||
|
10
lib/external/classes/external_description.php
vendored
10
lib/external/classes/external_description.php
vendored
@ -37,10 +37,18 @@ abstract class external_description {
|
||||
* Contructor.
|
||||
*
|
||||
* @param string $desc Description of element
|
||||
* @param int $required Whethe the element value is required
|
||||
* @param int $required Whether the element value is required. Valid values are VALUE_DEFAULT, VALUE_REQUIRED, VALUE_OPTIONAL.
|
||||
* @param mixed $default The default value
|
||||
*/
|
||||
public function __construct($desc, $required, $default) {
|
||||
if (!in_array($required, [VALUE_DEFAULT, VALUE_REQUIRED, VALUE_OPTIONAL], true)) {
|
||||
$requiredstr = $required;
|
||||
if (is_array($required)) {
|
||||
$requiredstr = "Array: " . implode(" ", $required);
|
||||
}
|
||||
debugging("Invalid \$required parameter value: '{$requiredstr}'.
|
||||
It must be either VALUE_DEFAULT, VALUE_REQUIRED, or VALUE_OPTIONAL", DEBUG_DEVELOPER);
|
||||
}
|
||||
$this->desc = $desc;
|
||||
$this->required = $required;
|
||||
$this->default = $default;
|
||||
|
4
lib/external/tests/external_api_test.php
vendored
4
lib/external/tests/external_api_test.php
vendored
@ -61,7 +61,7 @@ class external_api_test extends \advanced_testcase {
|
||||
|
||||
$params = ['text' => 'aaa'];
|
||||
$description = new external_function_parameters([
|
||||
'someid' => new external_value(PARAM_INT, 'Some int value', false),
|
||||
'someid' => new external_value(PARAM_INT, 'Some int value', VALUE_DEFAULT),
|
||||
'text' => new external_value(PARAM_ALPHA, 'Some text value'),
|
||||
]);
|
||||
$result = external_api::validate_parameters($description, $params);
|
||||
@ -73,7 +73,7 @@ class external_api_test extends \advanced_testcase {
|
||||
|
||||
$params = ['text' => 'aaa'];
|
||||
$description = new external_function_parameters([
|
||||
'someid' => new external_value(PARAM_INT, 'Some int value', false, 6),
|
||||
'someid' => new external_value(PARAM_INT, 'Some int value', VALUE_DEFAULT, 6),
|
||||
'text' => new external_value(PARAM_ALPHA, 'Some text value'),
|
||||
]);
|
||||
$result = external_api::validate_parameters($description, $params);
|
||||
|
67
lib/external/tests/external_value_test.php
vendored
Normal file
67
lib/external/tests/external_value_test.php
vendored
Normal file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
namespace core_external;
|
||||
|
||||
use advanced_testcase;
|
||||
|
||||
/**
|
||||
* Unit tests for core_external\external_description.
|
||||
*
|
||||
* @package core
|
||||
* @category test
|
||||
* @copyright 2023 Jun Pataleta
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @coversDefaultClass external_value
|
||||
*/
|
||||
class external_value_test extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Data provider for the required param test.
|
||||
*
|
||||
* @return array[]
|
||||
*/
|
||||
public function required_param_provider(): array {
|
||||
return [
|
||||
[ VALUE_DEFAULT, false ],
|
||||
[ VALUE_REQUIRED, false ],
|
||||
[ VALUE_OPTIONAL, false ],
|
||||
[ 'aaa', true, 'aaa' ],
|
||||
[ [VALUE_OPTIONAL], true, 'Array: ' . VALUE_OPTIONAL ],
|
||||
[ -1000, true, -1000 ],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the constructor for the $required parameter validation.
|
||||
*
|
||||
* @dataProvider required_param_provider
|
||||
* @param int $required The required param being tested.
|
||||
* @param bool $debuggingexpected Whether debugging is expected.
|
||||
* @param mixed $requiredstr The string value of the $required param in the debugging message.
|
||||
* @return void
|
||||
*/
|
||||
public function test_required_param_validation($required, $debuggingexpected, $requiredstr = '') {
|
||||
$externalvalue = new external_value(PARAM_INT, 'Cool description', $required);
|
||||
if ($debuggingexpected) {
|
||||
$this->assertDebuggingCalled("Invalid \$required parameter value: '{$requiredstr}'.
|
||||
It must be either VALUE_DEFAULT, VALUE_REQUIRED, or VALUE_OPTIONAL", DEBUG_DEVELOPER);
|
||||
}
|
||||
$this->assertEquals(PARAM_INT, $externalvalue->type);
|
||||
$this->assertEquals('Cool description', $externalvalue->desc);
|
||||
$this->assertEquals($required, $externalvalue->required);
|
||||
}
|
||||
}
|
@ -57,6 +57,9 @@ information provided here is intended especially for developers.
|
||||
The old class locations have been aliased for backwards compatibility and will emit a deprecation notice in a future
|
||||
release.
|
||||
* Convert a floating value to an integer in lib/graphlib.php to avoid PHP 8.1 deprecated function error.
|
||||
* The $required parameter for \core_external\external_description is now being validated in order to prevent
|
||||
unintentionally passing incorrect parameters to the external_description's (and its subclasses') constructors (e.g. the parameter
|
||||
description being incorrectly passed for the $required parameter). A debugging notice will be shown when such cases occur.
|
||||
|
||||
=== 4.1 ===
|
||||
|
||||
|
@ -193,7 +193,7 @@ class mod_page_external extends external_api {
|
||||
helper_for_get_mods_by_courses::standard_coursemodule_elements_returns(),
|
||||
[
|
||||
'content' => new external_value(PARAM_RAW, 'Page content'),
|
||||
'contentformat' => new external_format_value('content', 'Content format'),
|
||||
'contentformat' => new external_format_value('content', VALUE_REQUIRED, 'Content format'),
|
||||
'contentfiles' => new external_files('Files in the content'),
|
||||
'legacyfiles' => new external_value(PARAM_INT, 'Legacy files flag'),
|
||||
'legacyfileslast' => new external_value(PARAM_INT, 'Legacy files last control flag'),
|
||||
|
@ -242,7 +242,7 @@ class core_tag_external extends external_api {
|
||||
'name' => new external_value(PARAM_TAG, 'name'),
|
||||
'rawname' => new external_value(PARAM_RAW, 'tag raw name (may contain capital letters)'),
|
||||
'description' => new external_value(PARAM_RAW, 'tag description'),
|
||||
'descriptionformat' => new external_format_value(PARAM_INT, 'tag description format'),
|
||||
'descriptionformat' => new external_format_value(PARAM_INT, VALUE_REQUIRED, 'tag description format'),
|
||||
'flag' => new external_value(PARAM_INT, 'flag', VALUE_OPTIONAL),
|
||||
'official' => new external_value(PARAM_INT,
|
||||
'whether this flag is standard (deprecated, use isstandard)', VALUE_OPTIONAL),
|
||||
|
Loading…
x
Reference in New Issue
Block a user