silverstripe-framework/tests/widgets/WidgetControllerTest.php
Ingo Schommer 2cc0d016f4 API CHANGE Removed unnecessary WidgetFormProxy class and Widget->FormObjectLink(), broken functionality since the RequestHandler restructuring in 2.3. Use Widget_Controller instead.
FEATURE Added Widget_Controller class to enable nested forms within Wiget class.
ENHANCEMENT Changed WidgetArea.ss to iterate over $WidgetControllers instead of $Widgets, to allow forms rendered within to retain their controller context (through Widget_Controller and $failover mechanisms).
ENHANCEMENT Added handleWidgets() to ContentController to support new Widget_Controller class

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@85789 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-09-07 03:28:23 +00:00

84 lines
1.9 KiB
PHP

<?php
/**
* @package sapphire
* @subpackage tests
*/
class WidgetControllerTest extends FunctionalTest {
static $fixture_file = 'sapphire/tests/widgets/WidgetControllerTest.yml';
function testWidgetFormRendering() {
$page = $this->objFromFixture('WidgetControllerTestPage', 'page1');
$page->publish('Stage', 'Live');
$widget = $this->objFromFixture('WidgetControllerTest_Widget', 'widget1');
$response = $this->get($page->URLSegment);
$formAction = sprintf('%s/widget/%d/Form', $page->URLSegment, $widget->ID);
$this->assertContains(
$formAction,
$response->getBody(),
"Widget forms are rendered through WidgetArea templates"
);
}
function testWidgetFormSubmission() {
$page = $this->objFromFixture('WidgetControllerTestPage', 'page1');
$page->publish('Stage', 'Live');
$widget = $this->objFromFixture('WidgetControllerTest_Widget', 'widget1');
$this->get($page->URLSegment);
$response = $this->submitForm('Form_Form', null, array('TestValue'=>'Updated'));
$this->assertContains(
'TestValue: Updated',
$response->getBody(),
"Form values are submitted to correct widget form"
);
$this->assertContains(
sprintf('Widget ID: %d', $widget->ID),
$response->getBody(),
"Widget form acts on correct widget, as identified in the URL"
);
}
}
/**
* @package sapphire
* @subpackage tests
*/
class WidgetControllerTest_Widget extends Widget implements TestOnly {
static $db = array(
'TestValue' => 'Text'
);
}
/**
* @package sapphire
* @subpackage tests
*/
class WidgetControllerTest_Widget_Controller extends Widget_Controller implements TestOnly {
function Form() {
$widgetform = new Form(
$this,
'Form',
new FieldSet(
new TextField('TestValue')
),
new FieldSet(
new FormAction('doAction')
)
);
return $widgetform;
}
function doAction($data, $form) {
return sprintf('TestValue: %s\nWidget ID: %d',
$data['TestValue'],
$this->widget->ID
);
}
}
?>