PhpSpreadsheet/unitTests/Classes/src/Worksheet/RowCellIteratorTest.php

86 lines
2.7 KiB
PHP
Raw Normal View History

<?php
2016-03-22 14:35:50 +00:00
namespace PHPExcel\Worksheet;
class RowCellIteratorTest extends \PHPUnit_Framework_TestCase
{
public $mockWorksheet;
public $mockRowCell;
2015-05-17 13:00:02 +00:00
public function setUp()
{
$this->mockCell = $this->getMockBuilder('PHPExcel_Cell')
->disableOriginalConstructor()
->getMock();
2016-03-22 14:19:00 +00:00
$this->mockWorksheet = $this->getMockBuilder('\PHPExcel\Worksheet')
->disableOriginalConstructor()
->getMock();
$this->mockWorksheet->expects($this->any())
->method('getHighestColumn')
->will($this->returnValue('E'));
$this->mockWorksheet->expects($this->any())
->method('getCellByColumnAndRow')
->will($this->returnValue($this->mockCell));
}
2015-05-17 13:00:02 +00:00
public function testIteratorFullRange()
{
2016-03-22 14:19:00 +00:00
$iterator = new \PHPExcel\Worksheet\RowCellIterator($this->mockWorksheet);
$RowCellIndexResult = 'A';
$this->assertEquals($RowCellIndexResult, $iterator->key());
2015-05-17 13:00:02 +00:00
foreach ($iterator as $key => $RowCell) {
$this->assertEquals($RowCellIndexResult++, $key);
$this->assertInstanceOf('PHPExcel_Cell', $RowCell);
}
2015-05-17 13:00:02 +00:00
}
2015-05-17 13:00:02 +00:00
public function testIteratorStartEndRange()
{
2016-03-22 14:19:00 +00:00
$iterator = new \PHPExcel\Worksheet\RowCellIterator($this->mockWorksheet, 2, 'B', 'D');
$RowCellIndexResult = 'B';
$this->assertEquals($RowCellIndexResult, $iterator->key());
2015-05-17 13:00:02 +00:00
foreach ($iterator as $key => $RowCell) {
$this->assertEquals($RowCellIndexResult++, $key);
$this->assertInstanceOf('PHPExcel_Cell', $RowCell);
}
2015-05-17 13:00:02 +00:00
}
2015-05-17 13:00:02 +00:00
public function testIteratorSeekAndPrev()
{
2015-05-17 17:26:34 +00:00
$ranges = range('A', 'E');
2016-03-22 14:19:00 +00:00
$iterator = new \PHPExcel\Worksheet\RowCellIterator($this->mockWorksheet, 2, 'B', 'D');
$RowCellIndexResult = 'D';
$iterator->seek('D');
$this->assertEquals($RowCellIndexResult, $iterator->key());
2015-05-17 16:34:30 +00:00
for ($i = 1; $i < array_search($RowCellIndexResult, $ranges); $i++) {
$iterator->prev();
$expectedResult = $ranges[array_search($RowCellIndexResult, $ranges) - $i];
$this->assertEquals($expectedResult, $iterator->key());
}
2015-05-17 13:00:02 +00:00
}
/**
2016-03-22 21:40:11 +00:00
* @expectedException \PHPExcel\Exception
*/
public function testSeekOutOfRange()
{
2016-03-22 14:19:00 +00:00
$iterator = new \PHPExcel\Worksheet\RowCellIterator($this->mockWorksheet, 2, 'B', 'D');
$iterator->seek(1);
}
/**
2016-03-22 21:40:11 +00:00
* @expectedException \PHPExcel\Exception
*/
public function testPrevOutOfRange()
{
2016-03-22 14:19:00 +00:00
$iterator = new \PHPExcel\Worksheet\RowCellIterator($this->mockWorksheet, 2, 'B', 'D');
$iterator->prev();
}
}