Skip to content

Commit

Permalink
Merge pull request #2886 from mpcjanssen/issue2883
Browse files Browse the repository at this point in the history
Fix issue #2883: XMLRPC doesn't return dates in iso8601 format
  • Loading branch information
phy25 committed Oct 20, 2019
2 parents 2b5dd8f + 2c849d6 commit 85f3a4c
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 3 deletions.
69 changes: 69 additions & 0 deletions _test/tests/inc/XmlRpcServer.test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

use dokuwiki\Remote\XmlRpcServer;

class XmlRpcServerTestWrapper extends XmlRpcServer
{
public $output;

public function output($xml) {
$this->output = $xml;
}
}

class XmlRpcServerTest extends DokuWikiTest
{
protected $server;

function setUp()
{
parent::setUp();
global $conf;

$conf['remote'] = 1;
$conf['remoteuser'] = '';
$conf['useacl'] = 0;

$this->server = new XmlRpcServerTestWrapper(true);
}


function testDateFormat()
{
$pageName = ":wiki:dokuwiki";
$file = wikiFN($pageName);
$timestamp = filemtime($file);
$ixrModifiedTime = (new DateTime('@' . $timestamp))->format(IXR_Date::XMLRPC_ISO8601);

$request = <<<EOD
<?xml version="1.0"?>
<methodCall>
<methodName>wiki.getPageInfo</methodName>
<param>
<value>
<string>$pageName</string>
</value>
</param>
</methodCall>
EOD;
$expected = <<<EOD
<methodResponse>
<params>
<param>
<value>
<struct>
<member><name>name</name><value><string>wiki:dokuwiki</string></value></member>
<member><name>lastModified</name><value><dateTime.iso8601>$ixrModifiedTime</dateTime.iso8601></value></member>
<member><name>author</name><value><string></string></value></member>
<member><name>version</name><value><int>$timestamp</int></value></member>
</struct>
</value>
</param>
</params>
</methodResponse>
EOD;

$this->server->serve($request);
$this->assertEquals(trim($expected), trim($this->server->output));
}
}
3 changes: 2 additions & 1 deletion inc/IXR_Library.php
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,7 @@ function getXml() {
*/
class IXR_Date {

const XMLRPC_ISO8601 = "Ymd\TH:i:sO" ;
/** @var DateTime */
protected $date;

Expand Down Expand Up @@ -861,7 +862,7 @@ protected function parseIso($iso) {
* @return string
*/
public function getIso() {
return $this->date->format(DateTime::ISO8601);
return $this->date->format(self::XMLRPC_ISO8601);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions inc/Remote/XmlRpcServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ class XmlRpcServer extends \IXR_Server
/**
* Constructor. Register methods and run Server
*/
public function __construct()
public function __construct($wait=false)
{
$this->remote = new Api();
$this->remote->setDateTransformation(array($this, 'toDate'));
$this->remote->setFileTransformation(array($this, 'toFile'));
parent::__construct();
parent::__construct(false, false, $wait);
}

/**
Expand Down

0 comments on commit 85f3a4c

Please sign in to comment.