/**
  * Ensure get/set message data is functioning as expected.
  */
 public function test_get_message_data()
 {
     $data = (object) array('foo' => 'bar', 'bat' => 'baz');
     /** @var unknown_service_api_called $event */
     $event = unknown_service_api_called::create();
     $event->set_message_data($data);
     $this->assertSame($data, $event->get_message_data());
 }
    public function test_get_message_data()
    {
        $xml = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<foo>
    <bar>baz</bar>
</foo>
XML;
        /** @var unknown_service_api_called $event */
        $event = unknown_service_api_called::create(array('other' => array('rawbody' => $xml, 'foo' => 'bar')));
        $data = $event->get_message_data();
        $this->assertInstanceOf('stdClass', $data);
        $this->assertCount(3, get_object_vars($data));
        $this->assertEquals('bar', $data->foo);
        $this->assertEquals($xml, $data->rawbody);
        $this->assertInstanceOf('SimpleXMLElement', $data->xml);
        $this->assertXmlStringEqualsXmlString($xml, $data->xml->asXML());
    }
예제 #3
0
        $data->xml = $xml;
        $data->messageid = lti_parse_message_id($xml);
        $data->messagetype = $messagetype;
        $data->consumerkey = $consumerkey;
        $data->sharedsecret = $sharedsecret;
        $eventdata = array();
        $eventdata['other'] = array();
        $eventdata['other']['messageid'] = $data->messageid;
        $eventdata['other']['messagetype'] = $messagetype;
        $eventdata['other']['consumerkey'] = $consumerkey;
        // Before firing the event, allow subplugins a chance to handle.
        if (lti_extend_lti_services($data)) {
            break;
        }
        // If an event handler handles the web service, it should set this global to true
        // So this code knows whether to send an "operation not supported" or not.
        global $ltiwebservicehandled;
        $ltiwebservicehandled = false;
        try {
            $event = \mod_lti\event\unknown_service_api_called::create($eventdata);
            $event->set_message_data($data);
            $event->trigger();
        } catch (Exception $e) {
            $ltiwebservicehandled = false;
        }
        if (!$ltiwebservicehandled) {
            $responsexml = lti_get_response_xml('unsupported', 'unsupported', lti_parse_message_id($xml), $messagetype);
            echo $responsexml->asXML();
        }
        break;
}