Add unit tests for ModuleActionParser

This commit is contained in:
Kijin Sung 2020-07-07 19:20:51 +09:00
parent 1abdb2d788
commit dbb8cd684e
2 changed files with 57 additions and 0 deletions

View file

@ -4,7 +4,59 @@ class ModuleActionParserTest extends \Codeception\TestCase\Test
{
public function testLoadXML()
{
// Basic info
$info = Rhymix\Framework\Parsers\ModuleActionParser::loadXML(\RX_BASEDIR . 'tests/_data/module/module.xml');
$this->assertTrue(is_object($info));
$this->assertEquals('dispTestView', $info->default_index_act);
$this->assertEquals('dispTestAdminIndex', $info->admin_index_act);
$this->assertEquals('', $info->setup_index_act);
// Actions
$this->assertEquals('view', $info->action->dispTestView->type);
$this->assertEquals('guest', $info->action->dispTestView->grant);
$this->assertEquals((object)['target' => 'view', 'check_var' => '', 'check_type' => ''], $info->action->dispTestView->permission);
$this->assertEquals('GET', $info->action->dispTestView->method);
$this->assertEquals('false', $info->action->dispTestView->standalone);
$this->assertEquals('true', $info->action->dispTestView->check_csrf);
$this->assertEquals(3, count($info->action->dispTestView->route));
$this->assertEquals(100, $info->action->dispTestView->route['$document_srl']['priority']);
$this->assertEquals(['document_srl' => 'int'], $info->action->dispTestView->route['$document_srl']['vars']);
$this->assertEquals(70, $info->action->dispTestView->route['$document_srl/comment/$comment_srl']['priority']);
$this->assertEquals(['document_srl' => 'int', 'comment_srl' => 'int'], $info->action->dispTestView->route['$document_srl/comment/$comment_srl']['vars']);
$this->assertEquals(50, $info->action->dispTestView->route['$document_srl/tag/$tag']['priority']);
$this->assertEquals(['document_srl' => 'int', 'tag' => 'word'], $info->action->dispTestView->route['$document_srl/tag/$tag']['vars']);
$this->assertEquals(['write' => ['priority' => 0, 'vars' => []]], $info->action->dispTestWrite->route);
$this->assertEquals('true', $info->action->dispTestWrite->meta_noindex);
$this->assertEquals('true', $info->action->dispTestWrite->global_route);
$this->assertEquals('controller', $info->action->procTestSubmitData->type);
$this->assertEquals('submitData', $info->action->procTestSubmitData->ruleset);
$this->assertEquals('', $info->action->procTestSubmitData->method);
$this->assertEquals('true', $info->action->dispTestAdminIndex->standalone);
$this->assertEquals('GET|POST', $info->action->procTestAdminSubmitData->method);
$this->assertEquals([], $info->action->procTestAdminSubmitData->route);
// Routes
$this->assertEquals(4, count($info->route->GET));
$this->assertEquals('dispTestView', $info->route->GET['#^(?P<document_srl>[0-9]+)$#u']);
$this->assertEquals('dispTestView', $info->route->GET['#^(?P<document_srl>[0-9]+)/comment/(?P<comment_srl>[0-9]+)$#u']);
$this->assertEquals('dispTestView', $info->route->GET['#^(?P<document_srl>[0-9]+)/tag/(?P<tag>[a-zA-Z0-9_]+)$#u']);
$this->assertEquals('dispTestWrite', $info->route->GET['#^write$#u']);
$this->assertEquals(0, count($info->route->POST));
// Grant
$this->assertEquals(['view'], array_keys(get_object_vars($info->grant)));
$this->assertEquals('View', $info->grant->view->title);
$this->assertEquals('guest', $info->grant->view->default);
// Menu
$this->assertEquals(['test'], array_keys(get_object_vars($info->menu)));
$this->assertEquals('Test Menu', $info->menu->test->title);
$this->assertEquals('dispTestAdminIndex', $info->menu->test->index);
$this->assertEquals(['dispTestAdminIndex'], $info->menu->test->acts);
$this->assertEquals('all', $info->menu->test->type);
// Error handlers
$this->assertTrue(is_array($info->error_handlers));
$this->assertEquals('dispTestErrorHandler', $info->error_handlers[404]);
}
}

View file

@ -4,6 +4,7 @@ class ModuleInfoParserTest extends \Codeception\TestCase\Test
{
public function testLoadXML()
{
// Basic info
Context::init();
Context::setLangType('ko');
$info = Rhymix\Framework\Parsers\ModuleInfoParser::loadXML(\RX_BASEDIR . 'tests/_data/module/info.xml');
@ -15,6 +16,8 @@ class ModuleInfoParserTest extends \Codeception\TestCase\Test
$this->assertEquals('service', $info->category);
$this->assertEquals('GPLv2', $info->license);
$this->assertEquals('https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html', $info->license_link);
// Author array
$this->assertTrue(is_array($info->author));
$this->assertEquals('Rhymix 개발자', $info->author[0]->name);
$this->assertEquals('devops@rhymix.org', $info->author[0]->email_address);
@ -23,12 +26,14 @@ class ModuleInfoParserTest extends \Codeception\TestCase\Test
$this->assertEquals('other.developer@rhymix.org', $info->author[1]->email_address);
$this->assertEquals('', $info->author[1]->homepage);
// Change language
Context::setLangType('en');
$info = Rhymix\Framework\Parsers\ModuleInfoParser::loadXML(\RX_BASEDIR . 'tests/_data/module/info.xml');
$this->assertEquals('Test Module', $info->title);
$this->assertEquals('This module is for unit testing.', $info->description);
$this->assertEquals('Rhymix Developer', $info->author[0]->name);
// Index actions (from module.xml)
$this->assertEquals('dispTestView', $info->default_index_act);
$this->assertEquals('dispTestAdminIndex', $info->admin_index_act);
$this->assertTrue(is_array($info->error_handlers));