mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-04-25 21:32:51 +09:00
Fix relative path used in unit tests
This commit is contained in:
parent
0fec44222d
commit
3260d90d18
6 changed files with 95 additions and 75 deletions
|
|
@ -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=<bar&baz=rhymix>';
|
||||
$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=<bar&baz=rhymix>';
|
||||
$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/'));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue