-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from hoogi91/feature/more-table-options
Feature/more table options
- Loading branch information
Showing
12 changed files
with
354 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
namespace Hoogi91\Spreadsheets\ViewHelpers\Cell; | ||
|
||
use Closure; | ||
use Hoogi91\Spreadsheets\Domain\ValueObject\CellDataValueObject; | ||
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; | ||
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; | ||
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic; | ||
|
||
/** | ||
* Class RenderViewHelper | ||
* @package Hoogi91\Spreadsheets\ViewHelpers\Cell | ||
*/ | ||
class RenderViewHelper extends AbstractViewHelper | ||
{ | ||
use CompileWithRenderStatic; | ||
|
||
/** | ||
* @var bool | ||
*/ | ||
protected $escapeChildren = false; | ||
|
||
/** | ||
* @var bool | ||
*/ | ||
protected $escapeOutput = false; | ||
|
||
/** | ||
* Initialize arguments. | ||
*/ | ||
public function initializeArguments(): void | ||
{ | ||
parent::initializeArguments(); | ||
$this->registerArgument( | ||
'cell', | ||
CellDataValueObject::class, | ||
'Cell object for which table cell should be rendered', | ||
true | ||
); | ||
$this->registerArgument('isHeader', 'bool', 'True to render <th> otherwise it will be <td>', false, false); | ||
} | ||
|
||
/** | ||
* @param array $arguments | ||
* @param Closure $renderChildrenClosure | ||
* @param RenderingContextInterface $renderingContext | ||
* | ||
* @return string | ||
*/ | ||
public static function renderStatic( | ||
array $arguments, | ||
Closure $renderChildrenClosure, | ||
RenderingContextInterface $renderingContext | ||
): string { | ||
$cell = $arguments['cell'] ?? null; | ||
if ($cell instanceof CellDataValueObject) { | ||
$attributes = $cell->getClass() !== '' ? ' class="' . $cell->getClass() . '"' : ''; | ||
$attributes .= $cell->getRowspan() > 0 ? ' rowspan="' . $cell->getRowspan() . '"' : ''; | ||
$attributes .= $cell->getColspan() > 0 ? ' colspan="' . $cell->getColspan() . '"' : ''; | ||
} | ||
|
||
return sprintf( | ||
(bool)($arguments['isHeader'] ?? 0) === true ? '<th%s>%s</th>' : '<td%s>%s</td>', | ||
$attributes ?? '', | ||
$renderChildrenClosure() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
|
||
namespace Hoogi91\Spreadsheets\Tests\Functional\ViewHelpers; | ||
|
||
use Hoogi91\Spreadsheets\Domain\ValueObject\CellDataValueObject; | ||
|
||
class CellRenderViewHelperTest extends AbstractViewHelperTestCase | ||
{ | ||
private const CELL_DEFAULT_CONTENT = '<td%s>content</td>'; | ||
private const CELL_HEADER_CONTENT = '<th%s>content</th>'; | ||
|
||
/** | ||
* @dataProvider cellProvider | ||
*/ | ||
public function testRender(string $expectedAttributes, ?array $cellMock, bool $isHeader = false): void | ||
{ | ||
if ($cellMock !== null) { | ||
$cellValue = $this->createConfiguredMock(CellDataValueObject::class, $cellMock); | ||
} | ||
|
||
self::assertEquals( | ||
sprintf( | ||
$isHeader === false ? self::CELL_DEFAULT_CONTENT : self::CELL_HEADER_CONTENT, | ||
$expectedAttributes !== '' ? ' ' . $expectedAttributes : '' | ||
), | ||
$this->getView( | ||
'<test:cell.render cell="{cell}" isHeader="{isHeader}">content</test:cell.render>', | ||
['cell' => $cellValue ?? null, 'isHeader' => $isHeader] | ||
)->render() | ||
); | ||
} | ||
|
||
/** | ||
* @dataProvider cellProvider | ||
*/ | ||
public function testRenderAsHeader(string $expectedAttributes, ?array $cellMock): void | ||
{ | ||
$this->testRender($expectedAttributes, $cellMock, true); | ||
} | ||
|
||
/** | ||
* Based on 01_fixture.xlsx cell coordinates | ||
* @return array | ||
*/ | ||
public function cellProvider(): array | ||
{ | ||
return [ | ||
'no cell' => ['', null], | ||
'no attributes' => [ | ||
'', | ||
['getClass' => '', 'getRowspan' => 0, 'getColspan' => 0] | ||
], | ||
'only class' => [ | ||
'class="cell"', | ||
['getClass' => 'cell', 'getRowspan' => 0, 'getColspan' => 0] | ||
], | ||
'only rowspan' => [ | ||
'rowspan="1"', | ||
['getClass' => '', 'getRowspan' => 1, 'getColspan' => 0] | ||
], | ||
'only colspan' => [ | ||
'colspan="1"', | ||
['getClass' => '', 'getRowspan' => 0, 'getColspan' => 1] | ||
], | ||
'class + rowspan' => [ | ||
'class="cell" rowspan="2"', | ||
['getClass' => 'cell', 'getRowspan' => 2, 'getColspan' => 0] | ||
], | ||
'class + colspan' => [ | ||
'class="cell" colspan="2"', | ||
['getClass' => 'cell', 'getRowspan' => 0, 'getColspan' => 2] | ||
], | ||
'rowspan + colspan' => [ | ||
'rowspan="3" colspan="3"', | ||
['getClass' => '', 'getRowspan' => 3, 'getColspan' => 3] | ||
], | ||
'class + rowspan + colspan' => [ | ||
'class="cell" rowspan="4" colspan="4"', | ||
['getClass' => 'cell', 'getRowspan' => 4, 'getColspan' => 4] | ||
], | ||
]; | ||
} | ||
} |
Oops, something went wrong.