mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
FIX: Ensure GridFieldDetailForm has the current record validator.
Currently the validator is only set through ModelAdmin and not through GridField directly. This will set the validator based on the record unless a custom validator has been provided. http://www.silverstripe.org/data-model-questions/show/34650?start=8#post331958
This commit is contained in:
parent
5e3420a640
commit
4ea62b44f9
@ -90,6 +90,12 @@ class GridFieldDetailForm implements GridField_URLHandler {
|
||||
$handler = Object::create($class, $gridField, $this, $record, $controller, $this->name);
|
||||
$handler->setTemplate($this->template);
|
||||
|
||||
// if no validator has been set on the GridField and the record has a
|
||||
// CMS validator, use that.
|
||||
if(!$this->getValidator() && method_exists($record, 'getCMSValidator')) {
|
||||
$this->setValidator($record->getCMSValidator());
|
||||
}
|
||||
|
||||
return $handler->handleRequest($request, DataModel::inst());
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,11 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package framework
|
||||
* @subpackage tests
|
||||
*/
|
||||
class GridFieldDetailFormTest extends FunctionalTest {
|
||||
|
||||
protected static $fixture_file = 'GridFieldDetailFormTest.yml';
|
||||
|
||||
protected $extraDataObjects = array(
|
||||
@ -9,6 +14,48 @@ class GridFieldDetailFormTest extends FunctionalTest {
|
||||
'GridFieldDetailFormTest_Category',
|
||||
);
|
||||
|
||||
public function testValidator() {
|
||||
$this->logInWithPermission('ADMIN');
|
||||
|
||||
$response = $this->get('GridFieldDetailFormTest_Controller');
|
||||
$this->assertFalse($response->isError());
|
||||
$parser = new CSSContentParser($response->getBody());
|
||||
$addlinkitem = $parser->getBySelector('.ss-gridfield .new-link');
|
||||
$addlink = (string) $addlinkitem[0]['href'];
|
||||
|
||||
$response = $this->get($addlink);
|
||||
$this->assertFalse($response->isError());
|
||||
|
||||
$parser = new CSSContentParser($response->getBody());
|
||||
$addform = $parser->getBySelector('#Form_ItemEditForm');
|
||||
$addformurl = (string) $addform[0]['action'];
|
||||
|
||||
$response = $this->post(
|
||||
$addformurl,
|
||||
array(
|
||||
'FirstName' => 'Jeremiah',
|
||||
'ajax' => 1,
|
||||
'action_doSave' => 1
|
||||
)
|
||||
);
|
||||
|
||||
$parser = new CSSContentParser($response->getBody());
|
||||
$errors = $parser->getBySelector('span.required');
|
||||
$this->assertEquals(1, count($errors));
|
||||
|
||||
$response = $this->post(
|
||||
$addformurl,
|
||||
array(
|
||||
'ajax' => 1,
|
||||
'action_doSave' => 1
|
||||
)
|
||||
);
|
||||
|
||||
$parser = new CSSContentParser($response->getBody());
|
||||
$errors = $parser->getBySelector('span.required');
|
||||
$this->assertEquals(2, count($errors));
|
||||
}
|
||||
|
||||
public function testAddForm() {
|
||||
$this->logInWithPermission('ADMIN');
|
||||
$group = GridFieldDetailFormTest_PeopleGroup::get()
|
||||
@ -247,7 +294,13 @@ class GridFieldDetailFormTest extends FunctionalTest {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @package framework
|
||||
* @subpackage tests
|
||||
*/
|
||||
|
||||
class GridFieldDetailFormTest_Person extends DataObject implements TestOnly {
|
||||
|
||||
private static $db = array(
|
||||
'FirstName' => 'Varchar',
|
||||
'Surname' => 'Varchar'
|
||||
@ -280,8 +333,19 @@ class GridFieldDetailFormTest_Person extends DataObject implements TestOnly {
|
||||
);
|
||||
return $fields;
|
||||
}
|
||||
|
||||
public function getCMSValidator() {
|
||||
return new RequiredFields(array(
|
||||
'FirstName', 'Surname'
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @package framework
|
||||
* @subpackage tests
|
||||
*/
|
||||
|
||||
class GridFieldDetailFormTest_PeopleGroup extends DataObject implements TestOnly {
|
||||
private static $db = array(
|
||||
'Name' => 'Varchar'
|
||||
@ -306,6 +370,11 @@ class GridFieldDetailFormTest_PeopleGroup extends DataObject implements TestOnly
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @package framework
|
||||
* @subpackage tests
|
||||
*/
|
||||
|
||||
class GridFieldDetailFormTest_Category extends DataObject implements TestOnly {
|
||||
|
||||
private static $db = array(
|
||||
@ -331,6 +400,11 @@ class GridFieldDetailFormTest_Category extends DataObject implements TestOnly {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @package framework
|
||||
* @subpackage tests
|
||||
*/
|
||||
|
||||
class GridFieldDetailFormTest_Controller extends Controller implements TestOnly {
|
||||
|
||||
private static $allowed_actions = array('Form');
|
||||
@ -354,6 +428,11 @@ class GridFieldDetailFormTest_Controller extends Controller implements TestOnly
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @package framework
|
||||
* @subpackage tests
|
||||
*/
|
||||
|
||||
class GridFieldDetailFormTest_GroupController extends Controller implements TestOnly {
|
||||
|
||||
private static $allowed_actions = array('Form');
|
||||
@ -370,6 +449,11 @@ class GridFieldDetailFormTest_GroupController extends Controller implements Test
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @package framework
|
||||
* @subpackage tests
|
||||
*/
|
||||
|
||||
class GridFieldDetailFormTest_CategoryController extends Controller implements TestOnly {
|
||||
|
||||
private static $allowed_actions = array('Form');
|
||||
@ -391,5 +475,8 @@ class GridFieldDetailFormTest_CategoryController extends Controller implements T
|
||||
}
|
||||
}
|
||||
|
||||
class GridFieldDetailFormTest_ItemRequest extends GridFieldDetailForm_ItemRequest implements TestOnly {
|
||||
}
|
||||
/**
|
||||
* @package framework
|
||||
* @subpackage tests
|
||||
*/
|
||||
class GridFieldDetailFormTest_ItemRequest extends GridFieldDetailForm_ItemRequest implements TestOnly { }
|
Loading…
Reference in New Issue
Block a user