Skip to content

Commit

Permalink
Fix tests v10
Browse files Browse the repository at this point in the history
  • Loading branch information
NielBuys committed Dec 20, 2024
1 parent cb54871 commit 6a13906
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 30 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"scripts": {
"test:coverage": [
"@putenv XDEBUG_MODE=coverage",
"phpunit --color=always --coverage-text --configuration tests/travis/sqlite.phpunit.xml"
"phpunit --color=always --coverage-text --configuration tests/phpunit.xml"
],
"post-install-cmd": [
"sed -i s/name{0}/name[0]/ vendor/mikey179/vfsstream/src/main/php/org/bovigo/vfs/vfsStream.php"
Expand Down
19 changes: 9 additions & 10 deletions system/libraries/Xmlrpc.php
Original file line number Diff line number Diff line change
Expand Up @@ -1152,20 +1152,19 @@ public function parseResponse($fp)
// Create and Set Up XML Parser
//-------------------------------------

$parser = xml_parser_create($this->xmlrpc_defencoding);
$this->xh = array(
'isf' => 0,
'ac' => '',
'headers' => array(),
'stack' => array(),
'valuestack' => array(),
'isf_reason' => 0
);
$parser = xml_parser_create($this->xmlrpc_defencoding);
$this->xh = array(
'isf' => 0,
'ac' => '',
'headers' => array(),
'stack' => array(),
'valuestack' => array(),
'isf_reason' => 0
);

xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, true);
xml_set_element_handler($parser, [$this, 'open_tag'], [$this, 'closing_tag']);
xml_set_character_data_handler($parser, [$this, 'character_data']);

//xml_set_default_handler($parser, 'default_handler');

// Get headers
Expand Down
27 changes: 14 additions & 13 deletions system/libraries/Xmlrpcs.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,21 +232,22 @@ public function parseRequest($data = '')
// Set up XML Parser
//-------------------------------------

$parser = xml_parser_create($this->xmlrpc_defencoding);
$parser_object = new XML_RPC_Message('filler');

$parser_object->xh = array(
'isf' => 0,
'isf_reason' => '',
'params' => array(),
'stack' => array(),
'valuestack' => array(),
'method' => ''
);
$parser = xml_parser_create($this->xmlrpc_defencoding);
$parser_object = new XML_RPC_Message('default_method', FALSE);

$parser_object->xh = array(
'isf' => 0,
'isf_reason' => '',
'params' => array(),
'stack' => array(),
'valuestack' => array(),
'method' => ''
);

xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, true);
xml_set_element_handler($parser, [$this, 'open_tag'], [$this, 'closing_tag']);
xml_set_character_data_handler($parser, [$this, 'character_data']);
xml_set_element_handler($parser, [$parser_object, 'open_tag'], [$parser_object, 'closing_tag']);
xml_set_character_data_handler($parser, [$parser_object, 'character_data']);

//xml_set_default_handler($parser, 'default_handler');

//-------------------------------------
Expand Down
39 changes: 33 additions & 6 deletions tests/mocks/libraries/xmlrpcs.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,42 @@ class Mock_Libraries_Xmlrpcs extends CI_Xmlrpcs {
public function serve()
{
$r = $this->parseRequest();

$payload = '<?xml version="1.0" encoding="'.$this->xmlrpc_defencoding.'"?'.'>'."\n".$this->debug_msg.$r->prepare_response();


if (isset($r->method_name) && isset($this->config['functions'][$r->method_name])) {
$callback = $this->config['functions'][$r->method_name]['function'];
if (is_callable($callback)) {
call_user_func($callback, $r->parameters);
} else {
throw new Exception('Invalid callback: ' . $callback);
}
}

$payload = '<?xml version="1.0" encoding="' . $this->xmlrpc_defencoding . '"?>' . "\n" .
$this->debug_msg . $r->prepare_response();

$this->mock_payload = "HTTP/1.1 200 OK\r\n";
$this->mock_payload .= "Content-Type: text/xml\r\n";
$this->mock_payload .= 'Content-Length: '.strlen($payload)."\r\n";

$this->mock_payload .= 'Content-Length: ' . strlen($payload) . "\r\n";
$this->mock_payload .= "\r\n";

$this->mock_payload .= $payload;
}

/**
* Mock XML request (example)
*/
public function xml_request()
{
// Return a mock XML request
return '<?xml version="1.0"?>
<methodCall>
<methodName>Testmethod</methodName>
<params>
<param>
<value>
<string>Test</string>
</value>
</param>
</params>
</methodCall>';
}
}

0 comments on commit 6a13906

Please sign in to comment.