2008-08-12 02:12:29 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class TableListFieldTest extends SapphireTest {
|
|
|
|
static $fixture_file = 'sapphire/tests/forms/TableListFieldTest.yml';
|
|
|
|
|
2008-08-13 03:39:46 +02:00
|
|
|
function testCanReferenceCustomMethodsAndFieldsOnObject() {
|
2008-08-12 02:12:29 +02:00
|
|
|
$table = new TableListField("Tester", "TableListFieldTest_Obj", array(
|
|
|
|
"A" => "Col A",
|
|
|
|
"B" => "Col B",
|
|
|
|
"C" => "Col C",
|
|
|
|
"D" => "Col D",
|
|
|
|
"E" => "Col E",
|
|
|
|
));
|
|
|
|
$result = $table->FieldHolder();
|
2008-08-13 03:39:46 +02:00
|
|
|
|
2008-08-12 02:12:29 +02:00
|
|
|
// 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);
|
|
|
|
}
|
2008-08-13 03:39:46 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2008-08-12 02:12:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class TableListFieldTest_Obj extends DataObject implements TestOnly {
|
|
|
|
static $db = array(
|
|
|
|
"A" => "Varchar",
|
|
|
|
"B" => "Varchar",
|
|
|
|
"C" => "Varchar",
|
|
|
|
);
|
|
|
|
|
|
|
|
function D() {
|
|
|
|
return $this->A . '/' . $this->B . '/' . $this->C;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getE() {
|
|
|
|
return $this->A . '-e';
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|