Esempio n. 1
0
 public function testCleanString()
 {
     $string = '12345';
     $this->assertEquals($string, $this->_helper->cleanString($string));
 }
Esempio n. 2
0
 /**
  * Check one attribute can be overridden in child
  *
  * @param string $attributeCode Attribute code
  * @param array $attributeParams Attribute params
  * @param array $rowData Row data
  * @param int $rowNumber
  * @return boolean
  */
 public function isAttributeValid($attributeCode, array $attributeParams, array $rowData, $rowNumber)
 {
     switch ($attributeParams['type']) {
         case 'varchar':
             $value = $this->_stringHelper->cleanString($rowData[$attributeCode]);
             $valid = $this->_stringHelper->strlen($value) < self::DB_MAX_VARCHAR_LENGTH;
             break;
         case 'decimal':
             $value = trim($rowData[$attributeCode]);
             $valid = (double) $value == $value && is_numeric($value);
             break;
         case 'select':
         case 'multiselect':
             $valid = isset($attributeParams['options'][strtolower($rowData[$attributeCode])]);
             break;
         case 'int':
             $value = trim($rowData[$attributeCode]);
             $valid = (int) $value == $value && is_numeric($value);
             break;
         case 'datetime':
             $value = trim($rowData[$attributeCode]);
             $valid = strtotime($value) !== false || preg_match('/^\\d{2}.\\d{2}.\\d{2,4}(?:\\s+\\d{1,2}.\\d{1,2}(?:.\\d{1,2})?)?$/', $value);
             break;
         case 'text':
             $value = $this->_stringHelper->cleanString($rowData[$attributeCode]);
             $valid = $this->_stringHelper->strlen($value) < self::DB_MAX_TEXT_LENGTH;
             break;
         default:
             $valid = true;
             break;
     }
     if (!$valid) {
         $this->addRowError($this->_helper('Mage_ImportExport_Helper_Data')->__("Invalid value for '%s'"), $rowNumber, $attributeCode);
     } elseif (!empty($attributeParams['is_unique'])) {
         if (isset($this->_uniqueAttributes[$attributeCode][$rowData[$attributeCode]])) {
             $this->addRowError($this->_helper('Mage_ImportExport_Helper_Data')->__("Duplicate Unique Attribute for '%s'"), $rowNumber, $attributeCode);
             return false;
         }
         $this->_uniqueAttributes[$attributeCode][$rowData[$attributeCode]] = true;
     }
     return (bool) $valid;
 }
Esempio n. 3
0
 public function cleanString($string)
 {
     $string = parent::cleanString($string);
     $string = preg_replace('/[^\\p{L}0-9\\-]/u', ' ', $string);
     return $string;
 }