1
0
mirror of https://github.com/flarum/core.git synced 2025-07-31 21:50:50 +02:00

Allow overriding routes (#2577)

This commit is contained in:
Sami Mazouz
2021-02-28 20:01:30 +01:00
committed by GitHub
parent ea291508ab
commit ea840ba594
6 changed files with 160 additions and 9 deletions

View File

@@ -0,0 +1,47 @@
<?php
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
namespace Flarum\Tests\unit\Http;
use Flarum\Http\RouteCollection;
use Flarum\Tests\unit\TestCase;
class RouteCollectionTest extends TestCase
{
/** @test */
public function can_add_routes()
{
$routeCollection = (new RouteCollection)
->addRoute('GET', '/index', 'index', function () {
echo 'index';
})
->addRoute('DELETE', '/posts', 'forum.posts.delete', function () {
echo 'delete posts';
});
$this->assertEquals('/index', $routeCollection->getPath('index'));
$this->assertEquals('/posts', $routeCollection->getPath('forum.posts.delete'));
}
/** @test */
public function can_add_routes_late()
{
$routeCollection = (new RouteCollection)->addRoute('GET', '/index', 'index', function () {
echo 'index';
});
$this->assertEquals('/index', $routeCollection->getPath('index'));
$routeCollection->addRoute('DELETE', '/posts', 'forum.posts.delete', function () {
echo 'delete posts';
});
$this->assertEquals('/posts', $routeCollection->getPath('forum.posts.delete'));
}
}