From def6645cdcaeec7db891ccacf84cd7c44241becf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Massart?= Date: Mon, 19 Dec 2022 15:45:30 +0800 Subject: [PATCH] MDL-76723 core_external: Test invalid required value for format fields --- lib/tests/exporter_test.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/tests/exporter_test.php b/lib/tests/exporter_test.php index bbcf5b43331..edb1e5ae93f 100644 --- a/lib/tests/exporter_test.php +++ b/lib/tests/exporter_test.php @@ -202,6 +202,26 @@ class exporter_test extends \advanced_testcase { // Assert nested elements are formatted correctly. $this->assertEquals('id', $properties['nestedarray']['type']['id']['description']); } + + public function test_format_properties_with_optional() { + $testable = new class([]) extends \core\external\exporter { + public static function define_properties() { + return [ + 'content' => [ + 'type' => PARAM_RAW, + 'optional' => true, + ], + 'contentformat' => [ + 'type' => PARAM_INT, + 'optional' => true, + ] + ]; + } + }; + $definition = $testable::get_read_structure(); + $this->assertEquals(VALUE_OPTIONAL, $definition->keys['content']->required); + $this->assertEquals(VALUE_OPTIONAL, $definition->keys['contentformat']->required); + } } /**