mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Fix forms namespace
This commit is contained in:
parent
b65c21241b
commit
2a278e2953
@ -131,18 +131,9 @@ class Director implements TemplateGlobalProvider
|
||||
// Generate output
|
||||
$result = static::handleRequest($request);
|
||||
|
||||
// Save session data. Note that inst_save() will start/resume the session if required.
|
||||
// Save session data. Note that save() will start/resume the session if required.
|
||||
$request->getSession()->save();
|
||||
|
||||
// Return code for a redirection request
|
||||
// @todo: Refactor into CLIApplication
|
||||
if ($result->isRedirect() && static::is_cli()) {
|
||||
$url = Director::makeRelative($result->getHeader('Location'));
|
||||
$request = clone $request;
|
||||
$request->setUrl($url);
|
||||
return static::direct($request);
|
||||
}
|
||||
|
||||
// Post-request handling
|
||||
$postRequest = RequestProcessor::singleton()->postRequest($request, $result);
|
||||
if ($postRequest === false) {
|
||||
@ -178,7 +169,7 @@ class Director implements TemplateGlobalProvider
|
||||
*/
|
||||
public static function test(
|
||||
$url,
|
||||
$postVars = null,
|
||||
$postVars = [],
|
||||
$session = array(),
|
||||
$httpMethod = null,
|
||||
$body = null,
|
||||
@ -213,13 +204,24 @@ class Director implements TemplateGlobalProvider
|
||||
}
|
||||
|
||||
// Default httpMethod
|
||||
$newVars['_SERVER']['REQUEST_METHOD'] = $httpMethod
|
||||
?: (($postVars || is_array($postVars)) ? "POST" : "GET");
|
||||
$newVars['_SERVER']['REQUEST_METHOD'] = $httpMethod ?: ($postVars ? "POST" : "GET");
|
||||
$newVars['_POST'] = (array)$postVars;
|
||||
|
||||
// Setup session
|
||||
$newVars['_SESSION'] = $session instanceof Session
|
||||
? $session->getAll()
|
||||
: ($session ?: []);
|
||||
if ($session instanceof Session) {
|
||||
// Note: If passing $session as object, ensure that changes are written back
|
||||
// This is important for classes such as FunctionalTest which emulate cross-request persistence
|
||||
$newVars['_SESSION'] = $session->getAll();
|
||||
$finally[] = function () use ($session) {
|
||||
if (isset($_SESSION)) {
|
||||
foreach ($_SESSION as $key => $value) {
|
||||
$session->set($key, $value);
|
||||
}
|
||||
}
|
||||
};
|
||||
} else {
|
||||
$newVars['_SESSION'] = $session ?: [];
|
||||
}
|
||||
|
||||
// Setup cookies
|
||||
$cookieJar = $cookies instanceof Cookie_Backend
|
||||
@ -268,6 +270,9 @@ class Director implements TemplateGlobalProvider
|
||||
}
|
||||
}
|
||||
|
||||
// Apply new vars to environment
|
||||
static::varsToEnv($newVars);
|
||||
|
||||
try {
|
||||
// Normal request handling
|
||||
return static::direct($request);
|
||||
|
@ -55,7 +55,7 @@ class ExtensionTestState implements TestState
|
||||
continue;
|
||||
}
|
||||
if (!isset($this->extensionsToReapply[$dataClass])) {
|
||||
$this->extensionsToReapply[$dataClass] = array();
|
||||
$this->extensionsToReapply[$dataClass] = [];
|
||||
}
|
||||
$this->extensionsToReapply[$dataClass][] = $extension;
|
||||
$dataClass::remove_extension($extension);
|
||||
@ -70,14 +70,13 @@ class ExtensionTestState implements TestState
|
||||
}
|
||||
$this->extensionsToRemove[$dataClass] = array();
|
||||
foreach ($extensions as $extension) {
|
||||
$dataClass = Extension::get_classname_without_arguments($extension);
|
||||
if (!class_exists($dataClass)) {
|
||||
$self = static::class;
|
||||
throw new LogicException("Test {$self} requires extension {$extension} which doesn't exist");
|
||||
$extension = Extension::get_classname_without_arguments($extension);
|
||||
if (!class_exists($extension)) {
|
||||
throw new LogicException("Test {$class} requires extension {$extension} which doesn't exist");
|
||||
}
|
||||
if (!$dataClass::has_extension($extension)) {
|
||||
if (!isset($this->extensionsToRemove[$dataClass])) {
|
||||
$this->extensionsToReapply[$dataClass] = array();
|
||||
$this->extensionsToReapply[$dataClass] = [];
|
||||
}
|
||||
$this->extensionsToRemove[$dataClass][] = $extension;
|
||||
$dataClass::add_extension($extension);
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace SilverStripe\Dev;
|
||||
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Control\Session;
|
||||
use SilverStripe\Control\HTTPResponse;
|
||||
use SilverStripe\Core\Config\Config;
|
||||
@ -408,11 +409,11 @@ class FunctionalTest extends SapphireTest
|
||||
public function useDraftSite($enabled = true)
|
||||
{
|
||||
if ($enabled) {
|
||||
$this->session()->inst_set('readingMode', 'Stage.Stage');
|
||||
$this->session()->inst_set('unsecuredDraftSite', true);
|
||||
$this->session()->set('readingMode', 'Stage.Stage');
|
||||
$this->session()->set('unsecuredDraftSite', true);
|
||||
} else {
|
||||
$this->session()->inst_set('readingMode', 'Stage.Live');
|
||||
$this->session()->inst_set('unsecuredDraftSite', false);
|
||||
$this->session()->set('readingMode', 'Stage.Live');
|
||||
$this->session()->set('unsecuredDraftSite', false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -904,7 +904,7 @@ class SapphireTest extends PHPUnit_Framework_TestCase
|
||||
// (e.g. Member will now have various subclasses of DataObjects that implement TestOnly)
|
||||
DataObject::reset();
|
||||
|
||||
// Set dummy controller
|
||||
// Set dummy controller;
|
||||
$controller = Controller::create();
|
||||
$controller->setRequest($request);
|
||||
$controller->pushCurrent();
|
||||
|
@ -61,6 +61,7 @@ class TestSession
|
||||
$this->controller = new Controller();
|
||||
$this->controller->setRequest($request);
|
||||
$this->controller->pushCurrent();
|
||||
$this->controller->doInit();
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
|
@ -26,6 +26,12 @@ class DefaultFormFactory implements FormFactory
|
||||
$this->constructExtensions();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RequestHandler $controller
|
||||
* @param string $name
|
||||
* @param array $context
|
||||
* @return Form
|
||||
*/
|
||||
public function getForm(RequestHandler $controller = null, $name = FormFactory::DEFAULT_NAME, $context = [])
|
||||
{
|
||||
// Validate context
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace SilverStripe\Forms;
|
||||
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Control\HasRequestHandler;
|
||||
use SilverStripe\Control\HTTP;
|
||||
use SilverStripe\Control\RequestHandler;
|
||||
@ -347,7 +348,9 @@ class Form extends ViewableData implements HasRequestHandler
|
||||
*/
|
||||
protected function getSession()
|
||||
{
|
||||
return $this->getRequestHandler()->getRequest()->getSession();
|
||||
// Note: Session may not be available if this form doesn't have a request handler
|
||||
$controller = $this->getController() ?: Controller::curr();
|
||||
return $controller->getRequest()->getSession();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4,9 +4,9 @@ namespace SilverStripe\Forms\GridField;
|
||||
|
||||
use SilverStripe\Admin\LeftAndMain;
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Control\RequestHandler;
|
||||
use SilverStripe\Control\HTTPRequest;
|
||||
use SilverStripe\Control\HTTPResponse;
|
||||
use SilverStripe\Control\RequestHandler;
|
||||
use SilverStripe\Forms\FieldList;
|
||||
use SilverStripe\Forms\Form;
|
||||
use SilverStripe\Forms\FormAction;
|
||||
|
@ -134,9 +134,7 @@ class GridFieldExportButton implements GridField_HTMLProvider, GridField_ActionP
|
||||
}
|
||||
|
||||
/** @var GridFieldDataColumns $dataCols */
|
||||
$dataCols = $gridField->getConfig()->getComponentByType(
|
||||
'SilverStripe\\Forms\\GridField\\GridFieldDataColumns'
|
||||
);
|
||||
$dataCols = $gridField->getConfig()->getComponentByType(GridFieldDataColumns::class);
|
||||
if ($dataCols) {
|
||||
return $dataCols->getDisplayFields($gridField);
|
||||
}
|
||||
|
@ -365,7 +365,7 @@ class TinyMCEConfig extends HTMLEditorConfig
|
||||
|
||||
/**
|
||||
* Enable one or several plugins. Will properly handle being passed a plugin that is already disabled
|
||||
* @param string $plugin,... a string, or several strings, or a single array of strings - The plugins to enable
|
||||
* @param string|array $plugin,... a string, or several strings, or a single array of strings - The plugins to enable
|
||||
* @return $this
|
||||
*/
|
||||
public function disablePlugins($plugin)
|
||||
|
@ -10,6 +10,14 @@ use SilverStripe\Dev\TestOnly;
|
||||
*/
|
||||
class TestController extends Controller implements TestOnly
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
if (Controller::has_curr()) {
|
||||
$this->setRequest(Controller::curr()->getRequest());
|
||||
}
|
||||
}
|
||||
|
||||
private static $url_segment = 'TestController';
|
||||
|
||||
public $Content = "default content";
|
||||
|
@ -7,6 +7,14 @@ use SilverStripe\Dev\TestOnly;
|
||||
|
||||
class TestController extends Controller implements TestOnly
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
if (Controller::has_curr()) {
|
||||
$this->setRequest(Controller::curr()->getRequest());
|
||||
}
|
||||
}
|
||||
|
||||
private static $url_segment = 'TestController';
|
||||
|
||||
private static $allowed_actions = array(
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace SilverStripe\Control\Tests\RequestHandlingTest;
|
||||
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Control\HTTPRequest;
|
||||
use SilverStripe\Control\HTTPResponse;
|
||||
use SilverStripe\Control\HTTPResponse_Exception;
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
@ -41,25 +42,28 @@ class TestController extends Controller implements TestOnly
|
||||
{
|
||||
$this->failover = new ControllerFailover();
|
||||
parent::__construct();
|
||||
if (Controller::has_curr()) {
|
||||
$this->setRequest(Controller::curr()->getRequest());
|
||||
}
|
||||
}
|
||||
|
||||
public function index($request)
|
||||
public function index(HTTPRequest $request)
|
||||
{
|
||||
return "This is the controller";
|
||||
}
|
||||
|
||||
public function method($request)
|
||||
public function method(HTTPRequest $request)
|
||||
{
|
||||
return "This is a method on the controller: " . $request->param('ID') . ', ' . $request->param('OtherID');
|
||||
}
|
||||
|
||||
public function legacymethod($request)
|
||||
public function legacymethod(HTTPRequest $request)
|
||||
{
|
||||
return "\$this->urlParams can be used, for backward compatibility: " . $this->urlParams['ID'] . ', '
|
||||
. $this->urlParams['OtherID'];
|
||||
}
|
||||
|
||||
public function virtualfile($request)
|
||||
public function virtualfile(HTTPRequest $request)
|
||||
{
|
||||
return "This is the virtualfile method";
|
||||
}
|
||||
|
@ -169,17 +169,14 @@ class CheckboxSetFieldTest extends SapphireTest
|
||||
|
||||
public function testLoadDataFromObject()
|
||||
{
|
||||
$article = $this->objFromFixture(Article::class, 'articlewithouttags');
|
||||
$articleWithTags = $this->objFromFixture(Article::class, 'articlewithtags');
|
||||
$tag1 = $this->objFromFixture(Tag::class, 'tag1');
|
||||
$tag2 = $this->objFromFixture(Tag::class, 'tag2');
|
||||
|
||||
$field = new CheckboxSetField("Tags", "Test field", DataObject::get(Tag::class)->map());
|
||||
/**
|
||||
* @skipUpgrade
|
||||
*/
|
||||
/** @skipUpgrade */
|
||||
$form = new Form(
|
||||
new Controller(),
|
||||
Controller::curr(),
|
||||
'Form',
|
||||
new FieldList($field),
|
||||
new FieldList()
|
||||
|
@ -2,14 +2,13 @@
|
||||
|
||||
namespace SilverStripe\Forms\Tests;
|
||||
|
||||
use SilverStripe\Control\Tests\ControllerTest\TestController;
|
||||
use SilverStripe\Security\Member;
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\Forms\ConfirmedPasswordField;
|
||||
use SilverStripe\Forms\FieldList;
|
||||
use SilverStripe\Forms\Form;
|
||||
use SilverStripe\Forms\RequiredFields;
|
||||
use SilverStripe\Security\Member;
|
||||
|
||||
class ConfirmedPasswordFieldTest extends SapphireTest
|
||||
{
|
||||
@ -39,10 +38,8 @@ class ConfirmedPasswordFieldTest extends SapphireTest
|
||||
$member->Password = "valueB";
|
||||
$member->write();
|
||||
|
||||
/**
|
||||
* @skipUpgrade
|
||||
*/
|
||||
$form = new Form(new TestController(), 'Form', new FieldList($field), new FieldList());
|
||||
/** @skipUpgrade */
|
||||
$form = new Form(Controller::curr(), 'Form', new FieldList($field), new FieldList());
|
||||
$form->loadDataFrom($member);
|
||||
|
||||
$this->assertEquals('', $field->Value());
|
||||
@ -92,10 +89,8 @@ class ConfirmedPasswordFieldTest extends SapphireTest
|
||||
)
|
||||
);
|
||||
$validator = new RequiredFields();
|
||||
/**
|
||||
* @skipUpgrade
|
||||
*/
|
||||
$form = new Form(new TestController(), 'Form', new FieldList($field), new FieldList(), $validator);
|
||||
/** @skipUpgrade */
|
||||
new Form(Controller::curr(), 'Form', new FieldList($field), new FieldList(), $validator);
|
||||
$this->assertTrue(
|
||||
$field->validate($validator),
|
||||
"Validates when both passwords are the same"
|
||||
@ -120,11 +115,9 @@ class ConfirmedPasswordFieldTest extends SapphireTest
|
||||
|
||||
public function testFormValidation()
|
||||
{
|
||||
/**
|
||||
* @skipUpgrade
|
||||
*/
|
||||
/** @skipUpgrade */
|
||||
$form = new Form(
|
||||
new Controller(),
|
||||
Controller::curr(),
|
||||
'Form',
|
||||
new FieldList($field = new ConfirmedPasswordField('Password')),
|
||||
new FieldList()
|
||||
|
@ -2,16 +2,14 @@
|
||||
|
||||
namespace SilverStripe\Forms\Tests;
|
||||
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\Forms\DatetimeField;
|
||||
use SilverStripe\Forms\RequiredFields;
|
||||
use SilverStripe\Forms\DateField;
|
||||
use SilverStripe\Forms\Tests\DatetimeFieldTest\Model;
|
||||
use SilverStripe\Forms\TimeField;
|
||||
use SilverStripe\Forms\FieldList;
|
||||
use SilverStripe\Forms\FormAction;
|
||||
use SilverStripe\Forms\Form;
|
||||
use SilverStripe\Forms\FormAction;
|
||||
use SilverStripe\Forms\RequiredFields;
|
||||
use SilverStripe\Forms\Tests\DatetimeFieldTest\Model;
|
||||
use SilverStripe\i18n\i18n;
|
||||
use SilverStripe\ORM\FieldType\DBDatetime;
|
||||
|
||||
@ -452,7 +450,7 @@ class DatetimeFieldTest extends SapphireTest
|
||||
{
|
||||
/** @skipUpgrade */
|
||||
return new Form(
|
||||
new Controller(),
|
||||
Controller::curr(),
|
||||
'Form',
|
||||
new FieldList(),
|
||||
new FieldList(
|
||||
|
@ -479,7 +479,7 @@ class DropdownFieldTest extends SapphireTest
|
||||
)
|
||||
);
|
||||
$validator = new RequiredFields();
|
||||
$form = new Form(null, 'Form', new FieldList($field), new FieldList(), $validator);
|
||||
new Form(null, 'Form', new FieldList($field), new FieldList(), $validator);
|
||||
$field->setValue("One");
|
||||
$this->assertTrue($field->validate($validator));
|
||||
$field->setName("TestNew"); //try changing name of field
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace SilverStripe\Forms\Tests\EmailFieldTest;
|
||||
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Control\HTTPRequest;
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
use SilverStripe\Forms\EmailField;
|
||||
use SilverStripe\Forms\FieldList;
|
||||
@ -16,6 +17,13 @@ use SilverStripe\View\SSViewer;
|
||||
*/
|
||||
class TestController extends Controller implements TestOnly
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
if (Controller::has_curr()) {
|
||||
$this->setRequest(Controller::curr()->getRequest());
|
||||
}
|
||||
}
|
||||
|
||||
private static $allowed_actions = array('Form');
|
||||
|
||||
@ -25,11 +33,9 @@ class TestController extends Controller implements TestOnly
|
||||
|
||||
protected $template = 'BlankPage';
|
||||
|
||||
function Link($action = null)
|
||||
public function Link($action = null)
|
||||
{
|
||||
/**
|
||||
* @skipUpgrade
|
||||
*/
|
||||
/** @skipUpgrade */
|
||||
return Controller::join_links(
|
||||
'EmailFieldTest_Controller',
|
||||
$this->getRequest()->latestParam('Action'),
|
||||
@ -38,7 +44,10 @@ class TestController extends Controller implements TestOnly
|
||||
);
|
||||
}
|
||||
|
||||
function Form()
|
||||
/**
|
||||
* @return Form
|
||||
*/
|
||||
public function Form()
|
||||
{
|
||||
$form = new Form(
|
||||
$this,
|
||||
@ -60,13 +69,13 @@ class TestController extends Controller implements TestOnly
|
||||
return $form;
|
||||
}
|
||||
|
||||
function doSubmit($data, $form, $request)
|
||||
public function doSubmit($data, Form $form, HTTPRequest $request)
|
||||
{
|
||||
$form->sessionMessage('Test save was successful', 'good');
|
||||
return $this->redirectBack();
|
||||
}
|
||||
|
||||
function getViewer($action = null)
|
||||
public function getViewer($action = null)
|
||||
{
|
||||
return new SSViewer('BlankPage');
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ class FileFieldTest extends FunctionalTest
|
||||
public function testUploadRequiredFile()
|
||||
{
|
||||
$form = new Form(
|
||||
new Controller(),
|
||||
Controller::curr(),
|
||||
'Form',
|
||||
new FieldList(
|
||||
$fileField = new FileField('cv', 'Upload your CV')
|
||||
@ -46,7 +46,7 @@ class FileFieldTest extends FunctionalTest
|
||||
public function testUploadMissingRequiredFile()
|
||||
{
|
||||
$form = new Form(
|
||||
new Controller(),
|
||||
Controller::curr(),
|
||||
'Form',
|
||||
new FieldList(
|
||||
$fileField = new FileField('cv', 'Upload your CV')
|
||||
|
@ -51,7 +51,6 @@ class FormFactoryTest extends SapphireTest
|
||||
$this->assertInstanceOf(HiddenField::class, $form->Fields()->fieldByName('ID'));
|
||||
$this->assertInstanceOf(HiddenField::class, $form->Fields()->fieldByName('SecurityID'));
|
||||
|
||||
|
||||
// Check preview link
|
||||
/** @var LiteralField $previewLink */
|
||||
$previewLink = $form->Fields()->fieldByName('PreviewLink');
|
||||
|
@ -12,6 +12,14 @@ use SilverStripe\Versioned\Versioned;
|
||||
*/
|
||||
class TestController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
if (Controller::has_curr()) {
|
||||
$this->setRequest(Controller::curr()->getRequest());
|
||||
}
|
||||
}
|
||||
|
||||
private static $extensions = [
|
||||
ControllerExtension::class,
|
||||
];
|
||||
@ -25,6 +33,9 @@ class TestController extends Controller
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Form
|
||||
*/
|
||||
public function Form()
|
||||
{
|
||||
// Simple example; Just get the first draft record
|
||||
|
@ -2,16 +2,18 @@
|
||||
|
||||
namespace SilverStripe\Forms\Tests;
|
||||
|
||||
use SilverStripe\Core\Config\Config;
|
||||
use ReflectionClass;
|
||||
use SilverStripe\Core\ClassInfo;
|
||||
use SilverStripe\Core\Config\Config;
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\Forms\FormField;
|
||||
use SilverStripe\Forms\Tests\FormFieldTest\TestExtension;
|
||||
use SilverStripe\Forms\TextField;
|
||||
use SilverStripe\Forms\RequiredFields;
|
||||
use SilverStripe\Forms\CompositeField;
|
||||
use SilverStripe\Forms\FieldList;
|
||||
use SilverStripe\Forms\Form;
|
||||
use ReflectionClass;
|
||||
use SilverStripe\Forms\FormField;
|
||||
use SilverStripe\Forms\NullableField;
|
||||
use SilverStripe\Forms\RequiredFields;
|
||||
use SilverStripe\Forms\Tests\FormFieldTest\TestExtension;
|
||||
use SilverStripe\Forms\TextField;
|
||||
|
||||
class FormFieldTest extends SapphireTest
|
||||
{
|
||||
@ -205,7 +207,7 @@ class FormFieldTest extends SapphireTest
|
||||
|
||||
public function testEveryFieldTransformsReadonlyAsClone()
|
||||
{
|
||||
$fieldClasses = ClassInfo::subclassesFor('SilverStripe\\Forms\\FormField');
|
||||
$fieldClasses = ClassInfo::subclassesFor(FormField::class);
|
||||
foreach ($fieldClasses as $fieldClass) {
|
||||
$reflectionClass = new ReflectionClass($fieldClass);
|
||||
if (!$reflectionClass->isInstantiable()) {
|
||||
@ -215,12 +217,13 @@ class FormFieldTest extends SapphireTest
|
||||
if ($constructor->getNumberOfRequiredParameters() > 1) {
|
||||
continue;
|
||||
}
|
||||
if (is_a($fieldClass, 'SilverStripe\\Forms\\CompositeField', true)) {
|
||||
if (is_a($fieldClass, CompositeField::class, true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$fieldName = $reflectionClass->getShortName() . '_instance';
|
||||
if ($fieldClass = 'SilverStripe\\Forms\\NullableField') {
|
||||
/** @var FormField $instance */
|
||||
if ($fieldClass = NullableField::class) {
|
||||
$instance = new $fieldClass(new TextField($fieldName));
|
||||
} else {
|
||||
$instance = new $fieldClass($fieldName);
|
||||
@ -246,7 +249,7 @@ class FormFieldTest extends SapphireTest
|
||||
|
||||
public function testEveryFieldTransformsDisabledAsClone()
|
||||
{
|
||||
$fieldClasses = ClassInfo::subclassesFor('SilverStripe\\Forms\\FormField');
|
||||
$fieldClasses = ClassInfo::subclassesFor(FormField::class);
|
||||
foreach ($fieldClasses as $fieldClass) {
|
||||
$reflectionClass = new ReflectionClass($fieldClass);
|
||||
if (!$reflectionClass->isInstantiable()) {
|
||||
@ -256,12 +259,13 @@ class FormFieldTest extends SapphireTest
|
||||
if ($constructor->getNumberOfRequiredParameters() > 1) {
|
||||
continue;
|
||||
}
|
||||
if (is_a($fieldClass, 'SilverStripe\\Forms\\CompositeField', true)) {
|
||||
if (is_a($fieldClass, CompositeField::class, true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$fieldName = $reflectionClass->getShortName() . '_instance';
|
||||
if ($fieldClass = 'SilverStripe\\Forms\\NullableField') {
|
||||
/** @var FormField $instance */
|
||||
if ($fieldClass = NullableField::class) {
|
||||
$instance = new $fieldClass(new TextField($fieldName));
|
||||
} else {
|
||||
$instance = new $fieldClass($fieldName);
|
||||
@ -324,7 +328,7 @@ class FormFieldTest extends SapphireTest
|
||||
$field = new FormField('MyField');
|
||||
|
||||
// Make sure the user can update values.
|
||||
$field = $field->setSchemaData(['name' => 'MyUpdatedField']);
|
||||
$field->setSchemaData(['name' => 'MyUpdatedField']);
|
||||
$schema = $field->getSchemaData();
|
||||
$this->assertEquals($schema['name'], 'MyUpdatedField');
|
||||
|
||||
@ -347,12 +351,12 @@ class FormFieldTest extends SapphireTest
|
||||
$field = new FormField('MyField');
|
||||
|
||||
// Make sure the user can update values.
|
||||
$field = $field->setSchemaState(['value' => 'My custom value']);
|
||||
$field->setSchemaState(['value' => 'My custom value']);
|
||||
$schema = $field->getSchemaState();
|
||||
$this->assertEquals($schema['value'], 'My custom value');
|
||||
|
||||
// Make user the user can't define custom keys on the schema.
|
||||
$field = $field->setSchemaState(['myCustomKey' => 'yolo']);
|
||||
$field->setSchemaState(['myCustomKey' => 'yolo']);
|
||||
$schema = $field->getSchemaState();
|
||||
$this->assertEquals(array_key_exists('myCustomKey', $schema), false);
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ class FormRequestHandlerTest extends SapphireTest
|
||||
public function testCallsActionOnFormHandler()
|
||||
{
|
||||
$form = new TestForm(
|
||||
new Controller(),
|
||||
Controller::curr(),
|
||||
'Form',
|
||||
new FieldList(),
|
||||
new FieldList(new FormAction('mySubmitOnFormHandler'))
|
||||
@ -31,7 +31,7 @@ class FormRequestHandlerTest extends SapphireTest
|
||||
public function testCallsActionOnForm()
|
||||
{
|
||||
$form = new TestForm(
|
||||
new Controller(),
|
||||
Controller::curr(),
|
||||
'Form',
|
||||
new FieldList(),
|
||||
new FieldList(new FormAction('mySubmitOnForm'))
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace SilverStripe\Forms\Tests;
|
||||
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Forms\CurrencyField;
|
||||
use SilverStripe\Forms\DateField;
|
||||
use SilverStripe\Forms\NumericField;
|
||||
@ -16,6 +17,16 @@ use SilverStripe\Forms\PopoverField;
|
||||
|
||||
class FormSchemaTest extends SapphireTest
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
// Clear old messages
|
||||
$session = Controller::curr()->getRequest()->getSession();
|
||||
$session
|
||||
->clear("FormInfo.TestForm.result")
|
||||
->clear("FormInfo.TestForm.data");
|
||||
}
|
||||
|
||||
public function testGetSchema()
|
||||
{
|
||||
@ -86,6 +97,7 @@ class FormSchemaTest extends SapphireTest
|
||||
$actions = new FieldList();
|
||||
$validator = new RequiredFields('Title');
|
||||
$form = new Form(null, 'TestForm', $fields, $actions, $validator);
|
||||
$form->clearMessage();
|
||||
$form->loadDataFrom(
|
||||
[
|
||||
'Title' => null,
|
||||
|
@ -61,7 +61,7 @@ class FormTest extends FunctionalTest
|
||||
public function testLoadDataFromRequest()
|
||||
{
|
||||
$form = new Form(
|
||||
new Controller(),
|
||||
Controller::curr(),
|
||||
'Form',
|
||||
new FieldList(
|
||||
new TextField('key1'),
|
||||
@ -130,7 +130,7 @@ class FormTest extends FunctionalTest
|
||||
public function testLoadDataFromUnchangedHandling()
|
||||
{
|
||||
$form = new Form(
|
||||
new Controller(),
|
||||
Controller::curr(),
|
||||
'Form',
|
||||
new FieldList(
|
||||
new TextField('key1'),
|
||||
@ -158,7 +158,7 @@ class FormTest extends FunctionalTest
|
||||
public function testLoadDataFromObject()
|
||||
{
|
||||
$form = new Form(
|
||||
new Controller(),
|
||||
Controller::curr(),
|
||||
'Form',
|
||||
new FieldList(
|
||||
new HeaderField('MyPlayerHeader', 'My Player'),
|
||||
@ -200,7 +200,7 @@ class FormTest extends FunctionalTest
|
||||
public function testLoadDataFromClearMissingFields()
|
||||
{
|
||||
$form = new Form(
|
||||
new Controller(),
|
||||
Controller::curr(),
|
||||
'Form',
|
||||
new FieldList(
|
||||
new HeaderField('MyPlayerHeader', 'My Player'),
|
||||
@ -250,7 +250,7 @@ class FormTest extends FunctionalTest
|
||||
{
|
||||
$object = new Team();
|
||||
$form = new Form(
|
||||
new Controller(),
|
||||
Controller::curr(),
|
||||
'Form',
|
||||
new FieldList(
|
||||
new LookupField('Players', 'Players')
|
||||
@ -280,7 +280,7 @@ class FormTest extends FunctionalTest
|
||||
public function testLoadDataFromIgnoreFalseish()
|
||||
{
|
||||
$form = new Form(
|
||||
new Controller(),
|
||||
Controller::curr(),
|
||||
'Form',
|
||||
new FieldList(
|
||||
new TextField('Biography', 'Biography', 'Custom Default')
|
||||
@ -447,7 +447,7 @@ class FormTest extends FunctionalTest
|
||||
{
|
||||
$this->get('FormTest_Controller');
|
||||
|
||||
$result = $this->post(
|
||||
$this->post(
|
||||
'FormTest_Controller/Form',
|
||||
array(
|
||||
'Email' => 'test@test.com',
|
||||
|
@ -21,6 +21,13 @@ use SilverStripe\View\SSViewer;
|
||||
*/
|
||||
class TestController extends Controller implements TestOnly
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
if (Controller::has_curr()) {
|
||||
$this->setRequest(Controller::curr()->getRequest());
|
||||
}
|
||||
}
|
||||
|
||||
private static $allowed_actions = array('Form');
|
||||
|
||||
|
@ -2,17 +2,16 @@
|
||||
|
||||
namespace SilverStripe\Forms\Tests\GridField;
|
||||
|
||||
use SilverStripe\Dev\Debug;
|
||||
use SilverStripe\Core\Convert;
|
||||
use SilverStripe\Dev\CSSContentParser;
|
||||
use SilverStripe\Dev\FunctionalTest;
|
||||
use SilverStripe\Forms\GridField\GridFieldAddExistingAutocompleter;
|
||||
use SilverStripe\Forms\Tests\GridField\GridFieldAddExistingAutocompleterTest\TestController;
|
||||
use SilverStripe\Forms\Tests\GridField\GridFieldTest\Cheerleader;
|
||||
use SilverStripe\Forms\Tests\GridField\GridFieldTest\Permissions;
|
||||
use SilverStripe\Forms\Tests\GridField\GridFieldTest\Player;
|
||||
use SilverStripe\Forms\Tests\GridField\GridFieldTest\Team;
|
||||
use SilverStripe\ORM\ArrayList;
|
||||
use SilverStripe\Core\Convert;
|
||||
use SilverStripe\Dev\CSSContentParser;
|
||||
use SilverStripe\Dev\FunctionalTest;
|
||||
use SilverStripe\Forms\GridField\GridFieldAddExistingAutocompleter;
|
||||
|
||||
class GridFieldAddExistingAutocompleterTest extends FunctionalTest
|
||||
{
|
||||
|
@ -17,6 +17,13 @@ use SilverStripe\Forms\Tests\GridField\GridFieldTest\Player;
|
||||
*/
|
||||
class TestController extends Controller implements TestOnly
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
if (Controller::has_curr()) {
|
||||
$this->setRequest(Controller::curr()->getRequest());
|
||||
}
|
||||
}
|
||||
|
||||
private static $allowed_actions = array('Form');
|
||||
|
||||
@ -29,9 +36,7 @@ class TestController extends Controller implements TestOnly
|
||||
|
||||
public function Form()
|
||||
{
|
||||
/**
|
||||
* @var Player $player
|
||||
*/
|
||||
/** @var Player $player */
|
||||
$player = Player::get()->find('Email', 'player1@test.com');
|
||||
$config = GridFieldConfig::create()->addComponents(
|
||||
$relationComponent = new GridFieldAddExistingAutocompleter('before'),
|
||||
|
@ -2,7 +2,16 @@
|
||||
|
||||
namespace SilverStripe\Forms\Tests\GridField;
|
||||
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Control\HTTPRequest;
|
||||
use SilverStripe\Control\HTTPResponse_Exception;
|
||||
use SilverStripe\Dev\CSSContentParser;
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\Forms\FieldList;
|
||||
use SilverStripe\Forms\Form;
|
||||
use SilverStripe\Forms\GridField\GridField;
|
||||
use SilverStripe\Forms\GridField\GridFieldConfig;
|
||||
use SilverStripe\Forms\GridField\GridFieldDeleteAction;
|
||||
use SilverStripe\Forms\Tests\GridField\GridFieldTest\Cheerleader;
|
||||
use SilverStripe\Forms\Tests\GridField\GridFieldTest\Permissions;
|
||||
use SilverStripe\Forms\Tests\GridField\GridFieldTest\Player;
|
||||
@ -12,15 +21,6 @@ use SilverStripe\ORM\DataList;
|
||||
use SilverStripe\ORM\ValidationException;
|
||||
use SilverStripe\Security\Security;
|
||||
use SilverStripe\Security\SecurityToken;
|
||||
use SilverStripe\Dev\CSSContentParser;
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\Control\HTTPRequest;
|
||||
use SilverStripe\Control\Session;
|
||||
use SilverStripe\Forms\FieldList;
|
||||
use SilverStripe\Forms\Form;
|
||||
use SilverStripe\Forms\GridField\GridFieldConfig;
|
||||
use SilverStripe\Forms\GridField\GridFieldDeleteAction;
|
||||
use SilverStripe\Forms\GridField\GridField;
|
||||
|
||||
class GridFieldDeleteActionTest extends SapphireTest
|
||||
{
|
||||
@ -91,15 +91,13 @@ class GridFieldDeleteActionTest extends SapphireTest
|
||||
public function testActionsRequireCSRF()
|
||||
{
|
||||
$this->logInWithPermission('ADMIN');
|
||||
$this->setExpectedException(
|
||||
HTTPResponse_Exception::class,
|
||||
_t(
|
||||
"SilverStripe\\Forms\\Form.CSRF_FAILED_MESSAGE",
|
||||
"There seems to have been a technical problem. Please click the back button, ".
|
||||
"refresh your browser, and try again."
|
||||
),
|
||||
400
|
||||
);
|
||||
$this->expectException(HTTPResponse_Exception::class);
|
||||
$this->expectExceptionMessage(_t(
|
||||
"SilverStripe\\Forms\\Form.CSRF_FAILED_MESSAGE",
|
||||
"There seems to have been a technical problem. Please click the back button, ".
|
||||
"refresh your browser, and try again."
|
||||
));
|
||||
$this->expectExceptionCode(400);
|
||||
$stateID = 'testGridStateActionField';
|
||||
$request = new HTTPRequest(
|
||||
'POST',
|
||||
@ -121,7 +119,8 @@ class GridFieldDeleteActionTest extends SapphireTest
|
||||
$this->expectException(ValidationException::class);
|
||||
|
||||
$stateID = 'testGridStateActionField';
|
||||
Controller::curr()->getRequest()->getSession()->set(
|
||||
$session = Controller::curr()->getRequest()->getSession();
|
||||
$session->set(
|
||||
$stateID,
|
||||
array(
|
||||
'grid' => '',
|
||||
@ -141,6 +140,7 @@ class GridFieldDeleteActionTest extends SapphireTest
|
||||
$token->getName() => $token->getValue(),
|
||||
)
|
||||
);
|
||||
$request->setSession($session);
|
||||
$this->gridField->gridFieldAlterAction(array('StateID'=>$stateID), $this->form, $request);
|
||||
$this->assertEquals(
|
||||
3,
|
||||
@ -153,7 +153,8 @@ class GridFieldDeleteActionTest extends SapphireTest
|
||||
{
|
||||
$this->logInWithPermission('ADMIN');
|
||||
$stateID = 'testGridStateActionField';
|
||||
Session::set(
|
||||
$session = Controller::curr()->getRequest()->getSession();
|
||||
$session->set(
|
||||
$stateID,
|
||||
array(
|
||||
'grid'=>'',
|
||||
@ -173,6 +174,7 @@ class GridFieldDeleteActionTest extends SapphireTest
|
||||
$token->getName() => $token->getValue(),
|
||||
)
|
||||
);
|
||||
$request->setSession($session);
|
||||
$this->gridField->gridFieldAlterAction(array('StateID'=>$stateID), $this->form, $request);
|
||||
$this->assertEquals(2, $this->list->count(), 'User should be able to delete records with ADMIN permission.');
|
||||
}
|
||||
@ -183,11 +185,11 @@ class GridFieldDeleteActionTest extends SapphireTest
|
||||
|
||||
$config = GridFieldConfig::create()->addComponent(new GridFieldDeleteAction(true));
|
||||
|
||||
$session = Controller::curr()->getRequest()->getSession();
|
||||
$gridField = new GridField('testfield', 'testfield', $this->list, $config);
|
||||
$form = new Form(null, 'mockform', new FieldList(array($this->gridField)), new FieldList());
|
||||
|
||||
new Form(null, 'mockform', new FieldList(array($gridField)), new FieldList());
|
||||
$stateID = 'testGridStateActionField';
|
||||
Session::set(
|
||||
$session->set(
|
||||
$stateID,
|
||||
array(
|
||||
'grid'=>'',
|
||||
@ -207,7 +209,8 @@ class GridFieldDeleteActionTest extends SapphireTest
|
||||
$token->getName() => $token->getValue(),
|
||||
)
|
||||
);
|
||||
$this->gridField->gridFieldAlterAction(array('StateID'=>$stateID), $this->form, $request);
|
||||
$request->setSession($session);
|
||||
$gridField->gridFieldAlterAction(array('StateID'=>$stateID), $this->form, $request);
|
||||
$this->assertEquals(2, $this->list->count(), 'User should be able to delete records with ADMIN permission.');
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace SilverStripe\Forms\Tests\GridField;
|
||||
|
||||
use SilverStripe\Dev\CSSContentParser;
|
||||
use SilverStripe\Dev\Debug;
|
||||
use SilverStripe\Dev\FunctionalTest;
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Forms\HiddenField;
|
||||
@ -244,7 +245,6 @@ class GridFieldDetailFormTest extends FunctionalTest
|
||||
)
|
||||
);
|
||||
$this->assertFalse($response->isError());
|
||||
|
||||
$person = Person::get()->sort('FirstName')->First();
|
||||
$category = $person->Categories()->filter(array('Name' => 'Updated Category'))->First();
|
||||
$this->assertEquals(
|
||||
@ -363,18 +363,17 @@ class GridFieldDetailFormTest extends FunctionalTest
|
||||
}
|
||||
);
|
||||
// Note: A lot of scaffolding to execute the tested logic,
|
||||
// due to the coupling of form creation with request handling (and its context)
|
||||
/**
|
||||
* @skipUpgrade
|
||||
*/
|
||||
$request = new GridFieldDetailForm_ItemRequest(
|
||||
// due to the coupling of form creation with itemRequest handling (and its context)
|
||||
/** @skipUpgrade */
|
||||
$itemRequest = new GridFieldDetailForm_ItemRequest(
|
||||
GridField::create('Categories', 'Categories'),
|
||||
$component,
|
||||
$category,
|
||||
new Controller(),
|
||||
Controller::curr(),
|
||||
'Form'
|
||||
);
|
||||
$form = $request->ItemEditForm();
|
||||
$itemRequest->setRequest(Controller::curr()->getRequest());
|
||||
$form = $itemRequest->ItemEditForm();
|
||||
$this->assertNotNull($form->Fields()->fieldByName('Callback'));
|
||||
}
|
||||
|
||||
|
@ -50,18 +50,14 @@ class CategoryController extends Controller implements TestOnly
|
||||
$categoriesField->getConfig()->addComponent(new GridFieldEditButton());
|
||||
|
||||
$favGroupsField = new GridField('testgroupsfield', 'testgroupsfield', $person->FavouriteGroups());
|
||||
/**
|
||||
* @skipUpgrade
|
||||
*/
|
||||
/** @skipUpgrade */
|
||||
$favGroupsField->getConfig()->addComponent(new GridFieldDetailForm($this, 'Form'));
|
||||
$favGroupsField->getConfig()->addComponent(new GridFieldToolbarHeader());
|
||||
$favGroupsField->getConfig()->addComponent(new GridFieldAddNewButton('toolbar-header-right'));
|
||||
$favGroupsField->getConfig()->addComponent(new GridFieldEditButton());
|
||||
|
||||
$fields = new FieldList($categoriesField, $favGroupsField);
|
||||
/**
|
||||
* @skipUpgrade
|
||||
*/
|
||||
/** @skipUpgrade */
|
||||
return new Form($this, 'Form', $fields, new FieldList());
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,13 @@ use SilverStripe\Forms\GridField\GridFieldViewButton;
|
||||
|
||||
class TestController extends Controller implements TestOnly
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
if (Controller::has_curr()) {
|
||||
$this->setRequest(Controller::curr()->getRequest());
|
||||
}
|
||||
}
|
||||
|
||||
public function Link($action = null)
|
||||
{
|
||||
|
@ -43,11 +43,8 @@ class GridFieldPrintButtonTest extends SapphireTest
|
||||
->addComponent(new GridFieldPaginator(10))
|
||||
->addComponent($button);
|
||||
$gridField = new GridField('testfield', 'testfield', $list, $config);
|
||||
$controller = new Controller();
|
||||
/**
|
||||
* @skipUpgrade
|
||||
*/
|
||||
new Form($controller, 'Form', new FieldList($gridField), new FieldList());
|
||||
/** @skipUpgrade */
|
||||
new Form(Controller::curr(), 'Form', new FieldList($gridField), new FieldList());
|
||||
|
||||
// Printed data should ignore pagination limit
|
||||
$printData = $button->generatePrintData($gridField);
|
||||
|
@ -17,7 +17,7 @@ class GridField_URLHandlerTest extends FunctionalTest
|
||||
|
||||
public function testFormSubmission()
|
||||
{
|
||||
$result = $this->get("GridField_URLHandlerTest_Controller/Form/field/Grid/showform");
|
||||
$this->get("GridField_URLHandlerTest_Controller/Form/field/Grid/showform");
|
||||
$formResult = $this->submitForm('Form_Form', 'action_doAction', array('Test' => 'foo bar'));
|
||||
$this->assertEquals("Submitted foo bar to component", $formResult->getBody());
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace SilverStripe\Forms\Tests\GridField\GridField_URLHandlerTest;
|
||||
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Control\HTTPRequest;
|
||||
use SilverStripe\Control\RequestHandler;
|
||||
use SilverStripe\Forms\FieldList;
|
||||
use SilverStripe\Forms\Form;
|
||||
@ -38,8 +39,9 @@ class TestComponent extends RequestHandler implements GridField_URLHandler
|
||||
);
|
||||
}
|
||||
|
||||
public function handleItem($gridField, $request)
|
||||
public function handleItem(GridField $gridField, HTTPRequest $request)
|
||||
{
|
||||
$this->setRequest($request);
|
||||
$id = $request->param("ID");
|
||||
return new TestComponent_ItemRequest(
|
||||
$gridField,
|
||||
@ -53,16 +55,21 @@ class TestComponent extends RequestHandler implements GridField_URLHandler
|
||||
return $this->gridField->Link();
|
||||
}
|
||||
|
||||
public function showform($gridField, $request)
|
||||
public function showform(GridField $gridField, HTTPRequest $request)
|
||||
{
|
||||
$this->setRequest($request);
|
||||
return "<head>" . SSViewer::get_base_tag("") . "</head>" . $this->Form($gridField, $request)->forTemplate();
|
||||
}
|
||||
|
||||
/**
|
||||
* @skipUpgrade
|
||||
* @param GridField $gridField
|
||||
* @param HTTPRequest $request
|
||||
* @return Form
|
||||
*/
|
||||
public function Form($gridField, $request)
|
||||
public function Form(GridField $gridField, HTTPRequest $request)
|
||||
{
|
||||
$this->setRequest($request);
|
||||
$this->gridField = $gridField;
|
||||
return new Form(
|
||||
$this,
|
||||
@ -81,8 +88,9 @@ class TestComponent extends RequestHandler implements GridField_URLHandler
|
||||
return "Submitted " . $data['Test'] . " to component";
|
||||
}
|
||||
|
||||
public function testpage($gridField, $request)
|
||||
public function testpage(GridField $gridField, HTTPRequest $request)
|
||||
{
|
||||
$this->setRequest($request);
|
||||
return "Test page for component";
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,14 @@ use SilverStripe\ORM\ArrayList;
|
||||
*/
|
||||
class TestController extends Controller implements TestOnly
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
if (Controller::has_curr()) {
|
||||
$this->setRequest(Controller::curr()->getRequest());
|
||||
}
|
||||
}
|
||||
|
||||
public function Link($action = null)
|
||||
{
|
||||
return Controller::join_links('GridField_URLHandlerTest_Controller', $action, '/');
|
||||
|
@ -2,16 +2,17 @@
|
||||
|
||||
namespace SilverStripe\Forms\Tests\HTMLEditor;
|
||||
|
||||
use Exception;
|
||||
use PHPUnit_Framework_MockObject_MockObject;
|
||||
use SilverStripe\Control\Director;
|
||||
use SilverStripe\Core\Config\Config;
|
||||
use SilverStripe\Core\Convert;
|
||||
use SilverStripe\Core\Manifest\ModuleLoader;
|
||||
use SilverStripe\Core\Manifest\ModuleManifest;
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\Forms\HTMLEditor\HTMLEditorConfig;
|
||||
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
|
||||
use SilverStripe\Forms\HTMLEditor\TinyMCEConfig;
|
||||
use SilverStripe\Forms\HTMLEditor\HTMLEditorConfig;
|
||||
use \Exception;
|
||||
|
||||
class HTMLEditorConfigTest extends SapphireTest
|
||||
{
|
||||
@ -48,7 +49,7 @@ class HTMLEditorConfigTest extends SapphireTest
|
||||
|
||||
public function testEnablePluginsByArrayWithPaths()
|
||||
{
|
||||
Config::inst()->update(Director::class, 'alternate_base_url', 'http://mysite.com/subdir');
|
||||
Config::modify()->set(Director::class, 'alternate_base_url', 'http://mysite.com/subdir');
|
||||
$c = new TinyMCEConfig();
|
||||
$c->setTheme('modern');
|
||||
$c->setOption('language', 'es');
|
||||
@ -106,7 +107,7 @@ class HTMLEditorConfigTest extends SapphireTest
|
||||
$this->markTestSkipped('No silverstripe/admin module loaded');
|
||||
}
|
||||
TinyMCEConfig::config()->remove('base_dir');
|
||||
Config::inst()->update(Director::class, 'alternate_base_url', 'http://mysite.com/subdir');
|
||||
Config::modify()->set(Director::class, 'alternate_base_url', 'http://mysite.com/subdir');
|
||||
$c = new TinyMCEConfig();
|
||||
$c->setTheme('modern');
|
||||
$c->setOption('language', 'es');
|
||||
@ -191,36 +192,30 @@ class HTMLEditorConfigTest extends SapphireTest
|
||||
public function testExceptionThrownWhenTinyMCEPathCannotBeComputed()
|
||||
{
|
||||
TinyMCEConfig::config()->remove('base_dir');
|
||||
ModuleLoader::inst()->pushManifest(new ModuleManifest(
|
||||
dirname(__FILE__),
|
||||
false
|
||||
));
|
||||
$c = new TinyMCEConfig();
|
||||
ModuleLoader::inst()->pushManifest(new ModuleManifest(__DIR__));
|
||||
|
||||
$this->setExpectedExceptionRegExp(
|
||||
Exception::class,
|
||||
'/module is not installed/'
|
||||
);
|
||||
|
||||
$c->getScriptURL();
|
||||
|
||||
ModuleLoader::inst()->popManifest();
|
||||
try {
|
||||
$config = new TinyMCEConfig();
|
||||
$this->expectException(Exception::class);
|
||||
$this->expectExceptionMessageRegExp('/module is not installed/');
|
||||
$config->getScriptURL();
|
||||
} finally {
|
||||
ModuleLoader::inst()->popManifest();
|
||||
}
|
||||
}
|
||||
|
||||
public function testExceptionThrownWhenTinyMCEGZipPathDoesntExist()
|
||||
{
|
||||
HTMLEditorField::config()->set('use_gzip', true);
|
||||
/** @var TinyMCEConfig|PHPUnit_Framework_MockObject_MockObject $stub */
|
||||
$stub = $this->getMockBuilder(TinyMCEConfig::class)
|
||||
->setMethods(['getTinyMCEPath'])
|
||||
->getMock();
|
||||
$stub->method('getTinyMCEPath')
|
||||
->willReturn('fail');
|
||||
|
||||
$this->setExpectedExceptionRegExp(
|
||||
Exception::class,
|
||||
'/does not exist/'
|
||||
);
|
||||
|
||||
$this->expectException(Exception::class);
|
||||
$this->expectExceptionMessageRegExp('/does not exist/');
|
||||
$stub->getScriptURL();
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ class ValidatorTest extends SapphireTest
|
||||
$fieldList->add(new TextField($name));
|
||||
}
|
||||
|
||||
return new Form(new Controller(), "testForm", $fieldList, new FieldList([/* no actions */]));
|
||||
return new Form(Controller::curr(), "testForm", $fieldList, new FieldList([/* no actions */]));
|
||||
}
|
||||
|
||||
|
||||
|
@ -50,7 +50,7 @@ class GroupTest extends FunctionalTest
|
||||
$parentGroup = $this->objFromFixture(Group::class, 'parentgroup');
|
||||
|
||||
// Test single group relation through checkboxsetfield
|
||||
$form = new GroupTest\MemberForm(new Controller(), 'Form');
|
||||
$form = new GroupTest\MemberForm(Controller::curr(), 'Form');
|
||||
$member = $this->objFromFixture(TestMember::class, 'admin');
|
||||
$form->loadDataFrom($member);
|
||||
$checkboxSetField = $form->Fields()->fieldByName('Groups');
|
||||
@ -102,6 +102,8 @@ class GroupTest extends FunctionalTest
|
||||
|
||||
// Persists after writing to DB
|
||||
$group->write();
|
||||
|
||||
/** @var Group $group */
|
||||
$group = Group::get()->byID($group->ID);
|
||||
$this->assertEquals(array($member->ID), array_values($group->Members()->getIDList()));
|
||||
}
|
||||
|
@ -34,9 +34,9 @@ class MemberTest extends FunctionalTest
|
||||
Member::class => '*',
|
||||
];
|
||||
|
||||
public function __construct()
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
parent::__construct();
|
||||
parent::setUpBeforeClass();
|
||||
|
||||
//Setting the locale has to happen in the constructor (using the setUp and tearDown methods doesn't work)
|
||||
//This is because the test relies on the yaml file being interpreted according to a particular date format
|
||||
|
@ -229,7 +229,7 @@ class SecurityTest extends FunctionalTest
|
||||
public function testMemberIDInSessionDoesntExistInDatabaseHasToLogin()
|
||||
{
|
||||
/* Log in with a Member ID that doesn't exist in the DB */
|
||||
$this->session()->inst_set('loggedInAs', 500);
|
||||
$this->session()->set('loggedInAs', 500);
|
||||
|
||||
$this->autoFollowRedirection = true;
|
||||
|
||||
@ -244,13 +244,13 @@ class SecurityTest extends FunctionalTest
|
||||
$this->autoFollowRedirection = false;
|
||||
|
||||
/* Log the user out */
|
||||
$this->session()->inst_set('loggedInAs', null);
|
||||
$this->session()->set('loggedInAs', null);
|
||||
}
|
||||
|
||||
public function testLoginUsernamePersists()
|
||||
{
|
||||
// Test that username does not persist
|
||||
$this->session()->inst_set('SessionForms.MemberLoginForm.Email', 'myuser@silverstripe.com');
|
||||
$this->session()->set('SessionForms.MemberLoginForm.Email', 'myuser@silverstripe.com');
|
||||
Security::config()->remember_username = false;
|
||||
$this->get(Config::inst()->get(Security::class, 'login_url'));
|
||||
$items = $this
|
||||
@ -264,7 +264,7 @@ class SecurityTest extends FunctionalTest
|
||||
$this->assertEquals('off', (string)$form[0]->attributes()->autocomplete);
|
||||
|
||||
// Test that username does persist when necessary
|
||||
$this->session()->inst_set('SessionForms.MemberLoginForm.Email', 'myuser@silverstripe.com');
|
||||
$this->session()->set('SessionForms.MemberLoginForm.Email', 'myuser@silverstripe.com');
|
||||
Security::config()->remember_username = true;
|
||||
$this->get(Config::inst()->get(Security::class, 'login_url'));
|
||||
$items = $this
|
||||
@ -289,7 +289,7 @@ class SecurityTest extends FunctionalTest
|
||||
"Internal relative BackURLs work when passed through to login form"
|
||||
);
|
||||
// Log the user out
|
||||
$this->session()->inst_set('loggedInAs', null);
|
||||
$this->session()->set('loggedInAs', null);
|
||||
|
||||
// Test internal absolute redirect
|
||||
$response = $this->doTestLoginForm(
|
||||
@ -304,7 +304,7 @@ class SecurityTest extends FunctionalTest
|
||||
"Internal absolute BackURLs work when passed through to login form"
|
||||
);
|
||||
// Log the user out
|
||||
$this->session()->inst_set('loggedInAs', null);
|
||||
$this->session()->set('loggedInAs', null);
|
||||
|
||||
// Test external redirect
|
||||
$response = $this->doTestLoginForm('noexpiry@silverstripe.com', '1nitialPassword', 'http://myspoofedhost.com');
|
||||
@ -324,7 +324,7 @@ class SecurityTest extends FunctionalTest
|
||||
);
|
||||
|
||||
// Log the user out
|
||||
$this->session()->inst_set('loggedInAs', null);
|
||||
$this->session()->set('loggedInAs', null);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -336,7 +336,7 @@ class SecurityTest extends FunctionalTest
|
||||
$badResponse = $this->doTestLoginForm('testuser@example.com', 'badpassword');
|
||||
$this->assertEquals(302, $badResponse->getStatusCode());
|
||||
$this->assertRegExp('/Security\/login/', $badResponse->getHeader('Location'));
|
||||
$this->assertNull($this->session()->inst_get('loggedInAs'));
|
||||
$this->assertNull($this->session()->get('loggedInAs'));
|
||||
|
||||
/* UNEXPIRED PASSWORD GO THROUGH WITHOUT A HITCH */
|
||||
$goodResponse = $this->doTestLoginForm('testuser@example.com', '1nitialPassword');
|
||||
@ -345,7 +345,7 @@ class SecurityTest extends FunctionalTest
|
||||
Controller::join_links(Director::absoluteBaseURL(), 'test/link'),
|
||||
$goodResponse->getHeader('Location')
|
||||
);
|
||||
$this->assertEquals($this->idFromFixture(Member::class, 'test'), $this->session()->inst_get('loggedInAs'));
|
||||
$this->assertEquals($this->idFromFixture(Member::class, 'test'), $this->session()->get('loggedInAs'));
|
||||
|
||||
$this->logOut();
|
||||
|
||||
@ -358,7 +358,7 @@ class SecurityTest extends FunctionalTest
|
||||
);
|
||||
$this->assertEquals(
|
||||
$this->idFromFixture(Member::class, 'expiredpassword'),
|
||||
$this->session()->inst_get('loggedInAs')
|
||||
$this->session()->get('loggedInAs')
|
||||
);
|
||||
|
||||
// Make sure it redirects correctly after the password has been changed
|
||||
@ -383,7 +383,7 @@ class SecurityTest extends FunctionalTest
|
||||
Controller::join_links(Director::absoluteBaseURL(), 'test/back'),
|
||||
$changedResponse->getHeader('Location')
|
||||
);
|
||||
$this->assertEquals($this->idFromFixture(Member::class, 'test'), $this->session()->inst_get('loggedInAs'));
|
||||
$this->assertEquals($this->idFromFixture(Member::class, 'test'), $this->session()->get('loggedInAs'));
|
||||
|
||||
// Check if we can login with the new password
|
||||
$this->logOut();
|
||||
@ -393,7 +393,7 @@ class SecurityTest extends FunctionalTest
|
||||
Controller::join_links(Director::absoluteBaseURL(), 'test/link'),
|
||||
$goodResponse->getHeader('Location')
|
||||
);
|
||||
$this->assertEquals($this->idFromFixture(Member::class, 'test'), $this->session()->inst_get('loggedInAs'));
|
||||
$this->assertEquals($this->idFromFixture(Member::class, 'test'), $this->session()->get('loggedInAs'));
|
||||
}
|
||||
|
||||
public function testChangePasswordFromLostPassword()
|
||||
@ -429,13 +429,13 @@ class SecurityTest extends FunctionalTest
|
||||
// Follow redirection to form without hash in GET parameter
|
||||
$response = $this->get('Security/changepassword');
|
||||
$changedResponse = $this->doTestChangepasswordForm('1nitialPassword', 'changedPassword');
|
||||
$this->assertEquals($this->idFromFixture(Member::class, 'test'), $this->session()->inst_get('loggedInAs'));
|
||||
$this->assertEquals($this->idFromFixture(Member::class, 'test'), $this->session()->get('loggedInAs'));
|
||||
|
||||
// Check if we can login with the new password
|
||||
$this->logOut();
|
||||
$goodResponse = $this->doTestLoginForm('testuser@example.com', 'changedPassword');
|
||||
$this->assertEquals(302, $goodResponse->getStatusCode());
|
||||
$this->assertEquals($this->idFromFixture(Member::class, 'test'), $this->session()->inst_get('loggedInAs'));
|
||||
$this->assertEquals($this->idFromFixture(Member::class, 'test'), $this->session()->get('loggedInAs'));
|
||||
|
||||
$admin = DataObject::get_by_id(Member::class, $admin->ID, false);
|
||||
$this->assertNull($admin->LockedOutUntil);
|
||||
@ -487,7 +487,7 @@ class SecurityTest extends FunctionalTest
|
||||
|
||||
$this->doTestLoginForm('testuser@example.com', '1nitialPassword');
|
||||
$this->assertNull(
|
||||
$this->session()->inst_get('loggedInAs'),
|
||||
$this->session()->get('loggedInAs'),
|
||||
'The user can\'t log in after being locked out, even with the right password'
|
||||
);
|
||||
|
||||
@ -497,7 +497,7 @@ class SecurityTest extends FunctionalTest
|
||||
$member->write();
|
||||
$this->doTestLoginForm('testuser@example.com', '1nitialPassword');
|
||||
$this->assertEquals(
|
||||
$this->session()->inst_get('loggedInAs'),
|
||||
$this->session()->get('loggedInAs'),
|
||||
$member->ID,
|
||||
'After lockout expires, the user can login again'
|
||||
);
|
||||
@ -509,7 +509,7 @@ class SecurityTest extends FunctionalTest
|
||||
for ($i = 1; $i < Member::config()->lock_out_after_incorrect_logins; $i++) {
|
||||
$this->doTestLoginForm('testuser@example.com', 'incorrectpassword');
|
||||
}
|
||||
$this->assertNull($this->session()->inst_get('loggedInAs'));
|
||||
$this->assertNull($this->session()->get('loggedInAs'));
|
||||
$this->assertHasMessage(
|
||||
_t('SilverStripe\\Security\\Member.ERRORWRONGCRED', 'The provided details don\'t seem to be correct. Please try again.'),
|
||||
'The user can retry with a wrong password after the lockout expires'
|
||||
@ -517,7 +517,7 @@ class SecurityTest extends FunctionalTest
|
||||
|
||||
$this->doTestLoginForm('testuser@example.com', '1nitialPassword');
|
||||
$this->assertEquals(
|
||||
$this->session()->inst_get('loggedInAs'),
|
||||
$this->session()->get('loggedInAs'),
|
||||
$member->ID,
|
||||
'The user can login successfully after lockout expires, if staying below the threshold'
|
||||
);
|
||||
@ -659,7 +659,7 @@ class SecurityTest extends FunctionalTest
|
||||
public function doTestLoginForm($email, $password, $backURL = 'test/link')
|
||||
{
|
||||
$this->get(Config::inst()->get(Security::class, 'logout_url'));
|
||||
$this->session()->inst_set('BackURL', $backURL);
|
||||
$this->session()->set('BackURL', $backURL);
|
||||
$this->get(Config::inst()->get(Security::class, 'login_url'));
|
||||
|
||||
return $this->submitForm(
|
||||
@ -717,7 +717,7 @@ class SecurityTest extends FunctionalTest
|
||||
*/
|
||||
protected function getValidationResult()
|
||||
{
|
||||
$result = $this->session()->inst_get('FormInfo.MemberLoginForm_LoginForm.result');
|
||||
$result = $this->session()->get('FormInfo.MemberLoginForm_LoginForm.result');
|
||||
if ($result) {
|
||||
return unserialize($result);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user