1
0
mirror of https://github.com/flarum/core.git synced 2025-07-30 21:20:24 +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

@@ -47,6 +47,41 @@ class RoutesTest extends TestCase
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('Hello Flarumites!', $response->getBody());
}
/**
* @test
*/
public function existing_route_can_be_removed()
{
$this->extend(
(new Extend\Routes('api'))
->remove('GET', 'forum.show')
);
$response = $this->send(
$this->request('GET', '/api')
);
$this->assertEquals(404, $response->getStatusCode());
}
/**
* @test
*/
public function custom_route_can_override_existing_route_if_removed()
{
$this->extend(
(new Extend\Routes('api'))
->remove('GET', 'forum.show')
->get('/', 'forum.show', CustomRoute::class)
);
$response = $this->send(
$this->request('GET', '/api')
);
$this->assertEquals('Hello Flarumites!', $response->getBody());
}
}
class CustomRoute implements RequestHandlerInterface