/** * validates a primary or foreign key depending on the current schema data for this field * recognizes uuid (char36) and aiid (int10 unsigned) - not yet mixed (varchar36) * more useful than using numeric or notEmpty which are type specific * @param array $data * @param array $options * - allowEmpty * 2011-06-21 ms */ function validateKey($data = array(), $options = array()) { $key = array_shift(array_keys($data)); $value = array_shift($data); $schema = $this->schema($key); if (!$schema) { return true; } $defaults = array('allowEmpty' => false); $options = am($defaults, $options); if ($schema['type'] != 'integer') { if ($options['allowEmpty'] && $value === '') { return true; } return Validation::uuid($value); } if ($options['allowEmpty'] && $value === 0) { return true; } return is_numeric($value) && (int) $value == $value && $value > 0; }
public function testUuid() { $this->assertTrue(Validation::uuid('00000000-0000-0000-0000-000000000000')); $this->assertTrue(Validation::uuid('550e8400-e29b-11d4-a716-446655440000')); $this->assertFalse(Validation::uuid('BRAP-e29b-11d4-a716-446655440000')); $this->assertTrue(Validation::uuid('550E8400-e29b-11D4-A716-446655440000')); $this->assertFalse(Validation::uuid('550e8400-e29b11d4-a716-446655440000')); $this->assertFalse(Validation::uuid('550e8400-e29b-11d4-a716-4466440000')); $this->assertFalse(Validation::uuid('550e8400-e29b-11d4-a71-446655440000')); $this->assertFalse(Validation::uuid('550e8400-e29b-11d-a716-446655440000')); $this->assertFalse(Validation::uuid('550e8400-e29-11d4-a716-446655440000')); }
/** * Test that records can be inserted with UUID primary keys, and * that the primary key is not blank * * @return void */ public function testUuidPrimaryKeyInsertion() { $this->loadFixtures('Uuid'); $Model = ClassRegistry::init('Uuid'); $data = array('title' => 'A UUID should work', 'count' => 10); $Model->create($data); $this->assertTrue((bool) $Model->save()); $result = $Model->read(); $this->assertEquals($data['title'], $result['Uuid']['title']); $this->assertTrue(Validation::uuid($result['Uuid']['id']), 'Not a UUID'); }
/** * Is the passed ID valid ? * * By default we assume you want to validate an numeric string * like a normal incremental ids from MySQL * * Change the validateId settings key to "uuid" for UUID check instead * * @param mixed $id * @return boolean * @throws BadRequestException If id is invalid */ protected function _validateId($id) { $type = $this->config('validateId'); if ($type === null) { $type = $this->detectPrimaryKeyFieldType(); } if (!$type) { return true; } elseif ($type === 'uuid') { $valid = Validation::uuid($id); } else { $valid = is_numeric($id); } if ($valid) { return true; } $subject = $this->_trigger('invalidId', compact('id')); $message = $this->message('invalidId'); $exceptionClass = $message['class']; throw new $exceptionClass($message['text'], $message['code']); }
public function smsCheckPayment($paycode, &$payed) { if (Validation::uuid($paycode) == true) { /* Set payed always to true, Mollie offers no way to verify the payment * we need to trust on their callback */ $payed = 'true'; } else { $payed = 'false'; } return array('payed' => $payed); }
/** * Is the passed ID valid ? * * By default we assume you want to validate an numeric string * like a normal incremental ids from MySQL * * Change the validateId settings key to "uuid" for UUID check instead * * @param mixed $id * @return boolean */ protected function _validateId($id) { if (isset($this->settings['validateId'])) { $type = $this->settings['validateId']; } else { $type = $this->_detectPrimaryKeyFieldType(); } if (!$type) { return true; } elseif ($type === 'uuid') { $valid = Validation::uuid($id); } else { $valid = is_numeric($id); } if ($valid) { return true; } $subject = $this->trigger('invalidId', compact('id')); $this->_setFlash('invalid_id.error'); return $this->_redirect($subject, $this->_controller->referer()); }
/** * testSmsFetchPayment method * * @return void */ public function testSmsFetchPayment() { $ret = $this->Mollie->smsFetchPayment('12345678', 10000, 'nl'); $this->assertEqual($ret['amount'], 10000); $this->assertEqual(Validation::uuid($ret['paycode']), true); $url = parse_url($ret['targetUrl']); $this->assertEqual($url['host'], 'www.mollie.nl'); $this->assertEqual($url['scheme'], 'http'); $this->assertEqual($url['path'], '/partners/betaal/'); $query = null; parse_str($url['query'], $query); $this->assertEqual($query['partnerid'], $this->settings['partnerId']); $this->assertEqual($query['id'], '12345678'); $this->assertEqual($query['land'], 'nl'); $this->assertEqual($query['parameter'][1], $ret['paycode']); }
/** * * * @param integer|string $check * @param string $type * @return void */ public function assertId($check, $type = 'uuid') { switch ($type) { case 'numeric': $check = Validation::numeric($check); break; default: $check = Validation::uuid($check); $type = strtoupper($type); } if (!$check) { parent::fail("Failed asserting that '{$check}' is a valid {$type} primary key."); } $this->addToAssertionCount(1); }