mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #10211 from creative-commoners/pulls/4.10/seach-filter-tests
FIX Default GridField search fields with an index of 0 to use StartWithFilter
This commit is contained in:
commit
77e87875b3
@ -12,10 +12,10 @@ use SilverStripe\Forms\TextField;
|
||||
use SilverStripe\ORM\SS_List;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
use SilverStripe\ORM\DataList;
|
||||
use SilverStripe\ORM\Filters\SearchFilter;
|
||||
use SilverStripe\View\ArrayData;
|
||||
use SilverStripe\View\SSViewer;
|
||||
use LogicException;
|
||||
use SilverStripe\ORM\Filters\SearchFilter;
|
||||
|
||||
/**
|
||||
* This class is is responsible for adding objects to another object's has_many
|
||||
@ -347,7 +347,7 @@ class GridFieldAddExistingAutocompleter implements GridField_HTMLProvider, GridF
|
||||
// so we need to check the original setting.
|
||||
// If the field is defined $searchable_fields = array('MyField'),
|
||||
// then default to StartsWith filter, which makes more sense in this context.
|
||||
if (!$customSearchableFields || array_search($name, $customSearchableFields)) {
|
||||
if (!$customSearchableFields || array_search($name, $customSearchableFields) !== false) {
|
||||
$filter = 'StartsWith';
|
||||
} else {
|
||||
$filterName = $spec['filter'];
|
||||
|
@ -14,6 +14,7 @@ use SilverStripe\Forms\Tests\GridField\GridFieldAddExistingAutocompleterTest\Tes
|
||||
use SilverStripe\Forms\Tests\GridField\GridFieldTest\Cheerleader;
|
||||
use SilverStripe\Forms\Tests\GridField\GridFieldTest\Permissions;
|
||||
use SilverStripe\Forms\Tests\GridField\GridFieldTest\Player;
|
||||
use SilverStripe\Forms\Tests\GridField\GridFieldTest\Stadium;
|
||||
use SilverStripe\Forms\Tests\GridField\GridFieldTest\Team;
|
||||
use SilverStripe\ORM\ArrayList;
|
||||
|
||||
@ -29,7 +30,8 @@ class GridFieldAddExistingAutocompleterTest extends FunctionalTest
|
||||
Team::class,
|
||||
Cheerleader::class,
|
||||
Player::class,
|
||||
Permissions::class
|
||||
Permissions::class,
|
||||
Stadium::class,
|
||||
];
|
||||
|
||||
protected static $extra_controllers = [
|
||||
@ -41,15 +43,12 @@ class GridFieldAddExistingAutocompleterTest extends FunctionalTest
|
||||
$autoCompleter = new GridFieldAddExistingAutocompleter($targetFragment = 'before', ['Test']);
|
||||
$this->assertEquals(
|
||||
[
|
||||
'Name:PartialMatch',
|
||||
'City:StartsWith',
|
||||
'Cheerleaders.Name:StartsWith'
|
||||
'Name:StartsWith',
|
||||
'City:EndsWith',
|
||||
'Country:ExactMatch',
|
||||
'Type:Fulltext'
|
||||
],
|
||||
$autoCompleter->scaffoldSearchFields(Team::class)
|
||||
);
|
||||
$this->assertEquals(
|
||||
[ 'Name:StartsWith' ],
|
||||
$autoCompleter->scaffoldSearchFields(Cheerleader::class)
|
||||
$autoCompleter->scaffoldSearchFields(Stadium::class)
|
||||
);
|
||||
}
|
||||
|
||||
|
33
tests/php/Forms/GridField/GridFieldTest/Stadium.php
Normal file
33
tests/php/Forms/GridField/GridFieldTest/Stadium.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Forms\Tests\GridField\GridFieldTest;
|
||||
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
use SilverStripe\ORM\Filters\EndsWithFilter;
|
||||
|
||||
class Stadium extends DataObject implements TestOnly
|
||||
{
|
||||
private static $table_name = 'GridFieldTest_Stadium';
|
||||
|
||||
private static $db = [
|
||||
'Name' => 'Varchar',
|
||||
'City' => 'Varchar',
|
||||
'Country' => 'Varchar',
|
||||
'Type' => 'Varchar'
|
||||
];
|
||||
|
||||
private static $searchable_fields = [
|
||||
'Name',
|
||||
'City' => [
|
||||
'filter' => EndsWithFilter::class
|
||||
],
|
||||
'Country' => [
|
||||
'filter' => 'ExactMatchFilter'
|
||||
],
|
||||
];
|
||||
|
||||
private static $extensions = [
|
||||
StadiumExtension::class,
|
||||
];
|
||||
}
|
16
tests/php/Forms/GridField/GridFieldTest/StadiumExtension.php
Normal file
16
tests/php/Forms/GridField/GridFieldTest/StadiumExtension.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Forms\Tests\GridField\GridFieldTest;
|
||||
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
use SilverStripe\ORM\DataExtension;
|
||||
use SilverStripe\ORM\Filters\FulltextFilter;
|
||||
use SilverStripe\Forms\Tests\GridField\GridFieldTest\StadiumExtension;
|
||||
|
||||
class StadiumExtension extends DataExtension implements TestOnly
|
||||
{
|
||||
public function updateSearchableFields(&$fields)
|
||||
{
|
||||
$fields['Type']['filter'] = new FulltextFilter();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user