* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); require_once($_test_dir.'/unit/sfContextMock.class.php'); class myController { public function genUrl($parameters = array(), $absolute = false) { $url = is_array($parameters) && isset($parameters['sf_route']) ? $parameters['sf_route'] : 'module/action'; return ($absolute ? '/' : '').$url; } } class myRequest { public function getRelativeUrlRoot() { return '/public'; } public function isSecure() { return true; } public function getHost() { return 'example.org'; } } class BaseForm extends sfForm { public function getCSRFToken($secret = null) { return '==TOKEN=='; } } sfForm::enableCSRFProtection(); $t = new lime_test(44); $context = sfContext::getInstance(array('controller' => 'myController', 'request' => 'myRequest')); require_once(dirname(__FILE__).'/../../../lib/helper/AssetHelper.php'); require_once(dirname(__FILE__).'/../../../lib/helper/UrlHelper.php'); require_once(dirname(__FILE__).'/../../../lib/helper/TagHelper.php'); // url_for() $t->diag('url_for()'); $t->is(url_for('@test'), 'module/action', 'url_for() converts an internal URI to a web URI'); $t->is(url_for('@test', true), '/module/action', 'url_for() can take an absolute boolean as its second argument'); $t->is(url_for('@test', false), 'module/action', 'url_for() can take an absolute boolean as its second argument'); // link_to() $t->diag('link_to()'); $t->is(link_to('test', '@homepage'), 'test', 'link_to() returns an HTML "a" tag'); $t->is(link_to('test', '@homepage', array('absolute' => true)), 'test', 'link_to() can take an "absolute" option'); $t->is(link_to('test', '@homepage', array('absolute' => false)), 'test', 'link_to() can take an "absolute" option'); $t->is(link_to('test', '@homepage', array('query_string' => 'foo=bar')), 'test', 'link_to() can take a "query_string" option'); $t->is(link_to('test', '@homepage', array('anchor' => 'bar')), 'test', 'link_to() can take an "anchor" option'); $t->is(link_to('', '@homepage'), 'module/action', 'link_to() takes the url as the link name if the first argument is empty'); $t->like(link_to('test', '@homepage', array('method' => 'post')), '/==TOKEN==/', 'link_to() includes CSRF token from BaseForm'); // button_to() $t->diag('button_to()'); $t->is(button_to('test', '@homepage'), '', 'button_to() returns an HTML "input" tag'); $t->is(button_to('test', '@homepage', array('query_string' => 'foo=bar')), '', 'button_to() returns an HTML "input" tag'); $t->is(button_to('test', '@homepage', array('anchor' => 'bar')), '', 'button_to() returns an HTML "input" tag'); $t->is(button_to('test', '@homepage', array('popup' => 'true', 'query_string' => 'foo=bar')), '', 'button_to() returns an HTML "input" tag'); $t->is(button_to('test', '@homepage', 'popup=true'), '', 'button_to() accepts options as string'); $t->is(button_to('test', '@homepage', 'confirm=really?'), '', 'button_to() works with confirm option'); $t->is(button_to('test', '@homepage', 'popup=true confirm=really?'), '', 'button_to() works with confirm and popup option'); $t->like(button_to('test', '@homepage', array('method' => 'post')), '/==TOKEN==/', 'button_to() includes CSRF token from BaseForm'); class testObject { } try { $o1 = new testObject(); link_to($o1, '@homepage'); $t->fail('link_to() can take an object as its first argument if __toString() method is defined'); } catch (sfException $e) { $t->pass('link_to() can take an object as its first argument if __toString() method is defined'); } class testObjectWithToString { public function __toString() { return 'test'; } } $o2 = new testObjectWithToString(); $t->is(link_to($o2, '@homepage'), 'test', 'link_to() can take an object as its first argument'); // link_to_if() $t->diag('link_to_if()'); $t->is(link_to_if(true, 'test', '@homepage'), 'test', 'link_to_if() returns an HTML "a" tag if the condition is true'); $t->is(link_to_if(false, 'test', '@homepage'), 'test', 'link_to_if() returns an HTML "span" tag by default if the condition is false'); $t->is(link_to_if(false, 'test', '@homepage', array('tag' => 'div')), '