/**
  * Ensures that the filter follows expected behavior
  *
  * @return void
  */
 public function testBasic()
 {
     $valuesExpected = array('string' => 'string', 'aBc1@3' => 'abc1@3', 'A b C' => 'a b c');
     foreach ($valuesExpected as $input => $output) {
         $this->assertEquals($output, $this->_filter->filter($input));
     }
 }
Example #2
0
 /**
  * Defined by Zend_Filter_Interface
  *
  * Encrypts the content $value with the defined settings
  *
  * @param  string $value Content to encrypt
  * @return string The encrypted content
  */
 public function filter($value)
 {
     $lowerFilter = new \Zend_Filter_StringToLower();
     $value = $lowerFilter->filter(parent::filter($value));
     preg_match_all(self::SLUG_PATTERN, $value, $return);
     return implode($this->getWordSeparator(), $return[0]);
 }
Example #3
0
 /**
  * Extract Data
  *
  * @param  Zend_Controller_Request_Http $request   Request
  * @param  null                         $scope     Scope
  * @param  bool                         $scopeOnly Scope Only
  * @return array
  * @see Mage_Customer_Model_Form::extractData()
  */
 public function extractData(Zend_Controller_Request_Http $request, $scope = null, $scopeOnly = true)
 {
     $data = parent::extractData($request, $scope, $scopeOnly);
     if (isset($data['username']) && !Mage::getStoreConfigFlag('username/general/case_sensitive')) {
         $filter = new Zend_Filter_StringToLower(array('encoding' => 'UTF-8'));
         $data['username'] = $filter->filter($data['username']);
     }
     return $data;
 }
Example #4
0
 /**
  * Ensures that the filter follows expected behavior with
  * specified encoding
  *
  * @return void
  */
 public function testWithEncoding()
 {
     $valuesExpected = array('ü' => 'Ü', 'ñ' => 'Ñ', 'üñ123' => 'ÜÑ123');
     try {
         $this->_filter->setEncoding('UTF-8');
         foreach ($valuesExpected as $input => $output) {
             $this->assertEquals($output, $this->_filter->filter($input));
         }
     } catch (Zend_Filter_Exception $e) {
         $this->assertContains('mbstring is required', $e->getMessage());
     }
 }
 /**
  * @group ZF-9854
  */
 public function testDetectMbInternalEncoding()
 {
     if (!function_exists('mb_internal_encoding')) {
         $this->markTestSkipped("Function 'mb_internal_encoding' not available");
     }
     $this->assertEquals(mb_internal_encoding(), $this->_filter->getEncoding());
 }
Example #6
0
    /**
     * Defined by Zend_Filter_Interface
     *
     * Does a lowercase on the content of the given file
     *
     * @param  string $value Full path of file to change
     * @return string The given $value
     * @throws Zend_Filter_Exception
     */
    public function filter($value)
    {
        if (!file_exists($value)) {
            require_once 'Zend/Filter/Exception.php';
            throw new Zend_Filter_Exception("File '$value' not found");
        }

        if (!is_writable($value)) {
            require_once 'Zend/Filter/Exception.php';
            throw new Zend_Filter_Exception("File '$value' is not writable");
        }

        $content = file_get_contents($value);
        if (!$content) {
            require_once 'Zend/Filter/Exception.php';
            throw new Zend_Filter_Exception("Problem while reading file '$value'");
        }

        $content = parent::filter($content);
        $result  = file_put_contents($value, $content);

        if (!$result) {
            require_once 'Zend/Filter/Exception.php';
            throw new Zend_Filter_Exception("Problem while writing file '$value'");
        }

        return $value;
    }
Example #7
0
 /**
  * Load customer by username
  *
  * @param Mage_Customer_Model_Customer $customer
  * @param string $username
  * @return Mage_Customer_Model_Entity_Customer
  * @throws Mage_Core_Exception
  */
 public function loadByUsername(Mage_Customer_Model_Customer $customer, $username)
 {
     if (!Mage::getStoreConfigFlag('username/general/case_sensitive')) {
         $filter = new Zend_Filter_StringToLower(array('encoding' => 'UTF-8'));
         $username = $filter->filter($username);
     }
     $select = $this->_getReadAdapter()->select()->from($this->getEntityTable(), array($this->getEntityIdField()))->joinNatural(array('cev' => $this->getTable('customer_entity_varchar')))->joinNatural(array('ea' => $this->getTable('eav/attribute')))->where('ea.attribute_code=\'username\' AND cev.value=?', $username);
     if ($customer->getSharingConfig()->isWebsiteScope()) {
         if (!$customer->hasData('website_id')) {
             Mage::throwException(Mage::helper('customer')->__('Customer website ID must be specified when using the website scope.'));
         }
         $select->where('website_id=?', (int) $customer->getWebsiteId());
     }
     if ($id = $this->_getReadAdapter()->fetchOne($select, 'entity_id')) {
         $this->load($customer, $id);
     } else {
         $customer->setData(array());
     }
     return $this;
 }
Example #8
0
 /**
  * @ZF-9058
  */
 public function testCaseInsensitiveEncoding()
 {
     $filter = $this->_filter;
     $valuesExpected = array('Ü' => 'ü', 'Ñ' => 'ñ', 'ÜÑ123' => 'üñ123');
     try {
         $filter->setEncoding('UTF-8');
         foreach ($valuesExpected as $input => $output) {
             $this->assertEquals($output, $filter($input));
         }
         $this->_filter->setEncoding('utf-8');
         foreach ($valuesExpected as $input => $output) {
             $this->assertEquals($output, $filter($input));
         }
         $this->_filter->setEncoding('UtF-8');
         foreach ($valuesExpected as $input => $output) {
             $this->assertEquals($output, $filter($input));
         }
     } catch (\Zend\Filter\Exception $e) {
         $this->assertContains('mbstring is required', $e->getMessage());
     }
 }
 /**
  * Constructor
  *
  * @param string|array|Zend_Config $options OPTIONAL
  */
 public function __construct($options = null)
 {
     parent::__construct($options);
     $this->setEncoding("UTF-8");
 }