Skip to content

Commit

Permalink
Added some unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Viburnum committed Aug 17, 2016
1 parent 8056cda commit 74e0f3b
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
13 changes: 10 additions & 3 deletions src/StingerSoft/ExcelCreator/ConfiguredSheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,14 @@ public function applyData($startColumn = 0, $headerRow = 1) {
protected function renderHeaderRow($startColumn = 0, $headerRow = 1) {
$this->sheet->getStyle(\PHPExcel_Cell::stringFromColumnIndex($startColumn) . $headerRow . ':' . \PHPExcel_Cell::stringFromColumnIndex($startColumn + $this->bindings->count() - 1) . $headerRow)->applyFromArray($this->getDefaultHeaderStyling());
foreach($this->bindings as $binding) {
$this->sheet->setCellValueByColumnAndRow($startColumn, $headerRow, $this->decodeHtmlEntity($this->translate($binding->getLabel(), $binding->getLabelTranslationDomain())));
$cell = $this->sheet->getCellByColumnAndRow($startColumn, $headerRow);
$cell->setValue($this->decodeHtmlEntity($this->translate($binding->getLabel(), $binding->getLabelTranslationDomain())));
if($binding->getOutline()) {
$this->sheet->getColumnDimensionByColumn($startColumn)->setOutlineLevel($binding->getOutline());
}
if($binding->getHeaderFontColor() || $binding->getHeaderBackgroundColor()) {
$cell->getStyle()->applyFromArray($this->getDefaultHeaderStyling($binding->getHeaderFontColor(), $binding->getHeaderBackgroundColor()));
}
$startColumn++;
}
}
Expand Down Expand Up @@ -370,17 +374,20 @@ protected function getDefaultDataStyling($fontColor, $bgColor) {
*
* @return string[]
*/
protected function getDefaultHeaderStyling() {
protected function getDefaultHeaderStyling($fontColor = null, $bgColor = null) {
return array(
'font' => array(
'name' => $this->defaultFontFamily,
'size' => $this->defaultHeaderFontSize,
'color'=> array(
'rgb' => $fontColor ?: $this->defaultHeaderFontColor,
),
'bold' => true
),
'fill' => array(
'type' => \PHPExcel_Style_Fill::FILL_SOLID,
'color' => array(
'rgb' => $this->defaultHeaderBackgroundColor
'rgb' => $bgColor ?: $this->defaultHeaderBackgroundColor
)
),
'alignment' => array(
Expand Down
2 changes: 1 addition & 1 deletion src/StingerSoft/ExcelCreator/Formatter/YesNoFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ abstract class YesNoFormatter {

public static function createYesNoFormatter($yesLabel, $noLabel) {
return function($value) use ($yesLabel, $noLabel) {
return $value == true ? $yesLabel : $noLabel;
return filter_var($value, FILTER_VALIDATE_BOOLEAN) === true ? $yesLabel : $noLabel;
};
}
}
23 changes: 23 additions & 0 deletions tests/StingerSoft/ExcelCreator/Formatter/YesNoFormatterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

/*
* This file is part of the Stinger Excel Creator package.
*
* (c) Oliver Kotte <oliver.kotte@stinger-soft.net>
* (c) Florian Meyer <florian.meyer@stinger-soft.net>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace StingerSoft\ExcelCreator\Formatter;

class YesNoFormatterTest extends \PHPUnit_Framework_TestCase {

public function testCreateTranslationFormatter() {
$pirateYesNoformatter = YesNoFormatter::createYesNoFormatter('Arrrr!', 'Avast!');

$this->assertEquals('Arrrr!', $pirateYesNoformatter(true));
$this->assertEquals('Avast!', $pirateYesNoformatter(false));
$this->assertEquals('Avast!', $pirateYesNoformatter('nonono'));
}
}
4 changes: 4 additions & 0 deletions tests/StingerSoft/ExcelCreator/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public function testSimpleCycle() {
$binding->setColumnWidth('auto');
$binding->setWrapText(true);
$binding->setOutline(1);
$binding->setHeaderBackgroundColor('000000');
$binding->setHeaderFontColor('FFFFFF');
$binding->setDataFontColor('$FFFFFF');
$binding->setDataBackgroundColor('$FAFAFA');
$binding->setFormatter(function ($value) {
return strtoupper($value);
});
Expand Down

0 comments on commit 74e0f3b

Please sign in to comment.