-
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.
Merge pull request #10904 from creative-commoners/pulls/5/more-placeh…
…olders ENH Do not use placeholders by default for foreignIDFilter()
- Loading branch information
Showing
11 changed files
with
258 additions
and
12 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
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
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
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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
namespace SilverStripe\Security\Tests; | ||
|
||
use SilverStripe\Dev\SapphireTest; | ||
use SilverStripe\Security\Tests\GroupTest\TestMember; | ||
use SilverStripe\Core\Config\Config; | ||
use SilverStripe\ORM\DataList; | ||
|
||
class Member_GroupSetTest extends SapphireTest | ||
{ | ||
protected static $fixture_file = 'GroupTest.yml'; | ||
|
||
protected static $extra_dataobjects = [ | ||
TestMember::class | ||
]; | ||
|
||
/** | ||
* @dataProvider provideForForeignIDPlaceholders | ||
*/ | ||
public function testForForeignIDPlaceholders(bool $config, bool $useInt, bool $expected): void | ||
{ | ||
Config::modify()->set(DataList::class, 'use_placeholders_for_integer_ids', $config); | ||
$member1 = $this->objFromFixture(TestMember::class, 'parentgroupuser'); | ||
$member2 = $this->objFromFixture(TestMember::class, 'allgroupuser'); | ||
$groups1 = $member1->Groups(); | ||
$groups2 = $member2->Groups(); | ||
$ids = $useInt ? [$member1->ID, $member2->ID] : ['Lorem', 'Ipsum']; | ||
$newGroupList = $groups1->forForeignID($ids); | ||
$sql = $newGroupList->dataQuery()->sql(); | ||
preg_match('#ID" IN \(([^\)]+)\)\)#', $sql, $matches); | ||
$usesPlaceholders = ($matches[1] ?? '') === '?, ?, ?, ?, ?' || str_contains($sql, '"Group"."ID" = ?'); | ||
$this->assertSame($expected, $usesPlaceholders); | ||
$expectedIDs = $useInt | ||
? array_unique(array_merge($groups1->column('ID'), $groups2->column('ID'))) | ||
: []; | ||
$this->assertEqualsCanonicalizing($expectedIDs, $newGroupList->column('ID')); | ||
} | ||
|
||
public function provideForForeignIDPlaceholders(): array | ||
{ | ||
return [ | ||
'config false' => [ | ||
'config' => false, | ||
'useInt' => true, | ||
'expected' => false, | ||
], | ||
'config false non-int' => [ | ||
'config' => false, | ||
'useInt' => false, | ||
'expected' => true, | ||
], | ||
'config true' => [ | ||
'config' => true, | ||
'useInt' => true, | ||
'expected' => true, | ||
], | ||
'config true non-int' => [ | ||
'config' => true, | ||
'useInt' => false, | ||
'expected' => true, | ||
], | ||
]; | ||
} | ||
} |