Skip to content

Commit

Permalink
UnitTests
Browse files Browse the repository at this point in the history
  • Loading branch information
ThaDafinser committed Oct 18, 2013
1 parent 46cb710 commit 165b7bd
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 32 deletions.
6 changes: 3 additions & 3 deletions src/ZfcDatagrid/Renderer/AbstractRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
22 changes: 10 additions & 12 deletions src/ZfcDatagrid/Renderer/PHPExcel/Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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();
Expand Down
15 changes: 0 additions & 15 deletions tests/ZfcDatagridTest/Column/AbstractColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
48 changes: 48 additions & 0 deletions tests/ZfcDatagridTest/Column/ExternalDataTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
namespace ZfcDatagridTest\Column;

use PHPUnit_Framework_TestCase;
use ZfcDatagrid\Column;
use ZfcDatagrid\Column\DataPopulation;

/**
* @group Column
* @covers ZfcDatagrid\Column\ExternalData
*/
class ExternalDataTest extends PHPUnit_Framework_TestCase
{

public function testConstruct()
{
$column = new Column\ExternalData('myData');

$this->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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
Expand Down
100 changes: 100 additions & 0 deletions tests/ZfcDatagridTest/Renderer/AbstractRendererTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?php
namespace ZfcDatagridTest\Renderer;

use ZfcDatagrid\Column\DataPopulation;
use ZfcDatagrid\Filter;
use ZfcDatagrid\Column\Type;
use ZfcDatagrid\Column\Style;
use PHPUnit_Framework_TestCase;

/**
* @group Column
* @covers ZfcDatagrid\Renderer\AbstractRenderer
*/
class AbstractRendererTest extends PHPUnit_Framework_TestCase
{

public function testOptions()
{
$renderer = $this->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());
}
}

0 comments on commit 165b7bd

Please sign in to comment.