From 51447b89ab10dd402a29aad2983dc3d5a3b49730 Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Wed, 8 Oct 2008 03:32:33 +0000 Subject: [PATCH] BUGFIX: Fixed pagination in TableListField after hsmith's changes git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@63819 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- forms/TableListField.php | 4 ++-- tests/forms/TableListFieldTest.php | 32 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/forms/TableListField.php b/forms/TableListField.php index 8d14917b1..8980d9d96 100755 --- a/forms/TableListField.php +++ b/forms/TableListField.php @@ -262,10 +262,10 @@ class TableListField extends FormField { function index() { return $this->FieldHolder(); } - + static $url_handlers = array( 'item/$ID' => 'handleItem', - '$Action!' => '$Action', + '$Action' => '$Action', ); function sourceClass() { diff --git a/tests/forms/TableListFieldTest.php b/tests/forms/TableListFieldTest.php index 47e512c55..ceb0532c4 100644 --- a/tests/forms/TableListFieldTest.php +++ b/tests/forms/TableListFieldTest.php @@ -94,6 +94,24 @@ class TableListFieldTest extends SapphireTest { $this->assertEquals(array(3 => "a3", 4 => "a4"), $itemMap); } + /** + * Get that visiting the field's URL returns the content of the field. + * This capability is used by ajax + */ + function testAjaxRefreshing() { + $controller = new TableListFieldTest_TestController(); + $table = $controller->TestForm()->Fields()->First(); + + $ajaxResponse = Director::test($table->Link())->getBody(); + + // Check that the column headings have been rendered + $this->assertRegExp('/]*>\s*Col A\s*<\/th>/', $ajaxResponse); + $this->assertRegExp('/]*>\s*Col B\s*<\/th>/', $ajaxResponse); + $this->assertRegExp('/]*>\s*Col C\s*<\/th>/', $ajaxResponse); + $this->assertRegExp('/]*>\s*Col D\s*<\/th>/', $ajaxResponse); + $this->assertRegExp('/]*>\s*Col E\s*<\/th>/', $ajaxResponse); + } + function testCsvExport() { $table = new TableListField("Tester", "TableListFieldTest_CsvExport", array( "A" => "Col A", @@ -162,4 +180,18 @@ class TableListFieldTest_TestController extends Controller { function Link() { return "TableListFieldTest_TestController/"; } + function TestForm() { + $table = new TableListField("Table", "TableListFieldTest_Obj", array( + "A" => "Col A", + "B" => "Col B", + "C" => "Col C", + "D" => "Col D", + "E" => "Col E", + )); + + // A TableListField must be inside a form for its links to be generated + return new Form($this, "TestForm", new FieldSet( + $table + ), new FieldSet()); + } } \ No newline at end of file