Beispiel #1
0
 public function testPrevCurrentNext()
 {
     $request = new RequestAggregate();
     $controller = new UsersController($request);
     $controller->initialize();
     $request->setRequest(new Param('/Users/page'));
     $request->setRequest(new Query([]));
     $controller->Paginator->paginate();
     $view = new ViewAdapter('../../app/View', '../../app/Layout', $controller);
     //current = 1
     $this->assertEquals(null, $view->Paginator->prev('prev'));
     $this->assertEquals(1, $view->Paginator->current());
     $this->assertEquals("<a href='/Users/page/?page=2'>next</a>", $view->Paginator->next('next'));
     $request->setRequest(new Query(['page' => 1]));
     $controller->Paginator->paginate();
     //current = 1
     $this->assertEquals(null, $view->Paginator->prev('prev'));
     $this->assertEquals(1, $view->Paginator->current());
     $this->assertEquals("<a href='/Users/page/?page=2'>next</a>", $view->Paginator->next('next'));
     $request->setRequest(new Query(['page' => 2]));
     $controller->Paginator->paginate();
     //current = 1
     $this->assertEquals("<a href='/Users/page/?page=1'>prev</a>", $view->Paginator->prev('prev'));
     $this->assertEquals(2, $view->Paginator->current());
     $this->assertEquals(null, $view->Paginator->next('next'));
 }
Beispiel #2
0
 public function testLoadComponent()
 {
     $request = new RequestAggregate();
     $request->setRequest(new Param('/Mocks/index/1'));
     $controller = new UsersController($request);
     $controller->initialize();
     $this->assertInstanceOf('MockComponent', $controller->Mock);
     $this->assertEquals('success', $controller->Mock->startup());
 }
Beispiel #3
0
 public function testParse()
 {
     $param = new Param('/Articles');
     $request = new RequestAggregate([$param]);
     $this->assertEquals(true, Router::has($request->getParam('url')));
     $this->assertEquals('Articles', Router::parse($request)->data('controller'));
     $this->assertEquals('index', Router::parse($request)->data('action'));
     $this->assertEquals([], Router::parse($request)->data('arguments'));
 }
Beispiel #4
0
    public function testDispatch()
    {
        $request = new RequestAggregate();
        $request->setRequest(new Param(''));
        Router::add('/', ['controller' => 'Pages', 'action' => 'index', 'arguments' => [1]]);
        $dispatcher = new Dispatcher($request);
        $expect = '<div><p>1</p>
</div>
';
        $this->expectOutputString($expect);
        $dispatcher->dispatch($request);
    }
 public function testPaginate()
 {
     $request = new RequestAggregate();
     $controller = new UsersController($request);
     $paginator = new PaginatorComponent($controller);
     $paginator->initialize('User', ['limit' => 1, 'order' => 'id DESC']);
     $request->setRequest(new Query(['page' => 1]));
     $limit1IdDesc = $paginator->paginate();
     $this->assertEquals(1, count($limit1IdDesc));
     $this->assertEquals('ten', $limit1IdDesc[0]->name);
     $request->setRequest(new Query(['page' => 10]));
     //	$notfound = $paginator->paginate();
     //	$this->assertEquals(1, count($notfound));
     //	$this->assertEquals('error', $notfound[0]->name);
     $request->setRequest(new Query(['page' => 1]));
     $id = 1;
     $where = $paginator->paginate(['where' => ['field' => 'id', 'comparision' => '=', 'value' => $id]]);
     $this->assertEquals(1, count($where));
     $this->assertEquals('one', $where[0]->name);
 }
 public function testCreateFromGrobals()
 {
     $_SERVER['REQUEST_URI'] = '/users/index/1';
     $request = RequestAggregate::createFromGlobals();
     print_r($request);
 }
Beispiel #7
0
<?php

require '../vendor/autoload.php';
require '../config/bootstrap.php';
use TRW\Router\Dispatcher;
use TRW\Request\RequestAggregate;
//$_SERVER['REQUEST_URI'] = '/Users/index/1';
$dispatcher = new Dispatcher();
$dispatcher->dispatch(RequestAggregate::createFromGlobals());