From d8047b071bff2e5776533302d1f85d2b36e8ad9f Mon Sep 17 00:00:00 2001 From: Mark Baker Date: Mon, 8 Jul 2019 19:55:14 +0200 Subject: [PATCH] Basic unit test and fix for loading data validations from xlsx file (#1063) --- .../Reader/Xlsx/DataValidations.php | 2 +- tests/PhpSpreadsheetTests/Reader/XlsxTest.php | 11 +++++++++++ tests/data/Reader/XLSX/dataValidationTest.xlsx | Bin 0 -> 6804 bytes 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 tests/data/Reader/XLSX/dataValidationTest.xlsx diff --git a/src/PhpSpreadsheet/Reader/Xlsx/DataValidations.php b/src/PhpSpreadsheet/Reader/Xlsx/DataValidations.php index fab702b1..4bb44129 100644 --- a/src/PhpSpreadsheet/Reader/Xlsx/DataValidations.php +++ b/src/PhpSpreadsheet/Reader/Xlsx/DataValidations.php @@ -19,7 +19,7 @@ class DataValidations public function load() { - foreach ($this->worksheetXml->dataValidation as $dataValidation) { + foreach ($this->worksheetXml->dataValidations->dataValidation as $dataValidation) { // Uppercase coordinate $range = strtoupper($dataValidation['sqref']); $rangeSet = explode(' ', $range); diff --git a/tests/PhpSpreadsheetTests/Reader/XlsxTest.php b/tests/PhpSpreadsheetTests/Reader/XlsxTest.php index e9ab52de..5cf6f93f 100644 --- a/tests/PhpSpreadsheetTests/Reader/XlsxTest.php +++ b/tests/PhpSpreadsheetTests/Reader/XlsxTest.php @@ -158,6 +158,17 @@ class XlsxTest extends TestCase $this->assertInstanceOf(Style::class, $conditionalRule->getStyle()); } + public function testLoadXlsxDataValidation() + { + $filename = './data/Reader/XLSX/dataValidationTest.xlsx'; + $reader = new Xlsx(); + $spreadsheet = $reader->load($filename); + + $worksheet = $spreadsheet->getActiveSheet(); + + $this->assertTrue($worksheet->getCell('B3')->hasDataValidation()); + } + /** * Test load Xlsx file without cell reference. * diff --git a/tests/data/Reader/XLSX/dataValidationTest.xlsx b/tests/data/Reader/XLSX/dataValidationTest.xlsx new file mode 100644 index 0000000000000000000000000000000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