Version 5.1 - All the GraphQL #32

Closed
timw4mail wants to merge 1160 commits from develop into master
5 changed files with 48 additions and 41 deletions
Showing only changes of commit c99d4ee53d - Show all commits

View File

@ -3,7 +3,7 @@
<head>
<title><?= $title ?></title>
<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>
var BASE_URL = "<?= $urlGenerator->base_url($url_type) ?>";
var CONTROLLER = "<?= $url_type ?>";
@ -28,7 +28,7 @@
<?= $helper->menu($menu_name) ?>
<?php if (is_view_page()): ?>
<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_selected('list', $urlGenerator->last_segment()) ?>"><a href="<?= $urlGenerator->url("{$route_path}/list") ?>">List View</a></li>
</ul>

View File

@ -4,11 +4,29 @@
*/
namespace Aviat\AnimeClient;
use Aviat\Ion\Di\ContainerInterface;
/**
* UrlGenerator class.
*/
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
*
@ -36,11 +54,9 @@ class UrlGenerator extends RoutingBase {
{
$config_path = trim($this->__get("{$type}_path"), "/");
// Set the appropriate HTTP host
$host = $_SERVER['HTTP_HOST'];
$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, '/');
// Remove any optional parameters from the route
$path = preg_replace('`{/.*?}`i', '', $path);
// Set the appropriate HTTP host
$host = $_SERVER['HTTP_HOST'];
// Remove any optional parameters from the route
// 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)
{
$type = trim($type);
$default_path = $this->__get("default_{$type}_path");
$default_path = $this->__get("default_{$type}_list_path");
if ( ! is_null($default_path))
{
return $this->url($default_path);
return $this->url("{$type}/{$default_path}");
}
return "";
@ -95,12 +123,6 @@ class UrlGenerator extends RoutingBase {
// Remove beginning/trailing slashes
$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
if ($path === '')
{
@ -108,7 +130,7 @@ class UrlGenerator extends RoutingBase {
if ($this->__get('default_to_list_view')) $path .= '/list';
}
return "//{$host}/{$path}";
return $this->url($path);
}
}
// End of UrlGenerator.php

View File

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

View File

@ -6,20 +6,6 @@ use Aviat\AnimeClient\UrlGenerator;
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()
{
return [
@ -140,5 +126,4 @@ class UrlGeneratorTest extends AnimeClient_TestCase {
$this->assertEquals($expected, $result);
}
}

View File

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