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