mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
BUGFIX: Fixed bug with unpaginated TableListFields. Added tests for TableListField pagination
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@60573 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
26051153b8
commit
cb86fdb3d1
@ -361,7 +361,7 @@ JS
|
||||
}
|
||||
|
||||
function sourceItems() {
|
||||
$SQL_limit = ($this->showPagination && $this->pageSize) ? "{$this->pageSize}" : "0";
|
||||
$SQL_limit = ($this->showPagination && $this->pageSize) ? "{$this->pageSize}" : null;
|
||||
if(isset($_REQUEST['ctf'][$this->Name()]['start']) && is_numeric($_REQUEST['ctf'][$this->Name()]['start'])) {
|
||||
$SQL_start = (isset($_REQUEST['ctf'][$this->Name()]['start'])) ? intval($_REQUEST['ctf'][$this->Name()]['start']) : "0";
|
||||
} else {
|
||||
|
@ -3,7 +3,7 @@
|
||||
class TableListFieldTest extends SapphireTest {
|
||||
static $fixture_file = 'sapphire/tests/forms/TableListFieldTest.yml';
|
||||
|
||||
function testCanReferenceCustomMethodsAndFiledsOnObject() {
|
||||
function testCanReferenceCustomMethodsAndFieldsOnObject() {
|
||||
$table = new TableListField("Tester", "TableListFieldTest_Obj", array(
|
||||
"A" => "Col A",
|
||||
"B" => "Col B",
|
||||
@ -11,14 +11,68 @@ class TableListFieldTest extends SapphireTest {
|
||||
"D" => "Col D",
|
||||
"E" => "Col E",
|
||||
));
|
||||
|
||||
$result = $table->FieldHolder();
|
||||
|
||||
|
||||
// Do a quick check to ensure that some of the D() and getE() values got through
|
||||
$this->assertRegExp('/>\s*a2\s*</', $result);
|
||||
$this->assertRegExp('/>\s*a2\/b2\/c2\s*</', $result);
|
||||
$this->assertRegExp('/>\s*a2-e</', $result);
|
||||
}
|
||||
|
||||
function testUnpaginatedSourceItemGeneration() {
|
||||
/* In this simple case, the source items should just list all the data objects specified */
|
||||
$table = new TableListField("Tester", "TableListFieldTest_Obj", array(
|
||||
"A" => "Col A",
|
||||
"B" => "Col B",
|
||||
"C" => "Col C",
|
||||
"D" => "Col D",
|
||||
"E" => "Col E",
|
||||
));
|
||||
$items = $table->sourceItems();
|
||||
$this->assertNotNull($items);
|
||||
|
||||
$itemMap = $items->toDropdownMap("ID", "A") ;
|
||||
$this->assertEquals(array(1 => "a1", 2 => "a2", 3 => "a3", 4 => "a4", 5 => "a5"), $itemMap);
|
||||
}
|
||||
|
||||
function testFirstPageOfPaginatedSourceItemGeneration() {
|
||||
/* With pagination enabled, only the first page of items should be shown */
|
||||
$table = new TableListField("Tester", "TableListFieldTest_Obj", array(
|
||||
"A" => "Col A",
|
||||
"B" => "Col B",
|
||||
"C" => "Col C",
|
||||
"D" => "Col D",
|
||||
"E" => "Col E",
|
||||
));
|
||||
$table->ShowPagination = true;
|
||||
$table->PageSize = 2;
|
||||
|
||||
$items = $table->sourceItems();
|
||||
$this->assertNotNull($items);
|
||||
|
||||
$itemMap = $items->toDropdownMap("ID", "A") ;
|
||||
$this->assertEquals(array(1 => "a1", 2 => "a2"), $itemMap);
|
||||
}
|
||||
|
||||
function testSecondPageOfPaginatedSourceItemGeneration() {
|
||||
/* With pagination enabled, only the first page of items should be shown */
|
||||
$table = new TableListField("Tester", "TableListFieldTest_Obj", array(
|
||||
"A" => "Col A",
|
||||
"B" => "Col B",
|
||||
"C" => "Col C",
|
||||
"D" => "Col D",
|
||||
"E" => "Col E",
|
||||
));
|
||||
$table->ShowPagination = true;
|
||||
$table->PageSize = 2;
|
||||
$_REQUEST['ctf']['Tester']['start'] = 2;
|
||||
|
||||
$items = $table->sourceItems();
|
||||
$this->assertNotNull($items);
|
||||
|
||||
$itemMap = $items->toDropdownMap("ID", "A") ;
|
||||
$this->assertEquals(array(3 => "a3", 4 => "a4"), $itemMap);
|
||||
}
|
||||
}
|
||||
|
||||
class TableListFieldTest_Obj extends DataObject implements TestOnly {
|
||||
|
@ -7,4 +7,16 @@ TableListFieldTest_Obj:
|
||||
A: a2
|
||||
B: b2
|
||||
C: c2
|
||||
|
||||
three:
|
||||
A: a3
|
||||
B: b3
|
||||
C: c3
|
||||
four:
|
||||
A: a4
|
||||
B: b4
|
||||
C: c4
|
||||
five:
|
||||
A: a5
|
||||
B: b5
|
||||
C: c5
|
||||
|
Loading…
x
Reference in New Issue
Block a user