Removed unused BaseHref view function

This commit is contained in:
Chris Kankiewicz
2020-02-18 09:45:39 -07:00
parent 04e14163fc
commit 62bb190f04
3 changed files with 0 additions and 64 deletions

View File

@@ -15,7 +15,6 @@ class TwigProvider
/** @const Constant description */
protected const VIEW_FUNCTIONS = [
ViewFunctions\Asset::class,
ViewFunctions\BaseHref::class,
ViewFunctions\Breadcrumbs::class,
ViewFunctions\Config::class,
ViewFunctions\Icon::class,

View File

@@ -1,22 +0,0 @@
<?php
namespace App\ViewFunctions;
class BaseHref extends ViewFunction
{
/** @var string The function name */
protected $name = 'base_href';
/**
* Return the URL for a given path.
*
* @return string
*/
public function __invoke(): string
{
$protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http';
$baseHref = sprintf('%s://%s%s', $protocol, $_SERVER['HTTP_HOST'] ?? 'localhost', dirname($_SERVER['SCRIPT_NAME']));
return rtrim($baseHref, '/') . '/';
}
}

View File

@@ -1,41 +0,0 @@
<?php
namespace Tests\ViewFunctions;
use App\ViewFunctions\BaseHref;
use Tests\TestCase;
class BaseHrefTest extends TestCase
{
public function teardown(): void
{
unset($_SERVER['HTTPS'], $_SERVER['SCRIPT_NAME']);
parent::tearDown();
}
public function test_it_can_return_the_base_href(): void
{
$baseHref = new BaseHref($this->container, $this->config);
$this->assertEquals('http://localhost/', $baseHref());
}
public function test_it_return_the_base_href_when_using_https(): void
{
$_SERVER['HTTPS'] = 'on';
$baseHref = new BaseHref($this->container, $this->config);
$this->assertEquals('https://localhost/', $baseHref());
}
public function test_it_can_return_the_base_href_when_in_a_subdirectory(): void
{
$_SERVER['SCRIPT_NAME'] = '/some/dir/index.php';
$baseHref = new BaseHref($this->container, $this->config);
$this->assertEquals('http://localhost/some/dir/', $baseHref());
}
}