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