diff --git a/CHANGELOG.md b/CHANGELOG.md index 20819876..d3ce9b5b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). - Stricter-typed comparison testing in COUNTIF() and COUNTIFS() evaluation [Issue #1046](https://github.com/PHPOffice/PhpSpreadsheet/issues/1046) - COUPNUM should not return zero when settlement is in the last period - [Issue #1020](https://github.com/PHPOffice/PhpSpreadsheet/issues/1020) and [PR #1021](https://github.com/PHPOffice/PhpSpreadsheet/pull/1021) - Fix handling of named ranges referencing sheets with spaces or "!" in their title +- Cover `getSheetByName()` with tests for name with quote and spaces - [#739](https://github.com/PHPOffice/PhpSpreadsheet/issues/739) ## [1.8.2] - 2019-07-08 diff --git a/tests/PhpSpreadsheetTests/SpreadsheetTest.php b/tests/PhpSpreadsheetTests/SpreadsheetTest.php new file mode 100644 index 00000000..5173bf22 --- /dev/null +++ b/tests/PhpSpreadsheetTests/SpreadsheetTest.php @@ -0,0 +1,56 @@ +object = new Spreadsheet(); + $sheet = $this->object->getActiveSheet(); + + $sheet->setTitle('someSheet1'); + $sheet = new Worksheet(); + $sheet->setTitle('someSheet2'); + $this->object->addSheet($sheet); + $sheet = new Worksheet(); + $sheet->setTitle('someSheet 3'); + $this->object->addSheet($sheet); + } + + /** + * @return array + */ + public function dataProviderForSheetNames() + { + $array = [ + [0, 'someSheet1'], + [0, "'someSheet1'"], + [1, 'someSheet2'], + [1, "'someSheet2'"], + [2, 'someSheet 3'], + [2, "'someSheet 3'"], + ]; + + return $array; + } + + /** + * @param $index + * @param $sheetName + * + * @dataProvider dataProviderForSheetNames + */ + public function testGetSheetByName($index, $sheetName) + { + $this->assertEquals($this->object->getSheet($index), $this->object->getSheetByName($sheetName)); + } +} diff --git a/tests/PhpSpreadsheetTests/Worksheet/WorksheetTest.php b/tests/PhpSpreadsheetTests/Worksheet/WorksheetTest.php index ce2df837..5e8bbcb2 100644 --- a/tests/PhpSpreadsheetTests/Worksheet/WorksheetTest.php +++ b/tests/PhpSpreadsheetTests/Worksheet/WorksheetTest.php @@ -138,6 +138,10 @@ class WorksheetTest extends TestCase ['testTitle!B2', 'testTitle', 'B2', 'B2'], ['test!Title!B2', 'test!Title', 'B2', 'B2'], ['test Title!B2', 'test Title', 'B2', 'B2'], + ['test!Title!B2', 'test!Title', 'B2', 'B2'], + ["'testSheet 1'!A3", "'testSheet 1'", 'A3', 'A3'], + ["'testSheet1'!A2", "'testSheet1'", 'A2', 'A2'], + ["'testSheet 2'!A1", "'testSheet 2'", 'A1', 'A1'], ]; }