2012-04-18 23:15:45 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2013-05-07 10:56:38 +02:00
|
|
|
* @package widgets
|
2012-04-18 23:15:45 +02:00
|
|
|
* @subpackage tests
|
|
|
|
*/
|
|
|
|
class WidgetControllerTest extends FunctionalTest {
|
2013-05-07 10:56:38 +02:00
|
|
|
|
2013-04-01 21:37:44 +02:00
|
|
|
protected static $fixture_file = 'WidgetControllerTest.yml';
|
2012-04-18 23:15:45 +02:00
|
|
|
|
|
|
|
protected $extraDataObjects = array(
|
|
|
|
'WidgetControllerTestPage',
|
|
|
|
'WidgetControllerTest_Widget',
|
|
|
|
);
|
|
|
|
|
|
|
|
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');
|
|
|
|
|
2013-05-07 10:56:38 +02:00
|
|
|
$response = $this->get($page->URLSegment);
|
2012-04-18 23:15:45 +02:00
|
|
|
$response = $this->submitForm('Form_Form', null, array('TestValue'=>'Updated'));
|
2013-05-07 10:56:38 +02:00
|
|
|
|
2012-04-18 23:15:45 +02:00
|
|
|
$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"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-05-07 10:56:38 +02:00
|
|
|
* @package widgets
|
2012-04-18 23:15:45 +02:00
|
|
|
* @subpackage tests
|
|
|
|
*/
|
|
|
|
class WidgetControllerTest_Widget extends Widget implements TestOnly {
|
2013-04-01 21:37:44 +02:00
|
|
|
private static $db = array(
|
2012-04-18 23:15:45 +02:00
|
|
|
'TestValue' => 'Text'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-05-07 10:56:38 +02:00
|
|
|
* @package widgets
|
2012-04-18 23:15:45 +02:00
|
|
|
* @subpackage tests
|
|
|
|
*/
|
2013-05-07 10:56:38 +02:00
|
|
|
class WidgetControllerTest_WidgetController extends WidgetController implements TestOnly {
|
|
|
|
|
|
|
|
private static $allowed_actions = array(
|
|
|
|
'Form'
|
|
|
|
);
|
|
|
|
|
2012-04-18 23:15:45 +02:00
|
|
|
function Form() {
|
|
|
|
$widgetform = new Form(
|
|
|
|
$this,
|
|
|
|
'Form',
|
|
|
|
new FieldList(
|
|
|
|
new TextField('TestValue')
|
|
|
|
),
|
|
|
|
new FieldList(
|
|
|
|
new FormAction('doAction')
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
return $widgetform;
|
|
|
|
}
|
|
|
|
|
|
|
|
function doAction($data, $form) {
|
|
|
|
return sprintf('TestValue: %s\nWidget ID: %d',
|
|
|
|
$data['TestValue'],
|
|
|
|
$this->widget->ID
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|