Skip to content

Commit d6b3514

Browse files
Christian WERNERPowerKiKi
Christian WERNER
authored andcommitted
Cover getSheetByName() with tests for name with quote and spaces
Fixes #739 Closes #893
1 parent 26e87c4 commit d6b3514

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
2222
- Stricter-typed comparison testing in COUNTIF() and COUNTIFS() evaluation [Issue #1046](https://github.com/PHPOffice/PhpSpreadsheet/issues/1046)
2323
- 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)
2424
- Fix handling of named ranges referencing sheets with spaces or "!" in their title
25+
- Cover `getSheetByName()` with tests for name with quote and spaces - [#739](https://github.com/PHPOffice/PhpSpreadsheet/issues/739)
2526

2627
## [1.8.2] - 2019-07-08
2728

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
namespace PhpOffice\PhpSpreadsheetTests;
4+
5+
use PhpOffice\PhpSpreadsheet\Spreadsheet;
6+
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
7+
use PHPUnit\Framework\TestCase;
8+
9+
class SpreadsheetTest extends TestCase
10+
{
11+
/** @var Spreadsheet */
12+
private $object;
13+
14+
public function setUp()
15+
{
16+
parent::setUp();
17+
$this->object = new Spreadsheet();
18+
$sheet = $this->object->getActiveSheet();
19+
20+
$sheet->setTitle('someSheet1');
21+
$sheet = new Worksheet();
22+
$sheet->setTitle('someSheet2');
23+
$this->object->addSheet($sheet);
24+
$sheet = new Worksheet();
25+
$sheet->setTitle('someSheet 3');
26+
$this->object->addSheet($sheet);
27+
}
28+
29+
/**
30+
* @return array
31+
*/
32+
public function dataProviderForSheetNames()
33+
{
34+
$array = [
35+
[0, 'someSheet1'],
36+
[0, "'someSheet1'"],
37+
[1, 'someSheet2'],
38+
[1, "'someSheet2'"],
39+
[2, 'someSheet 3'],
40+
[2, "'someSheet 3'"],
41+
];
42+
43+
return $array;
44+
}
45+
46+
/**
47+
* @param $index
48+
* @param $sheetName
49+
*
50+
* @dataProvider dataProviderForSheetNames
51+
*/
52+
public function testGetSheetByName($index, $sheetName)
53+
{
54+
$this->assertEquals($this->object->getSheet($index), $this->object->getSheetByName($sheetName));
55+
}
56+
}

tests/PhpSpreadsheetTests/Worksheet/WorksheetTest.php

+4
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ public function extractSheetTitleProvider()
138138
['testTitle!B2', 'testTitle', 'B2', 'B2'],
139139
['test!Title!B2', 'test!Title', 'B2', 'B2'],
140140
['test Title!B2', 'test Title', 'B2', 'B2'],
141+
['test!Title!B2', 'test!Title', 'B2', 'B2'],
142+
["'testSheet 1'!A3", "'testSheet 1'", 'A3', 'A3'],
143+
["'testSheet1'!A2", "'testSheet1'", 'A2', 'A2'],
144+
["'testSheet 2'!A1", "'testSheet 2'", 'A1', 'A1'],
141145
];
142146
}
143147

0 commit comments

Comments
 (0)