MINOR Apply PSR-2 linting

This commit is contained in:
Robbie Averill 2017-09-01 13:02:18 +12:00 committed by Daniel Hensby
parent 3ee4ff4cb7
commit 0ad1fc367e
No known key found for this signature in database
GPG Key ID: 5DE415D786BBB2FD
3 changed files with 46 additions and 41 deletions

View File

@ -158,7 +158,7 @@ class GridFieldAddNewMultiClass implements GridField_HTMLProvider, GridField_URL
} }
$sanitised = array(); $sanitised = array();
foreach($result as $class=>$title) { foreach ($result as $class => $title) {
$sanitised[$this->sanitiseClassName($class)] = $title; $sanitised[$this->sanitiseClassName($class)] = $title;
} }

View File

@ -516,11 +516,11 @@ class GridFieldOrderableRows extends RequestHandler implements
$sortTable = $this->getSortTable($list); $sortTable = $this->getSortTable($list);
$additionalSQL = ''; $additionalSQL = '';
$baseTable = $sortTable; $baseTable = $sortTable;
if(class_exists($sortTable)) { if (class_exists($sortTable)) {
$baseTable = singleton($sortTable)->baseTable(); $baseTable = singleton($sortTable)->baseTable();
} }
$isBaseTable = ($baseTable == $sortTable); $isBaseTable = ($baseTable == $sortTable);
if(!$list instanceof ManyManyList && $isBaseTable){ if (!$list instanceof ManyManyList && $isBaseTable) {
$additionalSQL = ', "LastEdited" = NOW()'; $additionalSQL = ', "LastEdited" = NOW()';
} }
@ -535,7 +535,7 @@ class GridFieldOrderableRows extends RequestHandler implements
$this->getSortTableClauseForIds($list, $id) $this->getSortTableClauseForIds($list, $id)
)); ));
if(!$isBaseTable) { if (!$isBaseTable) {
DB::query(sprintf( DB::query(sprintf(
'UPDATE "%s" SET "LastEdited" = NOW() WHERE %s', 'UPDATE "%s" SET "LastEdited" = NOW() WHERE %s',
$baseTable, $baseTable,
@ -570,11 +570,11 @@ class GridFieldOrderableRows extends RequestHandler implements
$additionalSQL = ''; $additionalSQL = '';
$baseTable = $table; $baseTable = $table;
if(class_exists($table)) { if (class_exists($table)) {
$baseTable = singleton($table)->baseTable(); $baseTable = singleton($table)->baseTable();
} }
$isBaseTable = ($baseTable == $table); $isBaseTable = ($baseTable == $table);
if(!$list instanceof ManyManyList && $isBaseTable){ if (!$list instanceof ManyManyList && $isBaseTable) {
$additionalSQL = ', "LastEdited" = NOW()'; $additionalSQL = ', "LastEdited" = NOW()';
} }
@ -591,7 +591,7 @@ class GridFieldOrderableRows extends RequestHandler implements
$this->getSortTableClauseForIds($list, $id) $this->getSortTableClauseForIds($list, $id)
)); ));
if(!$isBaseTable) { if (!$isBaseTable) {
DB::query(sprintf( DB::query(sprintf(
'UPDATE "%s" SET "LastEdited" = NOW() WHERE %s', 'UPDATE "%s" SET "LastEdited" = NOW() WHERE %s',
$baseTable, $baseTable,

View File

@ -13,54 +13,59 @@ use SilverStripe\Forms\GridField\GridFieldDetailForm;
use Symbiote\GridFieldExtensions\GridFieldAddNewMultiClass; use Symbiote\GridFieldExtensions\GridFieldAddNewMultiClass;
use Symbiote\GridFieldExtensions\GridFieldAddNewMultiClassHandler; use Symbiote\GridFieldExtensions\GridFieldAddNewMultiClassHandler;
class GridFieldAddNewMultiClassWithNamespacesTest extends SapphireTest { class GridFieldAddNewMultiClassWithNamespacesTest extends SapphireTest
{
public function testGetClassesWithNamespaces() { public function testGetClassesWithNamespaces()
$grid = new GridField('TestGridField'); {
$grid->setModelClass('Symbiote\\Test\\NamespacedClass'); $grid = new GridField('TestGridField');
$grid->setModelClass('Symbiote\\Test\\NamespacedClass');
$component = new GridFieldAddNewMultiClass(); $component = new GridFieldAddNewMultiClass();
$this->assertEquals( $this->assertEquals(
array( array(
'Symbiote-Test-NamespacedClass' => 'NamespacedClass' 'Symbiote-Test-NamespacedClass' => 'NamespacedClass'
), ),
$component->getClasses($grid), $component->getClasses($grid),
'Namespaced classes are sanitised' 'Namespaced classes are sanitised'
); );
} }
public function testHandleAddWithNamespaces() { public function testHandleAddWithNamespaces()
$grid = new GridField('TestGridField'); {
$grid->getConfig()->addComponent(new GridFieldDetailForm()); $grid = new GridField('TestGridField');
$grid->setModelClass('Symbiote\\Test\\NamespacedClass'); $grid->getConfig()->addComponent(new GridFieldDetailForm());
$grid->setForm(Form::create(Controller::create(), 'test', FieldList::create(), FieldList::create())); $grid->setModelClass('Symbiote\\Test\\NamespacedClass');
$grid->setForm(Form::create(Controller::create(), 'test', FieldList::create(), FieldList::create()));
$request = new HTTPRequest('POST', 'test'); $request = new HTTPRequest('POST', 'test');
$request->setRouteParams(array('ClassName' => 'Symbiote-Test-NamespacedClass')); $request->setRouteParams(array('ClassName' => 'Symbiote-Test-NamespacedClass'));
$component = new GridFieldAddNewMultiClass(); $component = new GridFieldAddNewMultiClass();
$response = $component->handleAdd($grid, $request); $response = $component->handleAdd($grid, $request);
$record = new \ReflectionProperty(GridFieldAddNewMultiClassHandler::class, 'record');
$record->setAccessible(true);
$this->assertInstanceOf('Symbiote\\Test\\NamespacedClass', $record->getValue($response));
}
$record = new \ReflectionProperty(GridFieldAddNewMultiClassHandler::class, 'record');
$record->setAccessible(true);
$this->assertInstanceOf('Symbiote\\Test\\NamespacedClass', $record->getValue($response));
}
} }
/**#@+ /**#@+
* @ignore * @ignore
*/ */
class NamespacedClass implements TestOnly { class NamespacedClass implements TestOnly
public function i18n_singular_name() { {
return 'NamespacedClass'; public function i18n_singular_name()
} {
return 'NamespacedClass';
}
public function canCreate() { public function canCreate()
return true; {
} return true;
}
} }
/**#@-*/ /**#@-*/