Fix the rest of the menu urls

This commit is contained in:
Timothy Warren 2015-10-20 15:59:51 -04:00
parent 935076cc63
commit c99d4ee53d
5 changed files with 48 additions and 41 deletions

View File

@ -3,7 +3,7 @@
<head> <head>
<title><?= $title ?></title> <title><?= $title ?></title>
<meta charset="utf-8" /> <meta charset="utf-8" />
<link rel="stylesheet" href="<?= $escape->attr($urlGenerator->asset_url('css.php?g=base')) ?>" /> <link rel="stylesheet" href="<?= $urlGenerator->asset_url('css.php?g=base') ?>" />
<script> <script>
var BASE_URL = "<?= $urlGenerator->base_url($url_type) ?>"; var BASE_URL = "<?= $urlGenerator->base_url($url_type) ?>";
var CONTROLLER = "<?= $url_type ?>"; var CONTROLLER = "<?= $url_type ?>";
@ -28,7 +28,7 @@
<?= $helper->menu($menu_name) ?> <?= $helper->menu($menu_name) ?>
<?php if (is_view_page()): ?> <?php if (is_view_page()): ?>
<br /> <br />
<ul class="align_right"> <ul>
<li class="<?= is_not_selected('list', $urlGenerator->last_segment()) ?>"><a href="<?= $urlGenerator->url($route_path) ?>">Cover View</a></li> <li class="<?= is_not_selected('list', $urlGenerator->last_segment()) ?>"><a href="<?= $urlGenerator->url($route_path) ?>">Cover View</a></li>
<li class="<?= is_selected('list', $urlGenerator->last_segment()) ?>"><a href="<?= $urlGenerator->url("{$route_path}/list") ?>">List View</a></li> <li class="<?= is_selected('list', $urlGenerator->last_segment()) ?>"><a href="<?= $urlGenerator->url("{$route_path}/list") ?>">List View</a></li>
</ul> </ul>

View File

@ -4,11 +4,29 @@
*/ */
namespace Aviat\AnimeClient; namespace Aviat\AnimeClient;
use Aviat\Ion\Di\ContainerInterface;
/** /**
* UrlGenerator class. * UrlGenerator class.
*/ */
class UrlGenerator extends RoutingBase { class UrlGenerator extends RoutingBase {
/**
* The current HTTP host
*/
protected $host;
/**
* Constructor
*
* @param ContainerInterface $container
*/
public function __construct(ContainerInterface $container)
{
parent::__construct($container);
$this->host = $container->get('request')->server->get('HTTP_HOST');
}
/** /**
* Get the base url for css/js/images * Get the base url for css/js/images
* *
@ -36,11 +54,9 @@ class UrlGenerator extends RoutingBase {
{ {
$config_path = trim($this->__get("{$type}_path"), "/"); $config_path = trim($this->__get("{$type}_path"), "/");
// Set the appropriate HTTP host
$host = $_SERVER['HTTP_HOST'];
$path = ($config_path !== '') ? $config_path : ""; $path = ($config_path !== '') ? $config_path : "";
return implode("/", ['/', $host, $path]); return implode("/", ['/', $this->host, $path]);
} }
/** /**
@ -53,13 +69,25 @@ class UrlGenerator extends RoutingBase {
{ {
$path = trim($path, '/'); $path = trim($path, '/');
// Remove any optional parameters from the route
$path = preg_replace('`{/.*?}`i', '', $path); $path = preg_replace('`{/.*?}`i', '', $path);
// Set the appropriate HTTP host // Remove any optional parameters from the route
$host = $_SERVER['HTTP_HOST']; // and replace them with existing route parameters, if they exist
$path_segments = explode('/', $path);
$segments = $this->segments();
return "//{$host}/{$path}"; for($i=0; $i<count($path_segments); $i++)
{
if ( ! array_key_exists($i + 1, $segments))
{
$segments[$i + 1] = "";
}
$path_segments[$i] = preg_replace('`{.*?}`i', $segments[$i + 1], $path_segments[$i]);
}
$path = implode('/', $path_segments);
return "//{$this->host}/{$path}";
} }
/** /**
@ -71,11 +99,11 @@ class UrlGenerator extends RoutingBase {
public function default_url($type) public function default_url($type)
{ {
$type = trim($type); $type = trim($type);
$default_path = $this->__get("default_{$type}_path"); $default_path = $this->__get("default_{$type}_list_path");
if ( ! is_null($default_path)) if ( ! is_null($default_path))
{ {
return $this->url($default_path); return $this->url("{$type}/{$default_path}");
} }
return ""; return "";
@ -95,12 +123,6 @@ class UrlGenerator extends RoutingBase {
// Remove beginning/trailing slashes // Remove beginning/trailing slashes
$path = trim($path, '/'); $path = trim($path, '/');
// Remove any optional parameters from the route
$path = preg_replace('`{/.*?}`i', '', $path);
// Set the appropriate HTTP host
$host = $_SERVER['HTTP_HOST'];
// Set the default view // Set the default view
if ($path === '') if ($path === '')
{ {
@ -108,7 +130,7 @@ class UrlGenerator extends RoutingBase {
if ($this->__get('default_to_list_view')) $path .= '/list'; if ($this->__get('default_to_list_view')) $path .= '/list';
} }
return "//{$host}/{$path}"; return $this->url($path);
} }
} }
// End of UrlGenerator.php // End of UrlGenerator.php

View File

@ -203,11 +203,11 @@ class BaseApiModelTest extends AnimeClient_TestCase {
$this->assertEquals($expected, $actual); $this->assertEquals($expected, $actual);
} }
public function dataAuthenticate() public function dataAuthenticate()
{ {
$test_token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJqdGkiOiI4YTA5ZDk4Ny1iZWQxLTQyMTktYWVmOS0wMTcxYWVjYTE3ZWUiLCJzY29wZSI6WyJhbGwiXSwic3ViIjoxMDgwMTIsImlzcyI6MTQ0NTAxNzczNSwiZXhwIjoxNDUyOTY2NTM1fQ.fpha1ZDN9dSFAuHeJesfOP9pCk5-ZnZk4uv3zumRMY0'; $test_token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJqdGkiOiI4YTA5ZDk4Ny1iZWQxLTQyMTktYWVmOS0wMTcxYWVjYTE3ZWUiLCJzY29wZSI6WyJhbGwiXSwic3ViIjoxMDgwMTIsImlzcyI6MTQ0NTAxNzczNSwiZXhwIjoxNDUyOTY2NTM1fQ.fpha1ZDN9dSFAuHeJesfOP9pCk5-ZnZk4uv3zumRMY0';
return [ return [
'successful authentication' => [ 'successful authentication' => [
'username' => 'timw4mailtest', 'username' => 'timw4mailtest',
@ -243,10 +243,10 @@ class BaseApiModelTest extends AnimeClient_TestCase {
'handler' => $handler, 'handler' => $handler,
'http_errors' => FALSE // Don't throw an exception for 400/500 class status codes 'http_errors' => FALSE // Don't throw an exception for 400/500 class status codes
]); ]);
// Set the mock client // Set the mock client
$this->model->__set('client', $client); $this->model->__set('client', $client);
// Check results based on mock data // Check results based on mock data
$actual = $this->model->authenticate($username, $password); $actual = $this->model->authenticate($username, $password);
$this->assertEquals($expected, $actual, "Incorrect method return value"); $this->assertEquals($expected, $actual, "Incorrect method return value");

View File

@ -6,20 +6,6 @@ use Aviat\AnimeClient\UrlGenerator;
class UrlGeneratorTest extends AnimeClient_TestCase { class UrlGeneratorTest extends AnimeClient_TestCase {
public function setUp()
{
$this->container = new Container([
'config' => new Config([
'foo' => 'bar',
'routing' => [
'asset_path' => '/assets',
],
'bar' => 'baz'
])
]);
$this->config = $this->container->get('config');
}
public function assetUrlProvider() public function assetUrlProvider()
{ {
return [ return [
@ -140,5 +126,4 @@ class UrlGeneratorTest extends AnimeClient_TestCase {
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
} }
} }

View File

@ -11,7 +11,7 @@ class AnimeClient_TestCase extends PHPUnit_Framework_TestCase {
protected $container; protected $container;
protected static $staticContainer; protected static $staticContainer;
protected static $session_handler; protected static $session_handler;
public static function setUpBeforeClass() public static function setUpBeforeClass()
{ {
// Use mock session handler // Use mock session handler
@ -23,12 +23,12 @@ class AnimeClient_TestCase extends PHPUnit_Framework_TestCase {
public function setUp() public function setUp()
{ {
parent::setUp(); parent::setUp();
$config_array = [ $config_array = [
'asset_path' => '//localhost/assets/', 'asset_path' => '//localhost/assets/',
'databaase' => [], 'databaase' => [],
'routing' => [ 'routing' => [
'asset_path' => '/assets'
], ],
'routes' => [ 'routes' => [
'convention' => [ 'convention' => [
@ -40,7 +40,7 @@ class AnimeClient_TestCase extends PHPUnit_Framework_TestCase {
'manga' => [] 'manga' => []
] ]
]; ];
// Set up DI container // Set up DI container
$di = require _dir(APP_DIR, 'bootstrap.php'); $di = require _dir(APP_DIR, 'bootstrap.php');
$container = $di($config_array); $container = $di($config_array);