Expose Sheet::isActive() to provide info about the last active sheet (#405)

This commit is contained in:
Adrien Loison authored and GitHub committed 2017-04-15 21:40:19 +02:00
1 parent 4a65466b61
commit 7f8b95b2f3
13 files changed
+231 -28

No files matched your search

+46
View File
@@ -0,0 +1,46 @@
<?php
namespace Box\Spout\Reader\CSV;
use Box\Spout\Common\Type;
use Box\Spout\Reader\ReaderFactory;
use Box\Spout\TestUsingResource;
/**
* Class SheetTest
*
* @package Box\Spout\Reader\CSV
*/
class SheetTest extends \PHPUnit_Framework_TestCase
{
use TestUsingResource;
/**
* @return void
*/
public function testReaderShouldReturnCorrectSheetInfos()
{
$sheet = $this->openFileAndReturnSheet('csv_standard.csv');
$this->assertEquals('', $sheet->getName());
$this->assertEquals(0, $sheet->getIndex());
$this->assertTrue($sheet->isActive());
}
/**
* @param string $fileName
* @return Sheet
*/
private function openFileAndReturnSheet($fileName)
{
$resourcePath = $this->getResourcePath($fileName);
$reader = ReaderFactory::create(Type::CSV);
$reader->open($resourcePath);
$sheet = $reader->getSheetIterator()->current();
$reader->close();
return $sheet;
}
}
+16 -1
View File
@@ -18,15 +18,30 @@ class SheetTest extends \PHPUnit_Framework_TestCase
/**
* @return void
*/
public function testNextSheetShouldReturnCorrectSheetInfos()
public function testReaderShouldReturnCorrectSheetInfos()
{
// NOTE: This spreadsheet has its second tab defined as active
$sheets = $this->openFileAndReturnSheets('two_sheets_with_custom_names.ods');
$this->assertEquals('Sheet First', $sheets[0]->getName());
$this->assertEquals(0, $sheets[0]->getIndex());
$this->assertFalse($sheets[0]->isActive());
$this->assertEquals('Sheet Last', $sheets[1]->getName());
$this->assertEquals(1, $sheets[1]->getIndex());
$this->assertTrue($sheets[1]->isActive());
}
/**
* @return void
*/
public function testReaderShouldDefineFirstSheetAsActiveByDefault()
{
// NOTE: This spreadsheet has no information about the active sheet
$sheets = $this->openFileAndReturnSheets('two_sheets_with_no_settings_xml_file.ods');
$this->assertTrue($sheets[0]->isActive());
$this->assertFalse($sheets[1]->isActive());
}
/**
+5 -2
View File
@@ -18,15 +18,18 @@ class SheetTest extends \PHPUnit_Framework_TestCase
/**
* @return void
*/
public function testNextSheetShouldReturnCorrectSheetInfos()
public function testReaderShouldReturnCorrectSheetInfos()
{
$sheets = $this->openFileAndReturnSheets('two_sheets_with_custom_names.xlsx');
// NOTE: This spreadsheet has its second tab defined as active
$sheets = $this->openFileAndReturnSheets('two_sheets_with_custom_names_and_custom_active_tab.xlsx');
$this->assertEquals('CustomName1', $sheets[0]->getName());
$this->assertEquals(0, $sheets[0]->getIndex());
$this->assertFalse($sheets[0]->isActive());
$this->assertEquals('CustomName2', $sheets[1]->getName());
$this->assertEquals(1, $sheets[1]->getIndex());
$this->assertTrue($sheets[1]->isActive());
}
/**