mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
MNT Test that we can't filter/sort eagerloaded data by relation (#10978)
This commit is contained in:
parent
87958e7484
commit
cbd358ab93
@ -953,6 +953,13 @@ class EagerLoadedListTest extends SapphireTest
|
|||||||
$this->assertFalse($subteam->canSortBy('SomethingElse'));
|
$this->assertFalse($subteam->canSortBy('SomethingElse'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testCannotSortByRelation()
|
||||||
|
{
|
||||||
|
$list = $this->getListWithRecords(TeamComment::class);
|
||||||
|
$this->assertFalse($list->canSortBy('Team'));
|
||||||
|
$this->assertFalse($list->canSortBy('Team.Title'));
|
||||||
|
}
|
||||||
|
|
||||||
public function testArrayAccess()
|
public function testArrayAccess()
|
||||||
{
|
{
|
||||||
$list = $this->getListWithRecords(Team::class)->sort('Title');
|
$list = $this->getListWithRecords(Team::class)->sort('Title');
|
||||||
@ -1112,6 +1119,14 @@ class EagerLoadedListTest extends SapphireTest
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testSortByRelation()
|
||||||
|
{
|
||||||
|
$list = $this->getListWithRecords(TeamComment::class);
|
||||||
|
$this->expectException(InvalidArgumentException::class);
|
||||||
|
$this->expectExceptionMessage('Cannot sort by relations on EagerLoadedList');
|
||||||
|
$list = $list->sort('Team.Title', 'ASC');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider provideSortInvalidParameters
|
* @dataProvider provideSortInvalidParameters
|
||||||
*/
|
*/
|
||||||
@ -1324,6 +1339,26 @@ class EagerLoadedListTest extends SapphireTest
|
|||||||
$this->assertTrue($subteam->canFilterBy("SubclassDatabaseField"));
|
$this->assertTrue($subteam->canFilterBy("SubclassDatabaseField"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testCannotFilterByRelation()
|
||||||
|
{
|
||||||
|
$list = $this->getListWithRecords(Team::class);
|
||||||
|
|
||||||
|
$this->assertFalse($list->canFilterBy('Captain.ShirtNumber'));
|
||||||
|
$this->assertFalse($list->canFilterBy('SomethingElse.ShirtNumber'));
|
||||||
|
$this->assertFalse($list->canFilterBy('Captain.SomethingElse'));
|
||||||
|
$this->assertFalse($list->canFilterBy('Captain.FavouriteTeam.Captain.ShirtNumber'));
|
||||||
|
|
||||||
|
// Has many
|
||||||
|
$this->assertFalse($list->canFilterBy('Fans.Name'));
|
||||||
|
$this->assertFalse($list->canFilterBy('SomethingElse.Name'));
|
||||||
|
$this->assertFalse($list->canFilterBy('Fans.SomethingElse'));
|
||||||
|
|
||||||
|
// Many many
|
||||||
|
$this->assertFalse($list->canFilterBy('Players.FirstName'));
|
||||||
|
$this->assertFalse($list->canFilterBy('SomethingElse.FirstName'));
|
||||||
|
$this->assertFalse($list->canFilterBy('Players.SomethingElse'));
|
||||||
|
}
|
||||||
|
|
||||||
public function testAddfilter()
|
public function testAddfilter()
|
||||||
{
|
{
|
||||||
$list = $this->getListWithRecords(TeamComment::class);
|
$list = $this->getListWithRecords(TeamComment::class);
|
||||||
@ -1441,6 +1476,60 @@ class EagerLoadedListTest extends SapphireTest
|
|||||||
$this->assertEquals(2, count($list->exclude('ID', $id) ?? []));
|
$this->assertEquals(2, count($list->exclude('ID', $id) ?? []));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testFilterAnyByRelation()
|
||||||
|
{
|
||||||
|
$list = $this->getListWithRecords(Player::class);
|
||||||
|
$this->expectException(InvalidArgumentException::class);
|
||||||
|
$this->expectExceptionMessage("Can't filter by column 'Teams.Title'");
|
||||||
|
$list = $list->filterAny(['Teams.Title' => 'Team']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFilterAggregate()
|
||||||
|
{
|
||||||
|
$list = $this->getListWithRecords(Team::class);
|
||||||
|
$this->expectException(InvalidArgumentException::class);
|
||||||
|
$this->expectExceptionMessage("Can't filter by column 'Players.Count()'");
|
||||||
|
$list->filter(['Players.Count()' => 2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFilterAnyAggregate()
|
||||||
|
{
|
||||||
|
$list = $this->getListWithRecords(Team::class);
|
||||||
|
$this->expectException(InvalidArgumentException::class);
|
||||||
|
$this->expectExceptionMessage("Can't filter by column 'Players.Count()'");
|
||||||
|
$list->filterAny(['Players.Count()' => 2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function provideCantFilterByRelation()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'many_many' => [
|
||||||
|
'Players.FirstName',
|
||||||
|
],
|
||||||
|
'has_many' => [
|
||||||
|
'Comments.Name',
|
||||||
|
],
|
||||||
|
'has_one' => [
|
||||||
|
'FavouriteTeam.Title',
|
||||||
|
],
|
||||||
|
'non-existent relation' => [
|
||||||
|
'MascotAnimal.Name',
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider provideCantFilterByRelation
|
||||||
|
*/
|
||||||
|
public function testCantFilterByRelation(string $column)
|
||||||
|
{
|
||||||
|
// Many to many
|
||||||
|
$list = $this->getListWithRecords(Team::class);
|
||||||
|
$this->expectException(InvalidArgumentException::class);
|
||||||
|
$this->expectExceptionMessage("Can't filter by column '$column'");
|
||||||
|
$list->filter($column, ['Captain', 'Captain 2']);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider provideFilterByNull
|
* @dataProvider provideFilterByNull
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user