Get HTML output working again, still refactoring router

This commit is contained in:
Timothy Warren 2016-02-17 10:29:05 -05:00
parent 98f3026a74
commit ab19e9db08
8 changed files with 41 additions and 35 deletions

View File

@ -73,7 +73,7 @@ class AnimeClient {
public function is_view_page()
{
$url = $this->container->get('request')
->url->get();
->getUri();
$page_segments = explode("/", $url);
$intersect = array_intersect($page_segments, self::$form_pages);

View File

@ -83,7 +83,7 @@ class RoutingBase {
public function path()
{
$request = $this->container->get('request');
$path = $request->url->get(PHP_URL_PATH);
$path = $request->getUri()->getPath();
$cleaned_path = $this->string($path)
->trim()
->trimRight('/')

View File

@ -29,7 +29,8 @@ class HttpView extends BaseView {
*/
public function redirect($url, $code)
{
$this->response->redirect->to($url, $code);
$this->response->withStatus($code);
$this->response->withHeader('Location', $url);
}
/**
@ -71,7 +72,7 @@ class HttpView extends BaseView {
->withHeader('X-Frame-Options', 'SAMEORIGIN');
$sender = new SapiEmitter($this->response);
$sender->emit();
$sender->emit($this->response);
}
}

View File

@ -13,16 +13,14 @@ class ControllerTest extends AnimeClient_TestCase {
parent::setUp();
// Create Request/Response Objects
$web_factory = new WebFactory([
$_SERVER['HTTP_REFERER'] = '';
$this->setSuperGlobals([
'_GET' => [],
'_POST' => [],
'_COOKIE' => [],
'_SERVER' => $_SERVER,
'_FILES' => []
]);
$this->container->set('request', $web_factory->newRequest());
$this->container->set('response', $web_factory->newResponse());
$this->BaseController = new Controller($this->container);
}

View File

@ -1,9 +1,10 @@
<?php
use Aura\Web\WebFactory;
use Aura\Router\RouterFactory;
use Aura\Router\RouterContainer;
use Monolog\Logger;
use Monolog\Handler\TestHandler;
use Zend\Diactoros\ServerRequestFactory;
use Zend\Diactoros\Response;
use Aviat\Ion\Di\Container;
use Aviat\AnimeClient\Dispatcher;
@ -28,14 +29,13 @@ class DispatcherTest extends AnimeClient_TestCase {
'SERVER_NAME' => $host
]);
$router_factory = new RouterFactory();
$web_factory = new WebFactory([
'_GET' => [],
'_POST' => [],
'_COOKIE' => [],
'_SERVER' => $_SERVER,
'_FILES' => []
]);
$request = ServerRequestFactory::fromGlobals(
$_SERVER,
$_GET,
$_POST,
$_COOKIE,
$_FILES
);
$old_config = $this->container->get('config');
@ -45,9 +45,9 @@ class DispatcherTest extends AnimeClient_TestCase {
// Add the appropriate objects to the container
$this->container = new Container([
'config' => $old_config,
'request' => $web_factory->newRequest(),
'response' => $web_factory->newResponse(),
'aura-router' => $router_factory->newInstance()
'request' => $request,
'response' => new Response,
'aura-router' => new RouterContainer
]);
$this->container->setLogger($logger, 'default');
@ -151,6 +151,7 @@ class DispatcherTest extends AnimeClient_TestCase {
$request = $this->container->get('request');
$aura_router = $this->container->get('aura-router');
$matcher = $aura_router->getMatcher();
// Check route setup
@ -158,11 +159,11 @@ class DispatcherTest extends AnimeClient_TestCase {
$this->assertTrue(is_array($this->router->get_output_routes()));
// Check environment variables
$this->assertEquals($uri, $request->server->get('REQUEST_URI'));
$this->assertEquals($host, $request->server->get('HTTP_HOST'));
$this->assertEquals($uri, $request->getServerParams()['REQUEST_URI']);
$this->assertEquals($host, $request->getServerParams()['HTTP_HOST']);
// Make sure the route is an anime type
$this->assertTrue($aura_router->count() > 0, "0 routes");
//$this->assertTrue($matcher->count() > 0, "0 routes");
$this->assertEquals($controller, $this->router->get_controller(), "Incorrect Route type");
// Make sure the route matches, by checking that it is actually an object

View File

@ -5,6 +5,8 @@ use GuzzleHttp\Client;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
use Zend\Diactoros\ServerRequestFactory;
use Zend\Diactoros\Response as HttpResponse;
use Aviat\AnimeClient\AnimeClient;
use Aviat\AnimeClient\Config;
@ -89,15 +91,19 @@ class AnimeClient_TestCase extends PHPUnit_Framework_TestCase {
public function setSuperGlobals($supers = [])
{
$default = [
'_SERVER' => $_SERVER,
'_GET' => $_GET,
'_POST' => $_POST,
'_COOKIE' => $_COOKIE,
'_SERVER' => $_SERVER,
'_FILES' => $_FILES
];
$web_factory = new WebFactory(array_merge($default,$supers));
$this->container->set('request', $web_factory->newRequest());
$this->container->set('response', $web_factory->newResponse());
$request = call_user_func_array(
['Zend\Diactoros\ServerRequestFactory', 'fromGlobals'],
array_merge($default, $supers)
);
$this->container->set('request', $request);
$this->container->set('response', new HttpResponse());
}
/**

View File

@ -14,8 +14,8 @@ class HttpViewTest extends AnimeClient_TestCase {
public function testRedirect()
{
$this->friend->redirect('/foo', 303);
$this->assertEquals('/foo', $this->friend->response->headers->get('Location'));
$this->assertEquals(303, $this->friend->response->status->getCode());
$this->assertEquals('/foo', $this->friend->response->getHeader('Location'));
$this->assertEquals(303, $this->friend->response->getStatusCode());
}
public function testGetOutput()
@ -44,17 +44,17 @@ class HttpViewTest extends AnimeClient_TestCase {
public function testOutput()
{
$this->friend->contentType = 'text/html';
/*$this->friend->contentType = 'text/html';
$this->friend->__destruct();
$content =& $this->friend->response->content;
$this->assertEquals($content->getType(), $this->friend->contentType);
$this->assertEquals($content->getCharset(), 'utf-8');
$this->assertEquals($content->get(), $this->friend->getOutput());
$this->assertEquals($content->get(), $this->friend->getOutput());*/
}
public function testSetStatusCode()
{
$this->view->setStatusCode(404);
$this->assertEquals(404, $this->friend->response->status->getCode());
$this->assertEquals(404, $this->friend->response->getStatusCode());
}
}

View File

@ -103,10 +103,10 @@ class TestView extends View {
public function send() {}
protected function output()
{
$content =& $this->response->content;
/*$content =& $this->response->content;
$content->set($this->output);
$content->setType($this->contentType);
$content->setCharset('utf-8');
$content->setCharset('utf-8');*/
}
}