1: <?php
  2: 
  3:   4:   5:   6: 
  7: class QControlBaseTests extends QUnitTestCaseBase {
  8:       9:  10:  11: 
 12:     protected static $ctlTest;
 13: 
 14:      15:  16: 
 17:     public static function setUpClass()
 18:     {
 19:         global $_FORM;
 20:         self::$ctlTest = $_FORM->ctlTest;
 21:     }
 22: 
 23:     protected function helpTest($objTestDataArray, $objProperiesArray, $strGetStyleMethod = "GetWrapperStyleAttributes") {
 24:         foreach ($objProperiesArray as $strProperty => $strCssProperty) {
 25:             $strValue = $objTestDataArray["Value"];
 26:             if ($strProperty) {
 27:                 self::$ctlTest->$strProperty = $strValue;
 28:             } else {
 29:                 self::$ctlTest->SetCssStyle ($strCssProperty, $strValue, true);
 30:             }
 31:             
 32:             $strAttrs = self::$ctlTest->$strGetStyleMethod() . ';';
 33:             
 34:             $intResult = strpos($strAttrs, $strCssProperty . ':' . $objTestDataArray["Expected"]);
 35:             $strMessage =
 36:                 $objTestDataArray["Msg"] .
 37:                 " Expected: '" . $objTestDataArray["Expected"] . "'" .
 38:                 " Obtained: '" . $strAttrs . "'";
 39:             $this->assertTrue(false !== $intResult, $strMessage);
 40:         }
 41:     }
 42: 
 43:     public function testCss() {     
 44:         $objCaseArray = array( 
 45:             array(
 46:                 "Value" => "0", "Expected" => "0;", "Msg" => "String zero renders with no 'px'"
 47:             ),
 48:             array(
 49:                 "Value" => "0.0", "Expected" => "0;", "Msg" => "String '0.0' renders with no 'px'"
 50:             ),
 51:             array(
 52:                 "Value" => (int)0, "Expected" => "0;", "Msg" => "Integer zero renders with no 'px'"
 53:             ),
 54:             array(
 55:                 "Value" => (float)0.0, "Expected" => "0;", "Msg" => "Float zero renders with no 'px'"
 56:             ),
 57:             array(
 58:                 "Value" => (double)0.0, "Expected" => "0;", "Msg" => "Double zero renders with no 'px'"
 59:             ),
 60:             array(
 61:                 "Value" => "0px", "Expected" => "0px;", "Msg" => "String value renders with no 'px'"
 62:             ),
 63:             array(
 64:                 "Value" => "0px", "Expected" => "0px;", "Msg" => "String zero with 'px' renders with no additional 'px'"
 65:             ),
 66: 
 67:             array(
 68:                 "Value" => "1", "Expected" => "1px;", "Msg" => "String '1' renders with 'px'"
 69:             ),
 70:             array(
 71:                 "Value" => "1.0", "Expected" => "1px;", "Msg" => "String '1.0' renders with 'px'"
 72:             ),
 73:             array(
 74:                 "Value" => "1.1", "Expected" => "1.1px;", "Msg" => "String '1.1' renders with 'px'"
 75:             ),
 76:             array(
 77:                 "Value" => (int)1, "Expected" => "1px;", "Msg" => "Integer 1 renders with 'px'"
 78:             ),
 79:             array(
 80:                 "Value" => (float)1.0, "Expected" => "1px;", "Msg" => "Float 1 renders with 'px'"
 81:             ),
 82:             array(
 83:                 "Value" => (float)1.1, "Expected" => "1.1px;", "Msg" => "Float 1.1 renders with 'px'"
 84:             ),
 85:             array(
 86:                 "Value" => (double)1.0, "Expected" => "1px;", "Msg" => "Double 1 renders with 'px'"
 87:             ),
 88:             array(
 89:                 "Value" => (double)1.1, "Expected" => "1.1px;", "Msg" => "Double 1.1 renders with 'px'"
 90:             ),
 91:             array(
 92:                 "Value" => "1px", "Expected" => "1px;", "Msg" => "String value renders with no 'px'"
 93:             ),
 94:             array(
 95:                 "Value" => "1px", "Expected" => "1px;", "Msg" => "String with 'px' renders with no additional 'px'"
 96:             ),
 97: 
 98:             array(
 99:                 "Value" => "0 0 0 0", "Expected" => "0 0 0 0;", "Msg" => "String with many values renders with no 'px'"
100:             ),
101:             array(
102:                 "Value" => "0px 0px 0px 0px", "Expected" => "0px 0px 0px 0px;", "Msg" => "String with many values renders with no additional 'px'"
103:             ),
104:             array(
105:                 "Value" => "1 1 1 1", "Expected" => "1 1 1 1;", "Msg" => "String with many values renders with no 'px'"
106:             ),
107:             array(
108:                 "Value" => "1px 1px 1px 1px", "Expected" => "1px 1px 1px 1px;", "Msg" => "String with many values renders with no additional 'px'"
109:             ),
110:             array(
111:                 "Value" => "dummy", "Expected" => "dummy;", "Msg" => "String with not a number value renders with no 'px'"
112:             ),
113:             array(
114:                 "Value" => "the dumbest", "Expected" => "the dumbest;", "Msg" => "String with multiple not a number values renders with no 'px'"
115:             )
116:         );
117: 
118:         foreach($objCaseArray as $objCase) {
119:             $this->helpTest($objCase, array("Left" => "left", "Top" => "top"), "GetWrapperStyleAttributes");
120:         }
121: 
122:         foreach($objCaseArray as $objCase) {
123:             $this->helpTest($objCase, array("BorderWidth" => "border-width", "Width" => "width", "Height" => "width", null => "margin"), "GetStyleAttributes");
124:         }
125: 
126:     }
127:     
128:     public function testAjaxChangeFormState() {
129:         if (!QApplication::$CliMode) {
130:             $this->assertTrue (self::$ctlTest->savedValue1 == 2, "Actions can change state for later queued actions.");
131:             $this->assertTrue (self::$ctlTest->savedValue2 == 2, "Actions can change state for later queued actions.");
132:         }
133:     }
134:     
135: }