From af2c0bae955872c86a7ec6df8d1027eb4f259733 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Tue, 15 Mar 2022 02:52:21 +0900 Subject: [PATCH] Fix relative path used in unit tests --- tests/_bootstrap.php | 4 +- .../unit/classes/FrontEndFileHandlerTest.php | 54 +++++++++--------- tests/unit/classes/TemplateHandlerTest.php | 36 +++++++----- tests/unit/framework/MailTest.php | 9 +-- tests/unit/framework/URLTest.php | 57 +++++++++++-------- .../unit/framework/filters/HTMLFilterTest.php | 10 ++-- 6 files changed, 95 insertions(+), 75 deletions(-) diff --git a/tests/_bootstrap.php b/tests/_bootstrap.php index 8017ed216..89f33a650 100644 --- a/tests/_bootstrap.php +++ b/tests/_bootstrap.php @@ -7,8 +7,8 @@ $_SERVER['SERVER_NAME'] = 'www.rhymix.org'; $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; $_SERVER['DOCUMENT_ROOT'] = dirname(dirname(__DIR__)); $_SERVER['SCRIPT_FILENAME'] = dirname(__DIR__) . '/index.php'; -$_SERVER['SCRIPT_NAME'] = '/rhymix/index.php'; -$_SERVER['REQUEST_URI'] = '/rhymix/index.php'; +$_SERVER['SCRIPT_NAME'] = '/' . basename(dirname(__DIR__)) . '/index.php'; +$_SERVER['REQUEST_URI'] = '/' . basename(dirname(__DIR__)) . '/index.php'; // Include the autoloader. require_once dirname(__DIR__) . '/common/autoload.php'; diff --git a/tests/unit/classes/FrontEndFileHandlerTest.php b/tests/unit/classes/FrontEndFileHandlerTest.php index 645257e94..20375312e 100644 --- a/tests/unit/classes/FrontEndFileHandlerTest.php +++ b/tests/unit/classes/FrontEndFileHandlerTest.php @@ -2,6 +2,7 @@ class FrontEndFileHandlerTest extends \Codeception\TestCase\Test { + private $baseurl; private $reservedCSS; private $reservedJS; private function _filemtime($file) @@ -11,6 +12,7 @@ class FrontEndFileHandlerTest extends \Codeception\TestCase\Test public function _before() { + $this->baseurl = '/' . basename(dirname(dirname(dirname(__DIR__)))) . '/'; $this->reservedCSS = HTMLDisplayHandler::$reservedCSS; $this->reservedJS = HTMLDisplayHandler::$reservedJS; 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', 'head')); $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' => '/rhymix/common/js/common.js' . $this->_filemtime('common/js/common.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' => $this->baseurl . 'common/js/common.js' . $this->_filemtime('common/js/common.js'), 'targetie' => null); $this->assertEquals($expected, $handler->getJsFileList()); } @@ -48,7 +50,7 @@ class FrontEndFileHandlerTest extends \Codeception\TestCase\Test $handler = new FrontEndFileHandler(); $handler->loadFile(array('./common/js/xml_handler.js', 'body')); $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')); } @@ -73,10 +75,10 @@ class FrontEndFileHandlerTest extends \Codeception\TestCase\Test $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_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' => '/rhymix/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' => '/rhymix/common/js/xml_js_filter.js' . $this->_filemtime('common/js/xml_js_filter.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' => $this->baseurl . 'common/js/common.js' . $this->_filemtime('common/js/common.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' => $this->baseurl . 'common/js/xml_js_filter.js' . $this->_filemtime('common/js/xml_js_filter.js'), 'targetie' => null); $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/common.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' => '/rhymix/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' => '/rhymix/common/js/xml_handler.js' . $this->_filemtime('common/js/xml_handler.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' => $this->baseurl . 'common/js/common.js' . $this->_filemtime('common/js/common.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' => $this->baseurl . 'common/js/xml_handler.js' . $this->_filemtime('common/js/xml_handler.js'), 'targetie' => null); $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_js_filter.js', 'head', '', -100000)); $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' => '/rhymix/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/common.js' . $this->_filemtime('common/js/common.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' => $this->baseurl . 'common/js/xml_js_filter.js' . $this->_filemtime('common/js/xml_js_filter.js'), 'targetie' => null); $this->assertEquals($expected, $handler->getJsFileList()); } @@ -164,7 +166,7 @@ class FrontEndFileHandlerTest extends \Codeception\TestCase\Test $handler = new FrontEndFileHandler(); $handler->loadFile(array('./common/xeicon/xeicon.min.css')); $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->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', 'ie7')); $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' => '/rhymix/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' => 'ie6'); + $expected[] = array('file' => $this->baseurl . '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' => 'ie8'); $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, 'ie8')); - $expected[] = array('file' => '/rhymix/common/css/common.css', 'media' => 'all', 'targetie' => 'ie6'); - $expected[] = array('file' => '/rhymix/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' => 'ie6'); + $expected[] = array('file' => $this->baseurl . 'common/css/common.css', 'media' => 'all', 'targetie' => 'ie7'); + $expected[] = array('file' => $this->baseurl . 'common/css/common.css', 'media' => 'all', 'targetie' => 'ie8'); $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', 'handled')); - $expected[] = array('file' => '/rhymix/common/css/common.css', 'media'=>'all', 'targetie' => null); - $expected[] = array('file' => '/rhymix/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'=>'all', 'targetie' => null); + $expected[] = array('file' => $this->baseurl . 'common/css/common.css','media'=>'screen', 'targetie' => null); + $expected[] = array('file' => $this->baseurl . 'common/css/common.css', 'media'=>'handled', 'targetie' => null); $this->assertEquals($expected, $handler->getCssFileList()); } @@ -243,7 +245,7 @@ class FrontEndFileHandlerTest extends \Codeception\TestCase\Test $result = $handler->getCssFileList(true); $this->assertEquals(4, count($result)); $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('http://external.host/style.css', $result[2]['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)); $result = $handler->getJsFileList(); $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']); } } diff --git a/tests/unit/classes/TemplateHandlerTest.php b/tests/unit/classes/TemplateHandlerTest.php index c45d92853..9cc760020 100644 --- a/tests/unit/classes/TemplateHandlerTest.php +++ b/tests/unit/classes/TemplateHandlerTest.php @@ -2,8 +2,14 @@ class TemplateHandlerTest extends \Codeception\TestCase\Test { - var $prefix = 'baseurl = '/' . basename(dirname(dirname(dirname(__DIR__)))) . '/'; + } + public function testParse() { $tests = array( @@ -145,12 +151,12 @@ class TemplateHandlerTest extends \Codeception\TestCase\Test // relative path1 array( '', - '?>' + '?>' ), // relative path2 array( '', - '?>' + '?>' ), // error case array( @@ -210,7 +216,7 @@ class TemplateHandlerTest extends \Codeception\TestCase\Test // issue 584 array( 'mobile', - PHP_EOL . 'if($__Context->oBodex->display_extra_images[\'mobile\'] && $__Context->arr_extra && $__Context->arr_extra->bodex->mobile){ ?>mobile' + PHP_EOL . 'if($__Context->oBodex->display_extra_images[\'mobile\'] && $__Context->arr_extra && $__Context->arr_extra->bodex->mobile){ ?>mobile' ), // issue 831 array( @@ -220,7 +226,7 @@ class TemplateHandlerTest extends \Codeception\TestCase\Test // issue 746 array( '', - '?>' + '?>' ), // issue 696 array( @@ -230,35 +236,35 @@ class TemplateHandlerTest extends \Codeception\TestCase\Test // https://github.com/xpressengine/xe-core/issues/1510 array( '', - PHP_EOL . 'if($__Context->foo->bar){ ?>' + PHP_EOL . 'if($__Context->foo->bar){ ?>' ), // https://github.com/xpressengine/xe-core/issues/1510 array( 'a!@#$%^&*()_-=[]{}?/', - PHP_EOL . 'if($__Context->foo->bar > 100){ ?>a!@#$%^&*()_-=[]{}?/' + PHP_EOL . 'if($__Context->foo->bar > 100){ ?>a!@#$%^&*()_-=[]{}?/' ), // https://github.com/xpressengine/xe-core/issues/1510 array( '', - PHP_EOL . 'if($__Context->foo->bar){ ?>' + PHP_EOL . 'if($__Context->foo->bar){ ?>' ), // https://github.com/xpressengine/xe-core/issues/1510 array( '', - PHP_EOL . 'if(!$__Context->module_info->title){ ?>' + PHP_EOL . 'if(!$__Context->module_info->title){ ?>' ), // https://github.com/xpressengine/xe-core/issues/1510 array( '', - PHP_EOL . 'if($__Context->mi->title){ ?>mi->use){ ?> class="tmp_class" src="/rhymix/tests/unit/classes/img/common/blank.gif" />' + PHP_EOL . 'if($__Context->mi->title){ ?>mi->use){ ?> class="tmp_class" src="' . $this->baseurl . 'tests/unit/classes/img/common/blank.gif" />' ), array( ' alt', - '?> foo->bar){ ?>alt' + '?> foo->bar){ ?>alt' ), array( '' . "\n" . ' alt', - '?>' . PHP_EOL . ' foo->bar){ ?>alt' + '?>' . PHP_EOL . ' foo->bar){ ?>alt' ), array( 'asf ', @@ -266,11 +272,11 @@ class TemplateHandlerTest extends \Codeception\TestCase\Test ), array( '', - '?>' + '?>' ), array( 'asdf src="../img/img.gif" asdf src asdf src="../img/img.gif" asdf', - '?>asdf src="../img/img.gif" asdf src asdf src="../img/img.gif" asdf' + '?>asdf src="../img/img.gif" asdf src asdf src="../img/img.gif" asdf' ), array( 'asdf src="../img/img.gif" asdf', @@ -279,7 +285,7 @@ class TemplateHandlerTest extends \Codeception\TestCase\Test // srcset (PR #1544) array( 'this is a test image.', - '?>this is a test image.' + '?>this is a test image.' ), // Rhymix improvements (PR #604) array( diff --git a/tests/unit/framework/MailTest.php b/tests/unit/framework/MailTest.php index 8f30b7356..f4f88fe95 100644 --- a/tests/unit/framework/MailTest.php +++ b/tests/unit/framework/MailTest.php @@ -83,6 +83,7 @@ class MailTest extends \Codeception\TestCase\Test public function testMailBody() { + $baseurl = '/' . basename(dirname(dirname(dirname(__DIR__)))) . '/'; $mail = new Rhymix\Framework\Mail; $mail->setBody('

Hello world!

', 'text/html'); @@ -98,11 +99,11 @@ class MailTest extends \Codeception\TestCase\Test $this->assertEquals('text/plain', $mail->getContentType()); $mail->setBody('

TEST

', 'text/html'); - $this->assertEquals('

TEST

', $mail->getBody()); + $this->assertEquals('

TEST

', $mail->getBody()); $mail->setBody('

TEST

', 'text/html'); - $this->assertEquals('

TEST

', $mail->getBody()); - $mail->setBody('

TEST

', 'text/html'); - $this->assertEquals('

TEST

', $mail->getBody()); + $this->assertEquals('

TEST

', $mail->getBody()); + $mail->setBody('

TEST

', 'text/html'); + $this->assertEquals('

TEST

', $mail->getBody()); $mail->setBody('

TEST

', 'text/plain'); $this->assertEquals('

TEST

', $mail->getBody()); diff --git a/tests/unit/framework/URLTest.php b/tests/unit/framework/URLTest.php index 88f391e59..3cd1ea9af 100644 --- a/tests/unit/framework/URLTest.php +++ b/tests/unit/framework/URLTest.php @@ -2,32 +2,41 @@ 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() { $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 - $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 - $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 - $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 - $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 - $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 - $_SERVER['REQUEST_URI'] = '/rhymix/?foo="bar"'; - $this->assertEquals('https://www.rhymix.org/rhymix/?foo=bar', Rhymix\Framework\URL::getCurrentURL()); - $_SERVER['REQUEST_URI'] = '/rhymix/?foo='; - $this->assertEquals('https://www.rhymix.org/rhymix/?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))); + $_SERVER['REQUEST_URI'] = '/' . $this->relurl . '/?foo="bar"'; + $this->assertEquals($this->baseurl . '?foo=bar', Rhymix\Framework\URL::getCurrentURL()); + $_SERVER['REQUEST_URI'] = '/' . $this->relurl . '/?foo='; + $this->assertEquals($this->baseurl . '?foo=bar&baz=rhymix', Rhymix\Framework\URL::getCurrentURL()); + $this->assertEquals($this->baseurl . '?baz=rhymix&l=ko', Rhymix\Framework\URL::getCurrentURL(array('l' => 'ko', 'foo' => null))); $_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/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() { $tests = array( - 'foo/bar' => 'https://www.rhymix.org/rhymix/foo/bar', - './foo/bar' => 'https://www.rhymix.org/rhymix/foo/bar', - '/foo/bar' => 'https://www.rhymix.org/rhymix/foo/bar', + 'foo/bar' => $this->baseurl . 'foo/bar', + './foo/bar' => $this->baseurl . 'foo/bar', + '/foo/bar' => $this->baseurl . 'foo/bar', '//www.example.com/foo' => 'https://www.example.com/foo', 'http://xn--cg4bkiv2oina.com/' => 'http://삼성전자.com/', ); @@ -73,16 +82,16 @@ class URLTest extends \Codeception\TestCase\Test public function testModifyURL() { // 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 - $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 - $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 - $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() @@ -92,17 +101,17 @@ class URLTest extends \Codeception\TestCase\Test public function testURLFromServerPath() { - $this->assertEquals('https://www.rhymix.org/rhymix/', 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('https://www.rhymix.org/rhymix/foo/bar', Rhymix\Framework\URL::fromServerPath(\RX_BASEDIR . '/foo/bar')); + $this->assertEquals($this->baseurl . '', Rhymix\Framework\URL::fromServerPath(\RX_BASEDIR)); + $this->assertEquals($this->baseurl . 'index.php', Rhymix\Framework\URL::fromServerPath(\RX_BASEDIR . 'index.php')); + $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('C:/Windows')); } public function testURLToServerPath() { - $this->assertEquals(\RX_BASEDIR . 'index.php', Rhymix\Framework\URL::toServerPath('http://www.rhymix.org/rhymix/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 . 'index.php', Rhymix\Framework\URL::toServerPath($this->baseurl . 'index.php')); + $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/../bar')); $this->assertEquals(false, Rhymix\Framework\URL::toServerPath('http://other.domain.com/')); diff --git a/tests/unit/framework/filters/HTMLFilterTest.php b/tests/unit/framework/filters/HTMLFilterTest.php index 123921a9c..e2db9590e 100644 --- a/tests/unit/framework/filters/HTMLFilterTest.php +++ b/tests/unit/framework/filters/HTMLFilterTest.php @@ -244,12 +244,14 @@ class HTMLFilterTest extends \Codeception\TestCase\Test public function testHTMLFilterFixMediaUrls() { + $baseurl = '/' . basename(dirname(dirname(dirname(dirname(__DIR__))))) . '/'; + $content = Rhymix\Framework\Filters\HTMLFilter::fixRelativeUrls('TEST'); - $this->assertEquals('TEST', $content); + $this->assertEquals('TEST', $content); $content = Rhymix\Framework\Filters\HTMLFilter::fixRelativeUrls(''); - $this->assertEquals('', $content); - $content = Rhymix\Framework\Filters\HTMLFilter::fixRelativeUrls(''); - $this->assertEquals('', $content); + $this->assertEquals('', $content); + $content = Rhymix\Framework\Filters\HTMLFilter::fixRelativeUrls(''); + $this->assertEquals('', $content); $content = Rhymix\Framework\Filters\HTMLFilter::fixRelativeUrls('TEST'); $this->assertEquals('TEST', $content); }