protected function _extractPrefixedFieldsAsActiveRecords($record) { foreach ($this->join_relations as $relation_name => $params) { $relation_info = $this->base_object->getRelationInfo($relation_name); if (isset($relation_info['can_be_null']) && $relation_info['can_be_null'] && !$record->get($this->prefix . $relation_info['field'])) { return; } $fields = new lmbSet(); $prefix = $this->prefix . $relation_name . '__'; if ($record instanceof lmbActiveRecord) { $data = $record->exportRaw(); } else { $data = $record->export(); } foreach ($data as $field => $value) { if (strpos($field, $prefix) === 0) { $non_prefixes_field_name = substr($field, strlen($prefix)); $fields->set($non_prefixes_field_name, $value); $record->remove($field); } } $related_object = lmbARRecordSetDecorator::createObjectFromRecord($fields, $relation_info['class'], $this->conn); $record->set($this->prefix . $relation_name, $related_object); } }
function testNotValidWithClassRestrictionWithCustomError() { $rule = new lmbRequiredObjectRule('testfield', 'Foo', 'Custom_Error'); $dataspace = new lmbSet(); $dataspace->set('testfield', new TestObjectForThisRule()); $this->error_list->expectOnce('addError', array('Custom_Error', array('Field' => 'testfield'), array())); $rule->validate($dataspace, $this->error_list); }
function testInvalidValueRuleError2() { $rule = new lmbInvalidValueRule('testfield', 1); $data = new lmbSet(); $data->set('testfield', '1'); $this->error_list->expectOnce('addError', array(lmb_i18n('{Field} value is wrong', 'validation'), array('Field' => 'testfield'), array())); $rule->validate($data, $this->error_list); }
function testPatternRuleFailedWithCustomError() { $rule = new lmbPatternRule('testfield', '/^\\w+$/', 'Custom_Error'); $data = new lmbSet(); $data->set('testfield', 'Simpletest is Cool!'); $this->error_list->expectOnce('addError', array('Custom_Error', array('Field' => 'testfield'), array())); $rule->validate($data, $this->error_list); }
function testRequiredRuleWithSpacedString() { $rule = new lmbRequiredRule('testfield'); $dataspace = new lmbSet(); $dataspace->set('testfield', "\n\t \n\t"); $this->error_list->expectOnce('addError', array(lmb_i18n('{Field} is required', 'validation'), array('Field' => 'testfield'), array())); $rule->validate($dataspace, $this->error_list); }
function testLessThanMinWithCustomError() { $rule = new lmbNumericValueRangeRule('testfield', 1, 5, 'Custom_Error'); $dataspace = new lmbSet(); $dataspace->set('testfield', -10); $this->error_list->expectOnce('addError', array('Custom_Error', array('Field' => 'testfield'), array('value' => 1))); $rule->validate($dataspace, $this->error_list); }
function testNumericRuleFailureWithCustomError() { $rule = new lmbNumericPrecisionRule('testfield', 3, 2, 'Custom_Error'); $dataspace = new lmbSet(); $dataspace->set('testfield', 'not a number'); $this->error_list->expectOnce('addError', array('Custom_Error', array('Field' => 'testfield'), array())); $rule->validate($dataspace, $this->error_list); }
function testFieldNotValidSelfError() { $rule = new lmbUniqueTableFieldRule('test', 'test_table', 'field2', $message = "ERROR_DUPLICATE_WOW"); $data = new lmbSet(); $data->set('test', 'wow'); $this->error_list->expectOnce('addError', array($message, array('Field' => 'test'), array('Value' => 'wow'))); $rule->validate($data, $this->error_list); }
function testInvalidForISO() { $rule = new lmbDateRule('testfield'); $dataspace = new lmbSet(); $dataspace->set('testfield', 'blah 12:30'); $this->error_list->expectOnce('addError'); $rule->validate($dataspace, $this->error_list); }
function testInArrayCustomError() { $rule = new lmbNotInArrayRule('testfield', array('www', 'ftp', 'smtp', 'mail'), $error = 'my_custom_error'); $data = new lmbSet(); $data->set('testfield', 'www'); $this->error_list->expectOnce('addError', array($error, array('Field' => 'testfield'), array())); $rule->validate($data, $this->error_list); }
function testValidValueRule_Error_Array() { $rule = new lmbValidValueRule('testfield', array('foo', 'bar')); $data = new lmbSet(); $data->set('testfield', 'baz'); $this->error_list->expectOnce('addError'); $rule->validate($data, $this->error_list); }
function testSizeRangeRuleTooSmallWithCustomErrorMessage() { $rule = new lmbSizeRangeRule('testfield', 30, 100, 'Error_custom'); $dataspace = new lmbSet(); $dataspace->set('testfield', '12345678901234567890'); $this->error_list->expectOnce('addError', array('Error_custom', array('Field' => 'testfield'), array('min' => 30, 'max' => 100))); $rule->validate($dataspace, $this->error_list); }
function testEmailDoubleUnderscore() { $rule = new lmbEmailRule('testfield'); $dataspace = new lmbSet(); $dataspace->set('testfield', '*****@*****.**'); $this->error_list->expectNever('addError'); $rule->validate($dataspace, $this->error_list); }
function testUrlRuleWithGarbage() { $rule = new lmbUrlRule('testfield'); $dataspace = new lmbSet(); $dataspace->set('testfield', 'as@#$@$%ADGasjdkjf'); $this->error_list->expectOnce('addError'); $rule->validate($dataspace, $this->error_list); }
function testInvalidValueRule_Success_Bool() { $rule = new lmbValidValueRule('testfield', false); $data = new lmbSet(); $data->set('testfield', 0); $this->error_list->expectNever('addError'); $rule->validate($data, $this->error_list); }
function testNotValidContainsSlash() { $rule = new lmbIdentifierRule('test'); $data = new lmbSet(); $data->set('test', 'test/test'); $this->error_list->expectOnce('addError', array(lmb_i18n('{Field} must contain only letters and numbers', 'validation'), array('Field' => 'test'), array())); $rule->validate($data, $this->error_list); }
function current() { $record = parent::current(); $data = $record->export(); $data['full'] = $this->prefix1 . $data['name'] . '-' . $data['job'] . $this->prefix2; $processed_record = new lmbSet(); $processed_record->import($data); return $processed_record; }
function testMatchRuleFailureWithCustomError() { $rule = new lmbMatchRule('testfield', 'testmatch', 'Custom_Error'); $dataspace = new lmbSet(); $dataspace->set('testfield', 'peaches'); $dataspace->set('testmatch', 'cream'); $this->error_list->expectOnce('addError', array('Custom_Error', array('Field' => 'testfield', 'MatchField' => 'testmatch'), array())); $rule->validate($dataspace, $this->error_list); }
function testWithComplexDBEParams() { $config = array('blog' => array('path' => '/blog/:controller/:action'), 'news' => array('path' => '/:controller/:action')); $routes = $this->_createRoutes($config); $template = '<route_url_set field="url" route="news" params="controller:{$#request.controller},action:{$#request.action}"/>' . '{$url}'; $this->registerTestingTemplate('/limb/routes_tag_dynamic_proper_dbe.html', $template); $page = $this->initTemplate('/limb/routes_tag_dynamic_proper_dbe.html'); $dataspace = new lmbSet(); $dataspace->set('controller', $controller = 'news'); $dataspace->set('action', $action = 'archive'); $page->set('request', $dataspace); $expected = lmbToolkit::instance()->getRoutesUrl(array('controller' => $controller, 'action' => $action), 'news'); $this->assertEqual($page->capture(), $expected); }
function testWithComplexDBEParams() { $config = array('blog' => array('path' => '/blog/:controller/:action'), 'news' => array('path' => '/:controller/:action')); $routes = $this->_createRoutes($config); $template = '<route_url route="news" params="controller:{$#request.controller},action:{$#request.action}" onclick="something"></route_url>'; $this->registerTestingTemplate('/limb/route_url_tag_dynamic_complex_dbe.html', $template); $page = $this->initTemplate('/limb/route_url_tag_dynamic_complex_dbe.html'); $dataspace = new lmbSet(); $dataspace->set('controller', $controller = 'news'); $dataspace->set('action', $action = 'archive'); $page->set('request', $dataspace); $url = lmbToolkit::instance()->getRoutesUrl(array('controller' => 'news', 'action' => 'archive'), 'news'); $expected = '<a onclick="something" href="' . $url . '"></a>'; $this->assertEqual($page->capture(), $expected); }
function testEmailMixedDashUnderscore() { $rule = new lmbEmailRule('testfield'); $dataspace = new lmbSet(); $dataspace->set('testfield', '*****@*****.**'); $this->error_list->expectNever('addError'); $rule->validate($dataspace, $this->error_list); }
function testDomainRuleLocalDomain() { $rule = new lmbDomainRule('testfield'); $dataspace = new lmbSet(); $dataspace->set('testfield', 'localhost'); $this->error_list->expectNever('addError'); $rule->validate($dataspace, $this->error_list); }
function testImplementsMagicGetSetUnsetMethods() { $ds = new lmbSet(); $ds->set('foo', 'Bar'); $this->assertEqual($ds->foo, 'Bar'); $ds->foo = 'Zoo'; $this->assertEqual($ds->foo, 'Zoo'); unset($ds->foo); $this->assertFalse(property_exists($ds, 'foo')); $ds->set('foo', 'Bar'); $this->assertTrue(isset($ds->foo)); $this->assertFalse(isset($ds->bar)); }
function get($key, $default = LIMB_UNDEFINED) { $_key = "__{$key}"; if (in_array($_key, $this->__reserved_attrs)) { return $this->{$_key}; } return parent::get($key, $default); }
function current() { $object = parent::current(); $fields = new lmbSet(); foreach ($this->attach_relations as $relation_name => $params) { $relation_type = $this->base_object->getRelationType($relation_name); $relation_info = $this->base_object->getRelationInfo($relation_name); switch ($relation_type) { case lmbActiveRecord::HAS_ONE: case lmbActiveRecord::MANY_BELONGS_TO: if (isset($this->loaded_attaches[$relation_name][$object->get($this->prefix . $relation_info['field'])])) { $fields->set($this->prefix . $relation_name, $this->loaded_attaches[$relation_name][$object->get($this->prefix . $relation_info['field'])]); } break; case lmbActiveRecord::BELONGS_TO: if (isset($this->loaded_attaches[$relation_name][$object->get($this->prefix . $this->base_object->getPrimaryKeyName())])) { $fields->set($this->prefix . $relation_name, $this->loaded_attaches[$relation_name][$object->get($this->prefix . $this->base_object->getPrimaryKeyName())]); } break; case lmbActiveRecord::HAS_MANY: case lmbActiveRecord::HAS_MANY_TO_MANY: $collection = $this->base_object->createRelationCollection($relation_name); $collection->setOwner($object); if (isset($this->loaded_attaches[$relation_name][$object->get($this->prefix . $this->base_object->getPrimaryKeyName())])) { $collection->setDataset(new lmbCollection($this->loaded_attaches[$relation_name][$object->get($this->prefix . $this->base_object->getPrimaryKeyName())])); } else { $collection->setDataset(new lmbCollection()); } $fields->set($this->prefix . $relation_name, $collection); break; } } $object->loadFromRecord($fields); return $object; }