From 3acf4f3e874cffaf88b3e1f308e4c3700e471dd8 Mon Sep 17 00:00:00 2001 From: Owen Leibman Date: Sun, 1 Nov 2020 20:28:24 -0800 Subject: [PATCH] Restore Omitted Read XML Test I omitted one test from my PR to improve test coverage for XML Read, because Travis reported an error that I could not duplicate on my system. The likeliest explanation seemed to be that there were commits to master which were not present in my fork. Whether or not that is true, I synced my fork with the master, and duplicated and fixed the problem. --- src/PhpSpreadsheet/Reader/Xml.php | 8 ++- .../Reader/Xml/XmlOddTest.php | 70 +++++++++++++++++++ 2 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 tests/PhpSpreadsheetTests/Reader/Xml/XmlOddTest.php diff --git a/src/PhpSpreadsheet/Reader/Xml.php b/src/PhpSpreadsheet/Reader/Xml.php index e4d251e28f..11aa1df3bd 100644 --- a/src/PhpSpreadsheet/Reader/Xml.php +++ b/src/PhpSpreadsheet/Reader/Xml.php @@ -617,9 +617,11 @@ public function loadIntoExisting($pFilename, Spreadsheet $spreadsheet) ++$rowID; } - $xmlX = $worksheet->children($namespaces['x']); - if (isset($xmlX->WorksheetOptions)) { - (new PageSettings($xmlX, $namespaces))->loadPageSettings($spreadsheet); + if (isset($namespaces['x'])) { + $xmlX = $worksheet->children($namespaces['x']); + if (isset($xmlX->WorksheetOptions)) { + (new PageSettings($xmlX, $namespaces))->loadPageSettings($spreadsheet); + } } } ++$worksheetID; diff --git a/tests/PhpSpreadsheetTests/Reader/Xml/XmlOddTest.php b/tests/PhpSpreadsheetTests/Reader/Xml/XmlOddTest.php new file mode 100644 index 0000000000..e0b43113b1 --- /dev/null +++ b/tests/PhpSpreadsheetTests/Reader/Xml/XmlOddTest.php @@ -0,0 +1,70 @@ +filename) { + unlink($this->filename); + $this->filename = ''; + } + } + + public function testWriteThenRead(): void + { + $xmldata = <<< 'EOT' + + + + Xml2003 Short Workbook + + + 2 + + + 9000 + 13860 + 240 + 75 + False + False + + + + + + + Test String 1 + + +
+
+
+EOT; + $this->filename = tempnam(File::sysGetTempDir(), 'phpspreadsheet-test'); + file_put_contents($this->filename, $xmldata); + $reader = new Xml(); + $spreadsheet = $reader->load($this->filename); + self::assertEquals(1, $spreadsheet->getSheetCount()); + + $sheet = $spreadsheet->getActiveSheet(); + self::assertEquals('Sample Data', $sheet->getTitle()); + self::assertEquals('Test String 1', $sheet->getCell('A8')->getValue()); + + $props = $spreadsheet->getProperties(); + self::assertEquals('Xml2003 Short Workbook', $props->getTitle()); + self::assertEquals('2', $props->getCustomPropertyValue('myڐInt')); + } +}