1: <?php
2:
3: 4: 5: 6:
7: class QCssTests extends QUnitTestCaseBase {
8:
9: protected function helpTest($objTestDataArray) {
10: $strValue = $objTestDataArray["Value"];
11: $strAttrs = QHtml::FormatLength($strValue);
12:
13: $strMessage =
14: $objTestDataArray["Msg"] .
15: " Expected: '" . $objTestDataArray["Expected"] . "'" .
16: " Obtained: '" . $strAttrs . "'";
17: $this->assertEquals($objTestDataArray["Expected"], $strAttrs, $strMessage);
18: }
19:
20: public function testFormatLength() {
21: $objCaseArray = array(
22: array(
23: "Value" => "0", "Expected" => "0", "Msg" => "String zero renders with no 'px'"
24: ),
25: array(
26: "Value" => "0.0", "Expected" => "0", "Msg" => "String '0.0' renders with no 'px'"
27: ),
28: array(
29: "Value" => (int)0, "Expected" => "0", "Msg" => "Integer zero renders with no 'px'"
30: ),
31: array(
32: "Value" => (float)0.0, "Expected" => "0", "Msg" => "Float zero renders with no 'px'"
33: ),
34: array(
35: "Value" => (double)0.0, "Expected" => "0", "Msg" => "Double zero renders with no 'px'"
36: ),
37: array(
38: "Value" => "0px", "Expected" => "0px", "Msg" => "String value renders with no 'px'"
39: ),
40: array(
41: "Value" => "0px", "Expected" => "0px", "Msg" => "String zero with 'px' renders with no additional 'px'"
42: ),
43:
44: array(
45: "Value" => "1", "Expected" => "1px", "Msg" => "String '1' renders with 'px'"
46: ),
47: array(
48: "Value" => "1.0", "Expected" => "1px", "Msg" => "String '1.0' renders with 'px'"
49: ),
50: array(
51: "Value" => "1.1", "Expected" => "1.1px", "Msg" => "String '1.1' renders with 'px'"
52: ),
53: array(
54: "Value" => (int)1, "Expected" => "1px", "Msg" => "Integer 1 renders with 'px'"
55: ),
56: array(
57: "Value" => (float)1.0, "Expected" => "1px", "Msg" => "Float 1 renders with 'px'"
58: ),
59: array(
60: "Value" => (float)1.1, "Expected" => "1.1px", "Msg" => "Float 1.1 renders with 'px'"
61: ),
62: array(
63: "Value" => (double)1.0, "Expected" => "1px", "Msg" => "Double 1 renders with 'px'"
64: ),
65: array(
66: "Value" => (double)1.1, "Expected" => "1.1px", "Msg" => "Double 1.1 renders with 'px'"
67: ),
68: array(
69: "Value" => "1px", "Expected" => "1px", "Msg" => "String value renders with no 'px'"
70: ),
71: array(
72: "Value" => "1px", "Expected" => "1px", "Msg" => "String with 'px' renders with no additional 'px'"
73: ),
74:
75: array(
76: "Value" => "0 0 0 0", "Expected" => "0 0 0 0", "Msg" => "String with many values renders with no 'px'"
77: ),
78: array(
79: "Value" => "0px 0px 0px 0px", "Expected" => "0px 0px 0px 0px", "Msg" => "String with many values renders with no additional 'px'"
80: ),
81: array(
82: "Value" => "1 1 1 1", "Expected" => "1 1 1 1", "Msg" => "String with many values renders with no 'px'"
83: ),
84: array(
85: "Value" => "1px 1px 1px 1px", "Expected" => "1px 1px 1px 1px", "Msg" => "String with many values renders with no additional 'px'"
86: ),
87: array(
88: "Value" => "dummy", "Expected" => "dummy", "Msg" => "String with not a number value renders with no 'px'"
89: ),
90: array(
91: "Value" => "the dumbest", "Expected" => "the dumbest", "Msg" => "String with multiple not a number values renders with no 'px'"
92: )
93: );
94:
95: foreach($objCaseArray as $objCase) {
96: $this->helpTest($objCase);
97: }
98:
99: }
100:
101: protected function helpTest2($objTestDataArray) {
102: $strOldValue = $objTestDataArray["OldValue"];
103: $newValue = $objTestDataArray["NewValue"];
104: $blnChanged = QHtml::SetLength($strOldValue, $newValue);
105:
106: $this->assertEquals($objTestDataArray["Changed"], $blnChanged);
107: $this->assertEquals($objTestDataArray["Expected"], $strOldValue);
108:
109: }
110:
111: public function testSetLength() {
112: $objCaseArray = array(
113: array(
114: "OldValue" => "0", "NewValue" => "0", "Changed"=>false, "Expected" => "0", "Msg" => "Zero set to zero."
115: ),
116: array(
117: "OldValue" => "1px", "NewValue" => "2em", "Changed"=>true, "Expected" => "2em", "Msg" => "1px changed to 2em."
118: ),
119: array(
120: "OldValue" => "1px", "NewValue" => "1px", "Changed"=>false, "Expected" => "1px", "Msg" => "1px not changed."
121: ),
122: array(
123: "OldValue" => "1px", "NewValue" => "+1", "Changed"=>true, "Expected" => "2px", "Msg" => "1 added to 1px."
124: ),
125: array(
126: "OldValue" => "1px", "NewValue" => "-1", "Changed"=>true, "Expected" => "0px", "Msg" => "1 subtracted from 1px."
127: ),
128: array(
129: "OldValue" => "1em", "NewValue" => "/2", "Changed"=>true, "Expected" => "0.5em", "Msg" => "1em divided in half."
130: ),
131: array(
132: "OldValue" => "1em", "NewValue" => "*2", "Changed"=>true, "Expected" => "2em", "Msg" => "1em multiplied by 2."
133: ),
134: array(
135: "OldValue" => "1.1em", "NewValue" => "*2", "Changed"=>true, "Expected" => "2.2em", "Msg" => "1.1em multiplied by 2."
136: ),
137: array(
138: "OldValue" => '10%', "NewValue" => "*2", "Changed"=>true, "Expected" => '20%', "Msg" => '10 percent multiplied by 2.'
139: )
140: );
141:
142: foreach($objCaseArray as $objCase) {
143: $this->helpTest2($objCase);
144: }
145: }
146:
147: protected function helpTestAddClass($objTestDataArray) {
148: $strOldValue = $objTestDataArray["OldValue"];
149: $newValue = $objTestDataArray["NewValue"];
150: $blnChanged = QHtml::AddClass($strOldValue, $newValue);
151:
152: $this->assertEquals($objTestDataArray["Changed"], $blnChanged);
153: $this->assertEquals($objTestDataArray["Expected"], $strOldValue);
154:
155: }
156:
157: public function testAddClass() {
158: $objCaseArray = array(
159: array(
160: "OldValue" => "", "NewValue" => "test", "Changed"=>true, "Expected" => "test"
161: ),
162: array(
163: "OldValue" => "test", "NewValue" => "test", "Changed"=>false, "Expected" => "test"
164: ),
165: array(
166: "OldValue" => "test class2", "NewValue" => "test", "Changed"=>false, "Expected" => "test class2"
167: ),
168: array(
169: "OldValue" => "test", "NewValue" => "class2", "Changed"=>true, "Expected" => "test class2"
170: ),
171: array(
172: "OldValue" => "test", "NewValue" => "class2 class3", "Changed"=>true, "Expected" => "test class2 class3"
173: )
174: );
175:
176: foreach($objCaseArray as $objCase) {
177: $this->helpTestAddClass($objCase);
178: }
179: }
180:
181: protected function helpTestRemoveClass($objTestDataArray) {
182: $strOldValue = $objTestDataArray["OldValue"];
183: $newValue = $objTestDataArray["NewValue"];
184: $blnChanged = QHtml::RemoveClass($strOldValue, $newValue);
185:
186: $this->assertEquals($objTestDataArray["Changed"], $blnChanged);
187: $this->assertEquals($objTestDataArray["Expected"], $strOldValue);
188:
189: }
190:
191: public function testRemoveClass() {
192: $objCaseArray = array(
193: array(
194: "OldValue" => "", "NewValue" => "test", "Changed"=>false, "Expected" => ""
195: ),
196: array(
197: "OldValue" => "test", "NewValue" => "test", "Changed"=>true, "Expected" => ""
198: ),
199: array(
200: "OldValue" => "test class2", "NewValue" => "test", "Changed"=>true, "Expected" => "class2"
201: ),
202: array(
203: "OldValue" => "test", "NewValue" => "class2", "Changed"=>false, "Expected" => "test"
204: ),
205: array(
206: "OldValue" => "test class2 class3", "NewValue" => "test class3", "Changed"=>true, "Expected" => "class2"
207: )
208: );
209:
210: foreach($objCaseArray as $objCase) {
211: $this->helpTestRemoveClass($objCase);
212: }
213: }
214:
215: public function testJavascriptDataConversions() {
216: $objCaseArray = array(
217: array(
218: "Value" => "bob", "Expected" => "bob"
219: ),
220: array(
221: "Value" => "Bob", "Expected" => "-bob"
222: ),
223: array(
224: "Value" => "bobSmith", "Expected" => "bob-smith"
225: ),
226: array(
227: "Value" => "bobSmithJones", "Expected" => "bob-smith-jones"
228: )
229: );
230:
231: foreach($objCaseArray as $objCase) {
232: $newValue = JavaScriptHelper::dataNameFromCamelCase($objCase["Value"]);
233: $this->assertEquals($objCase["Expected"], $newValue);
234: }
235:
236: $objCaseArray = array(
237: array(
238: "Value" => "bob", "Expected" => "bob"
239: ),
240: array(
241: "Value" => "-bob", "Expected" => "Bob"
242: ),
243: array(
244: "Value" => "bob-smith", "Expected" => "bobSmith"
245: ),
246: array(
247: "Value" => "bob-smith-jones", "Expected" => "bobSmithJones"
248: )
249: );
250:
251: foreach($objCaseArray as $objCase) {
252: $newValue = JavaScriptHelper::dataNameToCamelCase($objCase["Value"]);
253: $this->assertEquals($objCase["Expected"], $newValue);
254: }
255:
256: }
257:
258:
259: }