1
|
|
|
<?php |
2
|
|
|
class GridFieldPaginatorTest extends FunctionalTest { |
3
|
|
|
/** @var ArrayList */ |
4
|
|
|
protected $list; |
5
|
|
|
|
6
|
|
|
/** @var GridField */ |
7
|
|
|
protected $gridField; |
8
|
|
|
|
9
|
|
|
/** @var string */ |
10
|
|
|
protected static $fixture_file = 'GridFieldTest.yml'; |
11
|
|
|
|
12
|
|
|
/** @var Form */ |
13
|
|
|
protected $form; |
14
|
|
|
|
15
|
|
|
/** @var array */ |
16
|
|
|
protected $extraDataObjects = array('GridFieldTest_Team', 'GridFieldTest_Player'); |
17
|
|
|
|
18
|
|
|
public function setUp() { |
19
|
|
|
parent::setUp(); |
20
|
|
|
$this->list = new DataList('GridFieldTest_Team'); |
|
|
|
|
21
|
|
|
$config = GridFieldConfig::create()->addComponents( |
22
|
|
|
new GridFieldToolbarHeader(), // Required to support pagecount |
23
|
|
|
new GridFieldPaginator(2), |
24
|
|
|
new GridFieldPageCount('toolbar-header-right') |
25
|
|
|
); |
26
|
|
|
$this->gridField = new GridField('testfield', 'testfield', $this->list, $config); |
27
|
|
|
$this->form = new Form(new Controller(), 'mockform', new FieldList(array($this->gridField)), new FieldList()); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testThereIsPaginatorWhenMoreThanOnePage() { |
31
|
|
|
$fieldHolder = $this->gridField->FieldHolder(); |
32
|
|
|
$content = new CSSContentParser($fieldHolder); |
33
|
|
|
// Check that there is paginator render into the footer |
34
|
|
|
$this->assertEquals(1, count($content->getBySelector('.datagrid-pagination'))); |
35
|
|
|
|
36
|
|
|
// Check that the header and footer both contains a page count |
37
|
|
|
$this->assertEquals(2, count($content->getBySelector('.pagination-records-number'))); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testThereIsNoPaginatorWhenOnlyOnePage() { |
41
|
|
|
// We set the itemsPerPage to an reasonably big number so as to avoid test broke from small changes |
42
|
|
|
// on the fixture YML file |
43
|
|
|
$total = $this->list->count(); |
44
|
|
|
$this->gridField->getConfig()->getComponentByType("GridFieldPaginator")->setItemsPerPage($total); |
|
|
|
|
45
|
|
|
$fieldHolder = $this->gridField->FieldHolder(); |
46
|
|
|
$content = new CSSContentParser($fieldHolder); |
47
|
|
|
|
48
|
|
|
// Check that there is no paginator render into the footer |
49
|
|
|
$this->assertEquals(0, count($content->getBySelector('.datagrid-pagination'))); |
50
|
|
|
|
51
|
|
|
// Check that there is still 'View 1 - 4 of 4' part on the left of the paginator |
52
|
|
|
$this->assertEquals(2, count($content->getBySelector('.pagination-records-number'))); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function testPaginationAvoidsIllegalOffsets() { |
56
|
|
|
$grid = $this->gridField; |
57
|
|
|
$total = $this->list->count(); |
58
|
|
|
$perPage = $grid->getConfig()->getComponentByType('GridFieldPaginator')->getItemsPerPage(); |
|
|
|
|
59
|
|
|
// Get the last page that will contain results |
60
|
|
|
$lastPage = ceil($total / $perPage); |
61
|
|
|
// Set the paginator state to point to an 'invalid' page |
62
|
|
|
$grid->State->GridFieldPaginator->currentPage = $lastPage + 1; |
63
|
|
|
|
64
|
|
|
// Get the paginated list |
65
|
|
|
$list = $grid->getManipulatedList(); |
66
|
|
|
|
67
|
|
|
// Assert that the paginator state has been corrected and the list contains items |
68
|
|
|
$this->assertEquals(1, $grid->State->GridFieldPaginator->currentPage); |
69
|
|
|
$this->assertEquals($perPage, $list->count()); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
} |
73
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..