Пример #1
0
 public function testMuxCustomDispatch()
 {
     $mux = new Mux();
     $mux->mount('/bs/product', function ($x) {
         $x = new Mux();
         $x->any('/create', ['Product', 'createAction']);
         $x->any('/edit/:id', ['Product', 'editAction']);
         return $x;
     });
     $route = $mux->dispatch('/bs/product/create');
     $this->assertNotEmpty($route);
     $this->assertEquals('/create', $route[1]);
     $route = $mux->dispatch('/bs/product/edit/30');
     $this->assertNotEmpty($route);
     $this->assertEquals('/edit/:id', $route[3]['pattern']);
 }
Пример #2
0
 public static function mountWithUrlMap(array $map)
 {
     $mux = new Mux();
     foreach ($map as $path => $app) {
         if ($app instanceof Compositor) {
             $app = $app->wrap();
         }
         $mux->any($path, $app);
     }
     return new self($mux);
 }
Пример #3
0
 public function testMuxMountNoExpandAndDispatchToSubMux()
 {
     $mux = new \Pux\Mux();
     $mux->expand = false;
     ok($mux);
     $submux = new \Pux\Mux();
     $submux->any('/hello/:name', array('HelloController2', 'indexAction'));
     $submux->any('/foo', array('HelloController2', 'indexAction'));
     $mux->mount('/sub', $submux);
     ok($submux, 'submux');
     ok($submux->getRoutes(), 'submux routes');
     ok($mux->getRoutes(), 'mux routes');
     $submux2 = $mux->getSubMux($submux->getId());
     ok($submux2, 'submux2');
     ok($submux2->getRoutes(), 'submux2 routes');
     $r = $mux->dispatch('/sub/hello/John');
     ok($r);
     $this->assertPcreRoute($r, '/hello/:name');
     $r = $mux->dispatch('/sub/foo');
     $this->assertNonPcreRoute($r, '/foo');
 }
Пример #4
0
 public function testSubmuxPcreRouteFound()
 {
     $mux = new \Pux\Mux();
     ok($mux);
     is(0, $mux->length());
     $submux = new \Pux\Mux();
     $submux->any('/hello/:name', array('HelloController2', 'indexAction'));
     ok($submux);
     ok($routes = $submux->getRoutes());
     is(1, $submux->length());
     is(0, $mux->length());
     $mux->mount('/sub', $submux);
     $r = $mux->dispatch('/sub/hello/John');
     ok($r);
     $this->assertPcreRoute($r, '/sub/hello/:name');
 }
Пример #5
0
 /**
  * @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'));
 }
Пример #6
0
 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');
 }
Пример #7
0
 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');
 }