/** * 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)); } }
/** * 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()); } }
/** * 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; }
/** * 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]); }
/** * 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; }
/** * 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; }