public function testSetType() { $barcode = new Zend_Validate_Barcode('upc-a'); $this->assertTrue($barcode->isValid('065100004327')); $barcode->setType('ean-13'); $this->assertTrue($barcode->isValid('0075678164125')); }
private function isWorldWideId($worldWideId, $type) { $adapters = array('UPC' => array('8' => 'Upce', '12' => 'Upca'), 'EAN' => array('8' => 'Ean8', '13' => 'Ean13')); $length = strlen($worldWideId); if (!isset($adapters[$type], $adapters[$type][$length])) { return false; } try { $validator = new Zend_Validate_Barcode($adapters[$type][$length]); return $validator->isValid($worldWideId); } catch (Zend_Validate_Exception $e) { return true; } }
public function testUPCE() { $barcode = new Zend_Validate_Barcode('upce'); $this->assertTrue($barcode->isValid('02345673')); $this->assertFalse($barcode->isValid('02345672')); $this->assertFalse($barcode->isValid('123')); $this->assertTrue($barcode->isValid('123456')); $this->assertTrue($barcode->isValid('0234567')); }
/** * Particular validation for Upce barcode objects * (to suppress checksum character substitution) * * @param string $value * @param array $options * @throws Zend_Barcode_Object_Exception */ protected function _validateText($value, $options = array()) { $validator = new Zend_Validate_Barcode(array('adapter' => 'upce', 'checksum' => false)); $value = $this->_addLeadingZeros($value, true); if (!$validator->isValid($value)) { $message = implode("\n", $validator->getMessages()); /** * @see Zend_Barcode_Object_Exception */ throw new Zend_Barcode_Object_Exception($message); } }
/** * Standard validation for most of barcode objects * @param string $value * @param array $options */ protected function _validateText($value, $options = array()) { $validatorName = isset($options['validator']) ? $options['validator'] : $this->getType(); $validator = new Zend_Validate_Barcode(array('adapter' => $validatorName, 'checksum' => false)); $checksumCharacter = ''; $withChecksum = false; if ($this->_mandatoryChecksum) { $checksumCharacter = $this->_substituteChecksumCharacter; $withChecksum = true; } $value = $this->_addLeadingZeros($value, $withChecksum) . $checksumCharacter; if (!$validator->isValid($value)) { $message = implode("\n", $validator->getMessages()); /** * @see Zend_Barcode_Object_Exception */ require_once 'Zend/Barcode/Object/Exception.php'; throw new Zend_Barcode_Object_Exception($message); } }
/** * @group ZF-10116 */ public function testArrayLengthMessage() { $barcode = new Zend_Validate_Barcode('ean8'); $this->assertFalse($barcode->isValid('123')); $message = $barcode->getMessages(); $this->assertTrue(array_key_exists('barcodeInvalidLength', $message)); $this->assertContains("length of 7/8 characters", $message['barcodeInvalidLength']); }
/** * Particular validation for Ean8 barcode objects * (to suppress checksum character substitution) * @param string $value * @param array $options */ protected function _validateText($value, $options = array()) { $validator = new Zend_Validate_Barcode(array('adapter' => 'ean8', 'checksum' => false)); $value = $this->_addLeadingZeros($value, true); if (!$validator->isValid($value)) { $message = implode("\n", $validator->getMessages()); /** * @see Zend_Barcode_Object_Exception */ require_once PHP_LIBRARY_PATH . 'Zend/Barcode/Object/Exception.php'; throw new Zend_Barcode_Object_Exception($message); } }