mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #3845 from dnadesign/gridfieldexportbutton
FIX GridFieldExportButton should honour can method.
This commit is contained in:
commit
7923b88652
@ -132,6 +132,7 @@ class GridFieldExportButton implements GridField_HTMLProvider, GridField_ActionP
|
||||
}
|
||||
|
||||
foreach($items->limit(null) as $item) {
|
||||
if($item->hasMethod('canView') && $item->canView()) {
|
||||
$columnData = array();
|
||||
|
||||
foreach($csvColumns as $columnSource => $columnHeader) {
|
||||
@ -152,6 +153,7 @@ class GridFieldExportButton implements GridField_HTMLProvider, GridField_ActionP
|
||||
}
|
||||
$fileData .= implode($separator, $columnData);
|
||||
$fileData .= "\n";
|
||||
}
|
||||
|
||||
$item->destroy();
|
||||
}
|
||||
|
@ -1,4 +1,9 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package framework
|
||||
* @subpackage tests
|
||||
*/
|
||||
class GridFieldExportButtonTest extends SapphireTest {
|
||||
|
||||
protected $list;
|
||||
@ -10,7 +15,8 @@ class GridFieldExportButtonTest extends SapphireTest {
|
||||
protected static $fixture_file = 'GridFieldExportButtonTest.yml';
|
||||
|
||||
protected $extraDataObjects = array(
|
||||
'GridFieldExportButtonTest_Team'
|
||||
'GridFieldExportButtonTest_Team',
|
||||
'GridFieldExportButtonTest_NoView'
|
||||
);
|
||||
|
||||
public function setUp() {
|
||||
@ -22,6 +28,21 @@ class GridFieldExportButtonTest extends SapphireTest {
|
||||
$this->gridField = new GridField('testfield', 'testfield', $this->list, $config);
|
||||
}
|
||||
|
||||
public function testCanView() {
|
||||
$list = new DataList('GridFieldExportButtonTest_NoView');
|
||||
|
||||
$button = new GridFieldExportButton();
|
||||
$button->setExportColumns(array('Name' => 'My Name'));
|
||||
|
||||
$config = GridFieldConfig::create()->addComponent(new GridFieldExportButton());
|
||||
$gridField = new GridField('testfield', 'testfield', $list, $config);
|
||||
|
||||
$this->assertEquals(
|
||||
"\"My Name\"\n",
|
||||
$button->generateExportFileData($gridField)
|
||||
);
|
||||
}
|
||||
|
||||
public function testGenerateFileDataBasicFields() {
|
||||
$button = new GridFieldExportButton();
|
||||
$button->setExportColumns(array('Name' => 'My Name'));
|
||||
@ -94,8 +115,12 @@ class GridFieldExportButtonTest extends SapphireTest {
|
||||
$button->generateExportFileData($this->gridField)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @package framework
|
||||
* @subpackage tests
|
||||
*/
|
||||
class GridFieldExportButtonTest_Team extends DataObject implements TestOnly {
|
||||
|
||||
private static $db = array(
|
||||
@ -109,3 +134,20 @@ class GridFieldExportButtonTest_Team extends DataObject implements TestOnly {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @package framework
|
||||
* @subpackage tests
|
||||
*/
|
||||
class GridFieldExportButtonTest_NoView extends DataObject implements TestOnly {
|
||||
|
||||
private static $db = array(
|
||||
'Name' => 'Varchar',
|
||||
'City' => 'Varchar'
|
||||
);
|
||||
|
||||
public function canView($member = null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -6,3 +6,6 @@ GridFieldExportButtonTest_Team:
|
||||
Name: Test2
|
||||
City: City2
|
||||
|
||||
GridFieldExportButtonTest_NoView:
|
||||
item1:
|
||||
Name: Foo
|
Loading…
Reference in New Issue
Block a user