Improve Coverage for Gnumeric (#1517)
* Improve Coverage for Gnumeric I believe that both BaseReader and Gnumeric Reader are now 100% covered. My goal was to use PhpSpreadsheet to load the test file, save it as Xlsx, and visually compare the two, then add a test loaded with assertions. Results were generally pretty good, but there were no tests with assertions. I added a few cells to exercise some previously uncovered code. Code was extensively refactored; logic changes are noted below. Code allowed for specifying document properties in an old format. I considered removing that, but I found the original spec at http://www.jfree.org/jworkbook/download/gnumeric-xml.pdf This allowed me to create an old file, which was not handled correctly because of namespace differences. The code was corrected to allow for this difference. Added support for textRotation. Mapping of fill types was not correct. * PHP7.2 Error One assertion failed under PHP7.2. Apparently there was some change in the handling of SimpleXMLElement between 7.2 and 7.3. Casting to string before use eliminates the problem. * Scrutinizer Recommendations All minor, solved (hopefully) mostly by casts. * One Last Scrutinizer Fix ... I hope.
This commit is contained in:
parent
ce6ac1f040
commit
73379cdfb1
Binary file not shown.
Binary file not shown.
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpSpreadsheet\Reader;
|
namespace PhpOffice\PhpSpreadsheet\Reader;
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Reader\Exception as ReaderException;
|
||||||
use PhpOffice\PhpSpreadsheet\Reader\Security\XmlScanner;
|
use PhpOffice\PhpSpreadsheet\Reader\Security\XmlScanner;
|
||||||
use PhpOffice\PhpSpreadsheet\Shared\File;
|
use PhpOffice\PhpSpreadsheet\Shared\File;
|
||||||
|
|
||||||
|
@ -133,11 +134,7 @@ abstract class BaseReader implements IReader
|
||||||
|
|
||||||
public function getSecurityScanner()
|
public function getSecurityScanner()
|
||||||
{
|
{
|
||||||
if (property_exists($this, 'securityScanner')) {
|
return $this->securityScanner;
|
||||||
return $this->securityScanner;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -147,12 +144,18 @@ abstract class BaseReader implements IReader
|
||||||
*/
|
*/
|
||||||
protected function openFile($pFilename): void
|
protected function openFile($pFilename): void
|
||||||
{
|
{
|
||||||
File::assertFile($pFilename);
|
if ($pFilename) {
|
||||||
|
File::assertFile($pFilename);
|
||||||
|
|
||||||
// Open file
|
// Open file
|
||||||
$this->fileHandle = fopen($pFilename, 'rb');
|
$fileHandle = fopen($pFilename, 'rb');
|
||||||
if ($this->fileHandle === false) {
|
} else {
|
||||||
throw new Exception('Could not open file ' . $pFilename . ' for reading.');
|
$fileHandle = false;
|
||||||
|
}
|
||||||
|
if ($fileHandle !== false) {
|
||||||
|
$this->fileHandle = $fileHandle;
|
||||||
|
} else {
|
||||||
|
throw new ReaderException('Could not open file ' . $pFilename . ' for reading.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -123,6 +123,7 @@ class IOFactoryTest extends TestCase
|
||||||
return [
|
return [
|
||||||
['samples/templates/26template.xlsx', 'Xlsx', Reader\Xlsx::class],
|
['samples/templates/26template.xlsx', 'Xlsx', Reader\Xlsx::class],
|
||||||
['samples/templates/GnumericTest.gnumeric', 'Gnumeric', Reader\Gnumeric::class],
|
['samples/templates/GnumericTest.gnumeric', 'Gnumeric', Reader\Gnumeric::class],
|
||||||
|
['samples/templates/old.gnumeric', 'Gnumeric', Reader\Gnumeric::class],
|
||||||
['samples/templates/30template.xls', 'Xls', Reader\Xls::class],
|
['samples/templates/30template.xls', 'Xls', Reader\Xls::class],
|
||||||
['samples/templates/OOCalcTest.ods', 'Ods', Reader\Ods::class],
|
['samples/templates/OOCalcTest.ods', 'Ods', Reader\Ods::class],
|
||||||
['samples/templates/SylkTest.slk', 'Slk', Reader\Slk::class],
|
['samples/templates/SylkTest.slk', 'Slk', Reader\Slk::class],
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpSpreadsheetTests\Reader\Gnumeric;
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Reader\IReadFilter;
|
||||||
|
|
||||||
|
/** Define a Read Filter class implementing IReadFilter */
|
||||||
|
class GnumericFilter implements IReadFilter
|
||||||
|
{
|
||||||
|
public function readCell($column, $row, $worksheetName = '')
|
||||||
|
{
|
||||||
|
return $row !== 4;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,47 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpSpreadsheetTests\Reader\Gnumeric;
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Reader\Gnumeric;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
class GnumericInfoTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testListNames(): void
|
||||||
|
{
|
||||||
|
$filename = __DIR__
|
||||||
|
. '/../../../..'
|
||||||
|
. '/samples/templates/GnumericTest.gnumeric';
|
||||||
|
$reader = new Gnumeric();
|
||||||
|
$names = $reader->listWorksheetNames($filename);
|
||||||
|
self::assertCount(2, $names);
|
||||||
|
self::assertEquals('Sample Data', $names[0]);
|
||||||
|
self::assertEquals('Report Data', $names[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testListInfo(): void
|
||||||
|
{
|
||||||
|
$filename = __DIR__
|
||||||
|
. '/../../../..'
|
||||||
|
. '/samples/templates/GnumericTest.gnumeric';
|
||||||
|
$reader = new Gnumeric();
|
||||||
|
$info = $reader->listWorksheetInfo($filename);
|
||||||
|
$expected = [
|
||||||
|
[
|
||||||
|
'worksheetName' => 'Sample Data',
|
||||||
|
'lastColumnLetter' => 'N',
|
||||||
|
'lastColumnIndex' => 13,
|
||||||
|
'totalRows' => 31,
|
||||||
|
'totalColumns' => 14,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'worksheetName' => 'Report Data',
|
||||||
|
'lastColumnLetter' => 'K',
|
||||||
|
'lastColumnIndex' => 10,
|
||||||
|
'totalRows' => 65535,
|
||||||
|
'totalColumns' => 11,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
self::assertEquals($expected, $info);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,162 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpSpreadsheetTests\Reader\Gnumeric;
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Reader\Gnumeric;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Style\Border;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Style\Borders;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Style\Color;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Style\Fill;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Style\Font;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
class GnumericLoadTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testLoad(): void
|
||||||
|
{
|
||||||
|
$filename = __DIR__
|
||||||
|
. '/../../../..'
|
||||||
|
. '/samples/templates/GnumericTest.gnumeric';
|
||||||
|
$reader = new Gnumeric();
|
||||||
|
$spreadsheet = $reader->load($filename);
|
||||||
|
self::assertEquals(2, $spreadsheet->getSheetCount());
|
||||||
|
|
||||||
|
$sheet = $spreadsheet->getSheet(1);
|
||||||
|
self::assertEquals('Report Data', $sheet->getTitle());
|
||||||
|
self::assertEquals('BCD', $sheet->getCell('A4')->getValue());
|
||||||
|
$props = $spreadsheet->getProperties();
|
||||||
|
self::assertEquals('Mark Baker', $props->getCreator());
|
||||||
|
|
||||||
|
$sheet = $spreadsheet->getSheet(0);
|
||||||
|
self::assertEquals('Sample Data', $sheet->getTitle());
|
||||||
|
self::assertEquals('Test String 1', $sheet->getCell('A1')->getValue());
|
||||||
|
self::assertEquals('FFFF0000', $sheet->getCell('A1')->getStyle()->getFont()->getColor()->getARGB());
|
||||||
|
self::assertEquals(Font::UNDERLINE_SINGLE, $sheet->getCell('A3')->getStyle()->getFont()->getUnderline());
|
||||||
|
self::assertEquals('Test with (") in string', $sheet->getCell('A4')->getValue());
|
||||||
|
|
||||||
|
self::assertEquals(22269, $sheet->getCell('A10')->getValue());
|
||||||
|
self::assertEquals('dd/mm/yyyy', $sheet->getCell('A10')->getStyle()->getNumberFormat()->getFormatCode());
|
||||||
|
self::assertEquals('19/12/1960', $sheet->getCell('A10')->getFormattedValue());
|
||||||
|
self::assertEquals(1.5, $sheet->getCell('A11')->getValue());
|
||||||
|
self::assertEquals('# ?0/??0', $sheet->getCell('A11')->getStyle()->getNumberFormat()->getFormatCode());
|
||||||
|
// Same pattern, same value, different display in Gnumeric vs Excel
|
||||||
|
//self::assertEquals('1 1/2', $sheet->getCell('A11')->getFormattedValue());
|
||||||
|
|
||||||
|
self::assertEquals('=B1+C1', $sheet->getCell('H1')->getValue());
|
||||||
|
self::assertEquals('=E2&F2', $sheet->getCell('J2')->getValue());
|
||||||
|
self::assertEquals('=sum(C1:C4)', $sheet->getCell('I5')->getValue());
|
||||||
|
|
||||||
|
self::assertTrue($sheet->getCell('E1')->getStyle()->getFont()->getBold());
|
||||||
|
self::assertTrue($sheet->getCell('E1')->getStyle()->getFont()->getItalic());
|
||||||
|
|
||||||
|
self::assertFalse($sheet->getCell('E2')->getStyle()->getFont()->getBold());
|
||||||
|
self::assertFalse($sheet->getCell('E2')->getStyle()->getFont()->getItalic());
|
||||||
|
self::assertEquals(Font::UNDERLINE_NONE, $sheet->getCell('E2')->getStyle()->getFont()->getUnderline());
|
||||||
|
self::assertTrue($sheet->getCell('E3')->getStyle()->getFont()->getBold());
|
||||||
|
self::assertFalse($sheet->getCell('E3')->getStyle()->getFont()->getItalic());
|
||||||
|
self::assertEquals(Font::UNDERLINE_NONE, $sheet->getCell('E3')->getStyle()->getFont()->getUnderline());
|
||||||
|
self::assertFalse($sheet->getCell('E4')->getStyle()->getFont()->getBold());
|
||||||
|
self::assertTrue($sheet->getCell('E4')->getStyle()->getFont()->getItalic());
|
||||||
|
self::assertEquals(Font::UNDERLINE_NONE, $sheet->getCell('E4')->getStyle()->getFont()->getUnderline());
|
||||||
|
|
||||||
|
self::assertTrue($sheet->getCell('F1')->getStyle()->getFont()->getBold());
|
||||||
|
self::assertFalse($sheet->getCell('F1')->getStyle()->getFont()->getItalic());
|
||||||
|
self::assertEquals(Font::UNDERLINE_NONE, $sheet->getCell('F1')->getStyle()->getFont()->getUnderline());
|
||||||
|
self::assertFalse($sheet->getCell('F2')->getStyle()->getFont()->getBold());
|
||||||
|
self::assertFalse($sheet->getCell('F2')->getStyle()->getFont()->getItalic());
|
||||||
|
self::assertEquals(Font::UNDERLINE_NONE, $sheet->getCell('F2')->getStyle()->getFont()->getUnderline());
|
||||||
|
self::assertTrue($sheet->getCell('F3')->getStyle()->getFont()->getBold());
|
||||||
|
self::assertTrue($sheet->getCell('F3')->getStyle()->getFont()->getItalic());
|
||||||
|
self::assertEquals(Font::UNDERLINE_NONE, $sheet->getCell('F3')->getStyle()->getFont()->getUnderline());
|
||||||
|
self::assertFalse($sheet->getCell('F4')->getStyle()->getFont()->getBold());
|
||||||
|
self::assertFalse($sheet->getCell('F4')->getStyle()->getFont()->getItalic());
|
||||||
|
self::assertEquals(Font::UNDERLINE_NONE, $sheet->getCell('F4')->getStyle()->getFont()->getUnderline());
|
||||||
|
|
||||||
|
self::assertEquals(Border::BORDER_MEDIUM, $sheet->getCell('C10')->getStyle()->getBorders()->getTop()->getBorderStyle());
|
||||||
|
self::assertEquals(Border::BORDER_NONE, $sheet->getCell('C10')->getStyle()->getBorders()->getRight()->getBorderStyle());
|
||||||
|
self::assertEquals(Border::BORDER_NONE, $sheet->getCell('C10')->getStyle()->getBorders()->getBottom()->getBorderStyle());
|
||||||
|
self::assertEquals(Border::BORDER_NONE, $sheet->getCell('C10')->getStyle()->getBorders()->getLeft()->getBorderStyle());
|
||||||
|
self::assertEquals(Border::BORDER_NONE, $sheet->getCell('C12')->getStyle()->getBorders()->getTop()->getBorderStyle());
|
||||||
|
self::assertEquals(Border::BORDER_NONE, $sheet->getCell('C12')->getStyle()->getBorders()->getRight()->getBorderStyle());
|
||||||
|
self::assertEquals(Border::BORDER_MEDIUM, $sheet->getCell('C12')->getStyle()->getBorders()->getBottom()->getBorderStyle());
|
||||||
|
self::assertEquals(Border::BORDER_NONE, $sheet->getCell('C12')->getStyle()->getBorders()->getLeft()->getBorderStyle());
|
||||||
|
self::assertEquals(Border::BORDER_NONE, $sheet->getCell('C14')->getStyle()->getBorders()->getTop()->getBorderStyle());
|
||||||
|
self::assertEquals(Border::BORDER_NONE, $sheet->getCell('C14')->getStyle()->getBorders()->getRight()->getBorderStyle());
|
||||||
|
self::assertEquals(Border::BORDER_NONE, $sheet->getCell('C14')->getStyle()->getBorders()->getBottom()->getBorderStyle());
|
||||||
|
self::assertEquals(Border::BORDER_MEDIUM, $sheet->getCell('C14')->getStyle()->getBorders()->getLeft()->getBorderStyle());
|
||||||
|
self::assertEquals(Border::BORDER_NONE, $sheet->getCell('C16')->getStyle()->getBorders()->getTop()->getBorderStyle());
|
||||||
|
self::assertEquals(Border::BORDER_MEDIUM, $sheet->getCell('C16')->getStyle()->getBorders()->getRight()->getBorderStyle());
|
||||||
|
self::assertEquals(Border::BORDER_NONE, $sheet->getCell('C16')->getStyle()->getBorders()->getBottom()->getBorderStyle());
|
||||||
|
self::assertEquals(Border::BORDER_NONE, $sheet->getCell('C16')->getStyle()->getBorders()->getLeft()->getBorderStyle());
|
||||||
|
self::assertEquals(Border::BORDER_THICK, $sheet->getCell('C18')->getStyle()->getBorders()->getTop()->getBorderStyle());
|
||||||
|
self::assertEquals(Color::COLOR_RED, $sheet->getCell('C18')->getStyle()->getBorders()->getTop()->getColor()->getARGB());
|
||||||
|
self::assertEquals(Border::BORDER_THICK, $sheet->getCell('C18')->getStyle()->getBorders()->getRight()->getBorderStyle());
|
||||||
|
self::assertEquals(Color::COLOR_YELLOW, $sheet->getCell('C18')->getStyle()->getBorders()->getRight()->getColor()->getARGB());
|
||||||
|
self::assertEquals(Border::BORDER_THICK, $sheet->getCell('C18')->getStyle()->getBorders()->getRight()->getBorderStyle());
|
||||||
|
self::assertEquals(Border::BORDER_NONE, $sheet->getCell('C18')->getStyle()->getBorders()->getBottom()->getBorderStyle());
|
||||||
|
self::assertEquals(Border::BORDER_NONE, $sheet->getCell('C18')->getStyle()->getBorders()->getLeft()->getBorderStyle());
|
||||||
|
|
||||||
|
self::assertEquals(Fill::FILL_PATTERN_DARKHORIZONTAL, $sheet->getCell('K19')->getStyle()->getFill()->getFillType());
|
||||||
|
self::assertEquals('FF00CCFF', $sheet->getCell('K19')->getStyle()->getFill()->getEndColor()->getARGB());
|
||||||
|
self::assertEquals(Color::COLOR_BLUE, $sheet->getCell('K19')->getStyle()->getFill()->getStartColor()->getARGB());
|
||||||
|
self::assertEquals(Fill::FILL_PATTERN_GRAY0625, $sheet->getCell('L19')->getStyle()->getFill()->getFillType());
|
||||||
|
self::assertEquals(Color::COLOR_RED, $sheet->getCell('L19')->getStyle()->getFill()->getEndColor()->getARGB());
|
||||||
|
self::assertEquals(Color::COLOR_YELLOW, $sheet->getCell('L19')->getStyle()->getFill()->getStartColor()->getARGB());
|
||||||
|
self::assertEquals(Fill::FILL_SOLID, $sheet->getCell('K3')->getStyle()->getFill()->getFillType());
|
||||||
|
self::assertEquals(Color::COLOR_RED, $sheet->getCell('K3')->getStyle()->getFill()->getStartColor()->getARGB());
|
||||||
|
|
||||||
|
self::assertEquals(45, $sheet->getCell('E22')->getStyle()->getAlignment()->getTextRotation());
|
||||||
|
self::assertEquals(-90, $sheet->getCell('G22')->getStyle()->getAlignment()->getTextRotation());
|
||||||
|
self::assertEquals(Border::BORDER_DOUBLE, $sheet->getCell('N13')->getStyle()->getBorders()->getBottom()->getBorderStyle());
|
||||||
|
|
||||||
|
self::assertEquals(Borders::DIAGONAL_BOTH, $sheet->getCell('E18')->getStyle()->getBorders()->getDiagonalDirection());
|
||||||
|
self::assertEquals(Borders::DIAGONAL_DOWN, $sheet->getCell('I18')->getStyle()->getBorders()->getDiagonalDirection());
|
||||||
|
self::assertEquals(Borders::DIAGONAL_UP, $sheet->getCell('J18')->getStyle()->getBorders()->getDiagonalDirection());
|
||||||
|
self::assertEquals(Font::UNDERLINE_DOUBLE, $sheet->getCell('A24')->getStyle()->getFont()->getUnderline());
|
||||||
|
self::assertTrue($sheet->getCell('B23')->getStyle()->getFont()->getSubScript());
|
||||||
|
self::assertTrue($sheet->getCell('B24')->getStyle()->getFont()->getSuperScript());
|
||||||
|
self::assertFalse($sheet->getRowDimension(30)->getVisible());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testLoadFilter(): void
|
||||||
|
{
|
||||||
|
$filename = __DIR__
|
||||||
|
. '/../../../..'
|
||||||
|
. '/samples/templates/GnumericTest.gnumeric';
|
||||||
|
$reader = new Gnumeric();
|
||||||
|
$filter = new GnumericFilter();
|
||||||
|
$reader->setReadFilter($filter);
|
||||||
|
$spreadsheet = $reader->load($filename);
|
||||||
|
self::assertEquals(2, $spreadsheet->getSheetCount());
|
||||||
|
$sheet = $spreadsheet->getSheet(1);
|
||||||
|
self::assertEquals('Report Data', $sheet->getTitle());
|
||||||
|
self::assertEquals('', $sheet->getCell('A4')->getValue());
|
||||||
|
$props = $spreadsheet->getProperties();
|
||||||
|
self::assertEquals('Mark Baker', $props->getCreator());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testLoadOld(): void
|
||||||
|
{
|
||||||
|
$filename = __DIR__
|
||||||
|
. '/../../../..'
|
||||||
|
. '/samples/templates/old.gnumeric';
|
||||||
|
$reader = new Gnumeric();
|
||||||
|
$spreadsheet = $reader->load($filename);
|
||||||
|
$props = $spreadsheet->getProperties();
|
||||||
|
self::assertEquals('David Gilbert', $props->getCreator());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testLoadSelectedSheets(): void
|
||||||
|
{
|
||||||
|
$filename = __DIR__
|
||||||
|
. '/../../../..'
|
||||||
|
. '/samples/templates/GnumericTest.gnumeric';
|
||||||
|
$reader = new Gnumeric();
|
||||||
|
$reader->setLoadSheetsOnly(['Unknown Sheet', 'Report Data']);
|
||||||
|
$spreadsheet = $reader->load($filename);
|
||||||
|
self::assertEquals(1, $spreadsheet->getSheetCount());
|
||||||
|
$sheet = $spreadsheet->getSheet(0);
|
||||||
|
self::assertEquals('Report Data', $sheet->getTitle());
|
||||||
|
self::assertEquals('Third Heading', $sheet->getCell('C2')->getValue());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,269 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpSpreadsheetTests\Reader\Gnumeric;
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Cell\DataType;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Reader\Gnumeric;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Style\Alignment;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Style\Border;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Style\Fill;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Style\Font;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
class GnumericStylesTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @dataProvider providerBorderStyle
|
||||||
|
*/
|
||||||
|
public function testBorderStyle(string $style, string $expectedResult): void
|
||||||
|
{
|
||||||
|
$styles = Gnumeric::gnumericMappings();
|
||||||
|
$borders = $styles['borderStyle'];
|
||||||
|
self::assertEquals($expectedResult, $borders[$style]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testBorderStyleCoverage(): void
|
||||||
|
{
|
||||||
|
$styles = Gnumeric::gnumericMappings();
|
||||||
|
$expected = $styles['borderStyle'];
|
||||||
|
$covered = [];
|
||||||
|
foreach ($expected as $key => $val) {
|
||||||
|
$covered[$key] = 0;
|
||||||
|
}
|
||||||
|
$tests = $this->providerBorderStyle();
|
||||||
|
foreach ($tests as $test) {
|
||||||
|
$covered[$test[0]] = 1;
|
||||||
|
}
|
||||||
|
foreach ($covered as $key => $val) {
|
||||||
|
self::assertEquals(1, $val, "Borderstyle $key not tested");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider providerfillType
|
||||||
|
*/
|
||||||
|
public function testFillType(string $style, string $expectedResult): void
|
||||||
|
{
|
||||||
|
$styles = Gnumeric::gnumericMappings();
|
||||||
|
$borders = $styles['fillType'];
|
||||||
|
self::assertEquals($expectedResult, $borders[$style]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFillTypeCoverage(): void
|
||||||
|
{
|
||||||
|
$styles = Gnumeric::gnumericMappings();
|
||||||
|
$expected = $styles['fillType'];
|
||||||
|
$covered = [];
|
||||||
|
foreach ($expected as $key => $val) {
|
||||||
|
$covered[$key] = 0;
|
||||||
|
}
|
||||||
|
$tests = $this->providerfillType();
|
||||||
|
foreach ($tests as $test) {
|
||||||
|
$covered[$test[0]] = 1;
|
||||||
|
}
|
||||||
|
foreach ($covered as $key => $val) {
|
||||||
|
self::assertEquals(1, $val, "fillType $key not tested");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider providerHorizontal
|
||||||
|
*/
|
||||||
|
public function testHorizontal(string $style, string $expectedResult): void
|
||||||
|
{
|
||||||
|
$styles = Gnumeric::gnumericMappings();
|
||||||
|
$borders = $styles['horizontal'];
|
||||||
|
self::assertEquals($expectedResult, $borders[$style]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testHorizontalCoverage(): void
|
||||||
|
{
|
||||||
|
$styles = Gnumeric::gnumericMappings();
|
||||||
|
$expected = $styles['horizontal'];
|
||||||
|
$covered = [];
|
||||||
|
foreach ($expected as $key => $val) {
|
||||||
|
$covered[$key] = 0;
|
||||||
|
}
|
||||||
|
$tests = $this->providerHorizontal();
|
||||||
|
foreach ($tests as $test) {
|
||||||
|
$covered[$test[0]] = 1;
|
||||||
|
}
|
||||||
|
foreach ($covered as $key => $val) {
|
||||||
|
self::assertEquals(1, $val, "horizontal $key not tested");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider providerunderline
|
||||||
|
*/
|
||||||
|
public function testUnderline(string $style, string $expectedResult): void
|
||||||
|
{
|
||||||
|
$styles = Gnumeric::gnumericMappings();
|
||||||
|
$borders = $styles['underline'];
|
||||||
|
self::assertEquals($expectedResult, $borders[$style]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUnderlineCoverage(): void
|
||||||
|
{
|
||||||
|
$styles = Gnumeric::gnumericMappings();
|
||||||
|
$expected = $styles['underline'];
|
||||||
|
$covered = [];
|
||||||
|
foreach ($expected as $key => $val) {
|
||||||
|
$covered[$key] = 0;
|
||||||
|
}
|
||||||
|
$tests = $this->providerUnderline();
|
||||||
|
foreach ($tests as $test) {
|
||||||
|
$covered[$test[0]] = 1;
|
||||||
|
}
|
||||||
|
foreach ($covered as $key => $val) {
|
||||||
|
self::assertEquals(1, $val, "underline $key not tested");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider providerVertical
|
||||||
|
*/
|
||||||
|
public function testVertical(string $style, string $expectedResult): void
|
||||||
|
{
|
||||||
|
$styles = Gnumeric::gnumericMappings();
|
||||||
|
$borders = $styles['vertical'];
|
||||||
|
self::assertEquals($expectedResult, $borders[$style]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testVerticalCoverage(): void
|
||||||
|
{
|
||||||
|
$styles = Gnumeric::gnumericMappings();
|
||||||
|
$expected = $styles['vertical'];
|
||||||
|
$covered = [];
|
||||||
|
foreach ($expected as $key => $val) {
|
||||||
|
$covered[$key] = 0;
|
||||||
|
}
|
||||||
|
$tests = $this->providerVertical();
|
||||||
|
foreach ($tests as $test) {
|
||||||
|
$covered[$test[0]] = 1;
|
||||||
|
}
|
||||||
|
foreach ($covered as $key => $val) {
|
||||||
|
self::assertEquals(1, $val, "vertical $key not tested");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider providerDataType
|
||||||
|
*/
|
||||||
|
public function testDataType(string $style, string $expectedResult): void
|
||||||
|
{
|
||||||
|
$styles = Gnumeric::gnumericMappings();
|
||||||
|
$borders = $styles['dataType'];
|
||||||
|
self::assertEquals($expectedResult, $borders[$style]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDataTypeCoverage(): void
|
||||||
|
{
|
||||||
|
$styles = Gnumeric::gnumericMappings();
|
||||||
|
$expected = $styles['dataType'];
|
||||||
|
self::assertArrayNotHasKey('70', $expected);
|
||||||
|
self::assertArrayNotHasKey('80', $expected);
|
||||||
|
$covered = [];
|
||||||
|
foreach ($expected as $key => $val) {
|
||||||
|
$covered[$key] = 0;
|
||||||
|
}
|
||||||
|
$tests = $this->providerDataType();
|
||||||
|
foreach ($tests as $test) {
|
||||||
|
$covered[$test[0]] = 1;
|
||||||
|
}
|
||||||
|
foreach ($covered as $key => $val) {
|
||||||
|
self::assertEquals(1, $val, "dataType $key not tested");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function providerBorderStyle(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
['0', Border::BORDER_NONE],
|
||||||
|
['1', Border::BORDER_THIN],
|
||||||
|
['2', Border::BORDER_MEDIUM],
|
||||||
|
['3', Border::BORDER_SLANTDASHDOT],
|
||||||
|
['4', Border::BORDER_DASHED],
|
||||||
|
['5', Border::BORDER_THICK],
|
||||||
|
['6', Border::BORDER_DOUBLE],
|
||||||
|
['7', Border::BORDER_DOTTED],
|
||||||
|
['8', Border::BORDER_MEDIUMDASHED],
|
||||||
|
['9', Border::BORDER_DASHDOT],
|
||||||
|
['10', Border::BORDER_MEDIUMDASHDOT],
|
||||||
|
['11', Border::BORDER_DASHDOTDOT],
|
||||||
|
['12', Border::BORDER_MEDIUMDASHDOTDOT],
|
||||||
|
['13', Border::BORDER_MEDIUMDASHDOTDOT],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function providerFillType(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
['1', Fill::FILL_SOLID],
|
||||||
|
['2', Fill::FILL_PATTERN_DARKGRAY],
|
||||||
|
['3', Fill::FILL_PATTERN_MEDIUMGRAY],
|
||||||
|
['4', Fill::FILL_PATTERN_LIGHTGRAY],
|
||||||
|
['5', Fill::FILL_PATTERN_GRAY125],
|
||||||
|
['6', Fill::FILL_PATTERN_GRAY0625],
|
||||||
|
['7', Fill::FILL_PATTERN_DARKHORIZONTAL],
|
||||||
|
['8', Fill::FILL_PATTERN_DARKVERTICAL],
|
||||||
|
['9', Fill::FILL_PATTERN_DARKDOWN],
|
||||||
|
['10', Fill::FILL_PATTERN_DARKUP],
|
||||||
|
['11', Fill::FILL_PATTERN_DARKGRID],
|
||||||
|
['12', Fill::FILL_PATTERN_DARKTRELLIS],
|
||||||
|
['13', Fill::FILL_PATTERN_LIGHTHORIZONTAL],
|
||||||
|
['14', Fill::FILL_PATTERN_LIGHTVERTICAL],
|
||||||
|
['15', Fill::FILL_PATTERN_LIGHTUP],
|
||||||
|
['16', Fill::FILL_PATTERN_LIGHTDOWN],
|
||||||
|
['17', Fill::FILL_PATTERN_LIGHTGRID],
|
||||||
|
['18', Fill::FILL_PATTERN_LIGHTTRELLIS],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function providerHorizontal(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
['1', Alignment::HORIZONTAL_GENERAL],
|
||||||
|
['2', Alignment::HORIZONTAL_LEFT],
|
||||||
|
['4', Alignment::HORIZONTAL_RIGHT],
|
||||||
|
['8', Alignment::HORIZONTAL_CENTER],
|
||||||
|
['16', Alignment::HORIZONTAL_CENTER_CONTINUOUS],
|
||||||
|
['32', Alignment::HORIZONTAL_JUSTIFY],
|
||||||
|
['64', Alignment::HORIZONTAL_CENTER_CONTINUOUS],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function providerUnderline(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
['1', Font::UNDERLINE_SINGLE],
|
||||||
|
['2', Font::UNDERLINE_DOUBLE],
|
||||||
|
['3', Font::UNDERLINE_SINGLEACCOUNTING],
|
||||||
|
['4', Font::UNDERLINE_DOUBLEACCOUNTING],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function providerVertical(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
['1', Alignment::VERTICAL_TOP],
|
||||||
|
['2', Alignment::VERTICAL_BOTTOM],
|
||||||
|
['4', Alignment::VERTICAL_CENTER],
|
||||||
|
['8', Alignment::VERTICAL_JUSTIFY],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function providerDataType(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
['10', DataType::TYPE_NULL],
|
||||||
|
['20', DataType::TYPE_BOOL],
|
||||||
|
['30', DataType::TYPE_NUMERIC], // Integer doesn't exist in Excel
|
||||||
|
['40', DataType::TYPE_NUMERIC], // Float
|
||||||
|
['50', DataType::TYPE_ERROR],
|
||||||
|
['60', DataType::TYPE_STRING],
|
||||||
|
//'70': // Cell Range
|
||||||
|
//'80': // Array
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue