Skip to content

Commit

Permalink
ref #1325 Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
astronati committed Feb 27, 2020
1 parent e7f3318 commit 0cca72e
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions tests/PhpSpreadsheetTests/Reader/Xlsx/AutoFilterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx;

use PhpOffice\PhpSpreadsheet\Reader\Xlsx\AutoFilter;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter as WorksheetAutoFilter;
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();
}
}

0 comments on commit 0cca72e

Please sign in to comment.