mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-08-31 12:40:00 +00:00
Additional Coverage for Reader Xls (#3340)
* Additional Coverage for Reader Xls More than 750 lines are newly covered, increasing overall coverage on my machine from 91.14% to 93.09%. * Update FormulasTest.php
This commit is contained in:
@@ -4,39 +4,30 @@ namespace PhpOffice\PhpSpreadsheetTests\Reader\Xls;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Reader\Xls;
|
||||
use PhpOffice\PhpSpreadsheet\Style\Conditional;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ConditionalFormattingBasicTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var Worksheet
|
||||
*/
|
||||
protected $sheet;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$filename = 'tests/data/Reader/XLS/CF_Basic_Comparisons.xls';
|
||||
$reader = new Xls();
|
||||
$spreadsheet = $reader->load($filename);
|
||||
$this->sheet = $spreadsheet->getActiveSheet();
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider conditionalFormattingProvider
|
||||
*/
|
||||
public function testReadConditionalFormatting(string $expectedRange, array $expectedRules): void
|
||||
{
|
||||
$hasConditionalStyles = $this->sheet->conditionalStylesExists($expectedRange);
|
||||
$filename = 'tests/data/Reader/XLS/CF_Basic_Comparisons.xls';
|
||||
$reader = new Xls();
|
||||
$spreadsheet = $reader->load($filename);
|
||||
$sheet = $spreadsheet->getActiveSheet();
|
||||
$hasConditionalStyles = $sheet->conditionalStylesExists($expectedRange);
|
||||
self::assertTrue($hasConditionalStyles);
|
||||
|
||||
$conditionalStyles = $this->sheet->getConditionalStyles($expectedRange);
|
||||
$conditionalStyles = $sheet->getConditionalStyles($expectedRange);
|
||||
|
||||
foreach ($conditionalStyles as $index => $conditionalStyle) {
|
||||
self::assertSame($expectedRules[$index]['type'], $conditionalStyle->getConditionType());
|
||||
self::assertSame($expectedRules[$index]['operator'], $conditionalStyle->getOperatorType());
|
||||
self::assertSame($expectedRules[$index]['conditions'], $conditionalStyle->getConditions());
|
||||
}
|
||||
$spreadsheet->disconnectWorksheets();
|
||||
}
|
||||
|
||||
public function conditionalFormattingProvider(): array
|
||||
|
||||
@@ -4,39 +4,30 @@ namespace PhpOffice\PhpSpreadsheetTests\Reader\Xls;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Reader\Xls;
|
||||
use PhpOffice\PhpSpreadsheet\Style\Conditional;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ConditionalFormattingExpressionTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var Worksheet
|
||||
*/
|
||||
protected $sheet;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$filename = 'tests/data/Reader/XLS/CF_Expression_Comparisons.xls';
|
||||
$reader = new Xls();
|
||||
$spreadsheet = $reader->load($filename);
|
||||
$this->sheet = $spreadsheet->getActiveSheet();
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider conditionalFormattingProvider
|
||||
*/
|
||||
public function testReadConditionalFormatting(string $expectedRange, array $expectedRule): void
|
||||
{
|
||||
$hasConditionalStyles = $this->sheet->conditionalStylesExists($expectedRange);
|
||||
$filename = 'tests/data/Reader/XLS/CF_Expression_Comparisons.xls';
|
||||
$reader = new Xls();
|
||||
$spreadsheet = $reader->load($filename);
|
||||
$sheet = $spreadsheet->getActiveSheet();
|
||||
$hasConditionalStyles = $sheet->conditionalStylesExists($expectedRange);
|
||||
self::assertTrue($hasConditionalStyles);
|
||||
|
||||
$conditionalStyles = $this->sheet->getConditionalStyles($expectedRange);
|
||||
$conditionalStyles = $sheet->getConditionalStyles($expectedRange);
|
||||
|
||||
foreach ($conditionalStyles as $index => $conditionalStyle) {
|
||||
self::assertSame($expectedRule[$index]['type'], $conditionalStyle->getConditionType());
|
||||
self::assertSame($expectedRule[$index]['operator'], $conditionalStyle->getOperatorType());
|
||||
self::assertSame($expectedRule[$index]['conditions'], $conditionalStyle->getConditions());
|
||||
}
|
||||
$spreadsheet->disconnectWorksheets();
|
||||
}
|
||||
|
||||
public function conditionalFormattingProvider(): array
|
||||
|
||||
@@ -4,36 +4,27 @@ namespace PhpOffice\PhpSpreadsheetTests\Reader\Xls;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Cell\DataValidation;
|
||||
use PhpOffice\PhpSpreadsheet\Reader\Xls;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class DataValidationTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var Worksheet
|
||||
*/
|
||||
protected $sheet;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$filename = 'tests/data/Reader/XLS/DataValidation.xls';
|
||||
$reader = new Xls();
|
||||
$spreadsheet = $reader->load($filename);
|
||||
$this->sheet = $spreadsheet->getActiveSheet();
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataValidationProvider
|
||||
*/
|
||||
public function testDataValidation(string $expectedRange, array $expectedRule): void
|
||||
{
|
||||
$hasDataValidation = $this->sheet->dataValidationExists($expectedRange);
|
||||
$filename = 'tests/data/Reader/XLS/DataValidation.xls';
|
||||
$reader = new Xls();
|
||||
$spreadsheet = $reader->load($filename);
|
||||
$sheet = $spreadsheet->getActiveSheet();
|
||||
$hasDataValidation = $sheet->dataValidationExists($expectedRange);
|
||||
self::assertTrue($hasDataValidation);
|
||||
|
||||
$dataValidation = $this->sheet->getDataValidation($expectedRange);
|
||||
$dataValidation = $sheet->getDataValidation($expectedRange);
|
||||
self::assertSame($expectedRule['type'], $dataValidation->getType());
|
||||
self::assertSame($expectedRule['operator'], $dataValidation->getOperator());
|
||||
self::assertSame($expectedRule['formula'], $dataValidation->getFormula1());
|
||||
$spreadsheet->disconnectWorksheets();
|
||||
}
|
||||
|
||||
public function dataValidationProvider(): array
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xls;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Reader\Xls;
|
||||
use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional;
|
||||
|
||||
class FormulasTest extends AbstractFunctional
|
||||
{
|
||||
public function testFormulas(): void
|
||||
{
|
||||
// This file was created with Excel 365.
|
||||
$filename = 'tests/data/Reader/XLS/formulas.xls';
|
||||
$reader = new Xls();
|
||||
$spreadsheet = $reader->load($filename);
|
||||
$sheet = $spreadsheet->getActiveSheet();
|
||||
$originalArray = $sheet->toArray(null, false, false, false);
|
||||
|
||||
$newSpreadsheet = $this->writeAndReload($spreadsheet, 'Xls');
|
||||
$spreadsheet->disconnectWorksheets();
|
||||
$newWorksheet = $newSpreadsheet->getActiveSheet();
|
||||
$newArray = $newWorksheet->toArray(null, false, false, false);
|
||||
self::assertSame($originalArray, $newArray);
|
||||
$newSpreadsheet->disconnectWorksheets();
|
||||
}
|
||||
|
||||
public function testDatabaseFormulas(): void
|
||||
{
|
||||
// This file was created with Excel 2003.
|
||||
$filename = 'tests/data/Reader/XLS/formulas.database.xls';
|
||||
$reader = new Xls();
|
||||
$spreadsheet = $reader->load($filename);
|
||||
$sheet = $spreadsheet->getActiveSheet();
|
||||
$originalArray = $sheet->toArray(null, false, false, false);
|
||||
|
||||
$newSpreadsheet = $this->writeAndReload($spreadsheet, 'Xls');
|
||||
$spreadsheet->disconnectWorksheets();
|
||||
$newWorksheet = $newSpreadsheet->getActiveSheet();
|
||||
$newArray = $newWorksheet->toArray(null, false, false, false);
|
||||
self::assertSame($originalArray, $newArray);
|
||||
$newSpreadsheet->disconnectWorksheets();
|
||||
}
|
||||
}
|
||||
@@ -15,9 +15,11 @@ class HiddenWorksheetTest extends TestCase
|
||||
$spreadsheet = $reader->load($filename);
|
||||
$assertions = $this->worksheetAssertions();
|
||||
|
||||
$sheetCount = 0;
|
||||
foreach ($spreadsheet->getAllSheets() as $worksheet) {
|
||||
++$sheetCount;
|
||||
if (!array_key_exists($worksheet->getTitle(), $assertions)) {
|
||||
continue;
|
||||
self::fail('Unexpected worksheet' . $worksheet->getTitle());
|
||||
}
|
||||
|
||||
$sheetAssertions = $assertions[$worksheet->getTitle()];
|
||||
@@ -30,6 +32,7 @@ class HiddenWorksheetTest extends TestCase
|
||||
);
|
||||
}
|
||||
}
|
||||
self::assertCount($sheetCount, $assertions);
|
||||
$spreadsheet->disconnectWorksheets();
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xls;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Reader\Xls;
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
@@ -13,25 +12,18 @@ class PageSetupTest extends TestCase
|
||||
|
||||
private const MARGIN_UNIT_CONVERSION = 2.54; // Inches to cm
|
||||
|
||||
/**
|
||||
* @var Spreadsheet
|
||||
*/
|
||||
private $spreadsheet;
|
||||
|
||||
protected function setup(): void
|
||||
public function testPageSetup(): void
|
||||
{
|
||||
$filename = 'tests/data/Reader/XLS/PageSetup.xls';
|
||||
$reader = new Xls();
|
||||
$this->spreadsheet = $reader->load($filename);
|
||||
}
|
||||
|
||||
public function testPageSetup(): void
|
||||
{
|
||||
$spreadsheet = $reader->load($filename);
|
||||
$assertions = $this->pageSetupAssertions();
|
||||
|
||||
foreach ($this->spreadsheet->getAllSheets() as $worksheet) {
|
||||
$sheetCount = 0;
|
||||
foreach ($spreadsheet->getAllSheets() as $worksheet) {
|
||||
++$sheetCount;
|
||||
if (!array_key_exists($worksheet->getTitle(), $assertions)) {
|
||||
continue;
|
||||
self::fail('Unexpected worksheet ' . $worksheet->getTitle());
|
||||
}
|
||||
|
||||
$sheetAssertions = $assertions[$worksheet->getTitle()];
|
||||
@@ -45,15 +37,22 @@ class PageSetupTest extends TestCase
|
||||
);
|
||||
}
|
||||
}
|
||||
self::assertCount($sheetCount, $assertions);
|
||||
$spreadsheet->disconnectWorksheets();
|
||||
}
|
||||
|
||||
public function testPageMargins(): void
|
||||
{
|
||||
$filename = 'tests/data/Reader/XLS/PageSetup.xls';
|
||||
$reader = new Xls();
|
||||
$spreadsheet = $reader->load($filename);
|
||||
$assertions = $this->pageMarginAssertions();
|
||||
|
||||
foreach ($this->spreadsheet->getAllSheets() as $worksheet) {
|
||||
$sheetCount = 0;
|
||||
foreach ($spreadsheet->getAllSheets() as $worksheet) {
|
||||
++$sheetCount;
|
||||
if (!array_key_exists($worksheet->getTitle(), $assertions)) {
|
||||
continue;
|
||||
self::fail('Unexpected worksheet ' . $worksheet->getTitle());
|
||||
}
|
||||
|
||||
$sheetAssertions = $assertions[$worksheet->getTitle()];
|
||||
@@ -68,6 +67,8 @@ class PageSetupTest extends TestCase
|
||||
);
|
||||
}
|
||||
}
|
||||
self::assertCount($sheetCount, $assertions);
|
||||
$spreadsheet->disconnectWorksheets();
|
||||
}
|
||||
|
||||
private function pageSetupAssertions(): array
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user