Add unit test for XEXMLParser

This commit is contained in:
Kijin Sung 2025-05-17 12:54:47 +09:00
parent db72b670d8
commit 52f106968a
4 changed files with 53 additions and 1 deletions

View file

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<layout version="0.2">
<title xml:lang="ko">기본 레이아웃</title>
<title xml:lang="en">Default Layout</title>
<author email_address="devops@rhymix.org" link="https://rhymix.org/">
<name xml:lang="ko">라이믹스</name>
<name xml:lang="en">Rhymix</name>
</author>
<extra_vars>
<var name="logo_image" type="image">
<title xml:lang="ko">로고 이미지</title>
<title xml:lang="en">Logo Image</title>
</var>
<var name="web_font" type="select">
<title xml:lang="ko">웹 폰트</title>
<title xml:lang="en">Web Font</title>
<options value="Noto Sans">
<title>Noto Sans</title>
</options>
<options value="Pretendard">
<title>Pretendard</title>
</options>
</var>
</extra_vars>
</layout>

View file

@ -0,0 +1,27 @@
<?php
class XeXmlParserTest extends \Codeception\Test\Unit
{
public function testParse()
{
$xml = file_get_contents(\RX_BASEDIR . 'tests/_data/xml/xecompat.xml');
$output = Rhymix\Framework\Parsers\XEXMLParser::loadXMLString($xml, 'en');
$this->assertEquals('Default Layout', $output->layout->title->body);
$this->assertEquals('Rhymix', $output->layout->author->name->body);
$this->assertEquals('https://rhymix.org/', $output->layout->author->attrs->link);
$this->assertEquals('en', $output->layout->author->name->attrs->{'xml:lang'});
$this->assertEquals('logo_image', $output->layout->extra_vars->var[0]->attrs->name);
$this->assertEquals('web_font', $output->layout->extra_vars->var[1]->attrs->name);
$this->assertEquals('Noto Sans', $output->layout->extra_vars->var[1]->options[0]->attrs->value);
$this->assertEquals('Pretendard', $output->layout->extra_vars->var[1]->options[1]->title->body);
$output = Rhymix\Framework\Parsers\XEXMLParser::loadXMLString($xml, 'ko');
$this->assertEquals('기본 레이아웃', $output->layout->title->body);
$this->assertEquals('라이믹스', $output->layout->author->name->body);
$this->assertEquals('웹 폰트', $output->layout->extra_vars->var[1]->title->body);
$this->assertEquals('Noto Sans', $output->layout->extra_vars->var[1]->options[0]->attrs->value);
}
}

View file

@ -4,7 +4,7 @@ class XmlrpcParserTest extends \Codeception\Test\Unit
{
public function testParse()
{
$xml = file_get_contents(\RX_BASEDIR . 'tests/_data/xmlrpc/request.xml');
$xml = file_get_contents(\RX_BASEDIR . 'tests/_data/xml/xmlrpc.xml');
$params = Rhymix\Framework\Parsers\XMLRPCParser::parse($xml);
$this->assertTrue(is_array($params));
$this->assertEquals('board', $params['module']);