2012-05-18 01:18:55 +02:00
|
|
|
<?php
|
|
|
|
class GridFieldPaginatorTest extends FunctionalTest {
|
|
|
|
/** @var ArrayList */
|
|
|
|
protected $list;
|
|
|
|
|
|
|
|
/** @var GridField */
|
|
|
|
protected $gridField;
|
|
|
|
|
|
|
|
/** @var string */
|
2013-03-21 19:48:54 +01:00
|
|
|
protected static $fixture_file = 'GridFieldTest.yml';
|
2012-05-18 01:18:55 +02:00
|
|
|
|
|
|
|
/** @var Form */
|
|
|
|
protected $form;
|
|
|
|
|
|
|
|
/** @var array */
|
|
|
|
protected $extraDataObjects = array('GridFieldTest_Team', 'GridFieldTest_Player');
|
|
|
|
|
|
|
|
public function setUp() {
|
|
|
|
parent::setUp();
|
|
|
|
$this->list = new DataList('GridFieldTest_Team');
|
2012-09-25 05:55:59 +02:00
|
|
|
$config = GridFieldConfig::create()->addComponents(
|
|
|
|
new GridFieldToolbarHeader(), // Required to support pagecount
|
|
|
|
new GridFieldPaginator(2),
|
|
|
|
new GridFieldPageCount('toolbar-header-right')
|
|
|
|
);
|
2012-05-18 01:18:55 +02:00
|
|
|
$this->gridField = new GridField('testfield', 'testfield', $this->list, $config);
|
|
|
|
$this->form = new Form(new Controller(), 'mockform', new FieldList(array($this->gridField)), new FieldList());
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testThereIsPaginatorWhenMoreThanOnePage() {
|
2012-05-18 01:18:55 +02:00
|
|
|
$fieldHolder = $this->gridField->FieldHolder();
|
|
|
|
$content = new CSSContentParser($fieldHolder);
|
|
|
|
// Check that there is paginator render into the footer
|
|
|
|
$this->assertEquals(1, count($content->getBySelector('.datagrid-pagination')));
|
2012-09-25 05:55:59 +02:00
|
|
|
|
|
|
|
// Check that the header and footer both contains a page count
|
|
|
|
$this->assertEquals(2, count($content->getBySelector('.pagination-records-number')));
|
2012-05-18 01:18:55 +02:00
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testThereIsNoPaginatorWhenOnlyOnePage() {
|
2012-09-26 23:34:00 +02:00
|
|
|
// We set the itemsPerPage to an reasonably big number so as to avoid test broke from small changes
|
|
|
|
// on the fixture YML file
|
2012-05-18 01:18:55 +02:00
|
|
|
$total = $this->list->count();
|
|
|
|
$this->gridField->getConfig()->getComponentByType("GridFieldPaginator")->setItemsPerPage($total);
|
|
|
|
$fieldHolder = $this->gridField->FieldHolder();
|
|
|
|
$content = new CSSContentParser($fieldHolder);
|
|
|
|
|
|
|
|
// Check that there is no paginator render into the footer
|
|
|
|
$this->assertEquals(0, count($content->getBySelector('.datagrid-pagination')));
|
|
|
|
|
|
|
|
// Check that there is still 'View 1 - 4 of 4' part on the left of the paginator
|
2012-09-25 05:55:59 +02:00
|
|
|
$this->assertEquals(2, count($content->getBySelector('.pagination-records-number')));
|
2012-05-18 01:18:55 +02:00
|
|
|
}
|
|
|
|
}
|