mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-04 17:21:39 +09:00
Add unit tests for LangParser
This commit is contained in:
parent
716b0e19bd
commit
592c8041cb
2 changed files with 91 additions and 0 deletions
23
tests/_data/lang/lang.xml
Normal file
23
tests/_data/lang/lang.xml
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<lang>
|
||||||
|
<item name="testlang">
|
||||||
|
<value xml:lang="ko"><![CDATA[테스트 언어]]></value>
|
||||||
|
<value xml:lang="en"><![CDATA[Test Lang]]></value>
|
||||||
|
<value xml:lang="ja"><![CDATA[テスト言語]]></value>
|
||||||
|
</item>
|
||||||
|
<item name="testhtml">
|
||||||
|
<value xml:lang="ko"><![CDATA[<p>HTML<br>내용</p>]]></value>
|
||||||
|
<value xml:lang="en"><![CDATA[<p>HTML<br>Content</p>]]></value>
|
||||||
|
<value xml:lang="ja"><![CDATA[<p>HTML コンテンツ</p>]]></value>
|
||||||
|
</item>
|
||||||
|
<item name="testarray" type="array">
|
||||||
|
<item name="foo">
|
||||||
|
<value xml:lang="ko"><![CDATA[푸]]></value>
|
||||||
|
<value xml:lang="en"><![CDATA[FOO]]></value>
|
||||||
|
</item>
|
||||||
|
<item name="bar">
|
||||||
|
<value xml:lang="ko"><![CDATA[바]]></value>
|
||||||
|
<value xml:lang="en"><![CDATA[BAR]]></value>
|
||||||
|
</item>
|
||||||
|
</item>
|
||||||
|
</lang>
|
||||||
68
tests/unit/framework/parsers/LangParserTest.php
Normal file
68
tests/unit/framework/parsers/LangParserTest.php
Normal file
|
|
@ -0,0 +1,68 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class LangParserTest extends \Codeception\TestCase\Test
|
||||||
|
{
|
||||||
|
protected $_dir = 'tests/_data/lang';
|
||||||
|
|
||||||
|
public function _before()
|
||||||
|
{
|
||||||
|
$files = Rhymix\Framework\Storage::readDirectory(\RX_BASEDIR . $this->_dir);
|
||||||
|
foreach ($files as $file)
|
||||||
|
{
|
||||||
|
if (preg_match('/\.php$/', $file))
|
||||||
|
{
|
||||||
|
Rhymix\Framework\Storage::delete($file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function _after()
|
||||||
|
{
|
||||||
|
$files = Rhymix\Framework\Storage::readDirectory(\RX_BASEDIR . $this->_dir);
|
||||||
|
foreach ($files as $file)
|
||||||
|
{
|
||||||
|
if (preg_match('/\.php$/', $file))
|
||||||
|
{
|
||||||
|
Rhymix\Framework\Storage::delete($file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testConvertDirectory()
|
||||||
|
{
|
||||||
|
Rhymix\Framework\Parsers\LangParser::convertDirectory(\RX_BASEDIR . $this->_dir, ['ko', 'en']);
|
||||||
|
$this->assertTrue(file_exists(\RX_BASEDIR . $this->_dir . '/ko.php'));
|
||||||
|
$this->assertTrue(file_exists(\RX_BASEDIR . $this->_dir . '/en.php'));
|
||||||
|
$this->assertFalse(file_exists(\RX_BASEDIR . $this->_dir . '/ja.php'));
|
||||||
|
$this->assertFalse(file_exists(\RX_BASEDIR . $this->_dir . '/fr.php'));
|
||||||
|
|
||||||
|
$lang = new stdClass;
|
||||||
|
include \RX_BASEDIR . $this->_dir . '/ko.php';
|
||||||
|
$this->assertEquals('테스트 언어', $lang->testlang);
|
||||||
|
$this->assertEquals('<p>HTML<br>내용</p>', $lang->testhtml);
|
||||||
|
$this->assertEquals(['foo' => '푸', 'bar' => '바'], $lang->testarray);
|
||||||
|
|
||||||
|
$lang = new stdClass;
|
||||||
|
include \RX_BASEDIR . $this->_dir . '/en.php';
|
||||||
|
$this->assertEquals('Test Lang', $lang->testlang);
|
||||||
|
$this->assertEquals('<p>HTML<br>Content</p>', $lang->testhtml);
|
||||||
|
$this->assertEquals(['foo' => 'FOO', 'bar' => 'BAR'], $lang->testarray);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCompileXMLtoPHP()
|
||||||
|
{
|
||||||
|
$in = \RX_BASEDIR . $this->_dir . '/lang.xml';
|
||||||
|
$out = \RX_BASEDIR . $this->_dir . '/ja.php';
|
||||||
|
$noout = \RX_BASEDIR . $this->_dir . '/en.php';
|
||||||
|
$result = Rhymix\Framework\Parsers\LangParser::compileXMLtoPHP($in, 'ja', $out);
|
||||||
|
$this->assertEquals($out, $result);
|
||||||
|
$this->assertTrue(file_exists($result));
|
||||||
|
$this->assertFalse(file_exists($noout));
|
||||||
|
|
||||||
|
$lang = new stdClass;
|
||||||
|
include \RX_BASEDIR . $this->_dir . '/ja.php';
|
||||||
|
$this->assertEquals('テスト言語', $lang->testlang);
|
||||||
|
$this->assertEquals('<p>HTML コンテンツ</p>', $lang->testhtml);
|
||||||
|
$this->assertNull($lang->testarray);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue