silverstripe-widgets/tests/WidgetControllerTest.php

62 lines
1.9 KiB
PHP
Raw Permalink Normal View History

2012-04-18 23:15:45 +02:00
<?php
namespace SilverStripe\Widgets\Tests;
use SilverStripe\Dev\FunctionalTest;
use SilverStripe\Widgets\Tests\WidgetControllerTest\TestPage;
use SilverStripe\Widgets\Tests\WidgetControllerTest\TestWidget;
2015-11-18 05:08:21 +01:00
class WidgetControllerTest extends FunctionalTest
{
protected static $fixture_file = 'WidgetControllerTest.yml';
protected static $extra_dataobjects = [
TestPage::class,
TestWidget::class,
];
2021-10-21 02:14:57 +02:00
protected function setUp(): void
{
parent::setUp();
$this->actWithPermission('ADMIN', function () {
$this->objFromFixture(TestPage::class, 'page1')->publishRecursive();
});
}
2015-11-18 05:08:21 +01:00
public function testWidgetFormRendering()
{
$page = $this->objFromFixture(TestPage::class, 'page1');
$widget = $this->objFromFixture(TestWidget::class, 'widget1');
2015-11-18 05:08:21 +01:00
$response = $this->get($page->URLSegment);
2017-12-18 04:30:49 +01:00
$formAction = sprintf('%s/widget/%d/%s', $page->URLSegment, $widget->ID, 'Form');
2021-10-21 02:14:57 +02:00
$this->assertStringContainsString(
2015-11-18 05:08:21 +01:00
$formAction,
$response->getBody(),
"Widget forms are rendered through WidgetArea templates"
);
}
2015-11-18 05:08:21 +01:00
public function testWidgetFormSubmission()
{
$page = $this->objFromFixture(TestPage::class, 'page1');
$widget = $this->objFromFixture(TestWidget::class, 'widget1');
$this->get($page->URLSegment);
$response = $this->submitForm('Form_Form', null, array('TestValue' => 'Updated'));
2012-04-18 23:15:45 +02:00
2021-10-21 02:14:57 +02:00
$this->assertStringContainsString(
2015-11-18 05:08:21 +01:00
'TestValue: Updated',
$response->getBody(),
"Form values are submitted to correct widget form"
);
2021-10-21 02:14:57 +02:00
$this->assertStringContainsString(
2015-11-18 05:08:21 +01:00
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
}