diff --git a/src/ZfcDatagrid/Renderer/AbstractRenderer.php b/src/ZfcDatagrid/Renderer/AbstractRenderer.php index feac6e1d..fe3c1c1d 100644 --- a/src/ZfcDatagrid/Renderer/AbstractRenderer.php +++ b/src/ZfcDatagrid/Renderer/AbstractRenderer.php @@ -135,9 +135,9 @@ public function getTemplate() */ public function getTemplatePathDefault($type = 'layout') { - $options = $this->getOptions(); - if (isset($options['renderer'][$this->getName()]['templates'][$type])) { - return $options['renderer'][$this->getName()]['templates'][$type]; + $optionsRenderer = $this->getOptionsRenderer(); + if (isset($optionsRenderer['templates'][$type])) { + return $optionsRenderer['templates'][$type]; } if ($type === 'layout') { diff --git a/src/ZfcDatagrid/Renderer/PHPExcel/Renderer.php b/src/ZfcDatagrid/Renderer/PHPExcel/Renderer.php index 4cac55d9..c58fd482 100644 --- a/src/ZfcDatagrid/Renderer/PHPExcel/Renderer.php +++ b/src/ZfcDatagrid/Renderer/PHPExcel/Renderer.php @@ -21,25 +21,25 @@ class Renderer extends AbstractRenderer 'ZfcDatagrid\Column\Type\DateTime', 'ZfcDatagrid\Column\Type\Number', 'ZfcDatagrid\Column\Type\PhpArray', - 'ZfcDatagrid\Column\Type\String' + 'ZfcDatagrid\Column\Type\String' ); - - public function getName () + + public function getName() { return 'PHPExcel'; } - public function isExport () + public function isExport() { return true; } - public function isHtml () + public function isHtml() { return false; } - public function execute () + public function execute() { $options = $this->getOptions(); $optionsExport = $options['settings']['export']; @@ -71,13 +71,11 @@ public function execute () $columnsToExport[] = $column; } } - if(count($columnsToExport) === 0){ + if (count($columnsToExport) === 0) { throw new \Exception('No columns to export available'); } $this->calculateColumnWidth($columnsToExport); - - $xColumn = 0; $yRow = $optionsRenderer['startRowData']; foreach ($columnsToExport as $column) { @@ -118,7 +116,7 @@ public function execute () case 'ZfcDatagrid\Column\Style\Bold': $columnStyle->getFont()->setBold(true); break; - + case 'ZfcDatagrid\Column\Style\Italic': $columnStyle->getFont()->setItalic(true); break; @@ -201,7 +199,7 @@ public function execute () * * @param array $columns */ - protected function calculateColumnWidth (array $columns) + protected function calculateColumnWidth(array $columns) { // First make sure the columns width is 100 "percent" $this->calculateColumnWidthPercent($columns); @@ -221,7 +219,7 @@ protected function calculateColumnWidth (array $columns) * * @param PHPExcel $phpExcel */ - protected function setPrinting (PHPExcel $phpExcel) + protected function setPrinting(PHPExcel $phpExcel) { $options = $this->getOptions(); $optionsRenderer = $this->getOptionsRenderer(); diff --git a/tests/ZfcDatagridTest/Column/AbstractColumnTest.php b/tests/ZfcDatagridTest/Column/AbstractColumnTest.php index ce26c106..f70b0308 100644 --- a/tests/ZfcDatagridTest/Column/AbstractColumnTest.php +++ b/tests/ZfcDatagridTest/Column/AbstractColumnTest.php @@ -201,23 +201,8 @@ public function testSetGet () ), $column->getRendererParameters('someRenderer')); -// $object = new DataPopulation\Object(); -// $object->setObject(new DataPopulation\Object\Gravatar()); -// $this->assertEquals(false, $column->hasDataPopulation()); -// $column->setDataPopulation($object); -// $this->assertEquals(true, $column->hasDataPopulation()); -// $this->assertInstanceOf('ZfcDatagrid\Column\DataPopulation\Object', $column->getDataPopulation()); } -// public function testException(){ -// /* @var $column \ZfcDatagrid\Column\AbstractColumn */ -// $column = $this->getMockForAbstractClass('ZfcDatagrid\Column\AbstractColumn'); - -// $object = new DataPopulation\Object(); -// $this->setExpectedException('Exception'); -// $column->setDataPopulation($object); -// } - public function testRowClick(){ /* @var $column \ZfcDatagrid\Column\AbstractColumn */ $column = $this->getMockForAbstractClass('ZfcDatagrid\Column\AbstractColumn'); diff --git a/tests/ZfcDatagridTest/Column/ExternalDataTest.php b/tests/ZfcDatagridTest/Column/ExternalDataTest.php new file mode 100644 index 00000000..e4f3285c --- /dev/null +++ b/tests/ZfcDatagridTest/Column/ExternalDataTest.php @@ -0,0 +1,48 @@ +assertEquals('myData', $column->getUniqueId()); + + $this->assertFalse($column->isUserFilterEnabled()); + $this->assertFalse($column->isUserSortEnabled()); + } + + public function testSetGetData() + { + $column = new Column\ExternalData('myData'); + + + $object = new DataPopulation\Object(); + $object->setObject(new DataPopulation\Object\Gravatar()); + $this->assertEquals(false, $column->hasDataPopulation()); + + $column->setDataPopulation($object); + + $this->assertEquals(true, $column->hasDataPopulation()); + $this->assertInstanceOf('ZfcDatagrid\Column\DataPopulation\Object', $column->getDataPopulation()); + } + + public function testException() + { + $column = new Column\ExternalData('myData'); + + $object = new DataPopulation\Object(); + $this->setExpectedException('Exception'); + $column->setDataPopulation($object); + } +} \ No newline at end of file diff --git a/tests/ZfcDatagridTest/Column/StandardTest.php b/tests/ZfcDatagridTest/Column/SelectTest.php similarity index 93% rename from tests/ZfcDatagridTest/Column/StandardTest.php rename to tests/ZfcDatagridTest/Column/SelectTest.php index 03820e78..a534c187 100644 --- a/tests/ZfcDatagridTest/Column/StandardTest.php +++ b/tests/ZfcDatagridTest/Column/SelectTest.php @@ -7,9 +7,9 @@ /** * @group Column - * @covers ZfcDatagrid\Column\Standard + * @covers ZfcDatagrid\Column\Select */ -class StandardTest extends PHPUnit_Framework_TestCase +class SelectTest extends PHPUnit_Framework_TestCase { public function testConstructDefaultBoth () diff --git a/tests/ZfcDatagridTest/Renderer/AbstractRendererTest.php b/tests/ZfcDatagridTest/Renderer/AbstractRendererTest.php new file mode 100644 index 00000000..028e908a --- /dev/null +++ b/tests/ZfcDatagridTest/Renderer/AbstractRendererTest.php @@ -0,0 +1,100 @@ +getMockForAbstractClass('ZfcDatagrid\Renderer\AbstractRenderer'); + $renderer->setOptions(array( + 'test' + )); + + $this->assertEquals(array( + 'test' + ), $renderer->getOptions()); + } + + public function testRendererOptions() + { + $renderer = $this->getMockForAbstractClass('ZfcDatagrid\Renderer\AbstractRenderer'); + $renderer->expects($this->any()) + ->method('getName') + ->will($this->returnValue('abstract')); + + $this->assertEquals(array(), $renderer->getOptionsRenderer()); + + $renderer->setOptions(array( + 'renderer' => array( + 'abstract' => array( + 'test' + ) + ) + )); + + $this->assertEquals(array( + 'test' + ), $renderer->getOptionsRenderer()); + } + + public function testViewModel() + { + $renderer = $this->getMockForAbstractClass('ZfcDatagrid\Renderer\AbstractRenderer'); + + $this->assertNull($renderer->getViewModel()); + + $viewModel = $this->getMock('Zend\View\Model\ViewModel'); + $renderer->setViewModel($viewModel); + $this->assertSame($viewModel, $renderer->getViewModel()); + } + + public function testTemplate() + { + $renderer = $this->getMockForAbstractClass('ZfcDatagrid\Renderer\AbstractRenderer'); + $renderer->expects($this->any()) + ->method('getName') + ->will($this->returnValue('abstract')); + + $this->assertEquals('zfc-datagrid/renderer/abstract/layout', $renderer->getTemplate()); + $this->assertEquals('zfc-datagrid/toolbar/toolbar', $renderer->getToolbarTemplate()); + + $renderer->setTemplate('blubb/layout'); + $this->assertEquals('blubb/layout', $renderer->getTemplate()); + + $renderer->setToolbarTemplate('blubb/toolbar'); + $this->assertEquals('blubb/toolbar', $renderer->getToolbarTemplate()); + } + + public function testTemplateConfig() + { + $renderer = $this->getMockForAbstractClass('ZfcDatagrid\Renderer\AbstractRenderer'); + $renderer->expects($this->any()) + ->method('getName') + ->will($this->returnValue('abstract')); + + $renderer->setOptions(array( + 'renderer' => array( + 'abstract' => array( + 'templates' => array( + 'layout' => 'config/my/template', + 'toolbar' => 'config/my/toolbar' + ) + ) + ) + )); + + $this->assertEquals('config/my/template', $renderer->getTemplate()); + $this->assertEquals('config/my/toolbar', $renderer->getToolbarTemplate()); + } +} \ No newline at end of file