Jump to:

3373 Posts in 998 Topics by 712 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Unit Test for DataObjectDecorator

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 403 Views
  • juergr
    Avatar
    Community Member
    17 Posts

    Unit Test for DataObjectDecorator Link to this post

    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?

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: Unit Test for DataObjectDecorator Link to this post

    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.

  • juergr
    Avatar
    Community Member
    17 Posts

    Re: Unit Test for DataObjectDecorator Link to this post

    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...)

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: Unit Test for DataObjectDecorator Link to this post

    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";

    403 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.