aboutsummaryrefslogblamecommitdiffstats
path: root/tests/unit/XmlRpcTest.php
blob: 25dc18646fac54a7c72b395f30902db92ada1583 (plain) (tree)
























                                                                                       






















                                                                     
 
<?php

// SPDX-FileCopyrightText: 2024 Eilertsens Kodeknekkeri
// SPDX-FileCopyrightText: 2024 Harald Eilertsen
//
// SPDX-License-Identifier: AGPL-3.0-or-later

namespace VolseNet\Webtrap\Tests\Unit;

use PHPUnit\Framework\TestCase;
use VolseNet\Webtrap\XmlRpcMethod;

class XmlRpcTest extends TestCase
{
    public function testGetUserBlog(): void
    {
        $payload = '<methodCall><methodName>wp.getUsersBlogs</methodName>'
            . '<params><param><value>someuser</value></param>'
            . '<param><value>verysecretpassword</value></param></params></methodCall>';

        $method = XmlRpcMethod::parse($payload);

        $this->assertEquals('wp.getUsersBlogs', $method->name);
        $this->assertEquals(['someuser', 'verysecretpassword'], $method->params);
    }

    public function testShouldNotExpandEntities(): void
    {
        $payload = <<<'XML'
            <!DOCTYPE foo [ <!ENTITY xxx "expanded entity"> ]>
            <methodCall>
                <methodName>&xxx;</methodName>
            </methodCall>
            XML;

        $method = XmlRpcMethod::parse($payload);

        $this->assertNull($method);
    }

    public function testInvalidXMLShouldThrowRuntimeException(): void
    {
        $payload = '<someTag>some content</otherTag>';

        $this->expectException(\RuntimeException::class);

        XmlRpcMethod::parse($payload);
    }
}