mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
MINOR Added tests methods for Member::can*() methods to MemberTest
MINOR Added test Extension classes for testing decorated can*() methods (from r94359) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@95602 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
35628832d6
commit
69cda024ab
@ -348,6 +348,45 @@ class MemberTest extends FunctionalTest {
|
||||
$this->session()->inst_set('loggedInAs', null);
|
||||
}
|
||||
|
||||
public function testDecoratedCan() {
|
||||
$extensions = $this->removeExtensions(Object::get_extensions('Member'));
|
||||
$member = $this->objFromFixture('Member', 'test');
|
||||
|
||||
/* Normal behaviour is that you can't view a member unless canView() on an extension returns true */
|
||||
$this->assertFalse($member->canView());
|
||||
$this->assertFalse($member->canDelete());
|
||||
$this->assertFalse($member->canEdit());
|
||||
|
||||
/* Apply a decorator that allows viewing in any case (most likely the case for member profiles) */
|
||||
Object::add_extension('Member', 'MemberTest_ViewingAllowedExtension');
|
||||
$member2 = $this->objFromFixture('Member', 'staffmember');
|
||||
|
||||
$this->assertTrue($member2->canView());
|
||||
$this->assertFalse($member2->canDelete());
|
||||
$this->assertFalse($member2->canEdit());
|
||||
|
||||
/* Apply a decorator that denies viewing of the Member */
|
||||
Object::remove_extension('Member', 'MemberTest_ViewingAllowedExtension');
|
||||
Object::add_extension('Member', 'MemberTest_ViewingDeniedExtension');
|
||||
$member3 = $this->objFromFixture('Member', 'managementmember');
|
||||
|
||||
$this->assertFalse($member3->canView());
|
||||
$this->assertFalse($member3->canDelete());
|
||||
$this->assertFalse($member3->canEdit());
|
||||
|
||||
/* Apply a decorator that allows viewing and editing but denies deletion */
|
||||
Object::remove_extension('Member', 'MemberTest_ViewingDeniedExtension');
|
||||
Object::add_extension('Member', 'MemberTest_EditingAllowedDeletingDeniedExtension');
|
||||
$member4 = $this->objFromFixture('Member', 'accountingmember');
|
||||
|
||||
$this->assertTrue($member4->canView());
|
||||
$this->assertFalse($member4->canDelete());
|
||||
$this->assertTrue($member4->canEdit());
|
||||
|
||||
Object::remove_extension('Member', 'MemberTest_EditingAllowedDeletingDeniedExtension');
|
||||
$this->addExtensions($extensions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the given array of member extensions as class names.
|
||||
* This is useful for re-adding extensions after being removed
|
||||
@ -379,4 +418,33 @@ class MemberTest extends FunctionalTest {
|
||||
return $extensions;
|
||||
}
|
||||
|
||||
}
|
||||
class MemberTest_ViewingAllowedExtension extends DataObjectDecorator implements TestOnly {
|
||||
|
||||
public function canView() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
class MemberTest_ViewingDeniedExtension extends DataObjectDecorator implements TestOnly {
|
||||
|
||||
public function canView() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
class MemberTest_EditingAllowedDeletingDeniedExtension extends DataObjectDecorator implements TestOnly {
|
||||
|
||||
public function canView() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function canEdit() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function canDelete() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user