Skip to content
Permalink
Browse files

Add test case

  • Loading branch information...
dereuromark committed Nov 2, 2018
1 parent 93b4a6c commit d73dbfe4a51c9c43558d35a9ef3041695f108a7d
@@ -18,6 +18,7 @@
use Cake\Http\Response;
use Cake\Http\ServerRequest;
use Cake\Routing\Filter\RoutingFilter;
use Cake\Routing\RouteBuilder;
use Cake\Routing\Router;
use Cake\TestSuite\TestCase;
@@ -82,7 +83,7 @@ public function testBeforeDispatchSetsParameters()
*/
public function testBeforeDispatchRedirectRoute()
{
Router::scope('/', function ($routes) {
Router::scope('/', function (RouteBuilder $routes) {
$routes->redirect('/home', ['controller' => 'articles']);
$routes->connect('/:controller/:action/*');
});
@@ -582,7 +582,7 @@ public function testResources()
public function testResourcesPathOption()
{
$routes = new RouteBuilder($this->collection, '/api');
$routes->resources('Articles', ['path' => 'posts'], function ($routes) {
$routes->resources('Articles', ['path' => 'posts'], function (RouteBuilder $routes) {
$routes->resources('Comments');
});
$all = $this->collection->routes();
@@ -19,6 +19,7 @@
use Cake\Event\EventManager;
use Cake\Http\Response;
use Cake\Routing\DispatcherFactory;
use Cake\Routing\RouteBuilder;
use Cake\Routing\Router;
use Cake\Routing\Route\InflectedRoute;
use Cake\TestSuite\IntegrationTestCase;
@@ -43,7 +44,8 @@ public function setUp()
static::setAppNamespace();
Router::reload();
Router::scope('/', function ($routes) {
Router::extensions(['json']);
Router::scope('/', function (RouteBuilder $routes) {
$routes->setRouteClass(InflectedRoute::class);
$routes->get('/get/:controller/:action', []);
$routes->head('/head/:controller/:action', []);
@@ -570,6 +572,18 @@ public function testRequestSetsPropertiesHttpServer()
$this->assertEquals('value', $this->viewVariable('test'));
}
/**
* Tests URLs containing extensions.
*
* @return void
*/
public function testRequestWithExt()
{
$this->get(['controller' => 'Posts', 'action' => 'ajax', '_ext' => 'json']);
$this->assertResponseCode(200);
}
/**
* Assert that the stored template doesn't change when cells are rendered.
*
@@ -16,27 +16,41 @@
use Cake\Http\BaseApplication;
use Cake\Routing\Middleware\RoutingMiddleware;
use Cake\Routing\RouteBuilder;
use TestApp\Command\AbortCommand;
class Application extends BaseApplication
{
/**
* @return void
*/
public function bootstrap()
{
parent::bootstrap();
}
/**
* @param \Cake\Console\CommandCollection $commands
*
* @return \Cake\Console\CommandCollection
*/
public function console($commands)
{
return $commands
->add('abort_command', new AbortCommand())
->addMany($commands->autoDiscover());
}
/**
* @param \Cake\Http\MiddlewareQueue $middleware
*
* @return \Cake\Http\MiddlewareQueue
*/
public function middleware($middleware)
{
$middleware->add(new RoutingMiddleware());
$middleware->add(function ($req, $res, $next) {
/** @var \Cake\Http\ServerRequest $res */
$res = $next($req, $res);
return $res->withHeader('X-Middleware', 'true');
@@ -53,7 +67,7 @@ public function middleware($middleware)
*/
public function routes($routes)
{
$routes->scope('/app', function ($routes) {
$routes->scope('/app', function (RouteBuilder $routes) {
$routes->connect('/articles', ['controller' => 'Articles']);
});
}
@@ -39,6 +39,11 @@ public function bootstrap()
// Do nothing.
}
/**
* @param \Cake\Http\MiddlewareQueue $middlewareQueue
*
* @return \Cake\Http\MiddlewareQueue
*/
public function middleware($middlewareQueue)
{
$middlewareQueue->add(new RoutingMiddleware($this));
@@ -16,15 +16,24 @@
use Cake\Http\BaseApplication;
use Cake\Routing\Middleware\RoutingMiddleware;
use Cake\Routing\RouteBuilder;
class ApplicationWithPluginRoutes extends BaseApplication
{
/**
* @return void
*/
public function bootstrap()
{
parent::bootstrap();
$this->addPlugin('TestPlugin');
}
/**
* @param \Cake\Http\MiddlewareQueue $middleware
*
* @return \Cake\Http\MiddlewareQueue
*/
public function middleware($middleware)
{
$middleware->add(new RoutingMiddleware($this));
@@ -40,7 +49,7 @@ public function middleware($middleware)
*/
public function routes($routes)
{
$routes->scope('/app', function ($routes) {
$routes->scope('/app', function (RouteBuilder $routes) {
$routes->connect('/articles', ['controller' => 'Articles']);
});
$routes->loadPlugin('TestPlugin');
@@ -82,6 +82,19 @@ public function get()
// Do nothing.
}
/**
* Stub AJAX method
*
* @return void
*/
public function ajax()
{
$data = [];
$this->set(compact('data'));
$this->set('_serialize', ['data']);
}
/**
* Post endpoint for integration testing with security component.
*
@@ -12,10 +12,12 @@
* @since 2.0.0
* @license https://opensource.org/licenses/mit-license.php MIT License
*/
use Cake\Routing\RouteBuilder;
use Cake\Routing\Router;
Router::extensions('json');
Router::scope('/', function ($routes) {
Router::scope('/', function (RouteBuilder $routes) {
$routes->connect('/', ['controller' => 'pages', 'action' => 'display', 'home']);
$routes->connect(
'/some_alias',

0 comments on commit d73dbfe

Please sign in to comment.
You can’t perform that action at this time.