Fixing #138
[akelos.git] / test / unit / lib / AkActionView / helpers / url_helper.php
blob9d6f854b4b9af1506f7146bd09e174830a9668e7
1 <?php
3 require_once('_HelpersUnitTester.php');
4 require_once(AK_LIB_DIR.DS.'AkActionView'.DS.'helpers'.DS.'url_helper.php');
5 require_once(AK_LIB_DIR.DS.'AkActionView'.DS.'helpers'.DS.'asset_tag_helper.php');
8 class UrlHelperTests extends HelpersUnitTester
10 function setup()
12 $this->Controller = &new MockAkActionController($this);
13 $this->Controller->setReturnValue('urlFor', '/url/for/test');
14 //$this->Controller->setReturnValue('_getCompleteRequestUri','/url/for/test');
16 $this->url = new UrlHelper();
17 $this->url->setController($this->Controller);
20 function test_for_UrlHelper()
22 $this->assertReference($this->Controller, $this->url->_controller);
25 $input = array('disabled'=>1,'checked'=>false,'selected'=>'');
26 $expected = array('disabled'=>'disabled');
27 $this->assertEqual($this->url->_convert_boolean_attributes($input, array('disabled','checked','selected')),$expected);
29 $input = array('disabled'=>true,'id'=>'hithere');
30 $expected = array('disabled'=>'disabled','id'=>'hithere');
31 $this->assertEqual($this->url->_convert_boolean_attributes($input, 'disabled'),$expected);
33 $this->assertEqual($this->url->url_for(array('action'=>'create')),'/url/for/test');
35 $this->assertEqual($this->url->button_to('Edit'),
36 '<form method="post" action="/url/for/test" class="button-to"><div>'.
37 '<input type="submit" value="Edit" /></div></form>');
40 $this->assertEqual($this->url->link_to('Delete this page', array('action' => 'destroy', 'id' => 3), array('confirm' => 'Are you sure?')),'<a href="/url/for/test" onclick="return confirm(\'Are you sure?\');">Delete this page</a>');
41 $this->assertEqual($this->url->link_to('Help', array('action' => 'help'), array('popup' => true)),'<a href="/url/for/test" onclick="window.open(this.href);return false;">Help</a>');
42 $this->assertEqual($this->url->link_to('Help', array('action' => 'help'), array('popup' => true, 'confirm' => 'Are you sure?')),'<a href="/url/for/test" onclick="if (confirm(\'Are you sure?\')) { window.open(this.href); };return false;">Help</a>');
43 $this->assertEqual($this->url->link_to('Help', array('action' => 'help'), array('post' => true)),'<a href="/url/for/test" onclick="var f = document.createElement(\'form\'); document.body.appendChild(f); f.method = \'POST\'; f.action = this.href; f.submit();return false;">Help</a>');
44 $this->assertEqual($this->url->link_to('Destroy account', array('action' => 'destroy'), array('confirm' => 'Are you sure?'), array('post' => true)),'<a href="/url/for/test" onclick="return confirm(\'Are you sure?\');">Destroy account</a>');
46 $this->assertEqual($this->url->link_to_unless(true,'Destroy account', array('action' => 'destroy'), array('confirm' => 'Are you sure?'), array('post' => true)),'');
47 $this->assertEqual($this->url->link_to_unless(false,'Destroy account', array('action' => 'destroy'), array('confirm' => 'Are you sure?'), array('post' => true)),'<a href="/url/for/test" onclick="return confirm(\'Are you sure?\');">Destroy account</a>');
48 $this->assertEqual($this->url->_popup_javascript_function('A'),'window.open(this.href);');
49 $this->assertEqual($this->url->_popup_javascript_function(array('A','B','C')),'window.open(this.href,\'A\',\'C\');');
51 $this->assertEqual($this->url->_confirm_javascript_function('Are you sure?'),'confirm(\'Are you sure?\')');
54 $this->assertEqual($this->url->mail_to('me@domain.com', 'My email', array('cc' => 'ccaddress@domain.com', 'bcc' => 'bccaddress@domain.com', 'subject' => 'This is an example email', 'body' => 'This is the body of the message.')),'<a href="mailto:me@domain.com?cc=ccaddress%40domain.com&amp;bcc=bccaddress%40domain.com&amp;body=This%20is%20the%20body%20of%20the%20message.&amp;subject=This%20is%20an%20example%20email">My email</a>');
55 $this->assertEqual($this->url->mail_to('me@domain.com', 'My email', array('encode' => 'javascript')),'<script type="text/javascript">eval(unescape(\'%64%6f%63%75%6d%65%6e%74%2e%77%72%69%74%65%28%27%3c%61%20%68%72%65%66%3d%22%6d%61%69%6c%74%6f%3a%6d%65%40%64%6f%6d%61%69%6e%2e%63%6f%6d%22%3e%4d%79%20%65%6d%61%69%6c%3c%2f%61%3e%27%29%3b\'))</script>');
56 $this->assertEqual($this->url->mail_to('me@domain.com', 'My email', array('encode' => 'hex')),'<a href="mailto:%6d%65%40%64%6f%6d%61%69%6e%2e%63%6f%6d">My email</a>');
60 function test_should_encode_utf8_characters_as_entities_when_encoding_mail_to_links()
62 $escaped_iacute = '%26%69%61%63%75%74%65%3b';
63 $this->assertTrue(strstr($this->url->mail_to('test@example.com', 'mounstro de pulsa aquĆ­', array('encode' => 'javascript')), $escaped_iacute));
67 ak_test('UrlHelperTests');