3070 Posts in 869 Topics by 651 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 290 Views |
-
Unit Test for DataObjectDecorator

8 February 2012 at 9:04am
How do I write Unit Tests for DataObjectDecorators? I have a MemberDecorator which adds a lot of functionality and information to the member object and now i want to test these functions.
But when i try to call a function of the MemberDecorator i get a error "undefined method" on member.
Is there a way to tell the Saphire test that the Member Object is Decorated with another Object?
-
Re: Unit Test for DataObjectDecorator

8 February 2012 at 9:12pm
Is there a way to tell the Saphire test that the Member Object is Decorated with another Object?
Decorators are applied transparently so you have to test again member directly (ensuring of course your decorator is added). You can see what extensions are applied to what object using the methods on object - http://api.silverstripe.org/2.4/sapphire/core/Object.html.
-
Re: Unit Test for DataObjectDecorator

9 February 2012 at 8:44am
But how can I call a Method on the Decorator?
If i have a MemberDecorator->doSomethingImportant() function, how do i call this function thru the Member class as i would during normal developement?
Can you make a little example, because i realy don't get it. (Sometimes i'm a little dumb...)
-
Re: Unit Test for DataObjectDecorator

9 February 2012 at 11:09pm
As I said, they're applied transparently so if you create a function Foo() calling Foo() on a member class would work.
//
class MemberDecorator extends DataObjectDecorator {
function Foo() { return "hi"; }
}
//
DataObject::add_extension('Member', 'MemberDecorator');
//$member = Member::currentUser();
echo $member->Foo(); // "hi";
| 290 Views | ||
|
Page:
1
|
Go to Top |


