Uniqueness check on attribute names in get_property_list. Add tests for that, and for get_attributes
This commit is contained in:
parent
334f3414c3
commit
059bd6761d
2 changed files with 35 additions and 1 deletions
|
|
@ -67,12 +67,14 @@ Returns an array reference of the names of all properties, in the order they wer
|
|||
=cut
|
||||
|
||||
sub get_property_list {
|
||||
my $self = shift;
|
||||
my $self = shift;
|
||||
my @properties = ();
|
||||
my %seen = ();
|
||||
CLASS: foreach my $className (reverse $self->linearized_isa()) {
|
||||
my $meta = $self->initialize($className);
|
||||
next CLASS unless $meta->isa('WebGUI::Definition::Meta::Class');
|
||||
push @properties,
|
||||
grep { ! $seen{$_}++ } # Uniqueness check
|
||||
map { $_->name } # Just the name
|
||||
sort { $a->insertion_order <=> $b->insertion_order } # In insertion order
|
||||
grep { $_->isa('WebGUI::Definition::Meta::Property') } # that are Meta::Properties
|
||||
|
|
|
|||
|
|
@ -115,6 +115,18 @@ my $called_getProperties;
|
|||
|
||||
package main;
|
||||
|
||||
cmp_bag(
|
||||
[ map {$_->name} WGT::Class::AlsoAsset->meta->get_attributes ],
|
||||
[qw/property1 property2 property3/],
|
||||
'get_attributes returns attributes for my class'
|
||||
);
|
||||
|
||||
cmp_bag(
|
||||
[ map {$_->name} WGT::Class::Asset::Snippet->meta->get_attributes ],
|
||||
[qw/property10 property11/],
|
||||
'...even in a subclass'
|
||||
);
|
||||
|
||||
cmp_deeply(
|
||||
WGT::Class::Asset::Snippet->getProperties,
|
||||
[qw/property1 property2 property3 property10 property11/],
|
||||
|
|
@ -122,3 +134,23 @@ my $called_getProperties;
|
|||
);
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
package WGT::Class::Asset::NotherOne;
|
||||
use WebGUI::Definition::Asset;
|
||||
extends 'WGT::Class::AlsoAsset';
|
||||
|
||||
attribute tableName => 'snippet';
|
||||
property 'property10' => ();
|
||||
property 'property1' => ();
|
||||
|
||||
package main;
|
||||
|
||||
cmp_deeply(
|
||||
WGT::Class::Asset::NotherOne->getProperties,
|
||||
[qw/property1 property2 property3 property10/],
|
||||
'checking inheritance of properties by name, insertion order with an overridden property'
|
||||
);
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue