This commit is contained in:
2024-04-27 09:23:34 +02:00
commit 11e713ca6f
11884 changed files with 3263371 additions and 0 deletions

View File

@@ -0,0 +1,73 @@
<?php
class AdvancedValueBinderTest 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 provider()
{
if (!class_exists('PHPExcel_Style_NumberFormat')) {
$this->setUp();
}
$currencyUSD = PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_USD_SIMPLE;
$currencyEURO = str_replace('$', '€', PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_USD_SIMPLE);
return array(
array('10%', 0.1, PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE_00, ',', '.', '$'),
array('$10.11', 10.11, $currencyUSD, ',', '.', '$'),
array('$1,010.12', 1010.12, $currencyUSD, ',', '.', '$'),
array('$20,20', 20.2, $currencyUSD, '.', ',', '$'),
array('$2.020,20', 2020.2, $currencyUSD, '.', ',', '$'),
array('€2.020,20', 2020.2, $currencyEURO, '.', ',', '€'),
array('€ 2.020,20', 2020.2, $currencyEURO, '.', ',', '€'),
array('€2,020.22', 2020.22, $currencyEURO, ',', '.', '€'),
);
}
/**
* @dataProvider provider
*/
public function testCurrency($value, $valueBinded, $format, $thousandsSeparator, $decimalSeparator, $currencyCode)
{
$sheet = $this->getMock(
'PHPExcel_Worksheet',
array('getStyle', 'getNumberFormat', 'setFormatCode','getCellCacheController')
);
$cache = $this->getMockBuilder('PHPExcel_CachedObjectStorage_Memory')
->disableOriginalConstructor()
->getMock();
$cache->expects($this->any())
->method('getParent')
->will($this->returnValue($sheet));
$sheet->expects($this->once())
->method('getStyle')
->will($this->returnSelf());
$sheet->expects($this->once())
->method('getNumberFormat')
->will($this->returnSelf());
$sheet->expects($this->once())
->method('setFormatCode')
->with($format)
->will($this->returnSelf());
$sheet->expects($this->any())
->method('getCellCacheController')
->will($this->returnValue($cache));
PHPExcel_Shared_String::setCurrencyCode($currencyCode);
PHPExcel_Shared_String::setDecimalSeparator($decimalSeparator);
PHPExcel_Shared_String::setThousandsSeparator($thousandsSeparator);
$cell = new PHPExcel_Cell(NULL, PHPExcel_Cell_DataType::TYPE_STRING, $sheet);
$binder = new PHPExcel_Cell_AdvancedValueBinder();
$binder->bindValue($cell, $value);
$this->assertEquals($valueBinded, $cell->getValue());
}
}

View File

@@ -0,0 +1,24 @@
<?php
class DataTypeTest 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 testGetErrorCodes()
{
$result = call_user_func(array('PHPExcel_Cell_DataType','getErrorCodes'));
$this->assertInternalType('array', $result);
$this->assertGreaterThan(0, count($result));
$this->assertArrayHasKey('#NULL!', $result);
}
}

View File

@@ -0,0 +1,88 @@
<?php
class HyperlinkTest 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 testGetUrl()
{
$urlValue = 'http://www.phpexcel.net';
$testInstance = new PHPExcel_Cell_Hyperlink($urlValue);
$result = $testInstance->getUrl();
$this->assertEquals($urlValue,$result);
}
public function testSetUrl()
{
$initialUrlValue = 'http://www.phpexcel.net';
$newUrlValue = 'http://github.com/PHPOffice/PHPExcel';
$testInstance = new PHPExcel_Cell_Hyperlink($initialUrlValue);
$result = $testInstance->setUrl($newUrlValue);
$this->assertTrue($result instanceof PHPExcel_Cell_Hyperlink);
$result = $testInstance->getUrl();
$this->assertEquals($newUrlValue,$result);
}
public function testGetTooltip()
{
$tooltipValue = 'PHPExcel Web Site';
$testInstance = new PHPExcel_Cell_Hyperlink(NULL, $tooltipValue);
$result = $testInstance->getTooltip();
$this->assertEquals($tooltipValue,$result);
}
public function testSetTooltip()
{
$initialTooltipValue = 'PHPExcel Web Site';
$newTooltipValue = 'PHPExcel Repository on Github';
$testInstance = new PHPExcel_Cell_Hyperlink(NULL, $initialTooltipValue);
$result = $testInstance->setTooltip($newTooltipValue);
$this->assertTrue($result instanceof PHPExcel_Cell_Hyperlink);
$result = $testInstance->getTooltip();
$this->assertEquals($newTooltipValue,$result);
}
public function testIsInternal()
{
$initialUrlValue = 'http://www.phpexcel.net';
$newUrlValue = 'sheet://Worksheet1!A1';
$testInstance = new PHPExcel_Cell_Hyperlink($initialUrlValue);
$result = $testInstance->isInternal();
$this->assertFalse($result);
$testInstance->setUrl($newUrlValue);
$result = $testInstance->isInternal();
$this->assertTrue($result);
}
public function testGetHashCode()
{
$urlValue = 'http://www.phpexcel.net';
$tooltipValue = 'PHPExcel Web Site';
$initialExpectedHash = 'd84d713aed1dbbc8a7c5af183d6c7dbb';
$testInstance = new PHPExcel_Cell_Hyperlink($urlValue, $tooltipValue);
$result = $testInstance->getHashCode();
$this->assertEquals($initialExpectedHash,$result);
}
}