From 77cfbb626edb8fa4cf197e0895c576a687a0a1c8 Mon Sep 17 00:00:00 2001 From: Juan Leyva Date: Thu, 15 Aug 2019 13:29:16 +0100 Subject: [PATCH] MDL-66229 tool_mobile: New return field "disabled" in get_content WS --- admin/tool/mobile/classes/external.php | 8 ++++--- admin/tool/mobile/tests/externallib_test.php | 13 ++++++++++ .../mobile/tests/fixtures/output/mobile.php | 24 ++++++++++++++++++- 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/admin/tool/mobile/classes/external.php b/admin/tool/mobile/classes/external.php index e9d1c672021..73c81ffbeef 100644 --- a/admin/tool/mobile/classes/external.php +++ b/admin/tool/mobile/classes/external.php @@ -369,12 +369,12 @@ class external extends external_api { /** * Returns a piece of content to be displayed in the Mobile app, it usually returns a template, javascript and - * other structured data that will be used to render a view in the Mobile app.. + * other structured data that will be used to render a view in the Mobile app. * * Callbacks (placed in \$component\output\mobile) that are called by this web service are responsible for doing the * appropriate security checks to access the information to be returned. * - * @param string $component fame of the component. + * @param string $component name of the component. * @param string $method function method name in class \$component\output\mobile. * @param array $args optional arguments for the method. * @return array HTML, JavaScript and other required data and information to create a view in the app. @@ -423,6 +423,7 @@ class external extends external_api { 'otherdata' => $otherdata, 'files' => !empty($result['files']) ? $result['files'] : array(), 'restrict' => !empty($result['restrict']) ? $result['restrict'] : array(), + 'disabled' => !empty($result['disabled']) ? true : false, ); } @@ -465,7 +466,8 @@ class external extends external_api { ), ), 'Restrict this content to certain users or courses.' - ) + ), + 'disabled' => new external_value(PARAM_BOOL, 'Whether we consider this disabled or not.', VALUE_OPTIONAL), ) ); } diff --git a/admin/tool/mobile/tests/externallib_test.php b/admin/tool/mobile/tests/externallib_test.php index 6bfea7f165e..955fbb985e2 100644 --- a/admin/tool/mobile/tests/externallib_test.php +++ b/admin/tool/mobile/tests/externallib_test.php @@ -371,6 +371,19 @@ class tool_mobile_external_testcase extends externallib_advanced_testcase { $this->assertEquals(array(1, 2), $result['restrict']['users']); $this->assertEquals(array(3, 4), $result['restrict']['courses']); $this->assertEmpty($result['files']); + $this->assertFalse($result['disabled']); + } + + /** + * Test get_content disabled. + */ + public function test_get_content_disabled() { + + $paramval = 16; + $result = external::get_content('tool_mobile', 'test_view_disabled', + array(array('name' => 'param1', 'value' => $paramval))); + $result = external_api::clean_returnvalue(external::get_content_returns(), $result); + $this->assertTrue($result['disabled']); } /** diff --git a/admin/tool/mobile/tests/fixtures/output/mobile.php b/admin/tool/mobile/tests/fixtures/output/mobile.php index d803743f35d..451b00fb8d3 100644 --- a/admin/tool/mobile/tests/fixtures/output/mobile.php +++ b/admin/tool/mobile/tests/fixtures/output/mobile.php @@ -38,7 +38,6 @@ class mobile { /** * Returns a test view. * @param array $args Arguments from tool_mobile_get_content WS - * * @return array HTML, javascript and otherdata */ public static function test_view($args) { @@ -57,4 +56,27 @@ class mobile { 'files' => array() ); } + + /** + * Returns a test view disabled. + * @param array $args Arguments from tool_mobile_get_content WS + * @return array HTML, javascript and otherdata + */ + public static function test_view_disabled($args) { + $args = (object) $args; + + return array( + 'templates' => array( + array( + 'id' => 'main', + 'html' => 'The HTML code', + ), + ), + 'javascript' => 'alert();', + 'otherdata' => array('otherdata1' => $args->param1), + 'restrict' => array('users' => array(1, 2), 'courses' => array(3, 4)), + 'files' => array(), + 'disabled' => true, + ); + } }