Skip to content

Commit

Permalink
ENH Align ArrayList case sensitivity with other lists (#11529)
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli authored Jan 7, 2025
1 parent 3871869 commit bf05e17
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 39 deletions.
20 changes: 0 additions & 20 deletions src/Model/List/ArrayList.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use InvalidArgumentException;
use LogicException;
use SilverStripe\Dev\Debug;
use SilverStripe\Dev\Deprecation;
use SilverStripe\ORM\Filters\ExactMatchFilter;
use SilverStripe\ORM\Filters\SearchFilterable;
use SilverStripe\Model\ArrayData;
Expand Down Expand Up @@ -33,14 +32,6 @@ class ArrayList extends ModelData implements SS_List
{
use SearchFilterable;

/**
* Whether filter and exclude calls should be case sensitive by default or not.
* This configuration property is here for backwards compatability.
*
* @deprecated 5.1.0 use SearchFilter.default_case_sensitive instead
*/
private static bool $default_case_sensitive = true;

/**
* Holds the items in the list
*
Expand Down Expand Up @@ -690,17 +681,6 @@ protected function filterOrExclude(array $filters, bool $inclusive = true, bool
$hasNullFilter = true;
}
$searchFilter = $this->createSearchFilter($filterKey, $filterValue);

// Apply default case sensitivity for backwards compatability
if (!str_contains($filterKey, ':case') && !str_contains($filterKey, ':nocase')) {
$caseSensitive = Deprecation::withSuppressedNotice(fn() => static::config()->get('default_case_sensitive'));
if ($caseSensitive && in_array('case', $searchFilter->getSupportedModifiers())) {
$searchFilter->setModifiers($searchFilter->getModifiers() + ['case']);
} elseif (!$caseSensitive && in_array('nocase', $searchFilter->getSupportedModifiers())) {
$searchFilter->setModifiers($searchFilter->getModifiers() + ['nocase']);
}
}

$searchFilters[$filterKey] = $searchFilter;
}

Expand Down
38 changes: 19 additions & 19 deletions tests/php/Model/List/ArrayListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,20 +349,20 @@ public static function provideFindWithSearchfilters()
return [
// test a couple of search filters
// don't need to be as explicit as the filter tests, just check the syntax works
'exact match not case sensitive' => [
'args' => ['NoCase:nocase', 'case sensitive'],
'exact match case insensitive' => [
'args' => ['NoCase', 'case sensitive'],
'objects' => $objects,
'expected' => $objects[0],
],
'startswith match' => [
'args' => ['StartsWithTest:StartsWith', 'test'],
'objects' => $objects,
'expected' => $objects[3],
'expected' => $objects[0],
],
'startswith match no case' => [
'args' => ['StartsWithTest:StartsWith:nocase', 'test'],
'startswith match case' => [
'args' => ['StartsWithTest:StartsWith:case', 'test'],
'objects' => $objects,
'expected' => $objects[0],
'expected' => $objects[3],
],
'startswith match negated' => [
'args' => ['StartsWithTest:StartsWith:not', 'Test'],
Expand Down Expand Up @@ -1187,20 +1187,20 @@ public static function provideFilterWithSearchfilters()
'expected' => [$objects[3], $objects[4]],
],
// case sensitivity checks
'exact match case sensitive' => [
'exact match case insensitive' => [
'args' => [['NoCase' => 'case sensitive']],
'objects' => $objects,
'expected' => [$objects[1]],
'expected' => [$objects[0], $objects[1]],
],
'exact match case insensitive' => [
'args' => ['NoCase:nocase', 'case sensitive'],
'exact match case sensitive' => [
'args' => ['NoCase:case', 'case sensitive'],
'objects' => $objects,
'expected' => [$objects[0], $objects[1]],
'expected' => [$objects[1]],
],
'exact match mixed case filters' => [
'args' => [[
'NoCase:nocase' => 'case sensitive',
'CaseSensitive' => 'case sensitive',
'CaseSensitive:case' => 'case sensitive',
]],
'objects' => $objects,
'expected' => [$objects[1]],
Expand All @@ -1218,14 +1218,14 @@ public static function provideFilterWithSearchfilters()
],
// partialmatch filter
'partial match' => [
'args' => ['StartsWithTest:PartialMatch', 'start'],
'args' => [['StartsWithTest:PartialMatch' => 'start']],
'objects' => $objects,
'expected' => [$objects[2]],
'expected' => [$objects[1], $objects[2]],
],
'partial match with modifier' => [
'args' => [['StartsWithTest:PartialMatch:nocase' => 'start']],
'args' => ['StartsWithTest:PartialMatch:case', 'start'],
'objects' => $objects,
'expected' => [$objects[1], $objects[2]],
'expected' => [$objects[2]],
],
// greaterthan filter
'greaterthan match' => [
Expand Down Expand Up @@ -1324,12 +1324,12 @@ public static function provideFilterAnyWithSearchfilters()
'partial match' => [
'args' => ['StartsWithTest:PartialMatch', 'start'],
'objects' => $objects,
'expected' => [$objects[2]],
'expected' => [$objects[1], $objects[2]],
],
'partial match with modifier' => [
'args' => ['StartsWithTest:PartialMatch:nocase', 'start'],
'args' => ['StartsWithTest:PartialMatch:case', 'start'],
'objects' => $objects,
'expected' => [$objects[1], $objects[2]],
'expected' => [$objects[2]],
],
'greaterthan match' => [
'args' => ['GreaterThan100:GreaterThan', 100],
Expand Down

0 comments on commit bf05e17

Please sign in to comment.