Adding tests for securing private variable inclussion on templates.
[akelos.git] / test / unit / lib / AkActionView / helpers / javascript_helper.php
blob1ee66a821b4a5cef2880fc556f0cdb25bc7d8dd1
1 <?php
3 require_once('_HelpersUnitTester.php');
4 require_once(AK_LIB_DIR.DS.'AkActionView'.DS.'helpers'.DS.'javascript_helper.php');
7 class JavaScriptHelperTests extends HelpersUnitTester
8 {
9 function test_for_JavascriptHelper()
11 require_once(AK_LIB_DIR.DS.'AkActionView'.DS.'helpers'.DS.'javascript_helper.php');
13 $javascript = new JavaScriptHelper();
15 $this->assertEqual($javascript->link_to_function('Greeting', "alert('Hello world!')"),'<a href="#" onclick="alert(\'Hello world!\'); return false;">Greeting</a>');
16 $this->assertEqual($javascript->link_to_function('my link', "if confirm('Really?'){ do_delete(); }",array('href'=>'http://www.akelos.com')),'<a href="http://www.akelos.com" onclick="if confirm(\'Really?\'){ do_delete(); }; return false;">my link</a>');
19 $this->assertEqual($javascript->button_to_function("Greeting", "alert('Hello world!')"),'<input onclick="alert(\'Hello world!\');" type="button" value="Greeting" />');
20 $this->assertEqual($javascript->button_to_function("Delete", "if confirm('Really?'){ do_delete(); }",array('id'=>'confirm')),'<input id="confirm" onclick="if confirm(\'Really?\'){ do_delete(); };" type="button" value="Delete" />');
23 $this->assertEqual($javascript->javascript_tag("alert('All is good')"), "<script type=\"text/javascript\">\n//<![CDATA[\nalert('All is good')\n//]]>\n</script>");
25 $input = "
26 <div id='meesage'
28 class=\"hisghtlight\" />
30 $expected = "\\n <div id=\'meesage\'\\n \\n class=\\\"hisghtlight\\\" />\\n ";
31 $this->assertEqual($javascript->escape_javascript($input), $expected);
34 function test_javascript_tag()
36 $javascript = new JavaScriptHelper();
38 //static call
39 $this->AssertEqual(
40 JavascriptHelper::javascript_tag("alert('test akelos');"),
41 "<script type=\"text/javascript\">\n//<![CDATA[\nalert('test akelos');\n//]]>\n</script>"
44 //object call
45 $this->AssertEqual(
46 $javascript->javascript_tag("alert('test akelos');"),
47 "<script type=\"text/javascript\">\n//<![CDATA[\nalert('test akelos');\n//]]>\n</script>"
55 ak_test('JavaScriptHelperTests');