2015-04-27 21:47:47 +00:00
|
|
|
<?php
|
|
|
|
|
2016-08-31 17:18:12 +00:00
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Worksheet;
|
2016-08-13 17:22:11 +00:00
|
|
|
|
2016-08-31 17:18:12 +00:00
|
|
|
use PhpOffice\PhpSpreadsheet\Cell;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Worksheet;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Worksheet\ColumnCellIterator;
|
2015-05-30 11:25:17 +00:00
|
|
|
|
|
|
|
class ColumnCellIteratorTest extends \PHPUnit_Framework_TestCase
|
2015-04-27 21:47:47 +00:00
|
|
|
{
|
|
|
|
public $mockWorksheet;
|
|
|
|
public $mockColumnCell;
|
|
|
|
|
2015-05-17 13:00:02 +00:00
|
|
|
public function setUp()
|
|
|
|
{
|
2016-08-14 04:08:43 +00:00
|
|
|
$this->mockCell = $this->getMockBuilder(Cell::class)
|
2015-04-27 21:47:47 +00:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
|
2016-08-14 04:08:43 +00:00
|
|
|
$this->mockWorksheet = $this->getMockBuilder(Worksheet::class)
|
2015-04-27 21:47:47 +00:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$this->mockWorksheet->expects($this->any())
|
|
|
|
->method('getHighestRow')
|
|
|
|
->will($this->returnValue(5));
|
|
|
|
$this->mockWorksheet->expects($this->any())
|
|
|
|
->method('getCellByColumnAndRow')
|
|
|
|
->will($this->returnValue($this->mockCell));
|
|
|
|
}
|
|
|
|
|
2015-05-17 13:00:02 +00:00
|
|
|
public function testIteratorFullRange()
|
|
|
|
{
|
2015-05-30 11:25:17 +00:00
|
|
|
$iterator = new ColumnCellIterator($this->mockWorksheet, 'A');
|
2015-04-27 21:47:47 +00:00
|
|
|
$ColumnCellIndexResult = 1;
|
|
|
|
$this->assertEquals($ColumnCellIndexResult, $iterator->key());
|
2016-08-13 17:22:11 +00:00
|
|
|
|
2015-05-17 13:00:02 +00:00
|
|
|
foreach ($iterator as $key => $ColumnCell) {
|
2015-04-27 21:47:47 +00:00
|
|
|
$this->assertEquals($ColumnCellIndexResult++, $key);
|
2016-08-14 04:08:43 +00:00
|
|
|
$this->assertInstanceOf(Cell::class, $ColumnCell);
|
2015-04-27 21:47:47 +00:00
|
|
|
}
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
2015-04-27 21:47:47 +00:00
|
|
|
|
2015-05-17 13:00:02 +00:00
|
|
|
public function testIteratorStartEndRange()
|
|
|
|
{
|
2015-05-30 11:25:17 +00:00
|
|
|
$iterator = new ColumnCellIterator($this->mockWorksheet, 'A', 2, 4);
|
2015-04-27 21:47:47 +00:00
|
|
|
$ColumnCellIndexResult = 2;
|
|
|
|
$this->assertEquals($ColumnCellIndexResult, $iterator->key());
|
2016-08-13 17:22:11 +00:00
|
|
|
|
2015-05-17 13:00:02 +00:00
|
|
|
foreach ($iterator as $key => $ColumnCell) {
|
2015-04-27 21:47:47 +00:00
|
|
|
$this->assertEquals($ColumnCellIndexResult++, $key);
|
2016-08-14 04:08:43 +00:00
|
|
|
$this->assertInstanceOf(Cell::class, $ColumnCell);
|
2015-04-27 21:47:47 +00:00
|
|
|
}
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
2015-04-27 21:47:47 +00:00
|
|
|
|
2015-05-17 13:00:02 +00:00
|
|
|
public function testIteratorSeekAndPrev()
|
|
|
|
{
|
2015-05-30 11:25:17 +00:00
|
|
|
$iterator = new ColumnCellIterator($this->mockWorksheet, 'A', 2, 4);
|
2015-04-27 21:47:47 +00:00
|
|
|
$columnIndexResult = 4;
|
|
|
|
$iterator->seek(4);
|
|
|
|
$this->assertEquals($columnIndexResult, $iterator->key());
|
|
|
|
|
2016-08-16 15:33:57 +00:00
|
|
|
for ($i = 1; $i < $columnIndexResult - 1; ++$i) {
|
2015-04-27 21:47:47 +00:00
|
|
|
$iterator->prev();
|
|
|
|
$this->assertEquals($columnIndexResult - $i, $iterator->key());
|
|
|
|
}
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
2015-04-27 21:47:47 +00:00
|
|
|
|
|
|
|
/**
|
2016-08-31 17:18:12 +00:00
|
|
|
* @expectedException \PhpOffice\PhpSpreadsheet\Exception
|
2015-04-27 21:47:47 +00:00
|
|
|
*/
|
|
|
|
public function testSeekOutOfRange()
|
|
|
|
{
|
2015-05-30 11:25:17 +00:00
|
|
|
$iterator = new ColumnCellIterator($this->mockWorksheet, 'A', 2, 4);
|
2015-04-27 21:47:47 +00:00
|
|
|
$iterator->seek(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-08-31 17:18:12 +00:00
|
|
|
* @expectedException \PhpOffice\PhpSpreadsheet\Exception
|
2015-04-27 21:47:47 +00:00
|
|
|
*/
|
|
|
|
public function testPrevOutOfRange()
|
|
|
|
{
|
2015-05-30 11:25:17 +00:00
|
|
|
$iterator = new ColumnCellIterator($this->mockWorksheet, 'A', 2, 4);
|
2015-04-27 21:47:47 +00:00
|
|
|
$iterator->prev();
|
|
|
|
}
|
|
|
|
}
|