Files
oleibman 10ec62707e Improvements to Xml Reader
Fix #3999. Fix #4000. Fix #4002. Several bug reports and feature requests for Xml Reader arrived practically simultaneously. They are all small and hit the same code modules, so I have bundled them together in one PR.
- `loadSpreadsheetFromString` might try to open a file with a falsy name (like '0'), which results in an exception with a misleading message (or a completely unexpected result if a file with that name exists). Code will still throw an exception, but the message will no longer be misleading, and no file I/O will be attempted.
- function `trySimpleXmlLoadString` is deprecated. It should never have been implemented with public visibility, and the fact that it was made the fix above a little more difficult than it would otherwise have been. It is replaced with a private equivalent.
- Style reader function `parseStyles` will now use a better namespace-aware method of reading its Xml data. Peculiarly, the Xml for the Style elements can either include or not a namespace prefix. This is probably because the global namespace and the styles namespace are the same. The existing prefix-based code does not recognize their equivalence, but the new namespace-based code does. Xml Reader continues to use prefix-based code in several other places.
- Border line styles with Weight omitted or equal to 0 have been treated as no border, but they should be treated as 'hair' thickness.
- Support for Zoom is added to Xml Reader.
- In support of the above, new properties (and getters and setters) zoomScalePageLayoutView and zoomScaleSheetLayoutView are added to Worksheet/SheetView. (As far as I can tell, Excel does not support Sheet Layout View for Xml spreadsheets).
- Support is added for those new properties in Xlsx Reader and Writer.
- Xls Reader and Writer seem to work okay without changes. There is one test where Xls shows a different value for one of the properties than Xml or Xlsx, but the spreadsheet looks okay and I don't see any practical consequences of the difference.
- PageBreak support is added to Xml Reader.
- Code for writing out Column Page Breaks in Xlsx Writer was wrong (and, unsurprisingly, untested). A one-line change fixes it, and tests are added.
2024-04-27 16:42:42 -07:00

128 lines
4.5 KiB
PHP

<?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xml;
use PhpOffice\PhpSpreadsheet\Reader\Xml;
use PhpOffice\PhpSpreadsheet\Style\Border;
use PhpOffice\PhpSpreadsheet\Style\Fill;
use PHPUnit\Framework\TestCase;
class XmlStyleCoverageTest extends TestCase
{
/**
* @dataProvider providerBorderStyle
*/
public function testBorderStyle(string $style, string $expectedResult): void
{
$styles = Xml::XmlMappings();
$borders = $styles['borderStyle'];
self::assertEquals($expectedResult, $borders[$style]);
}
public function testBorderStyleCoverage(): void
{
$styles = Xml::XmlMappings();
$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 = Xml::xmlMappings();
$borders = $styles['fillType'];
self::assertEquals($expectedResult, $borders[$style]);
}
public function testFillTypeCoverage(): void
{
$styles = Xml::XmlMappings();
$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");
}
}
public static function providerBorderStyle(): array
{
return [
['continuous', Border::BORDER_HAIR],
['dash', Border::BORDER_DASHED],
['dashdot', Border::BORDER_DASHDOT],
['dashdotdot', Border::BORDER_DASHDOTDOT],
['dot', Border::BORDER_DOTTED],
['double', Border::BORDER_DOUBLE],
['0continuous', Border::BORDER_HAIR],
['0dash', Border::BORDER_DASHED],
['0dashdot', Border::BORDER_DASHDOT],
['0dashdotdot', Border::BORDER_DASHDOTDOT],
['0dot', Border::BORDER_DOTTED],
['0double', Border::BORDER_DOUBLE],
['1continuous', Border::BORDER_THIN],
['1dash', Border::BORDER_DASHED],
['1dashdot', Border::BORDER_DASHDOT],
['1dashdotdot', Border::BORDER_DASHDOTDOT],
['1dot', Border::BORDER_DOTTED],
['1double', Border::BORDER_DOUBLE],
['2continuous', Border::BORDER_MEDIUM],
['2dash', Border::BORDER_MEDIUMDASHED],
['2dashdot', Border::BORDER_MEDIUMDASHDOT],
['2dashdotdot', Border::BORDER_MEDIUMDASHDOTDOT],
['2dot', Border::BORDER_DOTTED],
['2double', Border::BORDER_DOUBLE],
['3continuous', Border::BORDER_THICK],
['3dash', Border::BORDER_MEDIUMDASHED],
['3dashdot', Border::BORDER_MEDIUMDASHDOT],
['3dashdotdot', Border::BORDER_MEDIUMDASHDOTDOT],
['3dot', Border::BORDER_DOTTED],
['3double', Border::BORDER_DOUBLE],
];
}
public static function providerFillType(): array
{
return [
['solid', Fill::FILL_SOLID],
['gray75', Fill::FILL_PATTERN_DARKGRAY],
['gray50', Fill::FILL_PATTERN_MEDIUMGRAY],
['gray25', Fill::FILL_PATTERN_LIGHTGRAY],
['gray125', Fill::FILL_PATTERN_GRAY125],
['gray0625', Fill::FILL_PATTERN_GRAY0625],
['horzstripe', Fill::FILL_PATTERN_DARKHORIZONTAL],
['vertstripe', Fill::FILL_PATTERN_DARKVERTICAL],
['reversediagstripe', Fill::FILL_PATTERN_DARKUP],
['diagstripe', Fill::FILL_PATTERN_DARKDOWN],
['diagcross', Fill::FILL_PATTERN_DARKGRID],
['thickdiagcross', Fill::FILL_PATTERN_DARKTRELLIS],
['thinhorzstripe', Fill::FILL_PATTERN_LIGHTHORIZONTAL],
['thinvertstripe', Fill::FILL_PATTERN_LIGHTVERTICAL],
['thinreversediagstripe', Fill::FILL_PATTERN_LIGHTUP],
['thindiagstripe', Fill::FILL_PATTERN_LIGHTDOWN],
['thinhorzcross', Fill::FILL_PATTERN_LIGHTGRID],
['thindiagcross', Fill::FILL_PATTERN_LIGHTTRELLIS],
];
}
}