Fix relative path used in unit tests

This commit is contained in:
Kijin Sung 2022-03-15 02:52:21 +09:00
parent 0fec44222d
commit 3260d90d18
6 changed files with 95 additions and 75 deletions

View file

@ -7,8 +7,8 @@ $_SERVER['SERVER_NAME'] = 'www.rhymix.org';
$_SERVER['REMOTE_ADDR'] = '127.0.0.1'; $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$_SERVER['DOCUMENT_ROOT'] = dirname(dirname(__DIR__)); $_SERVER['DOCUMENT_ROOT'] = dirname(dirname(__DIR__));
$_SERVER['SCRIPT_FILENAME'] = dirname(__DIR__) . '/index.php'; $_SERVER['SCRIPT_FILENAME'] = dirname(__DIR__) . '/index.php';
$_SERVER['SCRIPT_NAME'] = '/rhymix/index.php'; $_SERVER['SCRIPT_NAME'] = '/' . basename(dirname(__DIR__)) . '/index.php';
$_SERVER['REQUEST_URI'] = '/rhymix/index.php'; $_SERVER['REQUEST_URI'] = '/' . basename(dirname(__DIR__)) . '/index.php';
// Include the autoloader. // Include the autoloader.
require_once dirname(__DIR__) . '/common/autoload.php'; require_once dirname(__DIR__) . '/common/autoload.php';

View file

@ -2,6 +2,7 @@
class FrontEndFileHandlerTest extends \Codeception\TestCase\Test class FrontEndFileHandlerTest extends \Codeception\TestCase\Test
{ {
private $baseurl;
private $reservedCSS; private $reservedCSS;
private $reservedJS; private $reservedJS;
private function _filemtime($file) private function _filemtime($file)
@ -11,6 +12,7 @@ class FrontEndFileHandlerTest extends \Codeception\TestCase\Test
public function _before() public function _before()
{ {
$this->baseurl = '/' . basename(dirname(dirname(dirname(__DIR__)))) . '/';
$this->reservedCSS = HTMLDisplayHandler::$reservedCSS; $this->reservedCSS = HTMLDisplayHandler::$reservedCSS;
$this->reservedJS = HTMLDisplayHandler::$reservedJS; $this->reservedJS = HTMLDisplayHandler::$reservedJS;
HTMLDisplayHandler::$reservedCSS = '/xxx$/'; HTMLDisplayHandler::$reservedCSS = '/xxx$/';
@ -38,8 +40,8 @@ class FrontEndFileHandlerTest extends \Codeception\TestCase\Test
$handler->loadFile(array('./common/js/common.js', 'body')); $handler->loadFile(array('./common/js/common.js', 'body'));
$handler->loadFile(array('./common/js/common.js', 'head')); $handler->loadFile(array('./common/js/common.js', 'head'));
$handler->loadFile(array('./common/js/xml_js_filter.js', 'body')); $handler->loadFile(array('./common/js/xml_js_filter.js', 'body'));
$expected[] = array('file' => '/rhymix/common/js/js_app.js' . $this->_filemtime('common/js/js_app.js'), 'targetie' => null); $expected[] = array('file' => $this->baseurl . 'common/js/js_app.js' . $this->_filemtime('common/js/js_app.js'), 'targetie' => null);
$expected[] = array('file' => '/rhymix/common/js/common.js' . $this->_filemtime('common/js/common.js'), 'targetie' => null); $expected[] = array('file' => $this->baseurl . 'common/js/common.js' . $this->_filemtime('common/js/common.js'), 'targetie' => null);
$this->assertEquals($expected, $handler->getJsFileList()); $this->assertEquals($expected, $handler->getJsFileList());
} }
@ -48,7 +50,7 @@ class FrontEndFileHandlerTest extends \Codeception\TestCase\Test
$handler = new FrontEndFileHandler(); $handler = new FrontEndFileHandler();
$handler->loadFile(array('./common/js/xml_handler.js', 'body')); $handler->loadFile(array('./common/js/xml_handler.js', 'body'));
$handler->loadFile(array('./common/js/xml_js_filter.js', 'head')); $handler->loadFile(array('./common/js/xml_js_filter.js', 'head'));
$expected[] = array('file' => '/rhymix/common/js/xml_handler.js' . $this->_filemtime('common/js/xml_handler.js'), 'targetie' => null); $expected[] = array('file' => $this->baseurl . 'common/js/xml_handler.js' . $this->_filemtime('common/js/xml_handler.js'), 'targetie' => null);
$this->assertEquals($expected, $handler->getJsFileList('body')); $this->assertEquals($expected, $handler->getJsFileList('body'));
} }
@ -73,10 +75,10 @@ class FrontEndFileHandlerTest extends \Codeception\TestCase\Test
$handler->loadFile(array('./common/js/common.js', 'head', '', -100000)); $handler->loadFile(array('./common/js/common.js', 'head', '', -100000));
$handler->loadFile(array('./common/js/xml_handler.js', 'head', '', -100000)); $handler->loadFile(array('./common/js/xml_handler.js', 'head', '', -100000));
$handler->loadFile(array('./common/js/xml_js_filter.js', 'head', '', -100000)); $handler->loadFile(array('./common/js/xml_js_filter.js', 'head', '', -100000));
$expected[] = array('file' => '/rhymix/common/js/js_app.js' . $this->_filemtime('common/js/js_app.js'), 'targetie' => null); $expected[] = array('file' => $this->baseurl . 'common/js/js_app.js' . $this->_filemtime('common/js/js_app.js'), 'targetie' => null);
$expected[] = array('file' => '/rhymix/common/js/common.js' . $this->_filemtime('common/js/common.js'), 'targetie' => null); $expected[] = array('file' => $this->baseurl . 'common/js/common.js' . $this->_filemtime('common/js/common.js'), 'targetie' => null);
$expected[] = array('file' => '/rhymix/common/js/xml_handler.js' . $this->_filemtime('common/js/xml_handler.js'), 'targetie' => null); $expected[] = array('file' => $this->baseurl . 'common/js/xml_handler.js' . $this->_filemtime('common/js/xml_handler.js'), 'targetie' => null);
$expected[] = array('file' => '/rhymix/common/js/xml_js_filter.js' . $this->_filemtime('common/js/xml_js_filter.js'), 'targetie' => null); $expected[] = array('file' => $this->baseurl . 'common/js/xml_js_filter.js' . $this->_filemtime('common/js/xml_js_filter.js'), 'targetie' => null);
$this->assertEquals($expected, $handler->getJsFileList()); $this->assertEquals($expected, $handler->getJsFileList());
} }
@ -87,10 +89,10 @@ class FrontEndFileHandlerTest extends \Codeception\TestCase\Test
$handler->loadFile(array('./common/js/js_app.js', 'head', '', -100000)); $handler->loadFile(array('./common/js/js_app.js', 'head', '', -100000));
$handler->loadFile(array('./common/js/common.js', 'head', '', -100000)); $handler->loadFile(array('./common/js/common.js', 'head', '', -100000));
$handler->loadFile(array('./common/js/xml_js_filter.js', 'head', '', -100000)); $handler->loadFile(array('./common/js/xml_js_filter.js', 'head', '', -100000));
$expected[] = array('file' => '/rhymix/common/js/js_app.js' . $this->_filemtime('common/js/js_app.js'), 'targetie' => null); $expected[] = array('file' => $this->baseurl . 'common/js/js_app.js' . $this->_filemtime('common/js/js_app.js'), 'targetie' => null);
$expected[] = array('file' => '/rhymix/common/js/common.js' . $this->_filemtime('common/js/common.js'), 'targetie' => null); $expected[] = array('file' => $this->baseurl . 'common/js/common.js' . $this->_filemtime('common/js/common.js'), 'targetie' => null);
$expected[] = array('file' => '/rhymix/common/js/xml_js_filter.js' . $this->_filemtime('common/js/xml_js_filter.js'), 'targetie' => null); $expected[] = array('file' => $this->baseurl . 'common/js/xml_js_filter.js' . $this->_filemtime('common/js/xml_js_filter.js'), 'targetie' => null);
$expected[] = array('file' => '/rhymix/common/js/xml_handler.js' . $this->_filemtime('common/js/xml_handler.js'), 'targetie' => null); $expected[] = array('file' => $this->baseurl . 'common/js/xml_handler.js' . $this->_filemtime('common/js/xml_handler.js'), 'targetie' => null);
$this->assertEquals($expected, $handler->getJsFileList()); $this->assertEquals($expected, $handler->getJsFileList());
} }
@ -102,9 +104,9 @@ class FrontEndFileHandlerTest extends \Codeception\TestCase\Test
$handler->loadFile(array('./common/js/xml_handler.js', 'head', '', -100000)); $handler->loadFile(array('./common/js/xml_handler.js', 'head', '', -100000));
$handler->loadFile(array('./common/js/xml_js_filter.js', 'head', '', -100000)); $handler->loadFile(array('./common/js/xml_js_filter.js', 'head', '', -100000));
$handler->unloadFile('./common/js/js_app.js', '', 'all'); $handler->unloadFile('./common/js/js_app.js', '', 'all');
$expected[] = array('file' => '/rhymix/common/js/common.js' . $this->_filemtime('common/js/common.js'), 'targetie' => null); $expected[] = array('file' => $this->baseurl . 'common/js/common.js' . $this->_filemtime('common/js/common.js'), 'targetie' => null);
$expected[] = array('file' => '/rhymix/common/js/xml_handler.js' . $this->_filemtime('common/js/xml_handler.js'), 'targetie' => null); $expected[] = array('file' => $this->baseurl . 'common/js/xml_handler.js' . $this->_filemtime('common/js/xml_handler.js'), 'targetie' => null);
$expected[] = array('file' => '/rhymix/common/js/xml_js_filter.js' . $this->_filemtime('common/js/xml_js_filter.js'), 'targetie' => null); $expected[] = array('file' => $this->baseurl . 'common/js/xml_js_filter.js' . $this->_filemtime('common/js/xml_js_filter.js'), 'targetie' => null);
$this->assertEquals($expected, $handler->getJsFileList()); $this->assertEquals($expected, $handler->getJsFileList());
} }
@ -164,7 +166,7 @@ class FrontEndFileHandlerTest extends \Codeception\TestCase\Test
$handler = new FrontEndFileHandler(); $handler = new FrontEndFileHandler();
$handler->loadFile(array('./common/xeicon/xeicon.min.css')); $handler->loadFile(array('./common/xeicon/xeicon.min.css'));
$result = $handler->getCssFileList(); $result = $handler->getCssFileList();
$this->assertEquals('/rhymix/common/css/xeicon/xeicon.min.css' . $this->_filemtime('common/css/xeicon/xeicon.min.css'), $result[0]['file']); $this->assertEquals($this->baseurl . 'common/css/xeicon/xeicon.min.css' . $this->_filemtime('common/css/xeicon/xeicon.min.css'), $result[0]['file']);
$this->assertEquals('all', $result[0]['media']); $this->assertEquals('all', $result[0]['media']);
$this->assertEmpty($result[0]['targetie']); $this->assertEmpty($result[0]['targetie']);
} }
@ -175,9 +177,9 @@ class FrontEndFileHandlerTest extends \Codeception\TestCase\Test
$handler->loadFile(array('./common/js/js_app.js', 'head', 'ie6')); $handler->loadFile(array('./common/js/js_app.js', 'head', 'ie6'));
$handler->loadFile(array('./common/js/js_app.js', 'head', 'ie7')); $handler->loadFile(array('./common/js/js_app.js', 'head', 'ie7'));
$handler->loadFile(array('./common/js/js_app.js', 'head', 'ie8')); $handler->loadFile(array('./common/js/js_app.js', 'head', 'ie8'));
$expected[] = array('file' => '/rhymix/common/js/js_app.js' . $this->_filemtime('common/js/js_app.js'), 'targetie' => 'ie6'); $expected[] = array('file' => $this->baseurl . 'common/js/js_app.js' . $this->_filemtime('common/js/js_app.js'), 'targetie' => 'ie6');
$expected[] = array('file' => '/rhymix/common/js/js_app.js' . $this->_filemtime('common/js/js_app.js'), 'targetie' => 'ie7'); $expected[] = array('file' => $this->baseurl . 'common/js/js_app.js' . $this->_filemtime('common/js/js_app.js'), 'targetie' => 'ie7');
$expected[] = array('file' => '/rhymix/common/js/js_app.js' . $this->_filemtime('common/js/js_app.js'), 'targetie' => 'ie8'); $expected[] = array('file' => $this->baseurl . 'common/js/js_app.js' . $this->_filemtime('common/js/js_app.js'), 'targetie' => 'ie8');
$this->assertEquals($expected, $handler->getJsFileList()); $this->assertEquals($expected, $handler->getJsFileList());
} }
@ -188,9 +190,9 @@ class FrontEndFileHandlerTest extends \Codeception\TestCase\Test
$handler->loadFile(array('./common/css/common.css', null, 'ie7')); $handler->loadFile(array('./common/css/common.css', null, 'ie7'));
$handler->loadFile(array('./common/css/common.css', null, 'ie8')); $handler->loadFile(array('./common/css/common.css', null, 'ie8'));
$expected[] = array('file' => '/rhymix/common/css/common.css', 'media' => 'all', 'targetie' => 'ie6'); $expected[] = array('file' => $this->baseurl . 'common/css/common.css', 'media' => 'all', 'targetie' => 'ie6');
$expected[] = array('file' => '/rhymix/common/css/common.css', 'media' => 'all', 'targetie' => 'ie7'); $expected[] = array('file' => $this->baseurl . 'common/css/common.css', 'media' => 'all', 'targetie' => 'ie7');
$expected[] = array('file' => '/rhymix/common/css/common.css', 'media' => 'all', 'targetie' => 'ie8'); $expected[] = array('file' => $this->baseurl . 'common/css/common.css', 'media' => 'all', 'targetie' => 'ie8');
$this->assertEquals($expected, $handler->getCssFileList()); $this->assertEquals($expected, $handler->getCssFileList());
} }
@ -201,9 +203,9 @@ class FrontEndFileHandlerTest extends \Codeception\TestCase\Test
$handler->loadFile(array('./common/css/common.css', 'screen')); $handler->loadFile(array('./common/css/common.css', 'screen'));
$handler->loadFile(array('./common/css/common.css', 'handled')); $handler->loadFile(array('./common/css/common.css', 'handled'));
$expected[] = array('file' => '/rhymix/common/css/common.css', 'media'=>'all', 'targetie' => null); $expected[] = array('file' => $this->baseurl . 'common/css/common.css', 'media'=>'all', 'targetie' => null);
$expected[] = array('file' => '/rhymix/common/css/common.css','media'=>'screen', 'targetie' => null); $expected[] = array('file' => $this->baseurl . 'common/css/common.css','media'=>'screen', 'targetie' => null);
$expected[] = array('file' => '/rhymix/common/css/common.css', 'media'=>'handled', 'targetie' => null); $expected[] = array('file' => $this->baseurl . 'common/css/common.css', 'media'=>'handled', 'targetie' => null);
$this->assertEquals($expected, $handler->getCssFileList()); $this->assertEquals($expected, $handler->getCssFileList());
} }
@ -243,7 +245,7 @@ class FrontEndFileHandlerTest extends \Codeception\TestCase\Test
$result = $handler->getCssFileList(true); $result = $handler->getCssFileList(true);
$this->assertEquals(4, count($result)); $this->assertEquals(4, count($result));
$this->assertRegexp('/combined\/[0-9a-f]+\.css\?\d+$/', $result[0]['file']); $this->assertRegexp('/combined\/[0-9a-f]+\.css\?\d+$/', $result[0]['file']);
$this->assertEquals('/rhymix/common/css/bootstrap.css' . $this->_filemtime('common/css/bootstrap.css'), $result[1]['file']); $this->assertEquals($this->baseurl . 'common/css/bootstrap.css' . $this->_filemtime('common/css/bootstrap.css'), $result[1]['file']);
$this->assertEquals('IE', $result[1]['targetie']); $this->assertEquals('IE', $result[1]['targetie']);
$this->assertEquals('http://external.host/style.css', $result[2]['file']); $this->assertEquals('http://external.host/style.css', $result[2]['file']);
$this->assertRegexp('/combined\/[0-9a-f]+\.css\?\d+$/', $result[3]['file']); $this->assertRegexp('/combined\/[0-9a-f]+\.css\?\d+$/', $result[3]['file']);
@ -288,6 +290,6 @@ class FrontEndFileHandlerTest extends \Codeception\TestCase\Test
$this->assertEquals(0, count($result)); $this->assertEquals(0, count($result));
$result = $handler->getJsFileList(); $result = $handler->getJsFileList();
$this->assertEquals(1, count($result)); $this->assertEquals(1, count($result));
$this->assertEquals('/rhymix/common/js/xml2json.js' . $this->_filemtime('common/js/xml2json.js'), $result[0]['file']); $this->assertEquals($this->baseurl . 'common/js/xml2json.js' . $this->_filemtime('common/js/xml2json.js'), $result[0]['file']);
} }
} }

View file

@ -2,8 +2,14 @@
class TemplateHandlerTest extends \Codeception\TestCase\Test class TemplateHandlerTest extends \Codeception\TestCase\Test
{ {
var $prefix = '<?php if(!defined("__XE__"))exit;'; private $baseurl;
private $prefix = '<?php if(!defined("__XE__"))exit;';
public function _before()
{
$this->baseurl = '/' . basename(dirname(dirname(dirname(__DIR__)))) . '/';
}
public function testParse() public function testParse()
{ {
$tests = array( $tests = array(
@ -145,12 +151,12 @@ class TemplateHandlerTest extends \Codeception\TestCase\Test
// relative path1 // relative path1
array( 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="../local.gif" />',
'?><img src="http://naver.com/naver.gif"><input type="image" src="/rhymix/tests/unit/classes/local.gif" />' '?><img src="http://naver.com/naver.gif"><input type="image" src="' . $this->baseurl . 'tests/unit/classes/local.gif" />'
), ),
// relative path2 // relative path2
array( array(
'<img src="http://naver.com/naver.gif"><input type="image" src="../../../dir/local.gif" />', '<img src="http://naver.com/naver.gif"><input type="image" src="../../../dir/local.gif" />',
'?><img src="http://naver.com/naver.gif"><input type="image" src="/rhymix/tests/dir/local.gif" />' '?><img src="http://naver.com/naver.gif"><input type="image" src="' . $this->baseurl . 'tests/dir/local.gif" />'
), ),
// error case // error case
array( array(
@ -210,7 +216,7 @@ class TemplateHandlerTest extends \Codeception\TestCase\Test
// issue 584 // issue 584
array( array(
'<img cond="$oBodex->display_extra_images[\'mobile\'] && $arr_extra && $arr_extra->bodex->mobile" src="./images/common/mobile.gif" title="mobile" alt="mobile" />', '<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="/rhymix/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="' . $this->baseurl . 'tests/unit/classes/template/images/common/mobile.gif" title="mobile" alt="mobile" /><?php } ?>'
), ),
// issue 831 // issue 831
array( array(
@ -220,7 +226,7 @@ class TemplateHandlerTest extends \Codeception\TestCase\Test
// issue 746 // issue 746
array( array(
'<img src="../whatever/img.png" />', '<img src="../whatever/img.png" />',
'?><img src="/rhymix/tests/unit/classes/whatever/img.png" />' '?><img src="' . $this->baseurl . 'tests/unit/classes/whatever/img.png" />'
), ),
// issue 696 // issue 696
array( array(
@ -230,35 +236,35 @@ class TemplateHandlerTest extends \Codeception\TestCase\Test
// https://github.com/xpressengine/xe-core/issues/1510 // https://github.com/xpressengine/xe-core/issues/1510
array( array(
'<img cond="$foo->bar" src="../common/mobile.gif" />', '<img cond="$foo->bar" src="../common/mobile.gif" />',
PHP_EOL . 'if($__Context->foo->bar){ ?><img src="/rhymix/tests/unit/classes/common/mobile.gif" /><?php } ?>' PHP_EOL . 'if($__Context->foo->bar){ ?><img src="' . $this->baseurl . 'tests/unit/classes/common/mobile.gif" /><?php } ?>'
), ),
// https://github.com/xpressengine/xe-core/issues/1510 // https://github.com/xpressengine/xe-core/issues/1510
array( array(
'<img cond="$foo->bar > 100" alt="a!@#$%^&*()_-=[]{}?/" src="../common/mobile.gif" />', '<img cond="$foo->bar > 100" alt="a!@#$%^&*()_-=[]{}?/" src="../common/mobile.gif" />',
PHP_EOL . 'if($__Context->foo->bar > 100){ ?><img alt="a!@#$%^&*()_-=[]{}?/" src="/rhymix/tests/unit/classes/common/mobile.gif" /><?php } ?>' PHP_EOL . 'if($__Context->foo->bar > 100){ ?><img alt="a!@#$%^&*()_-=[]{}?/" src="' . $this->baseurl . 'tests/unit/classes/common/mobile.gif" /><?php } ?>'
), ),
// https://github.com/xpressengine/xe-core/issues/1510 // https://github.com/xpressengine/xe-core/issues/1510
array( array(
'<img src="../common/mobile.gif" cond="$foo->bar" />', '<img src="../common/mobile.gif" cond="$foo->bar" />',
PHP_EOL . 'if($__Context->foo->bar){ ?><img src="/rhymix/tests/unit/classes/common/mobile.gif" /><?php } ?>' PHP_EOL . 'if($__Context->foo->bar){ ?><img src="' . $this->baseurl . 'tests/unit/classes/common/mobile.gif" /><?php } ?>'
), ),
// https://github.com/xpressengine/xe-core/issues/1510 // https://github.com/xpressengine/xe-core/issues/1510
array( array(
'<img class="tmp_class" cond="!$module_info->title" src="../img/common/blank.gif" />', '<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="/rhymix/tests/unit/classes/img/common/blank.gif" /><?php } ?>' PHP_EOL . 'if(!$__Context->module_info->title){ ?><img class="tmp_class" src="' . $this->baseurl . 'tests/unit/classes/img/common/blank.gif" /><?php } ?>'
), ),
// https://github.com/xpressengine/xe-core/issues/1510 // https://github.com/xpressengine/xe-core/issues/1510
array( array(
'<img cond="$mi->title" class="tmp_class"|cond="$mi->use" src="../img/common/blank.gif" />', '<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="/rhymix/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="' . $this->baseurl . 'tests/unit/classes/img/common/blank.gif" /><?php } ?>'
), ),
array( array(
'<input foo="bar" /> <img cond="$foo->bar" alt="alt" src="../common/mobile.gif" />', '<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="/rhymix/tests/unit/classes/common/mobile.gif" /><?php } ?>' '?><input foo="bar" /> <?php if($__Context->foo->bar){ ?><img alt="alt" src="' . $this->baseurl . 'tests/unit/classes/common/mobile.gif" /><?php } ?>'
), ),
array( array(
'<input foo="bar" />' . "\n" . '<input foo="bar" /> <img cond="$foo->bar" alt="alt" src="../common/mobile.gif" />', '<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="/rhymix/tests/unit/classes/common/mobile.gif" /><?php } ?>' '?><input foo="bar" />' . PHP_EOL . '<input foo="bar" /> <?php if($__Context->foo->bar){ ?><img alt="alt" src="' . $this->baseurl . 'tests/unit/classes/common/mobile.gif" /><?php } ?>'
), ),
array( array(
'asf <img src="{$foo->bar}" />', 'asf <img src="{$foo->bar}" />',
@ -266,11 +272,11 @@ class TemplateHandlerTest extends \Codeception\TestCase\Test
), ),
array( array(
'<img alt="" '.PHP_EOL.' src="../whatever/img.png" />', '<img alt="" '.PHP_EOL.' src="../whatever/img.png" />',
'?><img alt="" '.PHP_EOL.' src="/rhymix/tests/unit/classes/whatever/img.png" />' '?><img alt="" '.PHP_EOL.' src="' . $this->baseurl . 'tests/unit/classes/whatever/img.png" />'
), ),
array( array(
'<input>asdf src="../img/img.gif" asdf</input> <img alt="src" src="../whatever/img.png" /> <input>asdf src="../img/img.gif" asdf</input>', '<input>asdf src="../img/img.gif" asdf</input> <img alt="src" src="../whatever/img.png" /> <input>asdf src="../img/img.gif" asdf</input>',
'?><input>asdf src="../img/img.gif" asdf</input> <img alt="src" src="/rhymix/tests/unit/classes/whatever/img.png" /> <input>asdf src="../img/img.gif" asdf</input>' '?><input>asdf src="../img/img.gif" asdf</input> <img alt="src" src="' . $this->baseurl . 'tests/unit/classes/whatever/img.png" /> <input>asdf src="../img/img.gif" asdf</input>'
), ),
array( array(
'<input>asdf src="../img/img.gif" asdf</input>', '<input>asdf src="../img/img.gif" asdf</input>',
@ -279,7 +285,7 @@ class TemplateHandlerTest extends \Codeception\TestCase\Test
// srcset (PR #1544) // srcset (PR #1544)
array( array(
'<img src="./img/sticker_banner_960w.png" alt="this is a test image." srcset="https://abc.com/static/img/test@2x.png 2x, http://abc.com/static/test@2.5x.png 2.5x,../img/test@3x.png 3x, ../img/test_960w.png 960w, {$mid}/image.png 480w">', '<img src="./img/sticker_banner_960w.png" alt="this is a test image." srcset="https://abc.com/static/img/test@2x.png 2x, http://abc.com/static/test@2.5x.png 2.5x,../img/test@3x.png 3x, ../img/test_960w.png 960w, {$mid}/image.png 480w">',
'?><img src="/rhymix/tests/unit/classes/template/img/sticker_banner_960w.png" alt="this is a test image." srcset="https://abc.com/static/img/test@2x.png 2x, http://abc.com/static/test@2.5x.png 2.5x, /rhymix/tests/unit/classes/img/test@3x.png 3x, /rhymix/tests/unit/classes/img/test_960w.png 960w, <?php echo $__Context->mid ?>/image.png 480w">' '?><img src="' . $this->baseurl . 'tests/unit/classes/template/img/sticker_banner_960w.png" alt="this is a test image." srcset="https://abc.com/static/img/test@2x.png 2x, http://abc.com/static/test@2.5x.png 2.5x, ' . $this->baseurl . 'tests/unit/classes/img/test@3x.png 3x, ' . $this->baseurl . 'tests/unit/classes/img/test_960w.png 960w, <?php echo $__Context->mid ?>/image.png 480w">'
), ),
// Rhymix improvements (PR #604) // Rhymix improvements (PR #604)
array( array(

View file

@ -83,6 +83,7 @@ class MailTest extends \Codeception\TestCase\Test
public function testMailBody() public function testMailBody()
{ {
$baseurl = '/' . basename(dirname(dirname(dirname(__DIR__)))) . '/';
$mail = new Rhymix\Framework\Mail; $mail = new Rhymix\Framework\Mail;
$mail->setBody('<p>Hello world!</p>', 'text/html'); $mail->setBody('<p>Hello world!</p>', 'text/html');
@ -98,11 +99,11 @@ class MailTest extends \Codeception\TestCase\Test
$this->assertEquals('text/plain', $mail->getContentType()); $this->assertEquals('text/plain', $mail->getContentType());
$mail->setBody('<p><img src="files/attach/foobar.jpg" alt="TEST" /></p>', 'text/html'); $mail->setBody('<p><img src="files/attach/foobar.jpg" alt="TEST" /></p>', 'text/html');
$this->assertEquals('<p><img src="https://www.rhymix.org/rhymix/files/attach/foobar.jpg" alt="TEST" /></p>', $mail->getBody()); $this->assertEquals('<p><img src="https://www.rhymix.org' . $baseurl . 'files/attach/foobar.jpg" alt="TEST" /></p>', $mail->getBody());
$mail->setBody('<p><img src="./files/attach/foobar.jpg" alt="TEST" /></p>', 'text/html'); $mail->setBody('<p><img src="./files/attach/foobar.jpg" alt="TEST" /></p>', 'text/html');
$this->assertEquals('<p><img src="https://www.rhymix.org/rhymix/files/attach/foobar.jpg" alt="TEST" /></p>', $mail->getBody()); $this->assertEquals('<p><img src="https://www.rhymix.org' . $baseurl . 'files/attach/foobar.jpg" alt="TEST" /></p>', $mail->getBody());
$mail->setBody('<p><img src="/rhymix/files/attach/foobar.jpg" alt="TEST" /></p>', 'text/html'); $mail->setBody('<p><img src="' . $baseurl . 'files/attach/foobar.jpg" alt="TEST" /></p>', 'text/html');
$this->assertEquals('<p><img src="https://www.rhymix.org/rhymix/files/attach/foobar.jpg" alt="TEST" /></p>', $mail->getBody()); $this->assertEquals('<p><img src="https://www.rhymix.org' . $baseurl . 'files/attach/foobar.jpg" alt="TEST" /></p>', $mail->getBody());
$mail->setBody('<p><img src="./files/attach/foobar.jpg" alt="TEST" /></p>', 'text/plain'); $mail->setBody('<p><img src="./files/attach/foobar.jpg" alt="TEST" /></p>', 'text/plain');
$this->assertEquals('<p><img src="./files/attach/foobar.jpg" alt="TEST" /></p>', $mail->getBody()); $this->assertEquals('<p><img src="./files/attach/foobar.jpg" alt="TEST" /></p>', $mail->getBody());

View file

@ -2,32 +2,41 @@
class URLTest extends \Codeception\TestCase\Test class URLTest extends \Codeception\TestCase\Test
{ {
private $baseurl;
private $relurl;
public function _before()
{
$this->baseurl = 'https://www.rhymix.org/' . basename(dirname(dirname(dirname(__DIR__)))) . '/';
$this->relurl = basename(dirname(dirname(dirname(__DIR__))));
}
public function testGetCurrentURL() public function testGetCurrentURL()
{ {
$old_request_uri = $_SERVER['REQUEST_URI']; $old_request_uri = $_SERVER['REQUEST_URI'];
$_SERVER['REQUEST_URI'] = '/rhymix/index.php?foo=bar&xe=sucks'; $_SERVER['REQUEST_URI'] = '/' . $this->relurl . '/index.php?foo=bar&xe=sucks';
// Getting the current URL // Getting the current URL
$this->assertEquals('https://www.rhymix.org/rhymix/index.php?foo=bar&xe=sucks', Rhymix\Framework\URL::getCurrentURL()); $this->assertEquals($this->baseurl . 'index.php?foo=bar&xe=sucks', Rhymix\Framework\URL::getCurrentURL());
// Adding items to the query string // Adding items to the query string
$this->assertEquals('https://www.rhymix.org/rhymix/index.php?foo=bar&xe=sucks&var=1&arr%5B0%5D=2&arr%5B1%5D=3', Rhymix\Framework\URL::getCurrentURL(array('var' => '1', 'arr' => array(2, 3)))); $this->assertEquals($this->baseurl . 'index.php?foo=bar&xe=sucks&var=1&arr%5B0%5D=2&arr%5B1%5D=3', Rhymix\Framework\URL::getCurrentURL(array('var' => '1', 'arr' => array(2, 3))));
// Removing item from the query string // Removing item from the query string
$this->assertEquals('https://www.rhymix.org/rhymix/index.php?xe=sucks', Rhymix\Framework\URL::getCurrentURL(array('foo' => null))); $this->assertEquals($this->baseurl . 'index.php?xe=sucks', Rhymix\Framework\URL::getCurrentURL(array('foo' => null)));
// Removing all items from the query string // Removing all items from the query string
$this->assertEquals('https://www.rhymix.org/rhymix/index.php', Rhymix\Framework\URL::getCurrentURL(array('foo' => null, 'xe' => null))); $this->assertEquals($this->baseurl . 'index.php', Rhymix\Framework\URL::getCurrentURL(array('foo' => null, 'xe' => null)));
// Adding and removing parameters at the same time // Adding and removing parameters at the same time
$this->assertEquals('https://www.rhymix.org/rhymix/index.php?xe=sucks&l=ko', Rhymix\Framework\URL::getCurrentURL(array('l' => 'ko', 'foo' => null))); $this->assertEquals($this->baseurl . 'index.php?xe=sucks&l=ko', Rhymix\Framework\URL::getCurrentURL(array('l' => 'ko', 'foo' => null)));
// Removing invalid characters in the current URL // Removing invalid characters in the current URL
$_SERVER['REQUEST_URI'] = '/rhymix/?foo="bar"'; $_SERVER['REQUEST_URI'] = '/' . $this->relurl . '/?foo="bar"';
$this->assertEquals('https://www.rhymix.org/rhymix/?foo=bar', Rhymix\Framework\URL::getCurrentURL()); $this->assertEquals($this->baseurl . '?foo=bar', Rhymix\Framework\URL::getCurrentURL());
$_SERVER['REQUEST_URI'] = '/rhymix/?foo=<bar&baz=rhymix>'; $_SERVER['REQUEST_URI'] = '/' . $this->relurl . '/?foo=<bar&baz=rhymix>';
$this->assertEquals('https://www.rhymix.org/rhymix/?foo=bar&baz=rhymix', Rhymix\Framework\URL::getCurrentURL()); $this->assertEquals($this->baseurl . '?foo=bar&baz=rhymix', Rhymix\Framework\URL::getCurrentURL());
$this->assertEquals('https://www.rhymix.org/rhymix/?baz=rhymix&l=ko', Rhymix\Framework\URL::getCurrentURL(array('l' => 'ko', 'foo' => null))); $this->assertEquals($this->baseurl . '?baz=rhymix&l=ko', Rhymix\Framework\URL::getCurrentURL(array('l' => 'ko', 'foo' => null)));
$_SERVER['REQUEST_URI'] = $old_request_uri; $_SERVER['REQUEST_URI'] = $old_request_uri;
} }
@ -37,15 +46,15 @@ class URLTest extends \Codeception\TestCase\Test
$this->assertEquals('https://www.rhymix.org/', Rhymix\Framework\URL::getCurrentDomainURL()); $this->assertEquals('https://www.rhymix.org/', Rhymix\Framework\URL::getCurrentDomainURL());
$this->assertEquals('https://www.rhymix.org/', Rhymix\Framework\URL::getCurrentDomainURL('/')); $this->assertEquals('https://www.rhymix.org/', Rhymix\Framework\URL::getCurrentDomainURL('/'));
$this->assertEquals('https://www.rhymix.org/foo/bar', Rhymix\Framework\URL::getCurrentDomainURL('/foo/bar')); $this->assertEquals('https://www.rhymix.org/foo/bar', Rhymix\Framework\URL::getCurrentDomainURL('/foo/bar'));
$this->assertEquals('https://www.rhymix.org/rhymix/index.php?foo=bar', Rhymix\Framework\URL::getCurrentDomainURL('rhymix/index.php?foo=bar')); $this->assertEquals($this->baseurl . 'index.php?foo=bar', Rhymix\Framework\URL::getCurrentDomainURL($this->relurl . '/index.php?foo=bar'));
} }
public function testGetCanonicalURL() public function testGetCanonicalURL()
{ {
$tests = array( $tests = array(
'foo/bar' => 'https://www.rhymix.org/rhymix/foo/bar', 'foo/bar' => $this->baseurl . 'foo/bar',
'./foo/bar' => 'https://www.rhymix.org/rhymix/foo/bar', './foo/bar' => $this->baseurl . 'foo/bar',
'/foo/bar' => 'https://www.rhymix.org/rhymix/foo/bar', '/foo/bar' => $this->baseurl . 'foo/bar',
'//www.example.com/foo' => 'https://www.example.com/foo', '//www.example.com/foo' => 'https://www.example.com/foo',
'http://xn--cg4bkiv2oina.com/' => 'http://삼성전자.com/', 'http://xn--cg4bkiv2oina.com/' => 'http://삼성전자.com/',
); );
@ -73,16 +82,16 @@ class URLTest extends \Codeception\TestCase\Test
public function testModifyURL() public function testModifyURL()
{ {
// Conversion to absolute // Conversion to absolute
$this->assertEquals('https://www.rhymix.org/rhymix/index.php?foo=bar', $url = Rhymix\Framework\URL::modifyURL('./index.php?foo=bar')); $this->assertEquals($this->baseurl . 'index.php?foo=bar', $url = Rhymix\Framework\URL::modifyURL('./index.php?foo=bar'));
// Adding items to the query string // Adding items to the query string
$this->assertEquals('https://www.rhymix.org/rhymix/index.php?foo=bar&var=1&arr%5B0%5D=2&arr%5B1%5D=3', Rhymix\Framework\URL::modifyURL($url, array('var' => '1', 'arr' => array(2, 3)))); $this->assertEquals($this->baseurl . 'index.php?foo=bar&var=1&arr%5B0%5D=2&arr%5B1%5D=3', Rhymix\Framework\URL::modifyURL($url, array('var' => '1', 'arr' => array(2, 3))));
// Removing item from the query string // Removing item from the query string
$this->assertEquals('https://www.rhymix.org/rhymix/index.php', Rhymix\Framework\URL::modifyURL($url, array('foo' => null))); $this->assertEquals($this->baseurl . 'index.php', Rhymix\Framework\URL::modifyURL($url, array('foo' => null)));
// Adding and removing parameters at the same time // Adding and removing parameters at the same time
$this->assertEquals('https://www.rhymix.org/rhymix/index.php?l=ko', Rhymix\Framework\URL::modifyURL($url, array('l' => 'ko', 'foo' => null))); $this->assertEquals($this->baseurl . 'index.php?l=ko', Rhymix\Framework\URL::modifyURL($url, array('l' => 'ko', 'foo' => null)));
} }
public function testIsInternalURL() public function testIsInternalURL()
@ -92,17 +101,17 @@ class URLTest extends \Codeception\TestCase\Test
public function testURLFromServerPath() public function testURLFromServerPath()
{ {
$this->assertEquals('https://www.rhymix.org/rhymix/', Rhymix\Framework\URL::fromServerPath(\RX_BASEDIR)); $this->assertEquals($this->baseurl . '', Rhymix\Framework\URL::fromServerPath(\RX_BASEDIR));
$this->assertEquals('https://www.rhymix.org/rhymix/index.php', Rhymix\Framework\URL::fromServerPath(\RX_BASEDIR . 'index.php')); $this->assertEquals($this->baseurl . 'index.php', Rhymix\Framework\URL::fromServerPath(\RX_BASEDIR . 'index.php'));
$this->assertEquals('https://www.rhymix.org/rhymix/foo/bar', Rhymix\Framework\URL::fromServerPath(\RX_BASEDIR . '/foo/bar')); $this->assertEquals($this->baseurl . 'foo/bar', Rhymix\Framework\URL::fromServerPath(\RX_BASEDIR . '/foo/bar'));
$this->assertEquals(false, Rhymix\Framework\URL::fromServerPath(dirname(dirname(\RX_BASEDIR)))); $this->assertEquals(false, Rhymix\Framework\URL::fromServerPath(dirname(dirname(\RX_BASEDIR))));
$this->assertEquals(false, Rhymix\Framework\URL::fromServerPath('C:/Windows')); $this->assertEquals(false, Rhymix\Framework\URL::fromServerPath('C:/Windows'));
} }
public function testURLToServerPath() public function testURLToServerPath()
{ {
$this->assertEquals(\RX_BASEDIR . 'index.php', Rhymix\Framework\URL::toServerPath('http://www.rhymix.org/rhymix/index.php')); $this->assertEquals(\RX_BASEDIR . 'index.php', Rhymix\Framework\URL::toServerPath($this->baseurl . 'index.php'));
$this->assertEquals(\RX_BASEDIR . 'foo/bar', Rhymix\Framework\URL::toServerPath('http://www.rhymix.org/rhymix/foo/bar?arg=baz')); $this->assertEquals(\RX_BASEDIR . 'foo/bar', Rhymix\Framework\URL::toServerPath($this->baseurl . 'foo/bar?arg=baz'));
$this->assertEquals(\RX_BASEDIR . 'foo/bar', Rhymix\Framework\URL::toServerPath('./foo/bar')); $this->assertEquals(\RX_BASEDIR . 'foo/bar', Rhymix\Framework\URL::toServerPath('./foo/bar'));
$this->assertEquals(\RX_BASEDIR . 'foo/bar', Rhymix\Framework\URL::toServerPath('foo/bar/../bar')); $this->assertEquals(\RX_BASEDIR . 'foo/bar', Rhymix\Framework\URL::toServerPath('foo/bar/../bar'));
$this->assertEquals(false, Rhymix\Framework\URL::toServerPath('http://other.domain.com/')); $this->assertEquals(false, Rhymix\Framework\URL::toServerPath('http://other.domain.com/'));

View file

@ -244,12 +244,14 @@ class HTMLFilterTest extends \Codeception\TestCase\Test
public function testHTMLFilterFixMediaUrls() public function testHTMLFilterFixMediaUrls()
{ {
$baseurl = '/' . basename(dirname(dirname(dirname(dirname(__DIR__))))) . '/';
$content = Rhymix\Framework\Filters\HTMLFilter::fixRelativeUrls('<img src="files/attach/foobar.jpg" alt="TEST" />'); $content = Rhymix\Framework\Filters\HTMLFilter::fixRelativeUrls('<img src="files/attach/foobar.jpg" alt="TEST" />');
$this->assertEquals('<img src="https://www.rhymix.org/rhymix/files/attach/foobar.jpg" alt="TEST" />', $content); $this->assertEquals('<img src="https://www.rhymix.org' . $baseurl . 'files/attach/foobar.jpg" alt="TEST" />', $content);
$content = Rhymix\Framework\Filters\HTMLFilter::fixRelativeUrls('<img src="./files/attach/foobar.jpg" editor_component="foobar" />'); $content = Rhymix\Framework\Filters\HTMLFilter::fixRelativeUrls('<img src="./files/attach/foobar.jpg" editor_component="foobar" />');
$this->assertEquals('<img src="https://www.rhymix.org/rhymix/files/attach/foobar.jpg" />', $content); $this->assertEquals('<img src="https://www.rhymix.org' . $baseurl . 'files/attach/foobar.jpg" />', $content);
$content = Rhymix\Framework\Filters\HTMLFilter::fixRelativeUrls('<img src="/rhymix/files/attach/foobar.jpg" id="foobar" data-file-srl="2345" />'); $content = Rhymix\Framework\Filters\HTMLFilter::fixRelativeUrls('<img src="' . $baseurl . 'files/attach/foobar.jpg" id="foobar" data-file-srl="2345" />');
$this->assertEquals('<img src="https://www.rhymix.org/rhymix/files/attach/foobar.jpg" />', $content); $this->assertEquals('<img src="https://www.rhymix.org' . $baseurl . 'files/attach/foobar.jpg" />', $content);
$content = Rhymix\Framework\Filters\HTMLFilter::fixRelativeUrls('<img src="//external.site/files/attach/foobar.jpg" alt="TEST" class="zbxe_widget_output" widget="baz" />'); $content = Rhymix\Framework\Filters\HTMLFilter::fixRelativeUrls('<img src="//external.site/files/attach/foobar.jpg" alt="TEST" class="zbxe_widget_output" widget="baz" />');
$this->assertEquals('<img src="//external.site/files/attach/foobar.jpg" alt="TEST" />', $content); $this->assertEquals('<img src="//external.site/files/attach/foobar.jpg" alt="TEST" />', $content);
} }