Fixed entity definition in test cases.

The test cases have been updated to use the new extensible mechanism
for defining and registering entities.

Ticket #2043
This commit is contained in:
Endi Sukma Dewata 2011-11-17 12:09:00 -06:00 committed by Endi S. Dewata
parent a9e4316d5a
commit e84bd27af2
4 changed files with 107 additions and 70 deletions

View File

@ -217,6 +217,7 @@ IPA.entity = function(spec) {
return [that.name + '-pkey']; return [that.name + '-pkey'];
}; };
that.entity_init = that.init;
return that; return that;
}; };

View File

@ -167,20 +167,13 @@ var IPA = function() {
}; };
that.register = function(name, factory) { that.register = function(name, factory) {
that.remove_entity(name);
that.entity_factories[name] = factory; that.entity_factories[name] = factory;
}; };
that.get_entities = function() { that.create_entity = function(name) {
return that.entities.values;
};
that.get_entity = function(name) {
var entity = that.entities.get(name);
if (!entity) {
var factory = that.entity_factories[name]; var factory = that.entity_factories[name];
if (!factory) { if (!factory) return null;
return null;
}
try { try {
var builder = that.entity_builder(); var builder = that.entity_builder();
@ -190,12 +183,13 @@ var IPA = function() {
name: name name: name
}); });
entity = builder.build(); var entity = builder.build();
entity.init({ entity.init({
builder: builder builder: builder
}); });
that.add_entity(entity); return entity;
} catch (e) { } catch (e) {
if (e.expected) { if (e.expected) {
@ -203,13 +197,26 @@ var IPA = function() {
entities are not to be registered. */ entities are not to be registered. */
return null; return null;
} }
if (e.message) { if (e.message) {
alert(e.message); alert(e.message);
} else { } else {
alert(e); alert(e);
} }
return null; return null;
} }
};
that.get_entities = function() {
return that.entities.values;
};
that.get_entity = function(name) {
var entity = that.entities.get(name);
if (!entity) {
entity = that.create_entity(name);
if (entity) that.add_entity(entity);
} }
return entity; return entity;
}; };

View File

@ -156,30 +156,58 @@ test("Testing details lifecycle: create, load.", function(){
return widget; return widget;
} }
var entity = IPA. IPA.register('user', function(spec) {
entity_builder().
entity('user'). var that = IPA.entity(spec);
details_facet({sections:[
that.init = function(params) {
that.entity_init(params);
params.builder.details_facet({
sections: [
{ {
name: 'identity', name: 'identity',
label: IPA.messages.details.identity, label: IPA.messages.details.identity,
fields:['title','givenname','sn','cn','displayname', 'initials'] fields: [ 'title', 'givenname', 'sn', 'cn', 'displayname', 'initials' ]
}, },
{ {
name: 'contact', name: 'contact',
label:'contact', label: 'contact',
fields: fields: [
[ {factory: test_widget,name:'test'}, {
{factory: IPA.multivalued_text_widget, name:'mail'}, factory: test_widget,
{factory: IPA.multivalued_text_widget, name:'test'
name:'telephonenumber'}, },
{factory: IPA.multivalued_text_widget, name:'pager'}, {
{factory: IPA.multivalued_text_widget, name:'mobile'}, factory: IPA.multivalued_text_widget,
{factory: IPA.multivalued_text_widget, name:'mail'
name:'facsimiletelephonenumber'}] },
{
factory: IPA.multivalued_text_widget,
name:'telephonenumber'
},
{
factory: IPA.multivalued_text_widget,
name:'pager'
},
{
factory: IPA.multivalued_text_widget,
name:'mobile'
},
{
factory: IPA.multivalued_text_widget,
name:'facsimiletelephonenumber'
} }
]}).build(); ]
}
]
});
};
return that;
});
var entity = IPA.get_entity('user');
var entity_container = $('<div/>', { var entity_container = $('<div/>', {
name: 'user', name: 'user',

View File

@ -31,14 +31,20 @@ module('entity',{
url: 'data', url: 'data',
on_success: function(data, text_status, xhr) { on_success: function(data, text_status, xhr) {
IPA.entity_factories.user = function(){ IPA.register('user', function(spec) {
return IPA.
entity_builder(). var that = IPA.entity(spec);
entity('user').
search_facet({ that.init = function(params) {
columns:['uid']}). that.entity_init(params);
build();
params.builder.search_facet({
columns: [ 'uid' ]
});
}; };
return that;
});
}, },
on_error: function(xhr, text_status, error_thrown) { on_error: function(xhr, text_status, error_thrown) {
ok(false, "ipa_init() failed: "+error_thrown); ok(false, "ipa_init() failed: "+error_thrown);
@ -60,12 +66,7 @@ test('Testing IPA.entity_set_search_definition().', function() {
return true; return true;
}; };
var entity = IPA. var entity = IPA.get_entity('user');
entity_builder().
entity('user').
search_facet({
columns:['uid']}).
build();
var entity_container = $('<div/>', { var entity_container = $('<div/>', {
name: 'user', name: 'user',