-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix XLSX file loading with autofilter containing '$'
The `setRange` method of the `Xlsx/AutoFilter` class expects a filter range format like "A1:E10". The returned value from `$this->worksheetXml->autoFilter['ref']` could contain "$" and returning a value like "$A$1:$E$10". Fixes #687 Fixes #1325 Closes #1326
- Loading branch information
Showing
3 changed files
with
72 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx; | ||
|
||
use PhpOffice\PhpSpreadsheet\Reader\Xlsx\AutoFilter; | ||
use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter as WorksheetAutoFilter; | ||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class AutoFilterTest extends TestCase | ||
{ | ||
private function getWorksheetInstance() | ||
{ | ||
return $this->getMockBuilder(Worksheet::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
} | ||
|
||
private function getXMLInstance($ref) | ||
{ | ||
return new \SimpleXMLElement( | ||
'<?xml version="1.0" encoding="UTF-8"?>' . | ||
'<root>' . | ||
'<autoFilter ref="' . $ref . '"></autoFilter>' . | ||
'</root>' | ||
); | ||
} | ||
|
||
private function getAutoFilterInstance() | ||
{ | ||
$instance = $this->getMockBuilder(WorksheetAutoFilter::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
return $instance; | ||
} | ||
|
||
public function loadDataProvider() | ||
{ | ||
return [ | ||
['$B3$E8', 0, 'B3E8'], | ||
['$B3:$E8', 1, 'B3:E8'], | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider loadDataProvider | ||
* | ||
* @param string $ref | ||
* @param int $expectedReadAutoFilterCalled | ||
* @param string $expectedRef | ||
*/ | ||
public function testLoad($ref, $expectedReadAutoFilterCalled, $expectedRef) | ||
{ | ||
$worksheetAutoFilter = $this->getAutoFilterInstance(); | ||
$worksheetAutoFilter->expects($this->exactly($expectedReadAutoFilterCalled ? 1 : 0)) | ||
->method('setRange') | ||
->with($expectedRef); | ||
|
||
$worksheet = $this->getWorksheetInstance(); | ||
$worksheet->expects($this->exactly($expectedReadAutoFilterCalled ? 1 : 0)) | ||
->method('getAutoFilter') | ||
->willReturn($worksheetAutoFilter); | ||
|
||
$autoFilter = new AutoFilter($worksheet, $this->getXMLInstance($ref)); | ||
|
||
$autoFilter->load(); | ||
} | ||
} |