/**
  * Test get_string
  */
 public function test_get_string()
 {
     $this->resetAfterTest(true);
     $service = new stdClass();
     $service->name = 'Dummy Service';
     $service->id = 12;
     // String with two parameters.
     $returnedstring = core_external::get_string('addservice', 'webservice', array(array('name' => 'name', 'value' => $service->name), array('name' => 'id', 'value' => $service->id)));
     // We need to execute the return values cleaning process to simulate the web service server.
     $returnedstring = external_api::clean_returnvalue(core_external::get_string_returns(), $returnedstring);
     $corestring = get_string('addservice', 'webservice', $service);
     $this->assertEquals($corestring, $returnedstring);
     // String with one parameter.
     $acapname = 'A capability name';
     $returnedstring = core_external::get_string('missingrequiredcapability', 'webservice', array(array('value' => $acapname)));
     // We need to execute the return values cleaning process to simulate the web service server.
     $returnedstring = external_api::clean_returnvalue(core_external::get_string_returns(), $returnedstring);
     $corestring = get_string('missingrequiredcapability', 'webservice', $acapname);
     $this->assertEquals($corestring, $returnedstring);
     // String without parameters.
     $returnedstring = core_external::get_string('missingpassword', 'webservice');
     // We need to execute the return values cleaning process to simulate the web service server.
     $returnedstring = external_api::clean_returnvalue(core_external::get_string_returns(), $returnedstring);
     $corestring = get_string('missingpassword', 'webservice');
     $this->assertEquals($corestring, $returnedstring);
     // String with two parameter but one is invalid (not named).
     $this->setExpectedException('moodle_exception');
     $returnedstring = core_external::get_string('addservice', 'webservice', array(array('value' => $service->name), array('name' => 'id', 'value' => $service->id)));
 }
Beispiel #2
0
 /**
  * Test get_string with arguments containing HTML.
  */
 public function test_get_string_with_args_containing_html()
 {
     $result = core_external::get_string('added', 'moodle', null, [['value' => '<strong>Test</strong>']]);
     $actual = external_api::clean_returnvalue(core_external::get_string_returns(), $result);
     $expected = get_string('added', 'moodle', '<strong>Test</strong>');
     $this->assertSame($expected, $actual);
 }