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 testMuxMounting() { $mainMux = new Mux(); $mainMux->expand = false; $pageMux = new Mux(); $pageMux->add('/page1', array('PageController', 'page1')); $pageMux->add('/page2', array('PageController', 'page2')); $mainMux->mount('/sub', $pageMux); $pageMux2 = new Mux(); $pageMux2->add('/bar', array('PageController', 'page1')); $pageMux2->add('/zoo', array('PageController', 'page2')); is(2, $pageMux2->length()); $mainMux->mount('/foo', $pageMux2); is(2, $mainMux->length()); foreach (array('/sub/page1', '/sub/page2', '/foo/bar', '/foo/zoo') as $p) { $r = $mainMux->dispatch($p); ok($r, "Matched route for {$p}"); } return $mainMux; }
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'); }
public function testSubmuxPcreMountStaticSub() { $mux = new Mux(); $this->assertEquals(0, $mux->length()); $submux = new \Pux\Mux(); $submux->any('/hello/there', array('HelloController2', 'indexAction')); ok($routes = $submux->getRoutes()); $this->assertEquals(1, $submux->length()); $this->assertEquals(0, $mux->length()); $mux->mount('/sub/:country', $submux); $r = $mux->dispatch('/sub/UK/hello/there'); $this->assertNonPcreRoute($r, '/hello/there'); }