function testTag() { $data = array('actions' => array('create' => array('jip' => true), 'edit' => array('jip' => true), 'display' => array(), 'delete' => array('jip' => true))); $template = '<core:DATASOURCE id="realm"><limb:DSProcessor:GroupActions group_name="jip">'. '<list:LIST from="jip_actions"><list:ITEM>'. '<core:OPTIONAL for="jip">{$name}|</core:OPTIONAL>'. '</list:ITEM></list:LIST>'. '</core:DATASOURCE>'; RegisterTestingTemplate('/limb/actions_DSProcessor.html', $template); $page =& new Template('/limb/actions_DSProcessor.html'); $component =& $page->findChild('realm'); $dataspace = new Dataspace(); $dataspace->import($data); $component->registerDataSource($dataspace); $this->assertEqual($page->capture(), 'create|'. 'edit|'. 'delete|'); }
function testRequiredRuleFalse() { $this->validator->addRule(new RequiredRule('testfield')); $data = new Dataspace(); $data->set('testfield', false); $this->error_list->expectNever('addError'); $this->validator->validate($data); $this->assertTrue($this->validator->isValid()); }
function testTreeIdentifierRuleError() { $this->validator->addRule(new TreePathRule('test')); $data = new Dataspace(); $data->set('test', '/root/document/1'); $this->ErrorList->expectOnce('addError', array('validation', 'ERROR_INVALID_TREE_PATH', array('Field' => 'test'), NULL)); $this->validator->validate($data); $this->assertFalse($this->validator->isValid()); }
function testLoad() { $variations_data = array('original' => array('id' => $id1 = 200, 'name' => $name1 = 'original', 'etag' => $etag1 = 'etag1', 'width' => $width1 = 200, 'height' => $height1 = 100, 'media_id' => $media_id1 = 101, 'media_file_id' => $media_file_id1 = 'media_file_id1', 'file_name' => $file_name1 = 'file_name1', 'mime_type' => $mime_type1 = 'mime_type1', 'size' => $size1 = 500), 'icon' => array('id' => $id2 = 300, 'name' => $name2 = 'icon', 'etag' => $etag2 = 'etag2', 'width' => $width2 = 20, 'height' => $height2 = 10, 'media_id' => $media_id2 = 102, 'media_file_id' => $media_file_id2 = 'media_file_id2', 'file_name' => $file_name2 = 'file_name2', 'mime_type' => $mime_type2 = 'mime_type2', 'size' => $size2 = 50)); $result = array('id' => $id = 100, 'description' => $description = 'Description', 'variations' => $variations_data); $record = new Dataspace(); $record->import($result); $image = new ImageObject(); $this->mapper->load($record, $image); $this->assertEqual($image->getId(), $id); $this->assertEqual($image->getDescription(), $description); $this->_checkImageObjectVariations($image, $variations_data); }
function testSizeRangeRuleBlank() { $this->validator->addRule(new SizeRangeRule('testfield', 5, 10)); $data = new Dataspace(); $data->set('testfield', ''); $this->error_list->expectNever('addError'); $this->validator->validate($data); $this->assertTrue($this->validator->isValid()); }
function testUniqueUserEmailRuleCorrectEdit() { $this->validator->addRule(new UniqueUserEmailRule('test', '2@2.2')); $data = new Dataspace(); $data->set('test', '2@2.2'); $this->ErrorList->expectNever('addError'); $this->validator->validate($data); $this->assertTrue($this->validator->isValid()); }
function testUrlRuleInvalid() { $this->validator->addRule(new UrlRule('testfield')); $data = new Dataspace(); $data->set('testfield', '://not/a/valid/url'); $this->error_list->expectOnce('addError', array('testfield', 'BAD_URL', array())); $this->validator->validate($data); $this->assertFalse($this->validator->isValid()); }
function testCanadaZipRuleInvalid3() { $this->validator->addRule(new CanadaZipRule('test')); $data = new Dataspace(); $data->set('test', 'H2V2K1'); $this->error_list->expectOnce('addError', array('test', Strings :: get('error_invalid_zip_format', 'error'), array())); $this->validator->validate($data); $this->assertFalse($this->validator->isValid()); }
function testCanadaZipRuleInvalid3() { $this->validator->addRule(new CanadaZipRule('test')); $data = new Dataspace(); $data->set('test', 'H2V2K1'); $this->ErrorList->expectOnce('addError', array('validation', 'ERROR_INVALID_ZIP_FORMAT', array('Field' => 'test'), NULL)); $this->validator->validate($data); $this->assertFalse($this->validator->isValid()); }
function testLocaleDateRuleError() { $this->validator->addRule(new LocaleDateRule('test', 'en')); $data = new Dataspace(); $data->set('test', '02jjklklak/sdsdskj34-sdsdsjkjkj78'); $this->ErrorList->expectOnce('addError', array('validation', 'INVALID_DATE', array('Field' => 'test'), NULL)); $this->validator->validate($data); $this->assertFalse($this->validator->isValid()); }
function testNotValidContainsSlash() { $this->validator->addRule(new IdentifierRule('test')); $data = new Dataspace(); $data->set('test', 'test/test'); $this->ErrorList->expectOnce('addError', array('validation', 'INVALID', array('Field' => 'test'), NULL)); $this->validator->validate($data); $this->assertFalse($this->validator->isValid()); }
function testTreeIdentifierRuleError() { $this->validator->addRule(new TreePathRule('test')); $data = new Dataspace(); $data->set('test', '/root/document/1'); $this->error_list->expectOnce('addError', array('test', Strings :: get('error_invalid_tree_path', 'error'), array())); $this->validator->validate($data); $this->assertFalse($this->validator->isValid()); }
function testMatchRuleFailure() { $this->validator->addRule(new MatchRule('testfield', 'testmatch')); $data = new Dataspace(); $data->set('testfield', 'peaches'); $data->set('testmatch', 'cream'); $this->error_list->expectOnce('addError', array('testfield', Strings :: get('error_no_match', 'error'), array('match_field' => 'testmatch'))); $this->validator->validate($data); $this->assertFalse($this->validator->isValid()); }
function testTag() { $data = array('_node_path' => $path = '/cms/limb/', '_service_name' => $service_name = 'TestService'); $this->authorizer->expectOnce('getAccessibleActions', array($path, $service_name)); $actions = array('create' => array('name' => 'create'), 'edit' => array('name' => 'edit')); $this->authorizer->setReturnValue('getAccessibleActions', $actions); $template = '<core:DATASOURCE id="realm"><limb:DSProcessor:Actions>' . '<list:LIST from="actions"><list:ITEM>' . '{$name}|' . '</list:ITEM></list:LIST>' . '</core:DATASOURCE>'; RegisterTestingTemplate('/limb/actions_DSProcessor.html', $template); $page =& new Template('/limb/actions_DSProcessor.html'); $component =& $page->findChild('realm'); $dataspace = new Dataspace(); $dataspace->import($data); $component->registerDataSource($dataspace); $this->assertEqual($page->capture(), 'create|' . 'edit|'); }
function & fetchRecord() { $toolkit =& Limb :: toolkit(); $resolver =& $toolkit->getRequestResolver($this->resolver_name); if(!is_object($resolver)) die($this->resolver_name . ' request resolver not set:' . __FILE__ . ' at line '. __LINE__); $record = new Dataspace(); if(!$entity =& $resolver->resolve($toolkit->getRequest())) return $record; $record->import($entity->export()); return $record; }
function testFetchAllByPath() { $toolkit =& Limb::toolkit(); $request =& $toolkit->getRequest(); $uri =& $request->getUri(); $uri->setPath($path1 = '/about/news/1'); $object1 = new Dataspace(); $object1->set('title', $title1 = 'title1'); $object2 = new Dataspace(); $object2->set('title', $title2 = 'title2'); $object3 = new Dataspace(); $object3->set('title', $title3 = 'title1'); $this->db->insert('sys_object', array('oid' => $oid1 = 100, 'class_id' => $class_id1 = 1)); $this->db->insert('sys_object', array('oid' => $oid2 = 101, 'class_id' => $class_id2 = 2)); $this->db->insert('sys_object', array('oid' => $oid3 = 102, 'class_id' => $class_id3 = 3)); $this->db->insert('sys_class', array('id' => $class_id1, 'name' => $class_name1 = 'class_name1')); $this->db->insert('sys_class', array('id' => $class_id2, 'name' => $class_name2 = 'class_name2')); $this->db->insert('sys_class', array('id' => $class_id3, 'name' => $class_name3 = 'class_name3')); $this->translator->expectArgumentsAt(0, 'toId', array($path3 = '/about')); $this->translator->setReturnValueAt(0, 'toId', $oid3); $this->translator->expectArgumentsAt(1, 'toId', array($path2 = '/about/news')); $this->translator->setReturnValueAt(1, 'toId', $oid2); $this->translator->expectArgumentsAt(2, 'toId', array($path1)); $this->translator->setReturnValueAt(2, 'toId', $oid1); $this->translator->expectCallCount('toId', 3); $dao = new BreadcrumbsDAO(); $this->uow->expectArgumentsAt(0, 'load', array($class_name3, $oid3)); $this->uow->setReturnValueAt(0, 'load', $object3); $this->uow->expectArgumentsAt(1, 'load', array($class_name2, $oid2)); $this->uow->setReturnValueAt(1, 'load', $object2); $this->uow->expectArgumentsAt(2, 'load', array($class_name1, $oid1)); $this->uow->setReturnValueAt(2, 'load', $object1); $this->uow->expectCallCount('load', 3); $rs =& $dao->fetch(); $this->assertEqual($rs->getTotalRowCount(), 3); $rs->rewind(); $record =& $rs->current(); $this->assertEqual($record->get('title'), $title3); $this->assertEqual($record->get('_node_path'), $path3); $rs->next(); $record =& $rs->current(); $this->assertEqual($record->get('title'), $title2); $this->assertEqual($record->get('_node_path'), $path2); $rs->next(); $record =& $rs->current(); $this->assertEqual($record->get('title'), $title1); $this->assertEqual($record->get('_node_path'), $path1); }
function testLoad() { $mapper = new ObjectMapper(); $object = new Object(); $record = new Dataspace(); $record->import(array('oid' => $id = 10, 'class_id' => $class_id = 100, 'class_name' => $class_name = 'some_class')); $mapper->load($record, $object); $this->assertEqual($object->get('oid'), $id); $this->assertEqual($object->get('class_id'), $class_id); $this->assertEqual($object->get('class_name'), $class_name); }
function testLoad() { $mapper = new ServiceLocationMapper(); $object = new ServiceLocation(); $record = new Dataspace(); $record->import(array('_service_name' => $service_name = 'TestService', '_service_title' => $title = 'some title', '_service_id' => $id = 40, )); $mapper->load($record, $object); $this->assertEqual($object->get('name'), $service_name); $this->assertEqual($object->get('title'), $title); $this->assertEqual($object->get('id'), $id); }
function testLoad() { $mapper = new TreeNodeDataMapper(); $object = new Object(); $record = new Dataspace(); $record->import(array('_node_id' => $node_id = 10, '_node_parent_id' => $parent_node_id = 100, '_node_identifier' => $identifier = 'test', )); $mapper->load($record, $object); $this->assertEqual($object->get('id'), $node_id); $this->assertEqual($object->get('parent_id'), $parent_node_id); $this->assertEqual($object->get('identifier'), $identifier); }
function testPreserveState() { $template = '<form id="testForm" name="testForm" runat="server">' . '<limb:PRESERVE_STATE name="id">' . '</form>'; RegisterTestingTemplate('/limb/preserve_state1.html', $template); $data = new Dataspace(); $data->set('id', 10000); $page =& new Template('/limb/preserve_state1.html'); $form =& $page->findChild('testForm'); $form->registerDatasource($data); $this->assertEqual($page->capture(), '<form id="testForm" name="testForm">' . '<input type="hidden" name="id" value="10000">' . '</form>'); }
function testFetch() { $toolkit =& Limb :: toolkit(); $resolver = new MockRequestResolver($this); $toolkit->setRequestResolver('tree_based_entity', $resolver); $resolver->tally(); $entity = new Object(); $entity->set('class_name', $class_name = 'TestArticle'); $request =& $toolkit->getRequest(); $resolver->setReturnReference('resolve', $entity, array($request)); $dao = new TreeBasedEntityDAO(); $result =& $dao->fetchRecord(); $expected_result = new Dataspace(); $expected_result->set('class_name', $class_name); $this->assertEqual($result, $expected_result); }
function testTag() { $path = 'whatever'; $data = array('_node_id' => $node_id = 10); $this->translator->expectOnce('getPathToNode', array($node_id)); $this->translator->setReturnValue('getPathToNode', $path); $template = '<core:DATASOURCE id="realm"><limb:DSProcessor:Path>'. '{$_node_path}'. '</core:DATASOURCE>'; RegisterTestingTemplate('/limb/path_DSProcessor.html', $template); $page =& new Template('/limb/path_DSProcessor.html'); $component =& $page->findChild('realm'); $dataspace = new Dataspace(); $dataspace->import($data); $component->registerDataSource($dataspace); $this->assertEqual($page->capture(), $path); }
function testValid() { $this->tree->expectOnce('getNode', array($node_id = 10)); $this->tree->setReturnValue('getNode', array('whatever')); $this->validator->addRule(new TreeNodeIdRule('test')); $data = new Dataspace(); $data->set('test', $node_id); $this->ErrorList->expectNever('addError'); $this->validator->validate($data); $this->assertTrue($this->validator->isValid()); }
function testLoad() { $mapper = new VersionedObjectMapper($this->delegated_mapper); $object = new Object(); $result = array('whatever'); $record = new Dataspace(); $record->import($result); $this->delegated_mapper->expectOnce('load', array($record, $object)); $mapper->load($record, $object); }
function testEmailUserInvalidDomain() { $this->validator->addRule(new EmailRule('testfield')); $data = new Dataspace(); $data->set('testfield', 'billgates@micro$oft.com'); $this->error_list->expectOnce('addError', array('testfield', Strings :: get('bad_domain_characters', 'error'), array())); $this->validator->validate($data); $this->assertFalse($this->validator->isValid()); }
function testValidSinceTheSameObject() { $this->tree->expectOnce('isNode', array($parent_node_id = 10)); $this->tree->setReturnValue('isNode', true); $this->tree->expectOnce('getChildren', array($parent_node_id = 10)); $rs = new ArrayDataSet(array(array('identifier' => $identifier = 'test', 'id' => $node_id = 100))); $this->tree->setReturnReference('getChildren', $rs); $this->validator->addRule(new TreeIdentifierRule('test', $parent_node_id, $node_id)); $data = new Dataspace(); $data->set('test', $identifier); $this->ErrorList->expectNever('addError'); $this->validator->validate($data); $this->assertTrue($this->validator->isValid()); }
function testRefererFormSubmittedUseCurrent() { $template = "<form id='test' runat='server'><limb:form:REFERER use_current='TRUE'></form>"; RegisterTestingTemplate('/limb/form-ref5.html', $template); $page =& new Template('/limb/form-ref5.html'); $referer = 'put-me-into-result'; $dataspace = new Dataspace(); $dataspace->set('referer', $referer); $form =& $page->getChild('test'); $form->registerDataSource($dataspace); $_SERVER['HTTP_REFERER'] = 'another-referer'; $_SERVER['REQUEST_URI'] = 'another-referer'; $result = $page->capture(); $this->assertEqual($result, "<form id=\"test\"><input type='hidden' name='referer' value='$referer'></form>"); }
function testTreeIdentifierNodeIdNotSetError() { $this->validator->addRule(new TreeIdentifierRule('test', $this->node_id_ru)); $data = new Dataspace(); $data->set('test', 'doc1'); $this->error_list->expectOnce('addError', array('test', Strings :: get('error_duplicate_tree_identifier', 'error'), array())); $this->validator->validate($data); $this->assertFalse($this->validator->isValid()); }
function testTreeNodeIdRuleError() { $this->validator->addRule(new TreeNodeIdRule('test')); $data = new Dataspace(); $data->set('test', -10000); $this->error_list->expectOnce('addError', array('test', Strings :: get('error_invalid_tree_node_id', 'error'), array())); $this->validator->validate($data); $this->assertFalse($this->validator->isValid()); }
function testLoadOverrideRecordPrefix() { $mapper = new OneTableObjectMapper('OneTableObjectMapperTest', 'foo'); $object = new OneTableObjectMapperTestNewsObject(); $result = array('bar_id' => $id = 10, 'bar_content' => $content = 'some content', 'bar_annotation' => $annotation = 'some annotation', 'bar_news_date' => $news_date = 'some date'); $record = new Dataspace(); $record->import($result); $mapper->load($record, $object, 'bar_'); $this->assertEqual($object->get('id'), $id); $this->assertEqual($object->get('content'), $content); $this->assertEqual($object->get('annotation'), $annotation); $this->assertEqual($object->get('news_date'), $news_date); }