From b89968d20627805b7340a927588c2b9a7353f31b Mon Sep 17 00:00:00 2001 From: Mark Baker Date: Tue, 14 Jul 2020 10:58:50 +0200 Subject: [PATCH 1/7] Additional Unit Tests (#1582) --- .../ReferenceHelperTest.php | 17 +++++ tests/data/ReferenceHelperFormulaUpdates.php | 74 +++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 tests/data/ReferenceHelperFormulaUpdates.php diff --git a/tests/PhpSpreadsheetTests/ReferenceHelperTest.php b/tests/PhpSpreadsheetTests/ReferenceHelperTest.php index 374b63c9..08462b5b 100644 --- a/tests/PhpSpreadsheetTests/ReferenceHelperTest.php +++ b/tests/PhpSpreadsheetTests/ReferenceHelperTest.php @@ -95,4 +95,21 @@ class ReferenceHelperTest extends TestCase self::assertEquals($columnExpectedResult[$key], $value); } } + + /** + * @dataProvider providerFormulaUpdates + */ + public function testUpdateFormula(string $formula, int $insertRows, int $insertColumns, string $worksheet, string $expectedResult): void + { + $referenceHelper = ReferenceHelper::getInstance(); + + $result = $referenceHelper->updateFormulaReferences($formula, 'A1', $insertRows, $insertColumns, $worksheet); + + self::assertSame($expectedResult, $result); + } + + public function providerFormulaUpdates(): array + { + return require 'tests/data/ReferenceHelperFormulaUpdates.php'; + } } diff --git a/tests/data/ReferenceHelperFormulaUpdates.php b/tests/data/ReferenceHelperFormulaUpdates.php new file mode 100644 index 00000000..b97b8a35 --- /dev/null +++ b/tests/data/ReferenceHelperFormulaUpdates.php @@ -0,0 +1,74 @@ + Date: Wed, 15 Jul 2020 04:23:00 -0700 Subject: [PATCH 2/7] Restoring State After Static Changes in Tests (#1571) This request does not change any source code, only tests. For a change on which I was working, a test passed when run on its own, but failed when run as part of the full test suite. It turned out that an existing test had changed a static value, thousands separator in this case, and failed to restore it. The test turned out to be AdvancedBinderTest. The search for the offending test was more difficult than it should have been because 26 test scripts which had nothing to do with thousands separator nevertheless changed that value. They all changed decimal separator, currency code, and compatibility mode as well, again for no reason. I changed all of those to eliminate those operations. I changed the following tests, which actually do change the static properties identified above for a reason, to restore them as part of teardown. - CalculationTest sets compatibilityMode and locale - DayTest sets compatibilityMode, returnDateType, and excelCalendar - CountTest sets compatibilityMode - FunctionsTest sets compatibilityMode and returnDateType - AdvancedValueBinderTest sets currencyCode, decimalSeparator, thousandsSeparator - StringHelperTest sets currencyCode, decimalSeparator, thousandsSeparator - NumberFormatTest sets currencyCode, decimalSeparator, thousandsSeparator - HtmlNumberFormatTest sets currencyCode, decimalSeparator, thousandsSeparator --- .../Calculation/CalculationTest.php | 10 +++++++- .../Functions/DateTime/DayTest.php | 16 +++++++++++++ .../Functions/Statistical/CountTest.php | 8 +++++++ .../Functions/TextData/CharTest.php | 18 --------------- .../Functions/TextData/CleanTest.php | 18 --------------- .../Functions/TextData/CodeTest.php | 18 --------------- .../Functions/TextData/ConcatenateTest.php | 18 --------------- .../Functions/TextData/DollarTest.php | 18 --------------- .../Functions/TextData/ExactTest.php | 22 ------------------ .../Functions/TextData/FindTest.php | 18 --------------- .../Functions/TextData/FixedTest.php | 18 --------------- .../Functions/TextData/LeftTest.php | 18 --------------- .../Functions/TextData/LenTest.php | 18 --------------- .../Functions/TextData/LowerTest.php | 18 --------------- .../Functions/TextData/MidTest.php | 18 --------------- .../Functions/TextData/NumberValueTest.php | 18 --------------- .../Functions/TextData/ProperTest.php | 18 --------------- .../Functions/TextData/ReplaceTest.php | 18 --------------- .../Functions/TextData/RightTest.php | 18 --------------- .../Functions/TextData/SearchTest.php | 18 --------------- .../Functions/TextData/SubstituteTest.php | 18 --------------- .../Calculation/Functions/TextData/TTest.php | 18 --------------- .../Functions/TextData/TextJoinTest.php | 18 --------------- .../Functions/TextData/TextTest.php | 23 ------------------- .../Functions/TextData/TrimTest.php | 18 --------------- .../Functions/TextData/UpperTest.php | 18 --------------- .../Functions/TextData/ValueTest.php | 21 +++++++++-------- .../Calculation/FunctionsTest.php | 10 ++++++-- .../Cell/AdvancedValueBinderTest.php | 20 ++++++++++++++++ .../Shared/StringHelperTest.php | 16 +++++++++++++ .../Style/NumberFormatTest.php | 16 +++++++++++++ .../Writer/Html/HtmlNumberFormatTest.php | 5 ++++ 32 files changed, 110 insertions(+), 435 deletions(-) diff --git a/tests/PhpSpreadsheetTests/Calculation/CalculationTest.php b/tests/PhpSpreadsheetTests/Calculation/CalculationTest.php index 80431c4d..8e339207 100644 --- a/tests/PhpSpreadsheetTests/Calculation/CalculationTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/CalculationTest.php @@ -9,15 +9,23 @@ use PHPUnit\Framework\TestCase; class CalculationTest extends TestCase { + private $compatibilityMode; + + private $locale; + protected function setUp(): void { + $this->compatibilityMode = Functions::getCompatibilityMode(); + $calculation = Calculation::getInstance(); + $this->locale = $calculation->getLocale(); Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); } protected function tearDown(): void { + Functions::setCompatibilityMode($this->compatibilityMode); $calculation = Calculation::getInstance(); - $calculation->setLocale('en_us'); + $calculation->setLocale($this->locale); } /** diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DayTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DayTest.php index 8f4639eb..482e068d 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DayTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DayTest.php @@ -9,13 +9,29 @@ use PHPUnit\Framework\TestCase; class DayTest extends TestCase { + private $compatibilityMode; + + private $returnDateType; + + private $excelCalendar; + protected function setUp(): void { + $this->compatibilityMode = Functions::getCompatibilityMode(); + $this->returnDateType = Functions::getReturnDateType(); + $this->excelCalendar = Date::getExcelCalendar(); Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); Functions::setReturnDateType(Functions::RETURNDATE_EXCEL); Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900); } + protected function tearDown(): void + { + Functions::setCompatibilityMode($this->compatibilityMode); + Functions::setReturnDateType($this->returnDateType); + Date::setExcelCalendar($this->excelCalendar); + } + /** * @dataProvider providerDAY * diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/CountTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/CountTest.php index 26e621ec..65b698e3 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/CountTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/CountTest.php @@ -8,11 +8,19 @@ use PHPUnit\Framework\TestCase; class CountTest extends TestCase { + private $compatibilityMode; + protected function setUp(): void { + $this->compatibilityMode = Functions::getCompatibilityMode(); Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); } + protected function tearDown(): void + { + Functions::setCompatibilityMode($this->compatibilityMode); + } + /** * @dataProvider providerBasicCOUNT * diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/CharTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/CharTest.php index 70ea7526..cf22df02 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/CharTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/CharTest.php @@ -2,29 +2,11 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\TextData; -use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PHPUnit\Framework\TestCase; class CharTest extends TestCase { - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - - protected function tearDown(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - /** * @dataProvider providerCHAR * diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/CleanTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/CleanTest.php index 6aedb599..31dcc5e6 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/CleanTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/CleanTest.php @@ -2,29 +2,11 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\TextData; -use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PHPUnit\Framework\TestCase; class CleanTest extends TestCase { - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - - protected function tearDown(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - /** * @dataProvider providerCLEAN * diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/CodeTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/CodeTest.php index ec9f26d6..9c19f347 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/CodeTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/CodeTest.php @@ -2,29 +2,11 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\TextData; -use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PHPUnit\Framework\TestCase; class CodeTest extends TestCase { - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - - protected function tearDown(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - /** * @dataProvider providerCODE * diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ConcatenateTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ConcatenateTest.php index 18a2d684..068e7d8f 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ConcatenateTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ConcatenateTest.php @@ -2,29 +2,11 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\TextData; -use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PHPUnit\Framework\TestCase; class ConcatenateTest extends TestCase { - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - - protected function tearDown(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - /** * @dataProvider providerCONCATENATE * diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/DollarTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/DollarTest.php index 4a0f6013..1d482589 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/DollarTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/DollarTest.php @@ -2,29 +2,11 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\TextData; -use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PHPUnit\Framework\TestCase; class DollarTest extends TestCase { - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - - protected function tearDown(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - /** * @dataProvider providerDOLLAR * diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ExactTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ExactTest.php index 09d45a32..92d3935c 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ExactTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ExactTest.php @@ -2,29 +2,11 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\TextData; -use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PHPUnit\Framework\TestCase; class ExactTest extends TestCase { - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - - protected function tearDown(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - /** * @dataProvider providerEXACT * @@ -33,10 +15,6 @@ class ExactTest extends TestCase */ public function testEXACT($expectedResult, ...$args): void { - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(' '); - StringHelper::setCurrencyCode('$'); - $result = TextData::EXACT(...$args); self::assertSame($expectedResult, $result); } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/FindTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/FindTest.php index 38203a33..d4b1b77d 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/FindTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/FindTest.php @@ -2,29 +2,11 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\TextData; -use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PHPUnit\Framework\TestCase; class FindTest extends TestCase { - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - - protected function tearDown(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - /** * @dataProvider providerFIND * diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/FixedTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/FixedTest.php index 53e6a513..0cbaf80c 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/FixedTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/FixedTest.php @@ -2,29 +2,11 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\TextData; -use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PHPUnit\Framework\TestCase; class FixedTest extends TestCase { - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - - protected function tearDown(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - /** * @dataProvider providerFIXED * diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/LeftTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/LeftTest.php index 9a033ae7..e69a3fa0 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/LeftTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/LeftTest.php @@ -2,29 +2,11 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\TextData; -use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PHPUnit\Framework\TestCase; class LeftTest extends TestCase { - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - - protected function tearDown(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - /** * @dataProvider providerLEFT * diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/LenTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/LenTest.php index af784163..bca2b389 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/LenTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/LenTest.php @@ -2,29 +2,11 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\TextData; -use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PHPUnit\Framework\TestCase; class LenTest extends TestCase { - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - - protected function tearDown(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - /** * @dataProvider providerLEN * diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/LowerTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/LowerTest.php index 6ad522d8..9ba677c7 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/LowerTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/LowerTest.php @@ -2,29 +2,11 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\TextData; -use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PHPUnit\Framework\TestCase; class LowerTest extends TestCase { - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - - protected function tearDown(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - /** * @dataProvider providerLOWER * diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/MidTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/MidTest.php index df02575f..4c19248a 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/MidTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/MidTest.php @@ -2,29 +2,11 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\TextData; -use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PHPUnit\Framework\TestCase; class MidTest extends TestCase { - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - - protected function tearDown(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - /** * @dataProvider providerMID * diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/NumberValueTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/NumberValueTest.php index 006e4ce1..c186bb0b 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/NumberValueTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/NumberValueTest.php @@ -2,29 +2,11 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\TextData; -use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PHPUnit\Framework\TestCase; class NumberValueTest extends TestCase { - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - - protected function tearDown(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - /** * @dataProvider providerNUMBERVALUE * diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ProperTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ProperTest.php index d799b395..aae0e696 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ProperTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ProperTest.php @@ -2,29 +2,11 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\TextData; -use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PHPUnit\Framework\TestCase; class ProperTest extends TestCase { - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - - protected function tearDown(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - /** * @dataProvider providerPROPER * diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ReplaceTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ReplaceTest.php index ff3d58bb..ff9236e6 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ReplaceTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ReplaceTest.php @@ -2,29 +2,11 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\TextData; -use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PHPUnit\Framework\TestCase; class ReplaceTest extends TestCase { - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - - protected function tearDown(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - /** * @dataProvider providerREPLACE * diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/RightTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/RightTest.php index a89ea6ed..50fc86dc 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/RightTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/RightTest.php @@ -2,29 +2,11 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\TextData; -use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PHPUnit\Framework\TestCase; class RightTest extends TestCase { - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - - protected function tearDown(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - /** * @dataProvider providerRIGHT * diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/SearchTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/SearchTest.php index 919ec0fb..7bb92e83 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/SearchTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/SearchTest.php @@ -2,29 +2,11 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\TextData; -use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PHPUnit\Framework\TestCase; class SearchTest extends TestCase { - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - - protected function tearDown(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - /** * @dataProvider providerSEARCH * diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/SubstituteTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/SubstituteTest.php index d1884fd8..2a9d1012 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/SubstituteTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/SubstituteTest.php @@ -2,29 +2,11 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\TextData; -use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PHPUnit\Framework\TestCase; class SubstituteTest extends TestCase { - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - - protected function tearDown(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - /** * @dataProvider providerSUBSTITUTE * diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TTest.php index 1ce989b4..c7606c05 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TTest.php @@ -2,29 +2,11 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\TextData; -use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PHPUnit\Framework\TestCase; class TTest extends TestCase { - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - - protected function tearDown(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - /** * @dataProvider providerT * diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TextJoinTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TextJoinTest.php index 7eec585c..e8fb404d 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TextJoinTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TextJoinTest.php @@ -2,29 +2,11 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\TextData; -use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PHPUnit\Framework\TestCase; class TextJoinTest extends TestCase { - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - - protected function tearDown(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - /** * @dataProvider providerTEXTJOIN * diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TextTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TextTest.php index eab517cc..8d7b238b 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TextTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TextTest.php @@ -2,29 +2,11 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\TextData; -use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PHPUnit\Framework\TestCase; class TextTest extends TestCase { - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - - protected function tearDown(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - /** * @dataProvider providerTEXT * @@ -32,11 +14,6 @@ class TextTest extends TestCase */ public function testTEXT($expectedResult, ...$args): void { - // Enforce decimal and thousands separator values to UK/US, and currency code to USD - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - $result = TextData::TEXTFORMAT(...$args); self::assertEquals($expectedResult, $result); } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TrimTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TrimTest.php index 24ede75f..91890ded 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TrimTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TrimTest.php @@ -2,29 +2,11 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\TextData; -use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PHPUnit\Framework\TestCase; class TrimTest extends TestCase { - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - - protected function tearDown(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - /** * @dataProvider providerTRIM * diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/UpperTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/UpperTest.php index 1600f37c..13fb0b86 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/UpperTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/UpperTest.php @@ -2,29 +2,11 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\TextData; -use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PHPUnit\Framework\TestCase; class UpperTest extends TestCase { - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - - protected function tearDown(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); - } - /** * @dataProvider providerUPPER * diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ValueTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ValueTest.php index a5083b22..355193de 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ValueTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ValueTest.php @@ -2,27 +2,30 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\TextData; use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PHPUnit\Framework\TestCase; class ValueTest extends TestCase { + private $currencyCode; + + private $decimalSeparator; + + private $thousandsSeparator; + protected function setUp(): void { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); + $this->currencyCode = StringHelper::getCurrencyCode(); + $this->decimalSeparator = StringHelper::getDecimalSeparator(); + $this->thousandsSeparator = StringHelper::getThousandsSeparator(); } protected function tearDown(): void { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - StringHelper::setDecimalSeparator('.'); - StringHelper::setThousandsSeparator(','); - StringHelper::setCurrencyCode('$'); + StringHelper::setCurrencyCode($this->currencyCode); + StringHelper::setDecimalSeparator($this->decimalSeparator); + StringHelper::setThousandsSeparator($this->thousandsSeparator); } /** diff --git a/tests/PhpSpreadsheetTests/Calculation/FunctionsTest.php b/tests/PhpSpreadsheetTests/Calculation/FunctionsTest.php index 4412215a..dfa01822 100644 --- a/tests/PhpSpreadsheetTests/Calculation/FunctionsTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/FunctionsTest.php @@ -10,16 +10,22 @@ use PHPUnit\Framework\TestCase; class FunctionsTest extends TestCase { + private $compatibilityMode; + + private $returnDate; + protected function setUp(): void { + $this->compatibilityMode = Functions::getCompatibilityMode(); + $this->returnDate = Functions::getReturnDateType(); Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); Functions::setReturnDateType(Functions::RETURNDATE_EXCEL); } protected function tearDown(): void { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); - Functions::setReturnDateType(Functions::RETURNDATE_EXCEL); + Functions::setCompatibilityMode($this->compatibilityMode); + Functions::setReturnDateType($this->returnDate); } public function testCompatibilityMode(): void diff --git a/tests/PhpSpreadsheetTests/Cell/AdvancedValueBinderTest.php b/tests/PhpSpreadsheetTests/Cell/AdvancedValueBinderTest.php index 936092d4..630a2944 100644 --- a/tests/PhpSpreadsheetTests/Cell/AdvancedValueBinderTest.php +++ b/tests/PhpSpreadsheetTests/Cell/AdvancedValueBinderTest.php @@ -13,6 +13,26 @@ use PHPUnit\Framework\TestCase; class AdvancedValueBinderTest extends TestCase { + private $currencyCode; + + private $decimalSeparator; + + private $thousandsSeparator; + + protected function setUp(): void + { + $this->currencyCode = StringHelper::getCurrencyCode(); + $this->decimalSeparator = StringHelper::getDecimalSeparator(); + $this->thousandsSeparator = StringHelper::getThousandsSeparator(); + } + + protected function tearDown(): void + { + StringHelper::setCurrencyCode($this->currencyCode); + StringHelper::setDecimalSeparator($this->decimalSeparator); + StringHelper::setThousandsSeparator($this->thousandsSeparator); + } + public function provider() { $currencyUSD = NumberFormat::FORMAT_CURRENCY_USD_SIMPLE; diff --git a/tests/PhpSpreadsheetTests/Shared/StringHelperTest.php b/tests/PhpSpreadsheetTests/Shared/StringHelperTest.php index b11bf764..41ed0b21 100644 --- a/tests/PhpSpreadsheetTests/Shared/StringHelperTest.php +++ b/tests/PhpSpreadsheetTests/Shared/StringHelperTest.php @@ -7,14 +7,30 @@ use PHPUnit\Framework\TestCase; class StringHelperTest extends TestCase { + private $currencyCode; + + private $decimalSeparator; + + private $thousandsSeparator; + protected function setUp(): void { parent::setUp(); + $this->currencyCode = StringHelper::getCurrencyCode(); + $this->decimalSeparator = StringHelper::getDecimalSeparator(); + $this->thousandsSeparator = StringHelper::getThousandsSeparator(); // Reset Currency Code StringHelper::setCurrencyCode(null); } + protected function tearDown(): void + { + StringHelper::setCurrencyCode($this->currencyCode); + StringHelper::setDecimalSeparator($this->decimalSeparator); + StringHelper::setThousandsSeparator($this->thousandsSeparator); + } + public function testGetIsIconvEnabled(): void { $result = StringHelper::getIsIconvEnabled(); diff --git a/tests/PhpSpreadsheetTests/Style/NumberFormatTest.php b/tests/PhpSpreadsheetTests/Style/NumberFormatTest.php index e995eded..6bf7db04 100644 --- a/tests/PhpSpreadsheetTests/Style/NumberFormatTest.php +++ b/tests/PhpSpreadsheetTests/Style/NumberFormatTest.php @@ -8,12 +8,28 @@ use PHPUnit\Framework\TestCase; class NumberFormatTest extends TestCase { + private $currencyCode; + + private $decimalSeparator; + + private $thousandsSeparator; + protected function setUp(): void { + $this->currencyCode = StringHelper::getCurrencyCode(); + $this->decimalSeparator = StringHelper::getDecimalSeparator(); + $this->thousandsSeparator = StringHelper::getThousandsSeparator(); StringHelper::setDecimalSeparator('.'); StringHelper::setThousandsSeparator(','); } + protected function tearDown(): void + { + StringHelper::setCurrencyCode($this->currencyCode); + StringHelper::setDecimalSeparator($this->decimalSeparator); + StringHelper::setThousandsSeparator($this->thousandsSeparator); + } + /** * @dataProvider providerNumberFormat * diff --git a/tests/PhpSpreadsheetTests/Writer/Html/HtmlNumberFormatTest.php b/tests/PhpSpreadsheetTests/Writer/Html/HtmlNumberFormatTest.php index 9d306fa0..340e820b 100644 --- a/tests/PhpSpreadsheetTests/Writer/Html/HtmlNumberFormatTest.php +++ b/tests/PhpSpreadsheetTests/Writer/Html/HtmlNumberFormatTest.php @@ -10,12 +10,16 @@ use PhpOffice\PhpSpreadsheetTests\Functional; class HtmlNumberFormatTest extends Functional\AbstractFunctional { + private $currency; + private $decsep; private $thosep; protected function setUp(): void { + $this->currency = StringHelper::getCurrencyCode(); + StringHelper::setCurrencyCode('$'); $this->decsep = StringHelper::getDecimalSeparator(); StringHelper::setDecimalSeparator('.'); $this->thosep = StringHelper::getThousandsSeparator(); @@ -24,6 +28,7 @@ class HtmlNumberFormatTest extends Functional\AbstractFunctional protected function tearDown(): void { + StringHelper::setCurrencyCode($this->currency); StringHelper::setDecimalSeparator($this->decsep); StringHelper::setThousandsSeparator($this->thosep); } From 7cb4884b96174eb611621635e6fb603ef54178f7 Mon Sep 17 00:00:00 2001 From: Adrien Crivelli Date: Sun, 19 Jul 2020 11:33:01 +0900 Subject: [PATCH 3/7] WEBSERVICE is HTTP client agnostic HTTP client must be configured via `Settings::setHttpClient()`. This is a small breaking change, but only for the very few people who started using WEBSERVICE from last version. Fixes #1562 Closes #1568 --- CHANGELOG.md | 2 +- composer.json | 3 +- composer.lock | 312 ++++-------------- docs/topics/settings.md | 17 + src/PhpSpreadsheet/Calculation/Web.php | 6 +- src/PhpSpreadsheet/Settings.php | 48 ++- .../Functions/Web/WebServiceTest.php | 79 +++-- tests/data/Calculation/Web/WEBSERVICE.php | 10 +- 8 files changed, 180 insertions(+), 297 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 48ee6293..4d45ebac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). ### Fixed -- nothing +- WEBSERVICE is HTTP client agnostic and must be configured via `Settings::setHttpClient()` [#1562](https://github.com/PHPOffice/PhpSpreadsheet/issues/1562) ### Changed diff --git a/composer.json b/composer.json index d4810ce6..d0379949 100644 --- a/composer.json +++ b/composer.json @@ -57,7 +57,8 @@ "markbaker/complex": "^1.4", "markbaker/matrix": "^1.2", "psr/simple-cache": "^1.0", - "guzzlehttp/guzzle": "^7.0" + "psr/http-client": "^1.0", + "psr/http-factory": "^1.0" }, "require-dev": { "dompdf/dompdf": "^0.8.5", diff --git a/composer.lock b/composer.lock index 99de82bf..266608f2 100644 --- a/composer.lock +++ b/composer.lock @@ -4,211 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "b7ea4dea7ce2e1c2299029fe978d2173", + "content-hash": "931b86c12c78e665f1766ea922f95e0b", "packages": [ - { - "name": "guzzlehttp/guzzle", - "version": "7.0.1", - "source": { - "type": "git", - "url": "https://github.com/guzzle/guzzle.git", - "reference": "2d9d3c186a6637a43193e66b097c50e4451eaab2" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/2d9d3c186a6637a43193e66b097c50e4451eaab2", - "reference": "2d9d3c186a6637a43193e66b097c50e4451eaab2", - "shasum": "" - }, - "require": { - "ext-json": "*", - "guzzlehttp/promises": "^1.0", - "guzzlehttp/psr7": "^1.6.1", - "php": "^7.2.5", - "psr/http-client": "^1.0" - }, - "provide": { - "psr/http-client-implementation": "1.0" - }, - "require-dev": { - "ergebnis/composer-normalize": "^2.0", - "ext-curl": "*", - "php-http/client-integration-tests": "dev-phpunit8", - "phpunit/phpunit": "^8.5.5", - "psr/log": "^1.1" - }, - "suggest": { - "ext-curl": "Required for CURL handler support", - "ext-intl": "Required for Internationalized Domain Name (IDN) support", - "psr/log": "Required for using the Log middleware" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "7.0-dev" - } - }, - "autoload": { - "psr-4": { - "GuzzleHttp\\": "src/" - }, - "files": [ - "src/functions_include.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Michael Dowling", - "email": "mtdowling@gmail.com", - "homepage": "https://github.com/mtdowling" - }, - { - "name": "Márk Sági-Kazár", - "email": "mark.sagikazar@gmail.com", - "homepage": "https://sagikazarmark.hu" - } - ], - "description": "Guzzle is a PHP HTTP client library", - "homepage": "http://guzzlephp.org/", - "keywords": [ - "client", - "curl", - "framework", - "http", - "http client", - "psr-18", - "psr-7", - "rest", - "web service" - ], - "time": "2020-06-27T10:33:25+00:00" - }, - { - "name": "guzzlehttp/promises", - "version": "v1.3.1", - "source": { - "type": "git", - "url": "https://github.com/guzzle/promises.git", - "reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/guzzle/promises/zipball/a59da6cf61d80060647ff4d3eb2c03a2bc694646", - "reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646", - "shasum": "" - }, - "require": { - "php": ">=5.5.0" - }, - "require-dev": { - "phpunit/phpunit": "^4.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.4-dev" - } - }, - "autoload": { - "psr-4": { - "GuzzleHttp\\Promise\\": "src/" - }, - "files": [ - "src/functions_include.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Michael Dowling", - "email": "mtdowling@gmail.com", - "homepage": "https://github.com/mtdowling" - } - ], - "description": "Guzzle promises library", - "keywords": [ - "promise" - ], - "time": "2016-12-20T10:07:11+00:00" - }, - { - "name": "guzzlehttp/psr7", - "version": "1.6.1", - "source": { - "type": "git", - "url": "https://github.com/guzzle/psr7.git", - "reference": "239400de7a173fe9901b9ac7c06497751f00727a" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/guzzle/psr7/zipball/239400de7a173fe9901b9ac7c06497751f00727a", - "reference": "239400de7a173fe9901b9ac7c06497751f00727a", - "shasum": "" - }, - "require": { - "php": ">=5.4.0", - "psr/http-message": "~1.0", - "ralouphie/getallheaders": "^2.0.5 || ^3.0.0" - }, - "provide": { - "psr/http-message-implementation": "1.0" - }, - "require-dev": { - "ext-zlib": "*", - "phpunit/phpunit": "~4.8.36 || ^5.7.27 || ^6.5.8" - }, - "suggest": { - "zendframework/zend-httphandlerrunner": "Emit PSR-7 responses" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.6-dev" - } - }, - "autoload": { - "psr-4": { - "GuzzleHttp\\Psr7\\": "src/" - }, - "files": [ - "src/functions_include.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Michael Dowling", - "email": "mtdowling@gmail.com", - "homepage": "https://github.com/mtdowling" - }, - { - "name": "Tobias Schultze", - "homepage": "https://github.com/Tobion" - } - ], - "description": "PSR-7 message implementation that also provides common utility methods", - "keywords": [ - "http", - "message", - "psr-7", - "request", - "response", - "stream", - "uri", - "url" - ], - "time": "2019-07-01T23:21:34+00:00" - }, { "name": "maennchen/zipstream-php", "version": "2.1.0", @@ -482,20 +279,20 @@ }, { "name": "psr/http-client", - "version": "1.0.0", + "version": "1.0.1", "source": { "type": "git", "url": "https://github.com/php-fig/http-client.git", - "reference": "496a823ef742b632934724bf769560c2a5c7c44e" + "reference": "2dfb5f6c5eff0e91e20e913f8c5452ed95b86621" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/http-client/zipball/496a823ef742b632934724bf769560c2a5c7c44e", - "reference": "496a823ef742b632934724bf769560c2a5c7c44e", + "url": "https://api.github.com/repos/php-fig/http-client/zipball/2dfb5f6c5eff0e91e20e913f8c5452ed95b86621", + "reference": "2dfb5f6c5eff0e91e20e913f8c5452ed95b86621", "shasum": "" }, "require": { - "php": "^7.0", + "php": "^7.0 || ^8.0", "psr/http-message": "^1.0" }, "type": "library", @@ -527,7 +324,59 @@ "psr", "psr-18" ], - "time": "2018-10-30T23:29:13+00:00" + "time": "2020-06-29T06:28:15+00:00" + }, + { + "name": "psr/http-factory", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-factory.git", + "reference": "12ac7fcd07e5b077433f5f2bee95b3a771bf61be" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-factory/zipball/12ac7fcd07e5b077433f5f2bee95b3a771bf61be", + "reference": "12ac7fcd07e5b077433f5f2bee95b3a771bf61be", + "shasum": "" + }, + "require": { + "php": ">=7.0.0", + "psr/http-message": "^1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interfaces for PSR-7 HTTP message factories", + "keywords": [ + "factory", + "http", + "message", + "psr", + "psr-17", + "psr-7", + "request", + "response" + ], + "time": "2019-04-30T12:38:16+00:00" }, { "name": "psr/http-message", @@ -627,46 +476,6 @@ ], "time": "2017-10-23T01:57:42+00:00" }, - { - "name": "ralouphie/getallheaders", - "version": "3.0.3", - "source": { - "type": "git", - "url": "https://github.com/ralouphie/getallheaders.git", - "reference": "120b605dfeb996808c31b6477290a714d356e822" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822", - "reference": "120b605dfeb996808c31b6477290a714d356e822", - "shasum": "" - }, - "require": { - "php": ">=5.6" - }, - "require-dev": { - "php-coveralls/php-coveralls": "^2.1", - "phpunit/phpunit": "^5 || ^6.5" - }, - "type": "library", - "autoload": { - "files": [ - "src/getallheaders.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Ralph Khattar", - "email": "ralph.khattar@gmail.com" - } - ], - "description": "A polyfill for getallheaders.", - "time": "2019-03-08T08:55:37+00:00" - }, { "name": "symfony/polyfill-mbstring", "version": "v1.17.1", @@ -4382,5 +4191,6 @@ "ext-zip": "*", "ext-zlib": "*" }, - "platform-dev": [] + "platform-dev": [], + "plugin-api-version": "1.1.0" } diff --git a/docs/topics/settings.md b/docs/topics/settings.md index 4463ceeb..d28a9996 100644 --- a/docs/topics/settings.md +++ b/docs/topics/settings.md @@ -43,3 +43,20 @@ More details of the features available once a locale has been set, including a list of the languages and locales currently supported, can be found in [Locale Settings for Formulae](./recipes.md#locale-settings-for-formulae). + +## HTTP client + +In order to use the `WEBSERVICE` function in formulae, you must configure an +HTTP client. Assuming you chose Guzzle 7, this can be done like: + + +```php +use GuzzleHttp\Client; +use Http\Factory\Guzzle\RequestFactory; +use PhpOffice\PhpSpreadsheet\Settings; + +$client = new Client(); +$requestFactory = new RequestFactory(); + +Settings::setHttpClient($client, $requestFactory); +``` diff --git a/src/PhpSpreadsheet/Calculation/Web.php b/src/PhpSpreadsheet/Calculation/Web.php index 9f0faf99..5cfd2ea8 100644 --- a/src/PhpSpreadsheet/Calculation/Web.php +++ b/src/PhpSpreadsheet/Calculation/Web.php @@ -2,7 +2,6 @@ namespace PhpOffice\PhpSpreadsheet\Calculation; -use GuzzleHttp\Psr7\Request; use PhpOffice\PhpSpreadsheet\Settings; use Psr\Http\Client\ClientExceptionInterface; @@ -31,7 +30,8 @@ class Web // Get results from the the webservice $client = Settings::getHttpClient(); - $request = new Request('GET', $url); + $requestFactory = Settings::getRequestFactory(); + $request = $requestFactory->createRequest('GET', $url); try { $response = $client->sendRequest($request); @@ -43,7 +43,7 @@ class Web return Functions::VALUE(); // cURL error } - $output = (string) $response->getBody(); + $output = $response->getBody()->getContents(); if (strlen($output) > 32767) { return Functions::VALUE(); // Output not a string or too long } diff --git a/src/PhpSpreadsheet/Settings.php b/src/PhpSpreadsheet/Settings.php index 15218c72..cfa50573 100644 --- a/src/PhpSpreadsheet/Settings.php +++ b/src/PhpSpreadsheet/Settings.php @@ -2,11 +2,11 @@ namespace PhpOffice\PhpSpreadsheet; -use GuzzleHttp\Client; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Chart\Renderer\IRenderer; use PhpOffice\PhpSpreadsheet\Collection\Memory; use Psr\Http\Client\ClientInterface; +use Psr\Http\Message\RequestFactoryInterface; use Psr\SimpleCache\CacheInterface; class Settings @@ -47,9 +47,14 @@ class Settings /** * The HTTP client implementation to be used for network request. * - * @var ClientInterface + * @var null|ClientInterface */ - private static $client; + private static $httpClient; + + /** + * @var null|RequestFactoryInterface + */ + private static $requestFactory; /** * Set the locale code to use for formula translations and any special formatting. @@ -169,9 +174,19 @@ class Settings /** * Set the HTTP client implementation to be used for network request. */ - public static function setHttpClient(ClientInterface $httpClient): void + public static function setHttpClient(ClientInterface $httpClient, RequestFactoryInterface $requestFactory): void { - self::$client = $httpClient; + self::$httpClient = $httpClient; + self::$requestFactory = $requestFactory; + } + + /** + * Unset the HTTP client configuration. + */ + public static function unsetHttpClient(): void + { + self::$httpClient = null; + self::$requestFactory = null; } /** @@ -179,10 +194,25 @@ class Settings */ public static function getHttpClient(): ClientInterface { - if (!self::$client) { - self::$client = new Client(); - } + self::assertHttpClient(); - return self::$client; + return self::$httpClient; + } + + /** + * Get the HTTP request factory. + */ + public static function getRequestFactory(): RequestFactoryInterface + { + self::assertHttpClient(); + + return self::$requestFactory; + } + + private static function assertHttpClient(): void + { + if (!self::$httpClient || !self::$requestFactory) { + throw new Exception('HTTP client must be configured via Settings::setHttpClient() to be able to use WEBSERVICE function.'); + } } } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Web/WebServiceTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Web/WebServiceTest.php index acc83cff..2aff7b3d 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/Web/WebServiceTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Web/WebServiceTest.php @@ -2,47 +2,46 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Web; -use GuzzleHttp\Client; -use GuzzleHttp\Exception\ClientException; -use GuzzleHttp\Exception\ConnectException; -use GuzzleHttp\Handler\MockHandler; -use GuzzleHttp\HandlerStack; -use GuzzleHttp\Psr7\Request; -use GuzzleHttp\Psr7\Response; -use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Web; use PhpOffice\PhpSpreadsheet\Settings; use PHPUnit\Framework\TestCase; +use Psr\Http\Client\ClientInterface; +use Psr\Http\Message\RequestFactoryInterface; +use Psr\Http\Message\RequestInterface; +use Psr\Http\Message\ResponseInterface; +use Psr\Http\Message\StreamInterface; class WebServiceTest extends TestCase { - protected static $client; - - public static function setUpBeforeClass(): void + protected function tearDown(): void { - // Prevent URL requests being sent out - $mock = new MockHandler([ - new ClientException('This is not a valid URL', new Request('GET', 'test'), new Response()), - new ConnectException('This is a 404 error', new Request('GET', 'test')), - new Response('200', [], str_repeat('a', 40000)), - new Response('200', [], 'This is a test'), - ]); - - $handlerStack = HandlerStack::create($mock); - self::$client = new Client(['handler' => $handlerStack]); - } - - protected function setUp(): void - { - Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); + Settings::unsetHttpClient(); } /** * @dataProvider providerWEBSERVICE */ - public function testWEBSERVICE(string $expectedResult, string $url): void + public function testWEBSERVICE(string $expectedResult, string $url, ?array $responseData): void { - Settings::setHttpClient(self::$client); + if ($responseData) { + $body = $this->createMock(StreamInterface::class); + $body->expects(self::atMost(1))->method('getContents')->willReturn($responseData[1]); + + $response = $this->createMock(ResponseInterface::class); + $response->expects(self::once())->method('getStatusCode')->willReturn($responseData[0]); + $response->expects(self::atMost(1))->method('getBody')->willReturn($body); + + $client = $this->createMock(ClientInterface::class); + $client->expects(self::once())->method('sendRequest')->willReturn($response); + + $request = $this->createMock(RequestInterface::class); + + $requestFactory = $this->createMock(RequestFactoryInterface::class); + $requestFactory->expects(self::atMost(1))->method('createRequest')->willReturn($request); + + Settings::setHttpClient($client, $requestFactory); + } + $result = Web::WEBSERVICE($url); self::assertEquals($expectedResult, $result); } @@ -51,4 +50,28 @@ class WebServiceTest extends TestCase { return require 'tests/data/Calculation/Web/WEBSERVICE.php'; } + + public function testWEBSERVICEReturnErrorWhenClientThrows(): void + { + $exception = $this->createMock(\Psr\Http\Client\ClientExceptionInterface::class); + + $client = $this->createMock(ClientInterface::class); + $client->expects(self::once())->method('sendRequest')->willThrowException($exception); + + $request = $this->createMock(RequestInterface::class); + + $requestFactory = $this->createMock(RequestFactoryInterface::class); + $requestFactory->expects(self::atMost(1))->method('createRequest')->willReturn($request); + + Settings::setHttpClient($client, $requestFactory); + + $result = Web::WEBSERVICE('https://example.com'); + self::assertEquals('#VALUE!', $result); + } + + public function testWEBSERVICEThrowsIfNotClientConfigured(): void + { + $this->expectExceptionMessage('HTTP client must be configured via Settings::setHttpClient() to be able to use WEBSERVICE function.'); + Web::WEBSERVICE('https://example.com'); + } } diff --git a/tests/data/Calculation/Web/WEBSERVICE.php b/tests/data/Calculation/Web/WEBSERVICE.php index 6d9934da..c8294eb2 100644 --- a/tests/data/Calculation/Web/WEBSERVICE.php +++ b/tests/data/Calculation/Web/WEBSERVICE.php @@ -4,25 +4,27 @@ return [ [ '#VALUE!', 'http://www.thisurlisfartoolongLoremipsumdolorsitametconsecteturadipiscingelitAliquamimperdietmetusurnasedaliquampurusdapibusefficiturQuisqueatullamcorpermaurisacmattisanteDonecsagittisauguenullaegeinterduurnapharetrautQuisquealectusvelnisivolutpatpharetraSuspendisseconvallisvulputateblanditClassaptenttacitisociosquadlitoratorquentperconubianostraperinceptoshimenaeosProinjustdiampulvinaracjustoauctorimperdietsuscipitestEtiamacmaximusmassasitametvulputatedolorthisurlisfartoolongLoremipsumdolorsitametconsecteturadipiscingelitAliquamimperdietmetusurnasedaliquampurusdapibusefficiturQuisqueatullamcorpermaurisacmattisanteDonecsagittisauguenullaegeinterduurnapharetrautQuisquealectusvelnisivolutpatpharetraSuspendisseconvallisvulputateblanditClassaptenttacitisociosquadlitoratorquentperconubianostraperinceptoshimenaeosProinjustdiampulvinaracjustoauctorimperdietsuscipitestEtiamacmaximusmassasitametvulputatedolorthisurlisfartoolongLoremipsumdolorsitametconsecteturadipiscingelitAliquamimperdietmetusurnasedaliquampurusdapibusefficiturQuisqueatullamcorpermaurisacmattisanteDonecsagittisauguenullaegeinterduurnapharetrautQuisquealectusvelnisivolutpatpharetraSuspendisseconvallisvulputateblanditClassaptenttacitisociosquadlitoratorquentperconubianostraperinceptoshimenaeosProinjustdiampulvinaracjustoauctorimperdietsuscipitestEtiamacmaximusmassasitametvulputatedolorthisurlisfartoolongLoremipsumdolorsitametconsecteturadipiscingelitAliquamimperdietmetusurnasedaliquampurusdapibusefficiturQuisqueatullamcorpermaurisacmattisanteDonecsagittisauguenullaegeinterduurnapharetrautQuisquealectusvelnisivolutpatpharetraSuspendisseconvallisvulputateblanditClassaptenttacitisociosquadlitoratorquentperconubianostraperinceptoshimenaeosProinjustdiampulvinaracjustoauctorimperdietsuscipitestEtiamacmaximusmassasitametvulputatedolorthisurlisfartoolongLoremipsumdolorsitametconsecteturadipiscingelitAliquamimperdietmetusurnasedaliquampurusdapibusefficiturQuisqueatullamcorpermaurisacmattisanteDonecsagittisauguenullaegeinterduurnapharetrautQuisquealectusvelnisivolutpatpharetraSuspendisseconvallisvulputateblanditClassaptenttacitisociosquadlitoratorquentperconubianostraperinceptoshimenaeosProinjustdiampulvinaracjustoauctorimperdietsuscipitestEtiamacmaximusmassasitametvulputatedolorthisurlisfartoolongLoremipsumdolorsitametconsecteturadipiscingelitAliquamimperdietmetusurnasedaliquampurusdapibusefficiturQuisqueatullamcorpermaurisacmattisanteDonecsagittisauguenullaegeinterduurnapharetrautQuisquealectusvelnisivolutpatpharetraSuspendisseconvallisvulputateblanditClassaptenttacitisociosquadlitoratorquentperconubianostraperinceptoshimenaeosProinjustdiampulvinaracjustoauctorimperdietsuscipitestEtiamacmaximusmassasitametvulputatedolor.com', + null, ], [ '#VALUE!', 'ftp://www.bla.com', - ], - [ - '#VALUE!', - 'http://notevenanurl', + null, ], [ '#VALUE!', 'http://www.example1.com', + ['404', 'not found'], + ], [ '#VALUE!', 'http://www.example2.com', + ['200', str_repeat('a', 40000)], ], [ 'This is a test', 'http://www.example3.com', + ['200', 'This is a test'], ], ]; From 7e12575d867ce9a8a071c899ee59e21b90bab7cb Mon Sep 17 00:00:00 2001 From: Dhaval Purohit Date: Wed, 13 May 2020 13:56:49 +0530 Subject: [PATCH 4/7] Borders are complete even on rowspanned columns using HTML reader Fixed #1455 Closes #1473 --- CHANGELOG.md | 1 + src/PhpSpreadsheet/Reader/Html.php | 21 ++++++++++++- tests/PhpSpreadsheetTests/Reader/HtmlTest.php | 31 +++++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d45ebac..cd682780 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). ### Fixed - WEBSERVICE is HTTP client agnostic and must be configured via `Settings::setHttpClient()` [#1562](https://github.com/PHPOffice/PhpSpreadsheet/issues/1562) +- Borders were not complete on rowspanned columns using HTML reader [#1473](https://github.com/PHPOffice/PhpSpreadsheet/pull/1473) ### Changed diff --git a/src/PhpSpreadsheet/Reader/Html.php b/src/PhpSpreadsheet/Reader/Html.php index 2fe85b6f..d59e4744 100644 --- a/src/PhpSpreadsheet/Reader/Html.php +++ b/src/PhpSpreadsheet/Reader/Html.php @@ -682,7 +682,26 @@ class Html extends BaseReader return; } - $cellStyle = $sheet->getStyle($column . $row); + if (isset($attributeArray['rowspan'], $attributeArray['colspan'])) { + $columnTo = $column; + for ($i = 0; $i < (int) $attributeArray['colspan'] - 1; ++$i) { + ++$columnTo; + } + $range = $column . $row . ':' . $columnTo . ($row + (int) $attributeArray['rowspan'] - 1); + $cellStyle = $sheet->getStyle($range); + } elseif (isset($attributeArray['rowspan'])) { + $range = $column . $row . ':' . $column . ($row + (int) $attributeArray['rowspan'] - 1); + $cellStyle = $sheet->getStyle($range); + } elseif (isset($attributeArray['colspan'])) { + $columnTo = $column; + for ($i = 0; $i < (int) $attributeArray['colspan'] - 1; ++$i) { + ++$columnTo; + } + $range = $column . $row . ':' . $columnTo . $row; + $cellStyle = $sheet->getStyle($range); + } else { + $cellStyle = $sheet->getStyle($column . $row); + } // add color styles (background & text) from dom element,currently support : td & th, using ONLY inline css style with RGB color $styles = explode(';', $attributeArray['style']); diff --git a/tests/PhpSpreadsheetTests/Reader/HtmlTest.php b/tests/PhpSpreadsheetTests/Reader/HtmlTest.php index b0994a33..636aaa94 100644 --- a/tests/PhpSpreadsheetTests/Reader/HtmlTest.php +++ b/tests/PhpSpreadsheetTests/Reader/HtmlTest.php @@ -424,4 +424,35 @@ class HtmlTest extends TestCase self::assertEquals(10, $style->getAlignment()->getIndent()); unlink($filename); } + + public function testBorderWithRowspanAndColspan(): void + { + $html = ' + + + + + + + +
NOT SPANNEDSPANNED
NOT SPANNED
'; + + $reader = new Html(); + $spreadsheet = $reader->loadFromString($html); + $firstSheet = $spreadsheet->getSheet(0); + $style = $firstSheet->getStyle('B1:C2'); + + $borders = $style->getBorders(); + + $totalBorders = [ + $borders->getTop(), + $borders->getLeft(), + $borders->getBottom(), + $borders->getRight(), + ]; + + foreach ($totalBorders as $border) { + self::assertEquals(Border::BORDER_THIN, $border->getBorderStyle()); + } + } } From 2383aad5689778470491581442aab38cec41bf1d Mon Sep 17 00:00:00 2001 From: Adrien Crivelli Date: Sun, 19 Jul 2020 18:51:35 +0900 Subject: [PATCH 5/7] 1.14.1 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cd682780..31584ac9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com) and this project adheres to [Semantic Versioning](https://semver.org). -## [Unreleased] +## 1.14.1 - 2020-07-19 ### Added From a8197128c6f02e252fce4085c1b197a2b15ad20c Mon Sep 17 00:00:00 2001 From: Adrien Crivelli Date: Sun, 19 Jul 2020 18:54:34 +0900 Subject: [PATCH 6/7] Remove links that should never have been links --- CHANGELOG.md | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 31584ac9..3989a60e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,7 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). - nothing -## [1.14.0] - 2020-06-29 +## 1.14.0 - 2020-06-29 ### Added @@ -44,7 +44,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). - Xls Writer - Correct Timestamp Bug [#1493](https://github.com/PHPOffice/PhpSpreadsheet/pull/1493) - Don't ouput row and columns without any cells in HTML writer [#1235](https://github.com/PHPOffice/PhpSpreadsheet/issues/1235) -## [1.13.0] - 2020-05-31 +## 1.13.0 - 2020-05-31 ### Added @@ -70,7 +70,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). - Drop partial migration tool in favor of complete migration via RectorPHP [#1445](https://github.com/PHPOffice/PhpSpreadsheet/issues/1445) - Limit composer package to `src/` [#1424](https://github.com/PHPOffice/PhpSpreadsheet/pull/1424) -## [1.12.0] - 2020-04-27 +## 1.12.0 - 2020-04-27 ### Added @@ -86,7 +86,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). - MATCH with a static array should return the position of the found value based on the values submitted [#1332](https://github.com/PHPOffice/PhpSpreadsheet/pull/1332) - Fix Xlsx Reader's handling of undefined fill color [#1353](https://github.com/PHPOffice/PhpSpreadsheet/pull/1353) -## [1.11.0] - 2020-03-02 +## 1.11.0 - 2020-03-02 ### Added @@ -105,7 +105,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). - Fix XLSX file loading with autofilter containing '$' [#1326](https://github.com/PHPOffice/PhpSpreadsheet/pull/1326) - PHPDoc - Use `@return $this` for fluent methods [#1362](https://github.com/PHPOffice/PhpSpreadsheet/pull/1362) -## [1.10.1] - 2019-12-02 +## 1.10.1 - 2019-12-02 ### Changed @@ -120,7 +120,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). - ODS writer prevent invalid numeric value if locale decimal separator is comma [#1268](https://github.com/PHPOffice/PhpSpreadsheet/pull/1268) - Xlsx writer actually writes plotVisOnly and dispBlanksAs from chart properties [#1266](https://github.com/PHPOffice/PhpSpreadsheet/pull/1266) -## [1.10.0] - 2019-11-18 +## 1.10.0 - 2019-11-18 ### Changed @@ -145,7 +145,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). - Validate XIRR inputs and return correct error values [#1120](https://github.com/PHPOffice/PhpSpreadsheet/issues/1120) - Allow to read xlsx files with exotic workbook names like "workbook2.xml" [#1183](https://github.com/PHPOffice/PhpSpreadsheet/pull/1183) -## [1.9.0] - 2019-08-17 +## 1.9.0 - 2019-08-17 ### Changed @@ -176,20 +176,20 @@ and this project adheres to [Semantic Versioning](https://semver.org). - Fix `getCalculatedValue()` error with more than two INDIRECT [#1115](https://github.com/PHPOffice/PhpSpreadsheet/pull/1115) - Writer\Html did not hide columns [#985](https://github.com/PHPOffice/PhpSpreadsheet/pull/985) -## [1.8.2] - 2019-07-08 +## 1.8.2 - 2019-07-08 ### Fixed - Uncaught error when opening ods file and properties aren't defined [#1047](https://github.com/PHPOffice/PhpSpreadsheet/issues/1047) - Xlsx Reader Cell datavalidations bug [#1052](https://github.com/PHPOffice/PhpSpreadsheet/pull/1052) -## [1.8.1] - 2019-07-02 +## 1.8.1 - 2019-07-02 ### Fixed - Allow nullable theme for Xlsx Style Reader class [#1043](https://github.com/PHPOffice/PhpSpreadsheet/issues/1043) -## [1.8.0] - 2019-07-01 +## 1.8.0 - 2019-07-01 ### Security Fix (CVE-2019-12331) @@ -212,7 +212,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). - Fix a SUMIF warning with some versions of PHP when having different length of arrays provided as input [#873](https://github.com/PHPOffice/PhpSpreadsheet/pull/873) - Fix incorrectly handled backslash-escaped space characters in number format -## [1.7.0] - 2019-05-26 +## 1.7.0 - 2019-05-26 - Added support for inline styles in Html reader (borders, alignment, width, height) - QuotedText cells no longer treated as formulae if the content begins with a `=` @@ -226,7 +226,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). - Fix VLOOKUP - Fix return type hint -## [1.6.0] - 2019-01-02 +## 1.6.0 - 2019-01-02 ### Added @@ -254,13 +254,13 @@ and this project adheres to [Semantic Versioning](https://semver.org). - `master` is the new default branch, `develop` does not exist anymore -## [1.5.2] - 2018-11-25 +## 1.5.2 - 2018-11-25 ### Security - Improvements to the design of the XML Security Scanner [#771](https://github.com/PHPOffice/PhpSpreadsheet/issues/771) -## [1.5.1] - 2018-11-20 +## 1.5.1 - 2018-11-20 ### Security @@ -280,7 +280,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). - Mpdf export can exceed pcre.backtrack_limit [#637](https://github.com/PHPOffice/PhpSpreadsheet/issues/637) - Fix index overflow on data values array [#748](https://github.com/PHPOffice/PhpSpreadsheet/pull/748) -## [1.5.0] - 2018-10-21 +## 1.5.0 - 2018-10-21 ### Added @@ -295,7 +295,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). - OFFSET should allow omitted height and width [#561](https://github.com/PHPOffice/PhpSpreadsheet/issues/561) - Correctly determine delimiter when CSV contains line breaks inside enclosures [#716](https://github.com/PHPOffice/PhpSpreadsheet/issues/716) -## [1.4.1] - 2018-09-30 +## 1.4.1 - 2018-09-30 ### Fixed @@ -304,7 +304,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). - Fix warning when reading xlsx without styles [#631](https://github.com/PHPOffice/PhpSpreadsheet/pull/631) - Fix broken sample links on windows due to $baseDir having backslash [#653](https://github.com/PHPOffice/PhpSpreadsheet/pull/653) -## [1.4.0] - 2018-08-06 +## 1.4.0 - 2018-08-06 ### Added @@ -368,13 +368,13 @@ and this project adheres to [Semantic Versioning](https://semver.org). - Migration tool keep variables containing $PHPExcel untouched [#598](https://github.com/PHPOffice/PhpSpreadsheet/issues/598) - Rowspans/colspans were incorrect when adding worksheet using loadIntoExisting [#619](https://github.com/PHPOffice/PhpSpreadsheet/issues/619) -## [1.3.1] - 2018-06-12 +## 1.3.1 - 2018-06-12 ### Fixed - Ranges across Z and AA columns incorrectly threw an exception [#545](https://github.com/PHPOffice/PhpSpreadsheet/issues/545) -## [1.3.0] - 2018-06-10 +## 1.3.0 - 2018-06-10 ### Added @@ -393,13 +393,13 @@ and this project adheres to [Semantic Versioning](https://semver.org). - Fixed parsing of conditionals in COUNTIF functions [#526](https://github.com/PHPOffice/PhpSpreadsheet/issues/526) - Corruption errors for saved Xlsx docs with frozen panes [#532](https://github.com/PHPOffice/PhpSpreadsheet/issues/532) -## [1.2.1] - 2018-04-10 +## 1.2.1 - 2018-04-10 ### Fixed - Plain text and richtext mixed in same cell can be read [#442](https://github.com/PHPOffice/PhpSpreadsheet/issues/442) -## [1.2.0] - 2018-03-04 +## 1.2.0 - 2018-03-04 ### Added @@ -417,7 +417,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). - Select correct cell when calling freezePane [#389](https://github.com/PHPOffice/PhpSpreadsheet/issues/389) - `setStrikethrough()` did not set the font [#403](https://github.com/PHPOffice/PhpSpreadsheet/issues/403) -## [1.1.0] - 2018-01-28 +## 1.1.0 - 2018-01-28 ### Added @@ -435,7 +435,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). - Support XML file without styles [#331](https://github.com/PHPOffice/PhpSpreadsheet/pull/331) - Cell coordinates which are already a range cause an exception [#319](https://github.com/PHPOffice/PhpSpreadsheet/issues/319) -## [1.0.0] - 2017-12-25 +## 1.0.0 - 2017-12-25 ### Added @@ -454,7 +454,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). - Constant `TYPE_DOUGHTNUTCHART` is now `TYPE_DOUGHNUTCHART`. -## [1.0.0-beta2] - 2017-11-26 +## 1.0.0-beta2 - 2017-11-26 ### Added @@ -492,7 +492,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). - `PhpSpreadsheet\Style` => `PhpSpreadsheet\Style\Style` - `PhpSpreadsheet\Worksheet` => `PhpSpreadsheet\Worksheet\Worksheet` -## [1.0.0-beta] - 2017-08-17 +## 1.0.0-beta - 2017-08-17 ### Added From a79c736f4287b36e0b34bc275bd440aa6534f7a6 Mon Sep 17 00:00:00 2001 From: Adrien Crivelli Date: Sun, 19 Jul 2020 18:55:18 +0900 Subject: [PATCH 7/7] Update CHANGELOG --- CHANGELOG.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3989a60e..f6a0e9ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,28 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com) and this project adheres to [Semantic Versioning](https://semver.org). +## Unreleased - TBD + +### Added + +- Nothing. + +### Changed + +- Nothing. + +### Deprecated + +- Nothing. + +### Removed + +- Nothing. + +### Fixed + +- Nothing. + ## 1.14.1 - 2020-07-19 ### Added