forked from PHPOffice/PHPExcel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unit tests for row and column iterators
- Loading branch information
MarkBaker
committed
Apr 27, 2015
1 parent
d2b0ef2
commit f317842
Showing
5 changed files
with
186 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
unitTests/Classes/PHPExcel/Worksheet/ColumnCellIteratorTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
|
||
class ColumnCellIteratorTest extends PHPUnit_Framework_TestCase | ||
{ | ||
public $mockWorksheet; | ||
public $mockColumnCell; | ||
|
||
public function setUp() | ||
{ | ||
if (!defined('PHPEXCEL_ROOT')) { | ||
define('PHPEXCEL_ROOT', APPLICATION_PATH . '/'); | ||
} | ||
require_once(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php'); | ||
|
||
$this->mockCell = $this->getMockBuilder('PHPExcel_Cell') | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$this->mockWorksheet = $this->getMockBuilder('PHPExcel_Worksheet') | ||
->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)); | ||
} | ||
|
||
|
||
public function testIteratorFullRange() | ||
{ | ||
$iterator = new PHPExcel_Worksheet_ColumnCellIterator($this->mockWorksheet, 'A'); | ||
$ColumnCellIndexResult = 1; | ||
$this->assertEquals($ColumnCellIndexResult, $iterator->key()); | ||
|
||
foreach($iterator as $key => $ColumnCell) { | ||
$this->assertEquals($ColumnCellIndexResult++, $key); | ||
$this->assertInstanceOf('PHPExcel_Cell', $ColumnCell); | ||
} | ||
} | ||
|
||
public function testIteratorStartEndRange() | ||
{ | ||
$iterator = new PHPExcel_Worksheet_ColumnCellIterator($this->mockWorksheet, 'A', 2, 4); | ||
$ColumnCellIndexResult = 2; | ||
$this->assertEquals($ColumnCellIndexResult, $iterator->key()); | ||
|
||
foreach($iterator as $key => $ColumnCell) { | ||
$this->assertEquals($ColumnCellIndexResult++, $key); | ||
$this->assertInstanceOf('PHPExcel_Cell', $ColumnCell); | ||
} | ||
} | ||
|
||
public function testIteratorSeekAndPrev() | ||
{ | ||
$iterator = new PHPExcel_Worksheet_ColumnCellIterator($this->mockWorksheet, 'A', 2, 4); | ||
$columnIndexResult = 4; | ||
$iterator->seek(4); | ||
$this->assertEquals($columnIndexResult, $iterator->key()); | ||
|
||
for($i = 1; $i < $columnIndexResult-1; $i++) { | ||
$iterator->prev(); | ||
$this->assertEquals($columnIndexResult - $i, $iterator->key()); | ||
} | ||
} | ||
|
||
/** | ||
* @expectedException PHPExcel_Exception | ||
*/ | ||
public function testSeekOutOfRange() | ||
{ | ||
$iterator = new PHPExcel_Worksheet_ColumnCellIterator($this->mockWorksheet, 'A', 2, 4); | ||
$iterator->seek(1); | ||
} | ||
|
||
/** | ||
* @expectedException PHPExcel_Exception | ||
*/ | ||
public function testPrevOutOfRange() | ||
{ | ||
$iterator = new PHPExcel_Worksheet_ColumnCellIterator($this->mockWorksheet, 'A', 2, 4); | ||
$iterator->prev(); | ||
} | ||
|
||
} |
89 changes: 89 additions & 0 deletions
89
unitTests/Classes/PHPExcel/Worksheet/RowCellIteratorTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?php | ||
|
||
class RowCellIteratorTest extends PHPUnit_Framework_TestCase | ||
{ | ||
public $mockWorksheet; | ||
public $mockRowCell; | ||
|
||
public function setUp() | ||
{ | ||
if (!defined('PHPEXCEL_ROOT')) { | ||
define('PHPEXCEL_ROOT', APPLICATION_PATH . '/'); | ||
} | ||
require_once(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php'); | ||
|
||
$this->mockCell = $this->getMockBuilder('PHPExcel_Cell') | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$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)); | ||
} | ||
|
||
|
||
public function testIteratorFullRange() | ||
{ | ||
$iterator = new PHPExcel_Worksheet_RowCellIterator($this->mockWorksheet); | ||
$RowCellIndexResult = 'A'; | ||
$this->assertEquals($RowCellIndexResult, $iterator->key()); | ||
|
||
foreach($iterator as $key => $RowCell) { | ||
$this->assertEquals($RowCellIndexResult++, $key); | ||
$this->assertInstanceOf('PHPExcel_Cell', $RowCell); | ||
} | ||
} | ||
|
||
public function testIteratorStartEndRange() | ||
{ | ||
$iterator = new PHPExcel_Worksheet_RowCellIterator($this->mockWorksheet, 2, 'B', 'D'); | ||
$RowCellIndexResult = 'B'; | ||
$this->assertEquals($RowCellIndexResult, $iterator->key()); | ||
|
||
foreach($iterator as $key => $RowCell) { | ||
$this->assertEquals($RowCellIndexResult++, $key); | ||
$this->assertInstanceOf('PHPExcel_Cell', $RowCell); | ||
} | ||
} | ||
|
||
public function testIteratorSeekAndPrev() | ||
{ | ||
$ranges = range('A','E'); | ||
$iterator = new PHPExcel_Worksheet_RowCellIterator($this->mockWorksheet, 2, 'B', 'D'); | ||
$RowCellIndexResult = 'D'; | ||
$iterator->seek('D'); | ||
$this->assertEquals($RowCellIndexResult, $iterator->key()); | ||
|
||
for($i = 1; $i < array_search($RowCellIndexResult, $ranges); $i++) { | ||
$iterator->prev(); | ||
$expectedResult = $ranges[array_search($RowCellIndexResult, $ranges) - $i]; | ||
$this->assertEquals($expectedResult, $iterator->key()); | ||
} | ||
} | ||
|
||
/** | ||
* @expectedException PHPExcel_Exception | ||
*/ | ||
public function testSeekOutOfRange() | ||
{ | ||
$iterator = new PHPExcel_Worksheet_RowCellIterator($this->mockWorksheet, 2, 'B', 'D'); | ||
$iterator->seek(1); | ||
} | ||
|
||
/** | ||
* @expectedException PHPExcel_Exception | ||
*/ | ||
public function testPrevOutOfRange() | ||
{ | ||
$iterator = new PHPExcel_Worksheet_RowCellIterator($this->mockWorksheet, 2, 'B', 'D'); | ||
$iterator->prev(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters