public function testMuxGetMethod() { $mux = new Mux(); $mux->get('/news', array('NewsController', 'listAction')); $mux->get('/news_item', array('NewsController', 'itemAction'), array()); $routes = $mux->getRoutes(); $this->assertCount(2, $routes); $this->assertEquals(2, $mux->length()); $_SERVER['REQUEST_METHOD'] = "GET"; $this->assertNotNull($mux->dispatch('/news_item')); $this->assertNotNull($mux->dispatch('/news')); }
public function testSubmuxMergeOptions() { $mux = new Mux(); $this->assertEquals(0, $mux->length()); $submux = new Mux(); $submux->any('/foo', array('FooController', 'indexAction'), array('default' => array('suffix' => 'csv'))); $submux->any('/hello/:name', array('HelloController', 'indexAction'), array('default' => array('suffix' => 'json', 'prefix' => 'v1'))); $this->assertEquals(2, $submux->length()); ok($routes = $submux->getRoutes()); $this->assertEquals(2, $submux->length()); $this->assertEquals(0, $mux->length()); // XXX: we don't expand routes now, so we won't have the default // options for the subroutes... /* $mux->mount('/sub', $submux, array( 'default' => array('suffix' => 'xml', 'prefix' => 'v1'), 'require' => array('suffix' => '[a-z]{3,4}') )); */ $mux->mount('/sub', $submux); $this->assertEquals(1, $mux->length()); $r = $mux->dispatch('/sub/hello/John'); $this->assertNotNull($r); $this->assertEquals('json', $r[3]['default']['suffix']); $this->assertEquals('v1', $r[3]['default']['prefix']); $this->assertPcreRoute($r, '/hello/:name'); $r = $mux->dispatch('/sub/foo'); $this->assertNotNull($r); // ok($r[3]['default']['suffix'] == 'csv'); // ok($r[3]['require']['suffix'] == '[a-z]{3,4}'); $this->assertNonPcreRoute($r, '/foo'); }
/** * @depends testControllerConstructor */ public function testMountNoExpand($controller) { $mainMux = new Mux(); $mainMux->expand = false; $mainMux->mount('/product', $controller); $mainMux->any('/', array('ProductController', 'indexAction')); ok($mainMux->getRoutes()); count_ok(2, $mainMux->getRoutes(), 'route count should be 2'); ok($r = $mainMux->dispatch('/product'), 'matched /product'); // match indexAction $this->assertSame(array('CRUDProductController', 'indexAction'), $r[2]); ok($r = $mainMux->dispatch('/product/add')); $this->assertSame(array('CRUDProductController', 'addAction'), $r[2]); ok($r = $mainMux->dispatch('/product/del')); $this->assertSame(array('CRUDProductController', 'delAction'), $r[2]); ok(null == $mainMux->dispatch('/foo')); ok(null == $mainMux->dispatch('/bar')); }
public function testCallableSubMux() { $mux = new \Pux\Mux(); $mux->mount('/test', function (Mux $submux) { $submux->any('/hello/static', array('HelloController2', 'indexAction')); $submux->any('/hello/:name', array('HelloController2', 'indexAction')); }); ok($routes = $mux->getRoutes()); ok(is_array($routes)); $this->assertCount(1, $routes); $this->assertEquals('/test', $routes[0][1]); $r = $mux->dispatch('/test/hello/John'); $this->assertNotEmpty($r); $this->assertPcreRoute($r, '/hello/:name'); $r = $mux->dispatch('/test/hello/static'); $this->assertNotEmpty($r); $this->assertNonPcreRoute($r, '/hello/static'); }