2012-04-18 23:15:45 +02:00
|
|
|
<?php
|
2017-01-17 23:43:11 +01:00
|
|
|
|
|
|
|
namespace SilverStripe\Widgets\Tests;
|
|
|
|
|
|
|
|
use SilverStripe\Dev\FunctionalTest;
|
|
|
|
use SilverStripe\Widgets\Model\Widget;
|
|
|
|
use SilverStripe\Dev\TestOnly;
|
|
|
|
use SilverStripe\Forms\TextField;
|
|
|
|
use SilverStripe\Forms\FieldList;
|
|
|
|
use SilverStripe\Forms\FormAction;
|
|
|
|
use SilverStripe\Forms\Form;
|
|
|
|
use SilverStripe\Widgets\Controllers\WidgetController;
|
|
|
|
use SilverStripe\Widgets\Tests\WidgetControllerTest\TestPage;
|
|
|
|
use SilverStripe\Widgets\Tests\WidgetControllerTest\TestWidget;
|
|
|
|
|
2012-04-18 23:15:45 +02:00
|
|
|
/**
|
2013-05-07 10:56:38 +02:00
|
|
|
* @package widgets
|
2012-04-18 23:15:45 +02:00
|
|
|
* @subpackage tests
|
|
|
|
*/
|
2015-11-18 05:08:21 +01:00
|
|
|
class WidgetControllerTest extends FunctionalTest
|
|
|
|
{
|
|
|
|
protected static $fixture_file = 'WidgetControllerTest.yml';
|
2013-05-07 10:56:38 +02:00
|
|
|
|
2015-11-18 05:08:21 +01:00
|
|
|
protected $extraDataObjects = array(
|
2017-01-17 23:43:11 +01:00
|
|
|
TestPage::class,
|
|
|
|
TestWidget::class,
|
2015-11-18 05:08:21 +01:00
|
|
|
);
|
2017-01-17 23:43:11 +01:00
|
|
|
|
2015-11-18 05:08:21 +01:00
|
|
|
public function testWidgetFormRendering()
|
|
|
|
{
|
2017-01-17 23:43:11 +01:00
|
|
|
$page = $this->objFromFixture(TestPage::class, 'page1');
|
|
|
|
$page->copyVersionToStage('Stage', 'Live');
|
|
|
|
|
|
|
|
$widget = $this->objFromFixture(TestWidget::class, 'widget1');
|
|
|
|
|
2015-11-18 05:08:21 +01:00
|
|
|
$response = $this->get($page->URLSegment);
|
2017-01-17 23:43:11 +01:00
|
|
|
|
2015-11-18 05:08:21 +01:00
|
|
|
$formAction = sprintf('%s/widget/%d/Form', $page->URLSegment, $widget->ID);
|
|
|
|
$this->assertContains(
|
|
|
|
$formAction,
|
|
|
|
$response->getBody(),
|
|
|
|
"Widget forms are rendered through WidgetArea templates"
|
|
|
|
);
|
|
|
|
}
|
2017-01-17 23:43:11 +01:00
|
|
|
|
2015-11-18 05:08:21 +01:00
|
|
|
public function testWidgetFormSubmission()
|
|
|
|
{
|
2017-01-17 23:43:11 +01:00
|
|
|
$page = $this->objFromFixture(TestPage::class, 'page1');
|
|
|
|
$page->copyVersionToStage('Stage', 'Live');
|
|
|
|
|
|
|
|
$widget = $this->objFromFixture(TestWidget::class, 'widget1');
|
|
|
|
|
2015-11-18 05:08:21 +01:00
|
|
|
$response = $this->get($page->URLSegment);
|
2017-01-17 23:43:11 +01:00
|
|
|
$response = $this->submitForm('Form_Form', null, array('TestValue' => 'Updated'));
|
2012-04-18 23:15:45 +02:00
|
|
|
|
2015-11-18 05:08:21 +01: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"
|
|
|
|
);
|
|
|
|
}
|
2012-04-18 23:15:45 +02:00
|
|
|
}
|