public function testReverseUrlFromView() { $url = Pluf_HTTP_URL_reverse('Todo_Views::updateItem', array('32')); $this->assertEquals('/item/32/update/', $url); }
/** * Provide the full URL (without domain) to a view. * * @param string View. * @param array Parameters for the view (array()). * @param array Extra GET parameters for the view (array()). * @param bool Should the URL be encoded (true). * @return string URL. */ function Pluf_HTTP_URL_urlForView($view, $params = array(), $get_params = array(), $encoded = true) { return Pluf_HTTP_URL::generate(Pluf_HTTP_URL_reverse($view, $params), $get_params, $encoded); }
function testRecursif() { $GLOBALS['_PX_views'] = array(array('regex' => '#^/hello/$#', 'base' => '', 'model' => 'Pluf_Tests_Dispatch_Dispatcher', 'method' => 'hello3'), array('regex' => '#^/hello/#', 'base' => '', 'sub' => array(array('regex' => '#^world/$#', 'base' => '', 'model' => 'Pluf_Tests_Dispatch_Dispatcher', 'method' => 'hello'), array('regex' => '#^hello/$#', 'base' => '', 'model' => 'Pluf_Tests_Dispatch_Dispatcher', 'method' => 'hello4'))), array('regex' => '#^/hello1/#', 'base' => '', 'sub' => array(array('regex' => '#^world/$#', 'base' => '', 'model' => 'Pluf_Tests_Dispatch_Dispatcher', 'method' => 'hello1'))), array('regex' => '#^/hello2/#', 'base' => '', 'sub' => array(array('regex' => '#^world/$#', 'base' => '', 'model' => 'Pluf_Tests_Dispatch_Dispatcher', 'method' => 'hello2')))); $req1 = (object) array('query' => '/hello/world/'); // match $req2 = (object) array('query' => '/hello/world'); // match second pass $req3 = (object) array('query' => '/hello/you/'); // no match $h1 = (object) array('query' => '/hello1/world/'); // match $h2 = (object) array('query' => '/hello2/world/'); // match $h3 = (object) array('query' => '/hello/'); // match $h4 = (object) array('query' => '/hello/hello/'); // match $this->assertIdentical(200, Pluf_Dispatcher::match($req1)->status_code); $this->assertEqual('ok', Pluf_Dispatcher::match($req1)->content); $this->assertIdentical(1, Pluf_Dispatcher::match($h1)); $this->assertIdentical(2, Pluf_Dispatcher::match($h2)); $this->assertIdentical(3, Pluf_Dispatcher::match($h3)); $this->assertIdentical(4, Pluf_Dispatcher::match($h4)); $this->assertIsA(Pluf_Dispatcher::match($req2), 'Pluf_HTTP_Response_Redirect'); $this->assertIsA(Pluf_Dispatcher::match($req3), 'Pluf_HTTP_Response_NotFound'); Pluf::loadFunction('Pluf_HTTP_URL_reverse'); $this->assertEqual('/hello/world/', Pluf_HTTP_URL_reverse('Pluf_Tests_Dispatch_Dispatcher::hello')); $this->assertEqual('/hello1/world/', Pluf_HTTP_URL_reverse('Pluf_Tests_Dispatch_Dispatcher::hello1')); $this->assertEqual('/hello2/world/', Pluf_HTTP_URL_reverse('Pluf_Tests_Dispatch_Dispatcher::hello2')); $this->assertEqual('/hello/', Pluf_HTTP_URL_reverse('Pluf_Tests_Dispatch_Dispatcher::hello3')); $this->assertEqual('/hello/hello/', Pluf_HTTP_URL_reverse('Pluf_Tests_Dispatch_Dispatcher::hello4')); }