-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from creative-commoners/pulls/3.0/fill-unit-te…
…st-gap Cover AuditHookMemberGroupSet and AuditHookManyManyList with test
- Loading branch information
Showing
5 changed files
with
150 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,17 @@ | ||
SilverStripe\Security\Group: | ||
# One test could have ambiguous results if the member and the group have the same ID. | ||
# So we're creating a bunch of dummy groups to make sure the IDs are different. | ||
noop: | ||
Title: Noop | ||
foobar: | ||
Title: Foobar | ||
prisoners: | ||
Title: Prisoners | ||
Code: prisoners | ||
|
||
SilverStripe\Security\Member: | ||
leslie_lawless: | ||
FirstName: Leslie | ||
Surname: Lawless | ||
Email: leslie@example.com | ||
Groups: '=>SilverStripe\Security\Group.prisoners' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
namespace SilverStripe\Auditor\Tests; | ||
|
||
use SilverStripe\Auditor\Tests\AuditHookTest\Logger; | ||
use SilverStripe\Core\Injector\Injector; | ||
use SilverStripe\Dev\SapphireTest; | ||
use SilverStripe\Security\Member; | ||
use SilverStripe\Security\Group; | ||
use SilverStripe\Security\Security; | ||
|
||
class AuditHookManyManyListTest extends SapphireTest | ||
{ | ||
protected static $fixture_file = 'AuditHookMFATest.yml'; | ||
|
||
protected Logger $writer; | ||
|
||
protected Member $member; | ||
|
||
protected Group $group; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->writer = new Logger; | ||
|
||
// Phase singleton out, so the message log is purged. | ||
Injector::inst()->unregisterNamedObject('AuditLogger'); | ||
Injector::inst()->registerService($this->writer, 'AuditLogger'); | ||
|
||
$this->member = $this->objFromFixture(Member::class, 'leslie_lawless'); | ||
$this->group = $this->objFromFixture(Group::class, 'prisoners'); | ||
} | ||
|
||
public function testRemoveByID(): void | ||
{ | ||
$this->assertEquals( | ||
1, | ||
$this->group->Members()->filter('ID', $this->member->ID)->count(), | ||
'Leslie Lawless is part of the prisoners group' | ||
); | ||
|
||
$this->group->Members()->removeByID($this->member->ID); | ||
|
||
$message = $this->writer->getLastMessage(); | ||
$currentUser = Security::getCurrentUser(); | ||
$this->assertStringContainsString( | ||
sprintf( | ||
'"%s" (ID: %d) removed Member "%s" (ID: %d) from Group "%s" (ID: %d)', | ||
$currentUser->Email, | ||
$currentUser->ID, | ||
$this->member->Email, | ||
$this->member->ID, | ||
$this->group->Title, | ||
$this->group->ID, | ||
), | ||
$message, | ||
'Log contains who removed Leslie Lawless from the prisoners group' | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
namespace SilverStripe\Auditor\Tests; | ||
|
||
use SilverStripe\Auditor\Tests\AuditHookTest\Logger; | ||
use SilverStripe\Core\Injector\Injector; | ||
use SilverStripe\Dev\SapphireTest; | ||
use SilverStripe\Security\Member; | ||
use SilverStripe\Security\Group; | ||
use SilverStripe\Security\Security; | ||
|
||
class AuditHookMemberGroupSetTest extends SapphireTest | ||
{ | ||
protected static $fixture_file = 'AuditHookMFATest.yml'; | ||
|
||
protected Logger $writer; | ||
|
||
protected Member $member; | ||
|
||
protected Group $group; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->writer = new Logger; | ||
|
||
// Phase singleton out, so the message log is purged. | ||
Injector::inst()->unregisterNamedObject('AuditLogger'); | ||
Injector::inst()->registerService($this->writer, 'AuditLogger'); | ||
|
||
$this->member = $this->objFromFixture(Member::class, 'leslie_lawless'); | ||
$this->group = $this->objFromFixture(Group::class, 'prisoners'); | ||
} | ||
|
||
public function testRemoveByID(): void | ||
{ | ||
$this->assertEquals( | ||
1, | ||
$this->member->Groups()->filter('ID', $this->group->ID)->count(), | ||
'The Prisoners group is one of Leslie Lawless\' groups.' | ||
); | ||
|
||
$this->member->Groups()->removeByID($this->group->ID); | ||
|
||
$message = $this->writer->getLastMessage(); | ||
$currentUser = Security::getCurrentUser(); | ||
$this->assertStringContainsString( | ||
sprintf( | ||
'"%s" (ID: %d) removed Member "%s" (ID: %d) from Group "%s" (ID: %d)', | ||
$currentUser->Email, | ||
$currentUser->ID, | ||
$this->member->Email, | ||
$this->member->ID, | ||
$this->group->Title, | ||
$this->group->ID, | ||
), | ||
$message, | ||
'Log contains who removed "Prisoners" from Leslie Lawless\' groups.' | ||
); | ||
} | ||
} |