function testToUrlWithHttpOffset() { $old_offset = lmb_env_get('LIMB_HTTP_OFFSET_PATH'); $config = array('blog' => array('path' => '/blog', 'defaults' => array('controller' => 'Blog', 'action' => 'display'))); $routes = new lmbRoutes($config); lmb_env_set('LIMB_HTTP_OFFSET_PATH', 'app'); $this->assertEqual($routes->toUrl(array(), 'blog'), '/app/blog'); lmb_env_set('LIMB_HTTP_OFFSET_PATH', $old_offset); }
function testRequestMethod_SeveralRequestMethods() { $config = array(array('path' => '/blog', 'defaults' => array('controller' => 'blog', 'action' => 'display'), 'request_method' => 'GET'), array('path' => '/blog', 'defaults' => array('controller' => 'blog', 'action' => 'save'), 'request_method' => 'POST'), array('path' => '/news', 'defaults' => array('controller' => 'newsline', 'action' => 'display'))); $routes = new lmbRoutes($config); $result = $routes->dispatch('/blog', 'GET'); $this->assertEqual($result['controller'], 'blog'); $this->assertEqual($result['action'], 'display'); $result = $routes->dispatch('/blog', 'POST'); $this->assertEqual($result['controller'], 'blog'); $this->assertEqual($result['action'], 'save'); }
function testToUrlChecksRequirements() { $config = array('default' => array('path' => '/:controller/:action/', 'requirements' => array('controller' => '/^blog$/', 'action' => '/^[a-z]+$/'))); $routes = new lmbRoutes($config); $this->assertEqual($routes->toUrl(array('controller' => 'blog', 'action' => 'edit')), '/blog/edit/'); try { $routes->toUrl(array('controller' => 'admin', 'action' => '123edit')); $routes->toUrl(array('controller' => 'zzz', 'action' => 'edit')); $routes->toUrl(array('controller' => 'blog', 'action' => '@#%')); $this->fail("Some routes do NOT match required params!"); } catch (lmbException $e) { $this->assertPattern('/route .* not found .*/i', $e->getMessage()); } }
function testWithHTTPOffset() { $old_offset = lmb_env_get('LIMB_HTTP_OFFSET_PATH'); $config = array(array('path' => '/blog', 'defaults' => array('controller' => 'Blog', 'action' => 'display'))); $routes = new lmbRoutes($config); lmb_env_set('LIMB_HTTP_OFFSET_PATH', 'limb-app'); $result = $routes->dispatch('/limb-app/blog'); $this->assertEqual($result['controller'], 'Blog'); $this->assertEqual($result['action'], 'display'); lmb_env_set('LIMB_HTTP_OFFSET_PATH', $old_offset); }