mirror of
https://github.com/silverstripe/silverstripe-widgets
synced 2024-10-22 17:05:54 +02:00
FIX Update tests for removed core features, use Controller for requests instead of Forms, etc
This commit is contained in:
parent
ad6a965526
commit
7c85b1b5d9
@ -18,13 +18,12 @@ before_script:
|
||||
- phpenv config-rm xdebug.ini
|
||||
|
||||
- composer install --prefer-dist
|
||||
- composer require --prefer-dist --no-update silverstripe/framework:4.0.x-dev
|
||||
- composer require --prefer-dist --no-update silverstripe/recipe-cms:1.0.x-dev
|
||||
- if [[ $DB == PGSQL ]]; then composer require --prefer-dist --no-update silverstripe/postgresql:2.0.x-dev; fi
|
||||
- composer update
|
||||
|
||||
- if [[ $DB == PGSQL ]]; then composer require silverstripe/postgresql:2.0.x-dev --prefer-dist; fi
|
||||
|
||||
script:
|
||||
- if [[ $PHPUNIT_TEST ]]; then vendor/bin/phpunit tests/; fi
|
||||
- if [[ $PHPUNIT_TEST ]]; then vendor/bin/phpunit; fi
|
||||
- if [[ $PHPUNIT_COVERAGE_TEST ]]; then phpdbg -qrr vendor/bin/phpunit --coverage-clover=coverage.xml; fi
|
||||
- if [[ $PHPCS_TEST ]]; then vendor/bin/phpcs --standard=framework/phpcs.xml.dist src/ tests/ ; fi
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
[![Build Status](http://img.shields.io/travis/silverstripe/silverstripe-widgets.svg?style=flat-square)](https://travis-ci.org/silverstripe/silverstripe-widgets)
|
||||
[![Code Quality](http://img.shields.io/scrutinizer/g/silverstripe/silverstripe-widgets.svg?style=flat-square)](https://scrutinizer-ci.com/g/silverstripe/silverstripe-widgets)
|
||||
[![Code Coverage](https://codecov.io/gh/silverstripe/silverstripe-widgets/branch/master/graph/badge.svg)](https://codecov.io/gh/silverstripe/silverstripe-widgets)
|
||||
[![Version](http://img.shields.io/packagist/v/silverstripe/widgets.svg?style=flat-square)](https://packagist.org/packages/silverstripe/widgets)
|
||||
[![License](http://img.shields.io/packagist/l/silverstripe/widgets.svg?style=flat-square)](LICENSE.md)
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^5.7",
|
||||
"squizlabs/php_codesniffer": "*"
|
||||
"squizlabs/php_codesniffer": "^3.0"
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
|
@ -109,7 +109,7 @@ class WidgetController extends Controller
|
||||
*/
|
||||
public function Content()
|
||||
{
|
||||
return $this->renderWith(array_reverse(ClassInfo::ancestry($this->widget->class)));
|
||||
return $this->renderWith(array_reverse(ClassInfo::ancestry(get_class($this->widget))));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -142,7 +142,7 @@ class WidgetAreaEditor extends FormField
|
||||
throw new Exception("no form");
|
||||
}
|
||||
|
||||
$widgetData = $this->getForm()->getRequest()->requestVar('Widget');
|
||||
$widgetData = $this->getForm()->getController()->getRequest()->requestVar('Widget');
|
||||
if ($widgetData && isset($widgetData[$this->getName()])) {
|
||||
$widgetAreaData = $widgetData[$this->getName()];
|
||||
|
||||
|
@ -136,7 +136,7 @@ class Widget extends DataObject
|
||||
*/
|
||||
public function Content()
|
||||
{
|
||||
return $this->renderWith(array_reverse(ClassInfo::ancestry($this->class)));
|
||||
return $this->renderWith(array_reverse(ClassInfo::ancestry(__CLASS__)));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -147,7 +147,7 @@ class Widget extends DataObject
|
||||
public function getTitle()
|
||||
{
|
||||
return $this->getField('Title')
|
||||
?: _t($this->class . '.TITLE', $this->config()->title);
|
||||
?: _t(__CLASS__ . '.TITLE', $this->config()->get('title'));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -155,7 +155,7 @@ class Widget extends DataObject
|
||||
*/
|
||||
public function getCMSTitle()
|
||||
{
|
||||
return _t($this->class . '.CMSTITLE', $this->config()->cmsTitle);
|
||||
return _t(__CLASS__ . '.CMSTITLE', $this->config()->get('cmsTitle'));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -163,7 +163,7 @@ class Widget extends DataObject
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
return _t($this->class . '.DESCRIPTION', $this->config()->description);
|
||||
return _t(__CLASS__ . '.DESCRIPTION', $this->config()->get('description'));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -238,7 +238,7 @@ class Widget extends DataObject
|
||||
*/
|
||||
public function ClassName()
|
||||
{
|
||||
return str_replace('\\', '_', $this->class);
|
||||
return str_replace('\\', '_', get_class($this));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -260,7 +260,7 @@ class Widget extends DataObject
|
||||
return $this->controller;
|
||||
}
|
||||
|
||||
foreach (array_reverse(ClassInfo::ancestry($this->class)) as $widgetClass) {
|
||||
foreach (array_reverse(ClassInfo::ancestry(get_class($this))) as $widgetClass) {
|
||||
$controllerClass = "{$widgetClass}Controller";
|
||||
if (class_exists($controllerClass)) {
|
||||
break;
|
||||
@ -268,7 +268,7 @@ class Widget extends DataObject
|
||||
}
|
||||
|
||||
if (!class_exists($controllerClass)) {
|
||||
throw new Exception("Could not find controller class for $this->classname");
|
||||
throw new Exception("Could not find controller class for get_class($this)name");
|
||||
}
|
||||
|
||||
$this->controller = Injector::inst()->create($controllerClass, $this);
|
||||
@ -304,7 +304,7 @@ class Widget extends DataObject
|
||||
$this->write();
|
||||
|
||||
// The field must be written to ensure a unique ID.
|
||||
$this->Name = $this->class . $this->ID;
|
||||
$this->Name = get_class($this) . $this->ID;
|
||||
$this->write();
|
||||
}
|
||||
}
|
||||
|
@ -27,16 +27,16 @@ class WidgetAreaEditorTest extends SapphireTest
|
||||
*/
|
||||
protected $widgetToTest = TestWidget::class;
|
||||
|
||||
protected $extraDataObjects = array(
|
||||
protected static $extra_dataobjects = [
|
||||
FakePage::class,
|
||||
TestWidget::class,
|
||||
);
|
||||
];
|
||||
|
||||
protected $usesDatabase = true;
|
||||
|
||||
protected $requiredExtensions = array(
|
||||
SiteTree::class => array(WidgetPageExtension::class)
|
||||
);
|
||||
protected static $required_extensions = [
|
||||
SiteTree::class => [WidgetPageExtension::class]
|
||||
];
|
||||
|
||||
public function testFillingOneArea()
|
||||
{
|
||||
@ -56,12 +56,14 @@ class WidgetAreaEditorTest extends SapphireTest
|
||||
$editorSide = new WidgetAreaEditor('SideBar');
|
||||
$editorBott = new WidgetAreaEditor('BottomBar');
|
||||
$form = new Form(
|
||||
new ContentController(),
|
||||
$controller = new ContentController(),
|
||||
Form::class,
|
||||
new FieldList($editorSide, $editorBott),
|
||||
new FieldList()
|
||||
);
|
||||
$form->setRequest($request);
|
||||
$controller->setRequest($request);
|
||||
$controller->setRequest($request);
|
||||
$form->setController($controller);
|
||||
|
||||
$page = new FakePage();
|
||||
|
||||
@ -100,12 +102,13 @@ class WidgetAreaEditorTest extends SapphireTest
|
||||
$editorSide = new WidgetAreaEditor('SideBar');
|
||||
$editorBott = new WidgetAreaEditor('BottomBar');
|
||||
$form = new Form(
|
||||
new ContentController(),
|
||||
$controller = new ContentController(),
|
||||
Form::class,
|
||||
new FieldList($editorSide, $editorBott),
|
||||
new FieldList()
|
||||
);
|
||||
$form->setRequest($request);
|
||||
$controller->setRequest($request);
|
||||
$form->setController($controller);
|
||||
$page = new FakePage();
|
||||
|
||||
$form->saveInto($page);
|
||||
@ -150,12 +153,13 @@ class WidgetAreaEditorTest extends SapphireTest
|
||||
$editorSide = new WidgetAreaEditor('SideBar');
|
||||
$editorBott = new WidgetAreaEditor('BottomBar');
|
||||
$form = new Form(
|
||||
new ContentController(),
|
||||
$controller = new ContentController(),
|
||||
Form::class,
|
||||
new FieldList($editorSide, $editorBott),
|
||||
new FieldList()
|
||||
);
|
||||
$form->setRequest($request);
|
||||
$controller->setRequest($request);
|
||||
$form->setController($controller);
|
||||
$page = new FakePage();
|
||||
|
||||
$form->saveInto($page);
|
||||
@ -181,7 +185,8 @@ class WidgetAreaEditorTest extends SapphireTest
|
||||
)
|
||||
);
|
||||
$request = new HTTPRequest('get', 'post', array(), $data);
|
||||
$form->setRequest($request);
|
||||
$controller->setRequest($request);
|
||||
$form->setController($controller);
|
||||
$form->saveInto($page);
|
||||
|
||||
$page->write();
|
||||
@ -222,12 +227,13 @@ class WidgetAreaEditorTest extends SapphireTest
|
||||
$editorSide = new WidgetAreaEditor('SideBar');
|
||||
$editorBott = new WidgetAreaEditor('BottomBar');
|
||||
$form = new Form(
|
||||
new ContentController(),
|
||||
$controller = new ContentController(),
|
||||
Form::class,
|
||||
new FieldList($editorSide, $editorBott),
|
||||
new FieldList()
|
||||
);
|
||||
$form->setRequest($request);
|
||||
$controller->setRequest($request);
|
||||
$form->setController($controller);
|
||||
$page = new FakePage();
|
||||
|
||||
$form->saveInto($page);
|
||||
@ -248,7 +254,8 @@ class WidgetAreaEditorTest extends SapphireTest
|
||||
)
|
||||
);
|
||||
$request = new HTTPRequest('get', 'post', array(), $data);
|
||||
$form->setRequest($request);
|
||||
$controller->setRequest($request);
|
||||
$form->setController($controller);
|
||||
$form->saveInto($page);
|
||||
|
||||
$page->write();
|
||||
@ -288,12 +295,13 @@ class WidgetAreaEditorTest extends SapphireTest
|
||||
$editorSide = new WidgetAreaEditor('SideBar');
|
||||
$editorBott = new WidgetAreaEditor('BottomBar');
|
||||
$form = new Form(
|
||||
new ContentController(),
|
||||
$controller = new ContentController(),
|
||||
Form::class,
|
||||
new FieldList($editorSide, $editorBott),
|
||||
new FieldList()
|
||||
);
|
||||
$form->setRequest($request);
|
||||
$controller->setRequest($request);
|
||||
$form->setController($controller);
|
||||
$page = new FakePage();
|
||||
|
||||
$form->saveInto($page);
|
||||
@ -324,7 +332,8 @@ class WidgetAreaEditorTest extends SapphireTest
|
||||
)
|
||||
);
|
||||
$request = new HTTPRequest('get', 'post', array(), $data);
|
||||
$form->setRequest($request);
|
||||
$controller->setRequest($request);
|
||||
$form->setController($controller);
|
||||
$form->saveInto($page);
|
||||
|
||||
$page->write();
|
||||
@ -366,12 +375,13 @@ class WidgetAreaEditorTest extends SapphireTest
|
||||
$editorSide = new WidgetAreaEditor('SideBar');
|
||||
$editorBott = new WidgetAreaEditor('BottomBar');
|
||||
$form = new Form(
|
||||
new ContentController(),
|
||||
$controller = new ContentController(),
|
||||
Form::class,
|
||||
new FieldList($editorSide, $editorBott),
|
||||
new FieldList()
|
||||
);
|
||||
$form->setRequest($request);
|
||||
$controller->setRequest($request);
|
||||
$form->setController($controller);
|
||||
$page = new FakePage();
|
||||
|
||||
$form->saveInto($page);
|
||||
@ -402,7 +412,8 @@ class WidgetAreaEditorTest extends SapphireTest
|
||||
)
|
||||
);
|
||||
$request = new HTTPRequest('get', 'post', array(), $data);
|
||||
$form->setRequest($request);
|
||||
$controller->setRequest($request);
|
||||
$form->setController($controller);
|
||||
$form->saveInto($page);
|
||||
|
||||
$page->write();
|
||||
@ -444,12 +455,13 @@ class WidgetAreaEditorTest extends SapphireTest
|
||||
$editorSide = new WidgetAreaEditor('SideBar');
|
||||
$editorBott = new WidgetAreaEditor('BottomBar');
|
||||
$form = new Form(
|
||||
new ContentController(),
|
||||
$controller = new ContentController(),
|
||||
Form::class,
|
||||
new FieldList($editorSide, $editorBott),
|
||||
new FieldList()
|
||||
);
|
||||
$form->setRequest($request);
|
||||
$controller->setRequest($request);
|
||||
$form->setController($controller);
|
||||
$page = new FakePage();
|
||||
|
||||
$editorSide->saveInto($page);
|
||||
@ -476,7 +488,8 @@ class WidgetAreaEditorTest extends SapphireTest
|
||||
)
|
||||
);
|
||||
$request = new HTTPRequest('get', 'post', array(), $data);
|
||||
$form->setRequest($request);
|
||||
$controller->setRequest($request);
|
||||
$form->setController($controller);
|
||||
$form->saveInto($page);
|
||||
|
||||
$page->write();
|
||||
|
@ -7,7 +7,7 @@ use SilverStripe\Widgets\Model\Widget;
|
||||
|
||||
class TestWidget extends Widget implements TestOnly
|
||||
{
|
||||
private static $table_name = 'TestWidget';
|
||||
private static $table_name = 'WidgetAreaEditorTest_TestWidget';
|
||||
private static $cmsTitle = "Test widget";
|
||||
private static $title = "Test widget";
|
||||
private static $description = "Test widget";
|
||||
|
@ -21,10 +21,10 @@ class WidgetControllerTest extends FunctionalTest
|
||||
{
|
||||
protected static $fixture_file = 'WidgetControllerTest.yml';
|
||||
|
||||
protected $extraDataObjects = array(
|
||||
protected static $extra_dataobjects = [
|
||||
TestPage::class,
|
||||
TestWidget::class,
|
||||
);
|
||||
];
|
||||
|
||||
public function testWidgetFormRendering()
|
||||
{
|
||||
|
@ -1,10 +1,10 @@
|
||||
SilverStripe\Widgets\Tests\WidgetControllerTest\TestWidget:
|
||||
widget1:
|
||||
Title: Widget 1
|
||||
widget1:
|
||||
Title: Widget 1
|
||||
SilverStripe\Widgets\Model\WidgetArea:
|
||||
area1:
|
||||
Widgets: =>SilverStripe\Widgets\Tests\WidgetControllerTest\TestWidget.widget1
|
||||
area1:
|
||||
Widgets: =>SilverStripe\Widgets\Tests\WidgetControllerTest\TestWidget.widget1
|
||||
SilverStripe\Widgets\Tests\WidgetControllerTest\TestPage:
|
||||
page1:
|
||||
Title: Page1
|
||||
WidgetControllerTestSidebar: =>SilverStripe\Widgets\Model\WidgetArea.area1
|
||||
page1:
|
||||
Title: Page1
|
||||
WidgetControllerTestSidebar: =>SilverStripe\Widgets\Model\WidgetArea.area1
|
||||
|
@ -19,7 +19,12 @@ class TestPageController extends PageController implements TestOnly
|
||||
*/
|
||||
public function getViewer($action)
|
||||
{
|
||||
SSViewer::add_themes(["silverstripe/widgets:widgets/tests/WidgetControllerTest"]);
|
||||
if (file_exists('widgets')) {
|
||||
SSViewer::add_themes(['silverstripe/widgets:tests/WidgetControllerTest']);
|
||||
} else {
|
||||
// When installed as the root project, e.g. Travis
|
||||
SSViewer::add_themes(['tests/WidgetControllerTest']);
|
||||
}
|
||||
return new SSViewer(TestPage::class);
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ use SilverStripe\Widgets\Model\Widget;
|
||||
*/
|
||||
class TestWidget extends Widget implements TestOnly
|
||||
{
|
||||
private static $table_name = 'TestWidgetB';
|
||||
private static $table_name = 'WidgetControllerTest_TestWidget';
|
||||
|
||||
private static $db = array(
|
||||
'TestValue' => 'Text'
|
||||
|
Loading…
Reference in New Issue
Block a user