|
28 | 28 |
|
29 | 29 | use OC\AppFramework\OCS\BaseResponse; |
30 | 30 |
|
| 31 | +class ArrayValue implements \JsonSerializable { |
| 32 | + private $array; |
| 33 | + public function __construct(array $array) { |
| 34 | + $this->array = $array; |
| 35 | + } |
| 36 | + |
| 37 | + public function jsonSerialize(): mixed { |
| 38 | + return $this->array; |
| 39 | + } |
| 40 | +} |
| 41 | + |
31 | 42 | class BaseResponseTest extends \Test\TestCase { |
32 | 43 | public function testToXml(): void { |
33 | 44 | /** @var BaseResponse $response */ |
@@ -56,4 +67,32 @@ public function testToXml(): void { |
56 | 67 | $writer->outputMemory(true) |
57 | 68 | ); |
58 | 69 | } |
| 70 | + |
| 71 | + public function testToXmlJsonSerializable(): void { |
| 72 | + /** @var BaseResponse $response */ |
| 73 | + $response = $this->createMock(BaseResponse::class); |
| 74 | + |
| 75 | + $writer = new \XMLWriter(); |
| 76 | + $writer->openMemory(); |
| 77 | + $writer->setIndent(false); |
| 78 | + $writer->startDocument(); |
| 79 | + |
| 80 | + $data = [ |
| 81 | + 'hello' => 'hello', |
| 82 | + 'information' => new ArrayValue([ |
| 83 | + '@test' => 'some data', |
| 84 | + 'someElement' => 'withAttribute', |
| 85 | + ]), |
| 86 | + 'value without key', |
| 87 | + 'object' => new \stdClass(), |
| 88 | + ]; |
| 89 | + |
| 90 | + $this->invokePrivate($response, 'toXml', [$data, $writer]); |
| 91 | + $writer->endDocument(); |
| 92 | + |
| 93 | + $this->assertEquals( |
| 94 | + "<?xml version=\"1.0\"?>\n<hello>hello</hello><information test=\"some data\"><someElement>withAttribute</someElement></information><element>value without key</element><object/>\n", |
| 95 | + $writer->outputMemory(true) |
| 96 | + ); |
| 97 | + } |
59 | 98 | } |
0 commit comments