Skip to content
This repository
Browse code

Starting Test Case for JsHelper

  • Loading branch information...
commit c92cfa72382b527876a5d14d90daccb14a66d5ce 1 parent f0d03a9
Mark Story authored March 06, 2009
57  cake/tests/cases/libs/view/helpers/js.test.php
... ...
@@ -1,9 +1,9 @@
1 1
 <?php
2 2
 /* SVN FILE: $Id$ */
3 3
 /**
4  
- * Short description for file.
  4
+ * JsHelper Test Case
5 5
  *
6  
- * Long description for file
  6
+ * TestCase for the JsHelper
7 7
  *
8 8
  * PHP versions 4 and 5
9 9
  *
@@ -24,35 +24,22 @@
24 24
  * @lastmodified  $Date$
25 25
  * @license       http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
26 26
  */
27  
-if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) {
28  
-	define('CAKEPHP_UNIT_TEST_EXECUTION', 1);
29  
-}
30  
-
31  
-uses('view'.DS.'helpers'.DS.'app_helper', 'controller'.DS.'controller', 'model'.DS.'model', 'view'.DS.'helper', 'view'.DS.'helpers'.DS.'js');
  27
+App::import('Helper', 'Js');
32 28
 
33 29
 /**
34  
- * Short description for class.
  30
+ * JsHelper TestCase.
35 31
  *
36 32
  * @package       cake.tests
37 33
  * @subpackage    cake.tests.cases.libs.view.helpers
38 34
  */
39  
-class JsTest extends UnitTestCase {
40  
-/**
41  
- * skip method
42  
- *
43  
- * @access public
44  
- * @return void
45  
- */
46  
-	function skip() {
47  
-		$this->skipif (true, 'JsHelper test not implemented');
48  
-	}
  35
+class JsHelperTestCase extends CakeTestCase {
49 36
 /**
50 37
  * setUp method
51 38
  *
52 39
  * @access public
53 40
  * @return void
54 41
  */
55  
-	function setUp() {
  42
+	function startTest() {
56 43
 		$this->Js = new JsHelper();
57 44
 	}
58 45
 /**
@@ -61,9 +48,39 @@ function setUp() {
61 48
  * @access public
62 49
  * @return void
63 50
  */
64  
-	function tearDown() {
  51
+	function endTest() {
65 52
 		unset($this->Js);
66 53
 	}
  54
+/**
  55
+ * test escape string skills
  56
+ *
  57
+ * @return void
  58
+ **/
  59
+	function testEscaping() {
  60
+		$result = $this->Js->escape('');
  61
+		$expected = '';
  62
+		$this->assertEqual($result, $expected);
  63
+
  64
+		$result = $this->Js->escape('CakePHP' . "\n" . 'Rapid Development Framework');
  65
+		$expected = 'CakePHP\\nRapid Development Framework';
  66
+		$this->assertEqual($result, $expected);
  67
+
  68
+		$result = $this->Js->escape('CakePHP' . "\r\n" . 'Rapid Development Framework' . "\r" . 'For PHP');
  69
+		$expected = 'CakePHP\\nRapid Development Framework\\nFor PHP';
  70
+		$this->assertEqual($result, $expected);
  71
+
  72
+		$result = $this->Js->escape('CakePHP: "Rapid Development Framework"');
  73
+		$expected = 'CakePHP: \\"Rapid Development Framework\\"';
  74
+		$this->assertEqual($result, $expected);
  75
+
  76
+		$result = $this->Js->escape('CakePHP: \'Rapid Development Framework\'');
  77
+		$expected = 'CakePHP: \\\'Rapid Development Framework\\\'';
  78
+		$this->assertEqual($result, $expected);
  79
+
  80
+		$result = $this->Js->escape('my \\"string\\"');
  81
+		$expected = 'my \\\"string\\\"';
  82
+		$this->assertEqual($result, $expected);
  83
+	}
67 84
 }
68 85
 
69 86
 ?>

0 notes on commit c92cfa7

Please sign in to comment.
Something went wrong with that request. Please try again.