Skip to content

Do more testings and fix some problems #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"phpmd": "vendor/bin/phpmd src,tests text ./phpmd.xml",
"fix": [
"vendor/bin/php-cs-fixer fix -v",
"vendor/bin/phpcbf src,tests"
"vendor/bin/phpcbf src tests"
],
"tests": [
"clear",
Expand Down
25 changes: 15 additions & 10 deletions src/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ public static function getCurrentPage()
*/
public static function getBaseUrl()
{
$uri = self::addBackslash(self::getUriMethods(), 'both');
$url = self::addBackslash(self::getCurrentPage());
$uri = self::addBackSlash(self::getUriMethods(), 'both');
$url = self::addBackSlash(self::getCurrentPage());

if ($uri !== '/') {
$url = trim(str_replace($uri, '', $url), '/');
}

return self::addBackslash($url);
return self::addBackSlash($url);
}

/**
Expand Down Expand Up @@ -197,19 +197,24 @@ public static function getPort()
*
* @return string → path/url/ | /path/url | /path/url/
*/
public static function addBackslash($uri, $position = 'end')
public static function addBackSlash($uri, $position = 'end')
{
switch ($position) {
case 'top':
return (substr($uri, 1) === '/') ? $uri : '/' . $uri;
$uri = (substr($uri, 1) === '/') ? $uri : '/' . $uri;
break;
case 'end':
return (substr($uri, -1) === '/') ? $uri : $uri . '/';
$uri = (substr($uri, -1) === '/') ? $uri : $uri . '/';
break;
case 'both':
$uri = self::addBackslash($uri, 'top');
$uri = self::addBackslash($uri, 'end');

return $uri;
$uri = self::addBackSlash($uri, 'top');
$uri = self::addBackSlash($uri, 'end');
break;
default:
$uri = false;
}

return $uri;
}

/**
Expand Down
64 changes: 56 additions & 8 deletions tests/UrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,19 @@ public function testGetProtocol()
);
}

/**
* Get the protocol from the url if getProtocol pass the url.
*
* @since 1.1.5
*/
public function testGetProtocolWithUrl()
{
$this->assertContains(
'https',
Url::getProtocol('https://josantonius.com/')
);
}

/**
* Check if it is a secure site (SSL).
*
Expand All @@ -111,6 +124,31 @@ public function testGetDomain()
'josantonius.com',
Url::getDomain()
);

$this->assertFalse(Url::getDomain('josantonius'));
}

/**
* Get the server name if getDomain pass the domain.
*
* @since 1.1.5
*/
public function testGetDomainWithDomain()
{
$this->assertContains(
'josantonius.com',
Url::getDomain('josantonius.com')
);
}

/**
* Get the false if getDomain pass the invalid domain.
*
* @since 1.1.5
*/
public function testGetDomainWithInvalidDomain()
{
$this->assertFalse(Url::getDomain('josantonius'));
}

/**
Expand Down Expand Up @@ -187,11 +225,11 @@ public function testGetPort()
*
* @since 1.1.5
*/
public function testAddBackslashEnd()
public function testAddBackSlashEnd()
{
$this->assertContains(
'https://josantonius.com/',
Url::addBackslash('https://josantonius.com')
Url::addBackSlash('https://josantonius.com')
);
}

Expand All @@ -200,11 +238,11 @@ public function testAddBackslashEnd()
*
* @since 1.1.5
*/
public function testAddBackslashEndAlternativeVersion()
public function testAddBackSlashEndAlternativeVersion()
{
$this->assertContains(
'https://josantonius.com/',
Url::addBackslash('https://josantonius.com', 'end')
Url::addBackSlash('https://josantonius.com', 'end')
);
}

Expand All @@ -213,11 +251,11 @@ public function testAddBackslashEndAlternativeVersion()
*
* @since 1.1.5
*/
public function testAddBackslashTop()
public function testAddBackSlashTop()
{
$this->assertContains(
'/josantonius.com',
Url::addBackslash('josantonius.com', 'top')
Url::addBackSlash('josantonius.com', 'top')
);
}

Expand All @@ -226,14 +264,24 @@ public function testAddBackslashTop()
*
* @since 1.1.5
*/
public function testAddBackslashBoth()
public function testAddBackSlashBoth()
{
$this->assertContains(
'/josantonius.com/',
Url::addBackslash('josantonius.com', 'both')
Url::addBackSlash('josantonius.com', 'both')
);
}

/**
* Add backslash if it is the default case.
*
* @since 1.1.5
*/
public function testAddBackSlashDefault()
{
$this->assertFalse(Url::addBackSlash('josantonius.com', 'default'));
}

/**
* Go to the previous url.
*
Expand Down