/**
  * This test was needed because of the wierd type casting issues with 0 and 1 and '1' and '0' as keys in an array.
  * '0' and '1' turn into integers which they shouldn't and this messes up the oneOf sql query builder. Additionally
  * on some versions of MySQL, 0,1 in a NOT IN, will evaluate true to 'abc' which it shouldn't.  As a result
  * the 0/1 boolean values have been removed from the BooleanSanitizerUtil::getAcceptableValues().
  */
 public function testBooleanAcceptableValuesMappingAndSqlOneOfString()
 {
     $string = SQLOperatorUtil::resolveOperatorAndValueForOneOf('oneOf', BooleanSanitizerUtil::getAcceptableValues());
     $compareString = "IN('false','true','y','n','yes','no','0','1','')";
     // Not Coding Standard
     $this->assertEquals($compareString, $string);
 }
 protected function analyzeByValue($value)
 {
     $acceptableValues = BooleanSanitizerUtil::getAcceptableValues();
     $acceptableValuesMapping = BooleanSanitizerUtil::getAcceptableValuesResolvingValues();
     if (!in_array(strtolower($value), $acceptableValues)) {
         $this->messageCountData[static::INVALID]++;
     }
 }
 /**
  * @see DataAnalyzerInterface::runAndMakeMessages()
  */
 public function runAndMakeMessages(AnalyzerSupportedDataProvider $dataProvider, $columnName)
 {
     $acceptableValues = BooleanSanitizerUtil::getAcceptableValues();
     $inPart = SQLOperatorUtil::resolveOperatorAndValueForOneOf('oneOf', $acceptableValues);
     $where = DatabaseCompatibilityUtil::lower($columnName) . ' NOT ' . $inPart;
     $count = $dataProvider->getCountByWhere($where);
     if ($count > 0) {
         $label = '{count} value(s) have invalid check box values. ';
         $label .= 'These values will be set to false upon import.';
         $this->addMessage(Zurmo::t('ImportModule', $label, array('{count}' => $count)));
     }
 }
 /**
  * Given a value, attempt to convert the value to either true/false based on a mapping array of possible
  * boolean values.  If the value is not present, attemp to utilize the default value specified.
  * If the value presented is not a valid mapping value then a
  * InvalidValueToSanitizeException will be thrown.
  * @param mixed $value
  * @return sanitized value
  * @throws InvalidValueToSanitizeException
  */
 public function sanitizeValue($value)
 {
     $acceptableValues = BooleanSanitizerUtil::getAcceptableValues();
     $acceptableValuesResolvingValues = BooleanSanitizerUtil::getAcceptableValuesResolvingValues();
     if ($value == null) {
         if (isset($this->mappingRuleData['defaultValue']) && $this->mappingRuleData['defaultValue'] != null) {
             $key = array_search($this->mappingRuleData['defaultValue'], $acceptableValues);
             return $acceptableValuesResolvingValues[$this->mappingRuleData['defaultValue']];
         } else {
             return null;
         }
     }
     if (!in_array(strtolower($value), $acceptableValues)) {
         throw new InvalidValueToSanitizeException(Zurmo::t('ImportModule', 'Invalid check box format.'));
     } else {
         $key = array_search(strtolower($value), $acceptableValues);
         return $acceptableValuesResolvingValues[$key];
     }
 }
 /**
  * Given a value, attempt to convert the value to either true/false based on a mapping array of possible
  * boolean values.  If the value is not present, attemp to utilize the default value specified.
  * If the value presented is not a valid mapping value then a
  * InvalidValueToSanitizeException will be thrown.
  * @param string $modelClassName
  * @param string $attributeName
  * @param mixed $value
  * @param array $mappingRuleData
  */
 public static function sanitizeValue($modelClassName, $attributeName, $value, $mappingRuleData)
 {
     assert('is_string($modelClassName)');
     assert('is_string($attributeName)');
     assert('$mappingRuleData["defaultValue"] == null || $mappingRuleData["defaultValue"] == "1" ||
                 $mappingRuleData["defaultValue"] == "0"');
     $acceptableValues = BooleanSanitizerUtil::getAcceptableValues();
     $acceptableValuesResolvingValues = BooleanSanitizerUtil::getAcceptableValuesResolvingValues();
     if ($value == null) {
         if ($mappingRuleData['defaultValue'] != null) {
             $key = array_search($mappingRuleData['defaultValue'], $acceptableValues);
             return $acceptableValuesResolvingValues[$mappingRuleData['defaultValue']];
         } else {
             return null;
         }
     }
     if (!in_array(strtolower($value), $acceptableValues)) {
         throw new InvalidValueToSanitizeException(Zurmo::t('ImportModule', 'Invalid check box format.'));
     } else {
         $key = array_search(strtolower($value), $acceptableValues);
         return $acceptableValuesResolvingValues[$key];
     }
 }