mirror of
https://github.com/retailcrm/PHPExcel.git
synced 2024-11-22 21:36:05 +03:00
Initial phpunit unit test scripts
git-svn-id: https://phpexcel.svn.codeplex.com/svn/trunk@85526 2327b42d-5241-43d6-9e2a-de5ac946f064
This commit is contained in:
parent
9bec4af001
commit
34f3e8b706
56
unitTests/PHPExcel/AutoloaderTest.php
Normal file
56
unitTests/PHPExcel/AutoloaderTest.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
|
||||
class AutoloaderTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
if (!defined('PHPEXCEL_ROOT'))
|
||||
{
|
||||
define('PHPEXCEL_ROOT', APPLICATION_PATH . '/');
|
||||
}
|
||||
require_once(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
|
||||
}
|
||||
|
||||
public function testAutoloaderNonPHPExcelClass()
|
||||
{
|
||||
$className = 'InvalidClass';
|
||||
|
||||
$result = PHPExcel_Autoloader::Load($className);
|
||||
// Must return a boolean...
|
||||
$this->assertTrue(is_bool($result));
|
||||
// ... indicating failure
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
public function testAutoloaderInvalidPHPExcelClass()
|
||||
{
|
||||
$className = 'PHPExcel_Invalid_Class';
|
||||
|
||||
$result = PHPExcel_Autoloader::Load($className);
|
||||
// Must return a boolean...
|
||||
$this->assertTrue(is_bool($result));
|
||||
// ... indicating failure
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
public function testAutoloadValidPHPExcelClass()
|
||||
{
|
||||
$className = 'PHPExcel_IOFactory';
|
||||
|
||||
$result = PHPExcel_Autoloader::Load($className);
|
||||
// Check that class has been loaded
|
||||
$this->assertTrue(class_exists($className));
|
||||
}
|
||||
|
||||
public function testAutoloadInstantiateSuccess()
|
||||
{
|
||||
$result = new PHPExcel_Calculation_Function(1,2,3);
|
||||
// Must return an object...
|
||||
$this->assertTrue(is_object($result));
|
||||
// ... of the correct type
|
||||
$this->assertTrue(is_a($result,'PHPExcel_Calculation_Function'));
|
||||
}
|
||||
|
||||
}
|
172
unitTests/PHPExcel/Calculation/LogicalTest.php
Normal file
172
unitTests/PHPExcel/Calculation/LogicalTest.php
Normal file
@ -0,0 +1,172 @@
|
||||
<?php
|
||||
|
||||
|
||||
require_once 'testDataFileIterator.php';
|
||||
|
||||
class LogicalTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
if (!defined('PHPEXCEL_ROOT'))
|
||||
{
|
||||
define('PHPEXCEL_ROOT', APPLICATION_PATH . '/');
|
||||
}
|
||||
require_once(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
|
||||
}
|
||||
|
||||
public function testTRUE()
|
||||
{
|
||||
$result = PHPExcel_Calculation_Logical::TRUE();
|
||||
$this->assertEquals(TRUE, $result);
|
||||
}
|
||||
|
||||
public function testFALSE()
|
||||
{
|
||||
$result = PHPExcel_Calculation_Logical::FALSE();
|
||||
$this->assertEquals(FALSE, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerAND
|
||||
*/
|
||||
public function testAND()
|
||||
{
|
||||
$args = func_get_args();
|
||||
$expectedResult = array_pop($args);
|
||||
$result = call_user_func_array(array('PHPExcel_Calculation_Logical','LOGICAL_AND'),$args);
|
||||
$this->assertEquals($expectedResult, $result);
|
||||
}
|
||||
|
||||
public function providerAND()
|
||||
{
|
||||
return array(
|
||||
array( '#VALUE!' ), // No arguments
|
||||
array( NULL, TRUE ), // NULL
|
||||
array( TRUE, NULL, TRUE ), // Boolean TRUE and NULL
|
||||
array( FALSE, NULL, FALSE ), // Boolean FALSE and NULL
|
||||
array( TRUE, TRUE, TRUE ), // Both TRUE Booleans
|
||||
array( TRUE, FALSE, FALSE ), // Mixed Booleans
|
||||
array( FALSE, TRUE, FALSE ), // Mixed Booleans
|
||||
array( FALSE, FALSE, FALSE ), // Both FALSE Booleans
|
||||
array( TRUE, TRUE, FALSE, FALSE ), // Multiple Mixed Booleans
|
||||
array( TRUE, TRUE, TRUE, TRUE ), // Multiple TRUE Booleans
|
||||
array( FALSE, FALSE, FALSE, FALSE, FALSE ), // Multiple FALSE Booleans
|
||||
array( -1, -2, TRUE ),
|
||||
array( 0, 0, FALSE ),
|
||||
array( 0, 1, FALSE ),
|
||||
array( 1, 1, TRUE ),
|
||||
array( '1',1, '#VALUE!' ),
|
||||
array( 'TRUE',1, TRUE ), // 'TRUE' String
|
||||
array( 'FALSE',TRUE, FALSE ), // 'FALSE' String
|
||||
array( 'ABCD',1, '#VALUE!' ), // Non-numeric String
|
||||
array( -2, 1, TRUE ),
|
||||
array( -2, 0, FALSE ),
|
||||
);
|
||||
|
||||
// return new testDataFileIterator('rawTestData/Calculation/Logical/AND.data');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerOR
|
||||
*/
|
||||
public function testOR()
|
||||
{
|
||||
$args = func_get_args();
|
||||
$expectedResult = array_pop($args);
|
||||
$result = call_user_func_array(array('PHPExcel_Calculation_Logical','LOGICAL_OR'),$args);
|
||||
$this->assertEquals($expectedResult, $result);
|
||||
}
|
||||
|
||||
public function providerOR()
|
||||
{
|
||||
return array(
|
||||
array( '#VALUE!' ), // No arguments
|
||||
array( NULL, FALSE ), // NULL
|
||||
array( TRUE, NULL, TRUE ), // Boolean TRUE and NULL
|
||||
array( FALSE, NULL, FALSE ), // Boolean FALSE and NULL
|
||||
array( TRUE, TRUE, TRUE ), // Both TRUE Booleans
|
||||
array( TRUE, FALSE, TRUE ), // Mixed Booleans
|
||||
array( FALSE, TRUE, TRUE ), // Mixed Booleans
|
||||
array( FALSE, FALSE, FALSE ), // Both FALSE Booleans
|
||||
array( TRUE, TRUE, FALSE, TRUE ), // Multiple Mixed Booleans
|
||||
array( TRUE, TRUE, TRUE, TRUE ), // Multiple TRUE Booleans
|
||||
array( FALSE, FALSE, FALSE, FALSE, FALSE ), // Multiple FALSE Booleans
|
||||
array( -1, -2, TRUE ),
|
||||
array( 0, 0, FALSE ),
|
||||
array( 0, 1, TRUE ),
|
||||
array( 1, 1, TRUE ),
|
||||
array( 'TRUE',1, TRUE ), // 'TRUE' String
|
||||
array( 'FALSE',TRUE, TRUE ), // 'FALSE' String
|
||||
array( 'ABCD',1, '#VALUE!' ), // Non-numeric String
|
||||
array( -2, 1, TRUE ),
|
||||
array( -2, 0, TRUE ),
|
||||
);
|
||||
|
||||
// return new testDataFileIterator('rawTestData/Calculation/Logical/OR.data');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerNOT
|
||||
*/
|
||||
public function testNOT()
|
||||
{
|
||||
$args = func_get_args();
|
||||
$expectedResult = array_pop($args);
|
||||
$result = call_user_func_array(array('PHPExcel_Calculation_Logical','NOT'),$args);
|
||||
$this->assertEquals($expectedResult, $result);
|
||||
}
|
||||
|
||||
public function providerNOT()
|
||||
{
|
||||
return new testDataFileIterator('rawTestData/Calculation/Logical/NOT.data');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerIF
|
||||
*/
|
||||
public function testIF()
|
||||
{
|
||||
$args = func_get_args();
|
||||
$expectedResult = array_pop($args);
|
||||
$result = call_user_func_array(array('PHPExcel_Calculation_Logical','STATEMENT_IF'),$args);
|
||||
$this->assertEquals($expectedResult, $result);
|
||||
}
|
||||
|
||||
public function providerIF()
|
||||
{
|
||||
return array(
|
||||
array( 0 ),
|
||||
array( TRUE, 0 ),
|
||||
array( FALSE, FALSE ),
|
||||
array( TRUE, 'ABC', 'ABC' ),
|
||||
array( FALSE, 'ABC', FALSE ),
|
||||
array( TRUE, 'ABC', 'XYZ', 'ABC' ),
|
||||
array( FALSE, 'ABC', 'XYZ', 'XYZ' ),
|
||||
);
|
||||
|
||||
// return new testDataFileIterator('rawTestData/Calculation/Logical/IF.data');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerIFERROR
|
||||
*/
|
||||
public function testIFERROR()
|
||||
{
|
||||
$args = func_get_args();
|
||||
$expectedResult = array_pop($args);
|
||||
$result = call_user_func_array(array('PHPExcel_Calculation_Logical','IFERROR'),$args);
|
||||
$this->assertEquals($expectedResult, $result);
|
||||
}
|
||||
|
||||
public function providerIFERROR()
|
||||
{
|
||||
return array(
|
||||
array( TRUE, 'Not an Error', 'Not an Error'),
|
||||
array( '#VALUE!', 'Error', 'Error' ),
|
||||
);
|
||||
|
||||
// return new testDataFileIterator('rawTestData/Calculation/Logical/IFERROR.data');
|
||||
}
|
||||
|
||||
}
|
44
unitTests/bootstrap.php
Normal file
44
unitTests/bootstrap.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
* $Id: bootstrap.php 2892 2011-08-14 15:11:50Z markbaker@phpexcel.net $
|
||||
*
|
||||
* @copyright Copyright (C) 2011 PHPExcel. All rights reserved.
|
||||
* @package PHPExcel
|
||||
* @subpackage PHPExcel Unit Tests
|
||||
* @author Mark Baker
|
||||
*/
|
||||
|
||||
// PHP 5.3 Compat
|
||||
date_default_timezone_set('Europe/London');
|
||||
|
||||
// Define path to application directory
|
||||
defined('APPLICATION_PATH')
|
||||
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../Classes'));
|
||||
|
||||
// Define path to application tests directory
|
||||
defined('APPLICATION_TESTS_PATH')
|
||||
|| define('APPLICATION_TESTS_PATH', realpath(dirname(__FILE__) ));
|
||||
|
||||
// Define application environment
|
||||
defined('APPLICATION_ENV') || define('APPLICATION_ENV', 'ci');
|
||||
|
||||
// Ensure library/ is on include_path
|
||||
set_include_path(implode(PATH_SEPARATOR, array(
|
||||
realpath(APPLICATION_PATH . '/../Classes'),
|
||||
'./',
|
||||
get_include_path(),
|
||||
)));
|
||||
|
||||
|
||||
/**
|
||||
* @todo Sort out xdebug in vagrant so that this works in all sandboxes
|
||||
* For now, it is safer to test for it rather then remove it.
|
||||
*/
|
||||
echo "PHPExcel tests beginning\n";
|
||||
|
||||
if(extension_loaded('xdebug')) {
|
||||
echo "Xdebug extension loaded and running\n";
|
||||
xdebug_enable();
|
||||
} else {
|
||||
echo 'Xdebug not found, you should run the following at the command line: echo "zend_extension=/usr/lib64/php/modules/xdebug.so" > /etc/php.d/xdebug.ini' . "\n";
|
||||
}
|
38
unitTests/phpunit.xml
Normal file
38
unitTests/phpunit.xml
Normal file
@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit bootstrap="./bootstrap.php"
|
||||
backupGlobals="true"
|
||||
colors="true"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
processIsolation="false"
|
||||
syntaxCheck="true"
|
||||
verbose="true"
|
||||
strict="true"
|
||||
stopOnError="false"
|
||||
stopOnFailure="false"
|
||||
stopOnIncomplete="false"
|
||||
stopOnSkipped="false">
|
||||
<php>
|
||||
<ini name="memory_limit" value="2048M"/>
|
||||
</php>
|
||||
<testsuite name="PHPExcel Unit Test Suite">
|
||||
<directory suffix="Test.php">./PHPExcel</directory>
|
||||
</testsuite>
|
||||
<filter>
|
||||
<whitelist>
|
||||
<directory suffix=".php">../Classes</directory>
|
||||
<exclude>
|
||||
<directory>../Classes/PHPExcel/Shared/PDF</directory>
|
||||
<directory>../Classes/PHPExcel/Shared/PCLZip</directory>
|
||||
<directory>../Classes/PHPExcel/Shared/JAMA</directory>
|
||||
</exclude>
|
||||
</whitelist>
|
||||
</filter>
|
||||
<logging>
|
||||
<log type="coverage-html" target="./codeCoverage" charset="UTF-8"
|
||||
yui="true" highlight="false"
|
||||
lowUpperBound="35" highLowerBound="70"/>
|
||||
<log type="coverage-clover" target="./codeCoverage/codeCoverage.xml"/>
|
||||
</logging>
|
||||
</phpunit>
|
20
unitTests/rawTestData/Calculation/Logical/NOT.data
Normal file
20
unitTests/rawTestData/Calculation/Logical/NOT.data
Normal file
@ -0,0 +1,20 @@
|
||||
,TRUE
|
||||
NULL,TRUE
|
||||
-1,FALSE
|
||||
0,TRUE
|
||||
1,FALSE
|
||||
2,FALSE
|
||||
-1.5,FALSE
|
||||
1.5,FALSE
|
||||
"-1","#VALUE!"
|
||||
"0","#VALUE!"
|
||||
"1","#VALUE!"
|
||||
"2","#VALUE!"
|
||||
"-1.5","#VALUE!"
|
||||
"1.5","#VALUE!"
|
||||
"","#VALUE!"
|
||||
"ABC","#VALUE!"
|
||||
"FALSE",TRUE
|
||||
"TRUE",FALSE
|
||||
TRUE,FALSE
|
||||
FALSE,TRUE
|
79
unitTests/testDataFileIterator.php
Normal file
79
unitTests/testDataFileIterator.php
Normal file
@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
class testDataFileIterator implements Iterator
|
||||
{
|
||||
|
||||
protected $file;
|
||||
protected $key = 0;
|
||||
protected $current;
|
||||
|
||||
public function __construct($file)
|
||||
{
|
||||
$this->file = fopen($file, 'r');
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
fclose($this->file);
|
||||
}
|
||||
|
||||
public function rewind()
|
||||
{
|
||||
rewind($this->file);
|
||||
$this->current = $this->_parseNextDataset();
|
||||
$this->key = 0;
|
||||
}
|
||||
|
||||
public function valid()
|
||||
{
|
||||
return !feof($this->file);
|
||||
}
|
||||
|
||||
public function key()
|
||||
{
|
||||
return $this->key;
|
||||
}
|
||||
|
||||
public function current()
|
||||
{
|
||||
return $this->current;
|
||||
}
|
||||
|
||||
public function next()
|
||||
{
|
||||
$this->current = $this->_parseNextDataset();
|
||||
$this->key++;
|
||||
}
|
||||
|
||||
private function _parseNextDataset()
|
||||
{
|
||||
$dataSet = explode(',',trim(fgets($this->file)));
|
||||
foreach($dataSet as &$dataValue) {
|
||||
if (!is_numeric($dataValue)) {
|
||||
if($dataValue == '') {
|
||||
$dataValue = NULL;
|
||||
} elseif($dataValue == '""') {
|
||||
$dataValue = '';
|
||||
} elseif(($dataValue[0] == '"') && ($dataValue[strlen($dataValue)-1] == '"')) {
|
||||
$dataValue = substr($dataValue,1,-1);
|
||||
} else {
|
||||
switch (strtoupper($dataValue)) {
|
||||
case 'NULL' : $dataValue = NULL; break;
|
||||
case 'TRUE' : $dataValue = TRUE; break;
|
||||
case 'FALSE' : $dataValue = FALSE; break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (is_float($dataValue)) {
|
||||
$dataValue = (float) $dataValue;
|
||||
} else {
|
||||
$dataValue = (int) $dataValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($dataValue);
|
||||
|
||||
return $dataSet;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user