|
<?php |
|
|
|
namespace Tests\Unit; |
|
|
|
use Illuminate\Routing\Router; |
|
use PHPUnit\Framework\TestCase; |
|
use Illuminate\Events\Dispatcher; |
|
use App\Routing\RemovableRoutesMixin; |
|
|
|
class RemovableRoutesTest extends TestCase |
|
{ |
|
/** |
|
* @test |
|
*/ |
|
public function mixinAddsMethodsToRoute() |
|
{ |
|
$router = new Router(new Dispatcher()); |
|
|
|
$this->assertTrue(method_exists(Router::class, 'mixin')); |
|
|
|
$router->mixin(new RemovableRoutesMixin()); |
|
|
|
foreach (get_class_methods(RemovableRoutesMixin::class) as $method) { |
|
$this->assertTrue(Router::hasMacro($method)); |
|
} |
|
} |
|
|
|
/** |
|
* @test |
|
*/ |
|
public function routesCanBeRemovedWithMethod() |
|
{ |
|
$router = new Router(new Dispatcher()); |
|
$router->mixin(new RemovableRoutesMixin()); |
|
|
|
$this->assertFalse($router->has('foobar')); |
|
$this->assertFalse($router->has('bazqux')); |
|
$this->assertFalse($router->has('quxcorge')); |
|
$this->assertFalse($router->has('corgegrault')); |
|
$this->assertFalse($router->has('graultgarply')); |
|
$this->assertFalse($router->has('garplywaldo')); |
|
|
|
$router->get('foobar')->name('foobar'); |
|
$router->post('bazqux')->name('bazqux'); |
|
$router->put('quxcorge')->name('quxcorge'); |
|
$router->patch('corgegrault')->name('corgegrault'); |
|
$router->delete('graultgarply')->name('graultgarply'); |
|
$router->options('garplywaldo')->name('garplywaldo'); |
|
|
|
$router->getRoutes()->refreshNameLookups(); |
|
|
|
$this->assertTrue($router->has('foobar')); |
|
$this->assertTrue($router->has('bazqux')); |
|
$this->assertTrue($router->has('quxcorge')); |
|
$this->assertTrue($router->has('corgegrault')); |
|
$this->assertTrue($router->has('graultgarply')); |
|
$this->assertTrue($router->has('garplywaldo')); |
|
|
|
$router->remove('get', 'foobar'); |
|
$router->remove('post', 'bazqux'); |
|
$router->remove('put', 'quxcorge'); |
|
$router->remove('patch', 'corgegrault'); |
|
$router->remove('delete', 'graultgarply'); |
|
$router->remove('options', 'garplywaldo'); |
|
|
|
$this->assertFalse($router->has('foobar')); |
|
$this->assertFalse($router->has('bazqux')); |
|
$this->assertFalse($router->has('quxcorge')); |
|
$this->assertFalse($router->has('corgegrault')); |
|
$this->assertFalse($router->has('graultgarply')); |
|
$this->assertFalse($router->has('garplywaldo')); |
|
} |
|
|
|
/** |
|
* @test |
|
*/ |
|
public function routesCanBeRemovedUsingSpecificHelper() |
|
{ |
|
$router = new Router(new Dispatcher()); |
|
$router->mixin(new RemovableRoutesMixin()); |
|
|
|
$this->assertFalse($router->has('foobar')); |
|
$this->assertFalse($router->has('bazqux')); |
|
$this->assertFalse($router->has('quxcorge')); |
|
$this->assertFalse($router->has('corgegrault')); |
|
$this->assertFalse($router->has('graultgarply')); |
|
$this->assertFalse($router->has('garplywaldo')); |
|
|
|
$router->get('foobar')->name('foobar'); |
|
$router->post('bazqux')->name('bazqux'); |
|
$router->put('quxcorge')->name('quxcorge'); |
|
$router->patch('corgegrault')->name('corgegrault'); |
|
$router->delete('graultgarply')->name('graultgarply'); |
|
$router->options('garplywaldo')->name('garplywaldo'); |
|
|
|
$router->getRoutes()->refreshNameLookups(); |
|
|
|
$this->assertTrue($router->has('foobar')); |
|
$this->assertTrue($router->has('bazqux')); |
|
$this->assertTrue($router->has('quxcorge')); |
|
$this->assertTrue($router->has('corgegrault')); |
|
$this->assertTrue($router->has('graultgarply')); |
|
$this->assertTrue($router->has('garplywaldo')); |
|
|
|
$router->removeGet('foobar'); |
|
$router->removePost('bazqux'); |
|
$router->removePut('quxcorge'); |
|
$router->removePatch('corgegrault'); |
|
$router->removeDelete('graultgarply'); |
|
$router->removeOptions('garplywaldo'); |
|
|
|
$this->assertFalse($router->has('foobar')); |
|
$this->assertFalse($router->has('bazqux')); |
|
$this->assertFalse($router->has('quxcorge')); |
|
$this->assertFalse($router->has('corgegrault')); |
|
$this->assertFalse($router->has('graultgarply')); |
|
$this->assertFalse($router->has('garplywaldo')); |
|
} |
|
|
|
/** |
|
* @test |
|
*/ |
|
public function routesCanBeRemovedUsingDeleteAny() |
|
{ |
|
$router = new Router(new Dispatcher()); |
|
$router->mixin(new RemovableRoutesMixin()); |
|
|
|
$this->assertFalse($router->has('barbaz')); |
|
$this->assertFalse($router->has('foobar')); |
|
$this->assertFalse($router->has('bazqux')); |
|
$this->assertFalse($router->has('quxcorge')); |
|
$this->assertFalse($router->has('corgegrault')); |
|
$this->assertFalse($router->has('graultgarply')); |
|
$this->assertFalse($router->has('garplywaldo')); |
|
|
|
$router->any('barbaz')->name('barbaz'); |
|
$router->get('foobar')->name('foobar'); |
|
$router->post('foobar')->name('bazqux'); |
|
$router->put('quxcorge')->name('quxcorge'); |
|
$router->patch('corgegrault')->name('corgegrault'); |
|
$router->delete('graultgarply')->name('graultgarply'); |
|
$router->options('garplywaldo')->name('garplywaldo'); |
|
|
|
$router->getRoutes()->refreshNameLookups(); |
|
|
|
$this->assertTrue($router->has('barbaz')); |
|
$this->assertTrue($router->has('foobar')); |
|
$this->assertTrue($router->has('bazqux')); |
|
$this->assertTrue($router->has('quxcorge')); |
|
$this->assertTrue($router->has('corgegrault')); |
|
$this->assertTrue($router->has('graultgarply')); |
|
$this->assertTrue($router->has('garplywaldo')); |
|
|
|
$router->removeAny('barbaz'); |
|
$router->removeAny('foobar'); |
|
$router->removeAny('bazqux'); |
|
$router->removeAny('quxcorge'); |
|
$router->removeAny('corgegrault'); |
|
$router->removeAny('graultgarply'); |
|
$router->removeAny('garplywaldo'); |
|
|
|
$this->assertFalse($router->has('barbaz')); |
|
$this->assertFalse($router->has('foobar')); |
|
$this->assertFalse($router->has('bazqux')); |
|
$this->assertFalse($router->has('quxcorge')); |
|
$this->assertFalse($router->has('corgegrault')); |
|
$this->assertFalse($router->has('graultgarply')); |
|
$this->assertFalse($router->has('garplywaldo')); |
|
} |
|
} |
Thank you for this