Skip to content

Commit

Permalink
MNT fix broken tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Jul 1, 2022
1 parent ba46602 commit 468725f
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 9 deletions.
5 changes: 1 addition & 4 deletions docs/en/02_Developer_Guides/00_Model/11_Scaffolding.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use SilverStripe\ORM\DataObject;

class MyDataObject extends DataObject
{

private static $db = [
'IsActive' => 'Boolean',
'Title' => 'Varchar',
Expand Down Expand Up @@ -105,8 +104,8 @@ use SilverStripe\ORM\DataObject;

class MyDataObject extends DataObject
{

private static $searchable_fields = [
'Name',
'BirthDate' => [
'primary' => false
],
Expand Down Expand Up @@ -149,7 +148,6 @@ use SilverStripe\ORM\DataObject;

class MyDataObject extends DataObject
{

private static $searchable_fields = [
'Name' => 'PartialMatchFilter',
'ProductCode' => NumericField::class
Expand All @@ -165,7 +163,6 @@ use SilverStripe\ORM\DataObject;

class MyDataObject extends DataObject
{

private static $searchable_fields = [
'Name' => [
'field' => TextField::class,
Expand Down
2 changes: 1 addition & 1 deletion docs/en/04_Changelogs/4.12.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ use SilverStripe\ORM\DataObject;

class MyDataObject extends DataObject
{

private static $searchable_fields = [
'Name',
'BirthDate' => [
'primary' => false
],
Expand Down
2 changes: 1 addition & 1 deletion lang/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ en:
one: 'A Data Object'
other: '{count} Data Objects'
SINGULARNAME: 'Data Object'
GLOBALSEARCH: 'Global Search'
PRIMARYSEARCH: 'Primary Search'
SilverStripe\ORM\FieldType\DBBoolean:
ANY: Any
NOANSWER: 'No'
Expand Down
1 change: 1 addition & 0 deletions src/Forms/GridField/GridFieldFilterHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ public function getSearchFieldSchema(GridField $gridField)
$searchAction = GridField_FormAction::create($gridField, 'filter', false, 'filter', null);
$clearAction = GridField_FormAction::create($gridField, 'reset', false, 'reset', null);
$schema = [
'modelClass' => $gridField->getModelClass(),
'formSchemaUrl' => $schemaUrl,
'name' => $searchField,
'placeholder' => _t(__CLASS__ . '.Search', 'Search "{name}"', ['name' => $name]),
Expand Down
2 changes: 1 addition & 1 deletion src/ORM/Search/SearchContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ protected function individualFieldSearch(DataList $query, array $searchableField
if ($filter = $this->getFilter($searchField)) {
$filter->setModel($this->modelClass);
$filter->setValue($searchTerms);
$searchableFieldSpec = $searchableFields[$searchField];
$searchableFieldSpec = $searchableFields[$searchField] ?? [];
return $query->alterDataQuery(function ($dataQuery) use ($filter, $searchableFieldSpec) {
$this->applyFilter($filter, $dataQuery, $searchableFieldSpec);
});
Expand Down
11 changes: 9 additions & 2 deletions tests/php/Forms/GridField/GridFieldFilterHeaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use SilverStripe\Forms\Tests\GridField\GridFieldFilterHeaderTest\TeamGroup;
use SilverStripe\Forms\Tests\GridField\GridFieldFilterHeaderTest\TestController;
use SilverStripe\ORM\DataList;
use SilverStripe\ORM\DataObject;

class GridFieldFilterHeaderTest extends SapphireTest
{
Expand Down Expand Up @@ -89,9 +90,12 @@ public function testRenderHeaders()
public function testSearchFieldSchema()
{
$searchSchema = json_decode($this->component->getSearchFieldSchema($this->gridField) ?? '');
$modelClass = $searchSchema->modelClass;
/** @var DataObject $obj */
$obj = new $modelClass();

$this->assertEquals('field/testfield/schema/SearchForm', $searchSchema->formSchemaUrl);
$this->assertEquals('Name', $searchSchema->name);
$this->assertEquals($obj->primarySearchFieldName(), $searchSchema->name);
$this->assertEquals('Search "Teams"', $searchSchema->placeholder);
$this->assertEquals(new \stdClass, $searchSchema->filters);

Expand All @@ -110,9 +114,12 @@ public function testSearchFieldSchema()
);
$this->gridField->setRequest($request);
$searchSchema = json_decode($this->component->getSearchFieldSchema($this->gridField) ?? '');
$modelClass = $searchSchema->modelClass;
/** @var DataObject $obj */
$obj = new $modelClass();

$this->assertEquals('field/testfield/schema/SearchForm', $searchSchema->formSchemaUrl);
$this->assertEquals('Name', $searchSchema->name);
$this->assertEquals($obj->primarySearchFieldName(), $searchSchema->name);
$this->assertEquals('Search "Teams"', $searchSchema->placeholder);
$this->assertEquals('test', $searchSchema->filters->Search__Name);
$this->assertEquals('place', $searchSchema->filters->Search__City);
Expand Down

0 comments on commit 468725f

Please sign in to comment.