Reorganize unit tests

This commit is contained in:
Kijin Sung 2016-02-16 16:17:46 +09:00
parent be83a34b1e
commit 670baecb73
26 changed files with 48 additions and 55 deletions

View file

@ -17,7 +17,7 @@ before_script:
- if [[ ! -f codecept.phar ]]; then wget http://codeception.com/codecept.phar; fi
script:
- if [[ -f codecept.phar ]]; then php codecept.phar build; fi
- if [[ $TRAVIS_PHP_VERSION == "hhvm" ]]; then php codecept.phar run -d --fail-fast --env travis --skip Install; fi
- if [[ $TRAVIS_PHP_VERSION == "hhvm" ]]; then php codecept.phar run -d --fail-fast --env travis --skip install; fi
- if [[ $TRAVIS_PHP_VERSION != "hhvm" ]]; then php codecept.phar run -d --fail-fast --env travis; fi
- grunt lint
notifications:

View file

@ -1,15 +1,15 @@
<?php
require_once _XE_PATH_.'classes/file/FileHandler.class.php';
require_once _XE_PATH_.'classes/template/TemplateHandler.class.php';
$_SERVER['SCRIPT_NAME'] = '/xe/tests/Unit/classes/template/index.php';
$_SERVER['SCRIPT_NAME'] = '/xe/tests/unit/classes/template/index.php';
class TemplateHandlerTest extends \Codeception\TestCase\Test
{
var $prefix = '<?php if(!defined("__XE__"))exit;';
static public function provider()
public function testParse()
{
return array(
$tests = array(
// pipe cond
array(
'<a href="#" class="active"|cond="$cond > 10">Link</a>',
@ -98,12 +98,12 @@ class TemplateHandlerTest extends \Codeception\TestCase\Test
// #include
array(
'<dummy /><!--#include("sample.html")--><div>This is another dummy</div>',
'?><dummy /><?php $__tpl=TemplateHandler::getInstance();echo $__tpl->compile(\'tests/Unit/classes/template\',\'sample.html\') ?><div>This is another dummy</div>'
'?><dummy /><?php $__tpl=TemplateHandler::getInstance();echo $__tpl->compile(\'tests/unit/classes/template\',\'sample.html\') ?><div>This is another dummy</div>'
),
// <include target="file">
array(
'<dummy /><include target="../sample.html" /><div>This is another dummy</div>',
'?><dummy /><?php $__tpl=TemplateHandler::getInstance();echo $__tpl->compile(\'tests/Unit/classes\',\'sample.html\') ?><div>This is another dummy</div>'
'?><dummy /><?php $__tpl=TemplateHandler::getInstance();echo $__tpl->compile(\'tests/unit/classes\',\'sample.html\') ?><div>This is another dummy</div>'
),
// <load target="../../modules/page/lang/lang.xml">
array(
@ -113,12 +113,12 @@ class TemplateHandlerTest extends \Codeception\TestCase\Test
// <load target="style.css">
array(
'<dummy /><load target="css/style.css" /><dummy />',
'?><dummy /><!--#Meta:tests/Unit/classes/template/css/style.css--><?php $__tmp=array(\'tests/Unit/classes/template/css/style.css\',\'\',\'\',\'\');Context::loadFile($__tmp);unset($__tmp); ?><dummy />'
'?><dummy /><!--#Meta:tests/unit/classes/template/css/style.css--><?php $__tmp=array(\'tests/unit/classes/template/css/style.css\',\'\',\'\',\'\');Context::loadFile($__tmp);unset($__tmp); ?><dummy />'
),
// <unload target="style.css">
array(
'<dummy /><unload target="css/style.css" /><dummy />',
'?><dummy /><?php Context::unloadFile(\'tests/Unit/classes/template/css/style.css\',\'\',\'\'); ?><dummy />'
'?><dummy /><?php Context::unloadFile(\'tests/unit/classes/template/css/style.css\',\'\',\'\'); ?><dummy />'
),
// <!--%import("../../modules/page/tpl/filter/insert_config.xml")-->
array(
@ -128,12 +128,12 @@ class TemplateHandlerTest extends \Codeception\TestCase\Test
// <!--%import("../script.js",type="body")-->
array(
'<dummy /><!--%import("../script.js",type="body")--><dummy />',
'?><dummy /><!--#Meta:tests/Unit/classes/script.js--><?php $__tmp=array(\'tests/Unit/classes/script.js\',\'body\',\'\',\'\');Context::loadFile($__tmp);unset($__tmp); ?><dummy />'
'?><dummy /><!--#Meta:tests/unit/classes/script.js--><?php $__tmp=array(\'tests/unit/classes/script.js\',\'body\',\'\',\'\');Context::loadFile($__tmp);unset($__tmp); ?><dummy />'
),
// <!--%unload("../script.js",type="body")-->
array(
'<dummy /><!--%unload("../script.js",type="body")--><dummy />',
'?><dummy /><?php Context::unloadFile(\'tests/Unit/classes/script.js\',\'\'); ?><dummy />'
'?><dummy /><?php Context::unloadFile(\'tests/unit/classes/script.js\',\'\'); ?><dummy />'
),
// comment
array(
@ -148,7 +148,7 @@ class TemplateHandlerTest extends \Codeception\TestCase\Test
// relative path1
array(
'<img src="http://naver.com/naver.gif"><input type="image" src="../local.gif" />',
'?><img src="http://naver.com/naver.gif"><input type="image" src="/xe/tests/Unit/classes/local.gif" />'
'?><img src="http://naver.com/naver.gif"><input type="image" src="/xe/tests/unit/classes/local.gif" />'
),
// relative path2
array(
@ -213,7 +213,7 @@ class TemplateHandlerTest extends \Codeception\TestCase\Test
// issue 584
array(
'<img cond="$oBodex->display_extra_images[\'mobile\'] && $arr_extra && $arr_extra->bodex->mobile" src="./images/common/mobile.gif" title="mobile" alt="mobile" />',
PHP_EOL . 'if($__Context->oBodex->display_extra_images[\'mobile\'] && $__Context->arr_extra && $__Context->arr_extra->bodex->mobile){ ?><img src="/xe/tests/Unit/classes/template/images/common/mobile.gif" title="mobile" alt="mobile" /><?php } ?>'
PHP_EOL . 'if($__Context->oBodex->display_extra_images[\'mobile\'] && $__Context->arr_extra && $__Context->arr_extra->bodex->mobile){ ?><img src="/xe/tests/unit/classes/template/images/common/mobile.gif" title="mobile" alt="mobile" /><?php } ?>'
),
// issue 831
array(
@ -223,7 +223,7 @@ class TemplateHandlerTest extends \Codeception\TestCase\Test
// issue 746
array(
'<img src="../myxe/xe/img.png" />',
'?><img src="/xe/tests/Unit/classes/myxe/xe/img.png" />'
'?><img src="/xe/tests/unit/classes/myxe/xe/img.png" />'
),
// issue 696
array(
@ -233,35 +233,35 @@ class TemplateHandlerTest extends \Codeception\TestCase\Test
// https://github.com/xpressengine/xe-core/issues/1510
array(
'<img cond="$foo->bar" src="../common/mobile.gif" />',
PHP_EOL . 'if($__Context->foo->bar){ ?><img src="/xe/tests/Unit/classes/common/mobile.gif" /><?php } ?>'
PHP_EOL . 'if($__Context->foo->bar){ ?><img src="/xe/tests/unit/classes/common/mobile.gif" /><?php } ?>'
),
// https://github.com/xpressengine/xe-core/issues/1510
array(
'<img cond="$foo->bar > 100" alt="a!@#$%^&*()_-=[]{}?/" src="../common/mobile.gif" />',
PHP_EOL . 'if($__Context->foo->bar > 100){ ?><img alt="a!@#$%^&*()_-=[]{}?/" src="/xe/tests/Unit/classes/common/mobile.gif" /><?php } ?>'
PHP_EOL . 'if($__Context->foo->bar > 100){ ?><img alt="a!@#$%^&*()_-=[]{}?/" src="/xe/tests/unit/classes/common/mobile.gif" /><?php } ?>'
),
// https://github.com/xpressengine/xe-core/issues/1510
array(
'<img src="../common/mobile.gif" cond="$foo->bar" />',
PHP_EOL . 'if($__Context->foo->bar){ ?><img src="/xe/tests/Unit/classes/common/mobile.gif" /><?php } ?>'
PHP_EOL . 'if($__Context->foo->bar){ ?><img src="/xe/tests/unit/classes/common/mobile.gif" /><?php } ?>'
),
// https://github.com/xpressengine/xe-core/issues/1510
array(
'<img class="tmp_class" cond="!$module_info->title" src="../img/common/blank.gif" />',
PHP_EOL . 'if(!$__Context->module_info->title){ ?><img class="tmp_class" src="/xe/tests/Unit/classes/img/common/blank.gif" /><?php } ?>'
PHP_EOL . 'if(!$__Context->module_info->title){ ?><img class="tmp_class" src="/xe/tests/unit/classes/img/common/blank.gif" /><?php } ?>'
),
// https://github.com/xpressengine/xe-core/issues/1510
array(
'<img cond="$mi->title" class="tmp_class"|cond="$mi->use" src="../img/common/blank.gif" />',
PHP_EOL . 'if($__Context->mi->title){ ?><img<?php if($__Context->mi->use){ ?> class="tmp_class"<?php } ?> src="/xe/tests/Unit/classes/img/common/blank.gif" /><?php } ?>'
PHP_EOL . 'if($__Context->mi->title){ ?><img<?php if($__Context->mi->use){ ?> class="tmp_class"<?php } ?> src="/xe/tests/unit/classes/img/common/blank.gif" /><?php } ?>'
),
array(
'<input foo="bar" /> <img cond="$foo->bar" alt="alt" src="../common/mobile.gif" />',
'?><input foo="bar" /> <?php if($__Context->foo->bar){ ?><img alt="alt" src="/xe/tests/Unit/classes/common/mobile.gif" /><?php } ?>'
'?><input foo="bar" /> <?php if($__Context->foo->bar){ ?><img alt="alt" src="/xe/tests/unit/classes/common/mobile.gif" /><?php } ?>'
),
array(
'<input foo="bar" />' . "\n" . '<input foo="bar" /> <img cond="$foo->bar" alt="alt" src="../common/mobile.gif" />',
'?><input foo="bar" />' . PHP_EOL . '<input foo="bar" /> <?php if($__Context->foo->bar){ ?><img alt="alt" src="/xe/tests/Unit/classes/common/mobile.gif" /><?php } ?>'
'?><input foo="bar" />' . PHP_EOL . '<input foo="bar" /> <?php if($__Context->foo->bar){ ?><img alt="alt" src="/xe/tests/unit/classes/common/mobile.gif" /><?php } ?>'
),
array(
'asf <img src="{$foo->bar}" />',
@ -269,44 +269,40 @@ class TemplateHandlerTest extends \Codeception\TestCase\Test
),
array(
'<img alt="" '.PHP_EOL.' src="../myxe/xe/img.png" />',
'?><img alt="" '.PHP_EOL.' src="/xe/tests/Unit/classes/myxe/xe/img.png" />'
'?><img alt="" '.PHP_EOL.' src="/xe/tests/unit/classes/myxe/xe/img.png" />'
),
array(
'<input>asdf src="../img/img.gif" asdf</input> <img alt="src" src="../myxe/xe/img.png" /> <input>asdf src="../img/img.gif" asdf</input>',
'?><input>asdf src="../img/img.gif" asdf</input> <img alt="src" src="/xe/tests/Unit/classes/myxe/xe/img.png" /> <input>asdf src="../img/img.gif" asdf</input>'
'?><input>asdf src="../img/img.gif" asdf</input> <img alt="src" src="/xe/tests/unit/classes/myxe/xe/img.png" /> <input>asdf src="../img/img.gif" asdf</input>'
),
array(
'<input>asdf src="../img/img.gif" asdf</input>',
'?><input>asdf src="../img/img.gif" asdf</input>'
),
);
foreach ($tests as $test)
{
$tmpl = new TemplateHandlerWrapper;
$tmpl->init(__DIR__ . '/template', 'no_file.html');
$result = $tmpl->parse($test[0]);
$this->assertEquals($this->prefix . $test[1], $result);
}
}
/**
* @dataProvider provider
*/
public function testParse($tpl, $expected)
public function testParseNoContent()
{
$tmpl = new TemplateHandlerWrapper;
$tmpl->init(dirname(__FILE__), 'no_file.html');
$tmpl->init(__DIR__ . '/template', 'no_file.html');
$result = $tmpl->parse($tpl);
$this->assertEquals($result, $this->prefix.$expected);
}
public function testParse2()
{
$tmpl = new TemplateHandlerWrapper;
$tmpl->init(dirname(__FILE__), 'no_file.html');
$result = $tmpl->parse($tpl);
$this->assertEquals($result, '');
$this->assertEquals('', $result);
}
public function testCompileDirect()
{
$tmpl = TemplateHandler::getInstance();
$result = $tmpl->compileDirect(dirname(__FILE__), 'sample.html');
$result = $tmpl->compileDirect(__DIR__ . '/template', 'sample.html');
$result = trim($result);
$this->assertEquals($result, $this->prefix.PHP_EOL.'if($__Context->has_blog){ ?><a href="http://mygony.com">Taggon\'s blog</a><?php } ?>'.PHP_EOL.'<!--#Meta://external.host/js.js--><?php $__tmp=array(\'//external.host/js.js\',\'\',\'\',\'\');Context::loadFile($__tmp);unset($__tmp); ?>');

View file

@ -131,7 +131,7 @@ class ValidatorTest extends \Codeception\TestCase\Test
public function testCustomRuleXml()
{
$vd = new Validator(dirname(__FILE__).'/customrule.xml');
$vd = new Validator(__DIR__ . '/validator/customrule.xml');
$this->assertTrue($vd->validate(array('regex_field' => 'abc')));
$this->assertFalse($vd->validate(array('regex_field' => 'ABC')));
@ -172,7 +172,7 @@ class ValidatorTest extends \Codeception\TestCase\Test
public function testConditionXml()
{
$vd = new Validator(dirname(__FILE__).'/condition.xml');
$vd = new Validator(__DIR__ . '/validator/condition.xml');
$data = array('greeting1'=>'hello');
$this->assertTrue($vd->validate($data));
@ -185,15 +185,15 @@ class ValidatorTest extends \Codeception\TestCase\Test
$this->assertTrue($vd->validate($data));
// javascript
$vd->setCacheDir(dirname(__FILE__));
$vd->setCacheDir(__DIR__ . '/validator');
$js = $vd->getJsPath();
$this->assertFileEquals($js, dirname(__FILE__).'/condition.en.js');
$this->assertFileEquals($js, __DIR__ . '/validator/condition.en.js');
}
protected function tearDown()
{
// remove cache directory
$cache_dir = dirname(__FILE__).'/ruleset';
$cache_dir = __DIR__ . '/validator/ruleset';
if(is_dir($cache_dir))
{
$files = (array)glob($cache_dir.'/*');

View file

@ -1,10 +1,10 @@
<?php
class FuncIncTest extends \Codeception\TestCase\Test
class LegacyTest extends \Codeception\TestCase\Test
{
static public function provider()
public function testRemoveHackTag()
{
return array(
$tests = array(
// remove iframe
array(
'<div class="frame"><iframe src="path/to/file.html"></iframe><p><a href="#iframe">IFrame</a></p></div>',
@ -59,14 +59,11 @@ class FuncIncTest extends \Codeception\TestCase\Test
'<img alt="dummy" />'
)
);
}
/**
* @dataProvider provider
*/
public function testXss($source, $expected)
{
$result = removeHackTag($source);
$this->assertEquals($result, $expected);
foreach ($tests as $test)
{
$result = removeHackTag($test[0]);
$this->assertEquals($test[1], $result);
}
}
}