-
Notifications
You must be signed in to change notification settings - Fork 824
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FIX Sort without specifying a table name
Using a table name in sort() is not allowed in CMS 5. We could use orderBy() here but member is the table it will sort on by default anyway so there's no need. Also added unit tests, which should have caught this ages ago.
- Loading branch information
1 parent
2274b3e
commit e3f8fc2
Showing
4 changed files
with
128 additions
and
5 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 |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
|
||
namespace SilverStripe\Security\Tests; | ||
|
||
use InvalidArgumentException; | ||
use SilverStripe\Admin\LeftAndMain; | ||
use SilverStripe\Control\Cookie; | ||
use SilverStripe\Core\Config\Config; | ||
use SilverStripe\Core\Convert; | ||
|
@@ -12,6 +14,7 @@ | |
use SilverStripe\ORM\DataObject; | ||
use SilverStripe\ORM\DB; | ||
use SilverStripe\ORM\FieldType\DBDatetime; | ||
use SilverStripe\ORM\Map; | ||
use SilverStripe\ORM\ValidationException; | ||
use SilverStripe\ORM\ValidationResult; | ||
use SilverStripe\Security\Group; | ||
|
@@ -1618,4 +1621,121 @@ public function testChangePasswordToBlankIsValidated() | |
$result = $member->changePassword(''); | ||
$this->assertFalse($result->isValid()); | ||
} | ||
|
||
public function testMapInCMSGroupsNoLeftAndMain() | ||
{ | ||
if (class_exists(LeftAndMain::class)) { | ||
$this->markTestSkipped('LeftAndMain must not exist for this test.'); | ||
} | ||
$result = Member::mapInCMSGroups(); | ||
$this->assertInstanceOf(Map::class, $result); | ||
|
||
$this->assertEmpty($result, 'Without LeftAndMain, no groups are CMS groups.'); | ||
} | ||
|
||
/** | ||
* @dataProvider provideMapInCMSGroups | ||
*/ | ||
public function testMapInCMSGroups(array $groupFixtures, array $groupCodes, array $expectedUsers) | ||
{ | ||
if (!empty($groupFixtures) && !empty($groupCodes)) { | ||
throw new InvalidArgumentException('Data provider is misconfigured for this test.'); | ||
} | ||
|
||
if (!class_exists(LeftAndMain::class)) { | ||
$this->markTestSkipped('LeftAndMain must exist for this test.'); | ||
} | ||
|
||
$groups = []; | ||
|
||
// Convert fixture names to IDs | ||
if (!empty($groupFixtures)) { | ||
foreach ($groupFixtures as $index => $groupFixtureName) { | ||
$groups[$index] = $this->objFromFixture(Group::class, $groupFixtureName)->ID; | ||
} | ||
} | ||
|
||
// Convert codes to DataList | ||
if (!empty($groupCodes)) { | ||
$groups = Group::get()->filter(['Code' => $groupCodes]); | ||
} | ||
|
||
// Convert user fixtures to IDs | ||
foreach ($expectedUsers as $index => $userFixtureName) { | ||
// This is not an actual fixture - it was created by $this->logInWithPermission('ADMIN') | ||
if ($userFixtureName === 'ADMIN User') { | ||
$expectedUsers[$index] = Member::get()->filter(['Email' => '[email protected]'])->first()->ID; | ||
} else { | ||
$expectedUsers[$index] = $this->objFromFixture(Member::class, $userFixtureName)->ID; | ||
} | ||
} | ||
|
||
$result = Member::mapInCMSGroups($groups); | ||
$this->assertInstanceOf(Map::class, $result); | ||
|
||
$this->assertSame($expectedUsers, $result->keys()); | ||
} | ||
|
||
public function provideMapInCMSGroups() | ||
{ | ||
// Note: "ADMIN User" is not from the fixtures, that user is created by $this->logInWithPermission('ADMIN') | ||
return [ | ||
'defaults' => [ | ||
'groupFixtures' => [], | ||
'groupCodes' => [], | ||
'expectedUsers' => [ | ||
'admin', | ||
'other-admin', | ||
'ADMIN User', | ||
], | ||
], | ||
'single group in a list' => [ | ||
'groupFixtures' => [], | ||
'groupCodes' => [ | ||
'staffgroup' | ||
], | ||
'expectedUsers' => [ | ||
'staffmember', | ||
], | ||
], | ||
'single group in IDs array' => [ | ||
'groups' => [ | ||
'staffgroup', | ||
], | ||
'groupCodes' => [], | ||
'expectedUsers' => [ | ||
'staffmember', | ||
], | ||
], | ||
'multiple groups in a list' => [ | ||
'groupFixtures' => [], | ||
'groupCodes' => [ | ||
'staffgroup', | ||
'securityadminsgroup', | ||
], | ||
'expectedUsers' => [ | ||
'staffmember', | ||
'test', | ||
], | ||
], | ||
'multiple groups in IDs array' => [ | ||
'groupFixtures' => [ | ||
'staffgroup', | ||
'securityadminsgroup', | ||
], | ||
'groupCodes' => [], | ||
'expectedUsers' => [ | ||
'staffmember', | ||
'test', | ||
], | ||
], | ||
'group with no members' => [ | ||
'groupFixtures' => [], | ||
'groupCodes' => [ | ||
'memberless', | ||
], | ||
'expectedUsers' => [], | ||
], | ||
]; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -58,6 +58,8 @@ | |
Email: [email protected] | ||
Password: 1nitialPassword | ||
staffmember: | ||
FirstName: Staff | ||
Surname: User | ||
Email: [email protected] | ||
Groups: '=>SilverStripe\Security\Group.staffgroup' | ||
managementmember: | ||
|