diff --git a/tests/PhpSpreadsheetTests/Reader/Xlsx/AutoFilterTest.php b/tests/PhpSpreadsheetTests/Reader/Xlsx/AutoFilterTest.php new file mode 100644 index 0000000000..90ea17aa0d --- /dev/null +++ b/tests/PhpSpreadsheetTests/Reader/Xlsx/AutoFilterTest.php @@ -0,0 +1,69 @@ +getMockBuilder(Worksheet::class) + ->disableOriginalConstructor() + ->getMock(); + } + + private function getXMLInstance($ref) + { + return new \SimpleXMLElement( + '' . + '' . + '' . + '' + ); + } + + 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(); + } +}