mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2024-12-22 21:22:40 +00:00
parent
2d18be959c
commit
0480465e7e
3 changed files with 22 additions and 6 deletions
|
@ -188,7 +188,7 @@ class API extends \JKingWeb\Arsse\REST\AbstractHandler {
|
|||
$d = $p->ownerDocument;
|
||||
foreach ($data as $k => $v) {
|
||||
if (!is_array($v)) {
|
||||
$p->appendChild($d->createElement($k, $v));
|
||||
$p->appendChild($d->createElement($k, (string) $v));
|
||||
} elseif (isset($v[0])) {
|
||||
// this is a very simplistic check for an indexed array
|
||||
// it would not pass muster in the face of generic data,
|
||||
|
@ -206,9 +206,11 @@ class API extends \JKingWeb\Arsse\REST\AbstractHandler {
|
|||
$d = $p->ownerDocument;
|
||||
foreach ($data as $v) {
|
||||
if (!is_array($v)) {
|
||||
$p->appendChild($d->createElement($k, $v));
|
||||
// this case is never encountered with Fever's output
|
||||
$p->appendChild($d->createElement($k, (string) $v)); // @codeCoverageIgnore
|
||||
} elseif (isset($v[0])) {
|
||||
$p->appendChild($this->makeXMLIndexed($v, $d->createElement($k), substr($k, 0, strlen($k) - 1)));
|
||||
// this case is never encountered with Fever's output
|
||||
$p->appendChild($this->makeXMLIndexed($v, $d->createElement($k), substr($k, 0, strlen($k) - 1))); // @codeCoverageIgnore
|
||||
} else {
|
||||
$p->appendChild($this->makeXMLAssoc($v, $d->createElement($k)));
|
||||
}
|
||||
|
|
|
@ -17,11 +17,14 @@ use JKingWeb\Arsse\REST\Fever\API;
|
|||
use Psr\Http\Message\ResponseInterface;
|
||||
use Zend\Diactoros\ServerRequest;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
use Zend\Diactoros\Response\XmlResponse;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
use PHPUnit\Util\Json;
|
||||
|
||||
/** @covers \JKingWeb\Arsse\REST\Fever\API<extended> */
|
||||
class TestAPI extends \JKingWeb\Arsse\Test\AbstractTest {
|
||||
/** @var \JKingWeb\Arsse\REST\Fever\API */
|
||||
protected $h;
|
||||
|
||||
protected $articles = [
|
||||
'db' => [
|
||||
[
|
||||
|
@ -483,4 +486,14 @@ class TestAPI extends \JKingWeb\Arsse\Test\AbstractTest {
|
|||
$this->assertMessage($exp, $act);
|
||||
\Phake::verify(Arsse::$db)->articleMark; // only called one time, above
|
||||
}
|
||||
|
||||
public function testOutputToXml() {
|
||||
\Phake::when($this->h)->processRequest->thenReturn([
|
||||
'items' => $this->articles['rest'],
|
||||
'total_items' => 1024,
|
||||
]);
|
||||
$exp = new XmlResponse("<response><items><item><id>101</id><feed_id>8</feed_id><title>Article title 1</title><author></author><html><p>Article content 1</p></html><url>http://example.com/1</url><is_saved>0</is_saved><is_read>0</is_read><created_on_time>946684800</created_on_time></item><item><id>102</id><feed_id>8</feed_id><title>Article title 2</title><author></author><html><p>Article content 2</p></html><url>http://example.com/2</url><is_saved>0</is_saved><is_read>1</is_read><created_on_time>946771200</created_on_time></item><item><id>103</id><feed_id>9</feed_id><title>Article title 3</title><author></author><html><p>Article content 3</p></html><url>http://example.com/3</url><is_saved>1</is_saved><is_read>0</is_read><created_on_time>946857600</created_on_time></item><item><id>104</id><feed_id>9</feed_id><title>Article title 4</title><author></author><html><p>Article content 4</p></html><url>http://example.com/4</url><is_saved>1</is_saved><is_read>1</is_read><created_on_time>946944000</created_on_time></item><item><id>105</id><feed_id>10</feed_id><title>Article title 5</title><author></author><html><p>Article content 5</p></html><url>http://example.com/5</url><is_saved>0</is_saved><is_read>0</is_read><created_on_time>947030400</created_on_time></item></items><total_items>1024</total_items></response>");
|
||||
$act = $this->h->dispatch($this->req("api=xml"));
|
||||
$this->assertMessage($exp, $act);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,14 +9,13 @@ namespace JKingWeb\Arsse\Test;
|
|||
use JKingWeb\Arsse\Exception;
|
||||
use JKingWeb\Arsse\Arsse;
|
||||
use JKingWeb\Arsse\Conf;
|
||||
use JKingWeb\Arsse\CLI;
|
||||
use JKingWeb\Arsse\Misc\Date;
|
||||
use Psr\Http\Message\MessageInterface;
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
use Zend\Diactoros\Response\XmlResponse;
|
||||
|
||||
/** @coversNothing */
|
||||
abstract class AbstractTest extends \PHPUnit\Framework\TestCase {
|
||||
|
@ -93,6 +92,8 @@ abstract class AbstractTest extends \PHPUnit\Framework\TestCase {
|
|||
if ($exp instanceof JsonResponse) {
|
||||
$this->assertEquals($exp->getPayload(), $act->getPayload(), $text);
|
||||
$this->assertSame($exp->getPayload(), $act->getPayload(), $text);
|
||||
} elseif ($exp instanceof XmlResponse) {
|
||||
$this->assertXmlStringEqualsXmlString((string) $exp->getBody(), (string) $act->getBody(), $text);
|
||||
} else {
|
||||
$this->assertEquals((string) $exp->getBody(), (string) $act->getBody(), $text);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue