2012-07-31 20:56:11 +00:00
|
|
|
<?php
|
|
|
|
|
2016-08-25 04:53:15 +00:00
|
|
|
namespace PhpSpreadsheetTests\Calculation;
|
2012-07-31 20:56:11 +00:00
|
|
|
|
2016-08-16 14:24:47 +00:00
|
|
|
use PhpSpreadsheet\Calculation\Functions;
|
|
|
|
use PhpSpreadsheet\Calculation\TextData;
|
2016-08-16 15:33:57 +00:00
|
|
|
use PhpSpreadsheet\Shared\StringHelper;
|
2016-08-14 04:08:43 +00:00
|
|
|
|
2016-03-22 14:35:50 +00:00
|
|
|
class TextDataTest extends \PHPUnit_Framework_TestCase
|
2012-07-31 20:56:11 +00:00
|
|
|
{
|
|
|
|
public function setUp()
|
|
|
|
{
|
2016-08-14 04:08:43 +00:00
|
|
|
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
2012-07-31 20:56:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerCHAR
|
|
|
|
*/
|
2015-05-17 13:00:02 +00:00
|
|
|
public function testCHAR()
|
|
|
|
{
|
|
|
|
$args = func_get_args();
|
|
|
|
$expectedResult = array_pop($args);
|
2016-08-16 15:33:57 +00:00
|
|
|
$result = call_user_func_array([TextData::class, 'CHARACTER'], $args);
|
2015-05-17 13:00:02 +00:00
|
|
|
$this->assertEquals($expectedResult, $result);
|
|
|
|
}
|
2012-07-31 20:56:11 +00:00
|
|
|
|
|
|
|
public function providerCHAR()
|
|
|
|
{
|
2016-08-16 12:00:19 +00:00
|
|
|
return require 'data/Calculation/TextData/CHAR.php';
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
2012-07-31 20:56:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerCODE
|
|
|
|
*/
|
2015-05-17 13:00:02 +00:00
|
|
|
public function testCODE()
|
|
|
|
{
|
|
|
|
$args = func_get_args();
|
|
|
|
$expectedResult = array_pop($args);
|
2016-08-16 15:33:57 +00:00
|
|
|
$result = call_user_func_array([TextData::class, 'ASCIICODE'], $args);
|
2015-05-17 13:00:02 +00:00
|
|
|
$this->assertEquals($expectedResult, $result);
|
|
|
|
}
|
2012-07-31 20:56:11 +00:00
|
|
|
|
|
|
|
public function providerCODE()
|
|
|
|
{
|
2016-08-16 12:00:19 +00:00
|
|
|
return require 'data/Calculation/TextData/CODE.php';
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
2012-07-31 20:56:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerCONCATENATE
|
|
|
|
*/
|
2015-05-17 13:00:02 +00:00
|
|
|
public function testCONCATENATE()
|
|
|
|
{
|
|
|
|
$args = func_get_args();
|
|
|
|
$expectedResult = array_pop($args);
|
2016-08-16 15:33:57 +00:00
|
|
|
$result = call_user_func_array([TextData::class, 'CONCATENATE'], $args);
|
2015-05-17 13:00:02 +00:00
|
|
|
$this->assertEquals($expectedResult, $result);
|
|
|
|
}
|
2012-07-31 20:56:11 +00:00
|
|
|
|
|
|
|
public function providerCONCATENATE()
|
|
|
|
{
|
2016-08-16 12:00:19 +00:00
|
|
|
return require 'data/Calculation/TextData/CONCATENATE.php';
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
2012-07-31 20:56:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerLEFT
|
|
|
|
*/
|
2015-05-17 13:00:02 +00:00
|
|
|
public function testLEFT()
|
|
|
|
{
|
|
|
|
$args = func_get_args();
|
|
|
|
$expectedResult = array_pop($args);
|
2016-08-16 15:33:57 +00:00
|
|
|
$result = call_user_func_array([TextData::class, 'LEFT'], $args);
|
2015-05-17 13:00:02 +00:00
|
|
|
$this->assertEquals($expectedResult, $result);
|
|
|
|
}
|
2012-07-31 20:56:11 +00:00
|
|
|
|
|
|
|
public function providerLEFT()
|
|
|
|
{
|
2016-08-16 12:00:19 +00:00
|
|
|
return require 'data/Calculation/TextData/LEFT.php';
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
2012-07-31 20:56:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerMID
|
|
|
|
*/
|
2015-05-17 13:00:02 +00:00
|
|
|
public function testMID()
|
|
|
|
{
|
|
|
|
$args = func_get_args();
|
|
|
|
$expectedResult = array_pop($args);
|
2016-08-16 15:33:57 +00:00
|
|
|
$result = call_user_func_array([TextData::class, 'MID'], $args);
|
2015-05-17 13:00:02 +00:00
|
|
|
$this->assertEquals($expectedResult, $result);
|
|
|
|
}
|
2012-07-31 20:56:11 +00:00
|
|
|
|
|
|
|
public function providerMID()
|
|
|
|
{
|
2016-08-16 12:00:19 +00:00
|
|
|
return require 'data/Calculation/TextData/MID.php';
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
2012-07-31 20:56:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerRIGHT
|
|
|
|
*/
|
2015-05-17 13:00:02 +00:00
|
|
|
public function testRIGHT()
|
|
|
|
{
|
|
|
|
$args = func_get_args();
|
|
|
|
$expectedResult = array_pop($args);
|
2016-08-16 15:33:57 +00:00
|
|
|
$result = call_user_func_array([TextData::class, 'RIGHT'], $args);
|
2015-05-17 13:00:02 +00:00
|
|
|
$this->assertEquals($expectedResult, $result);
|
|
|
|
}
|
2012-07-31 20:56:11 +00:00
|
|
|
|
|
|
|
public function providerRIGHT()
|
|
|
|
{
|
2016-08-16 12:00:19 +00:00
|
|
|
return require 'data/Calculation/TextData/RIGHT.php';
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
2012-07-31 20:56:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerLOWER
|
|
|
|
*/
|
2015-05-17 13:00:02 +00:00
|
|
|
public function testLOWER()
|
|
|
|
{
|
|
|
|
$args = func_get_args();
|
|
|
|
$expectedResult = array_pop($args);
|
2016-08-16 15:33:57 +00:00
|
|
|
$result = call_user_func_array([TextData::class, 'LOWERCASE'], $args);
|
2015-05-17 13:00:02 +00:00
|
|
|
$this->assertEquals($expectedResult, $result);
|
|
|
|
}
|
2012-07-31 20:56:11 +00:00
|
|
|
|
|
|
|
public function providerLOWER()
|
|
|
|
{
|
2016-08-16 12:00:19 +00:00
|
|
|
return require 'data/Calculation/TextData/LOWER.php';
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
2012-07-31 20:56:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerUPPER
|
|
|
|
*/
|
2015-05-17 13:00:02 +00:00
|
|
|
public function testUPPER()
|
|
|
|
{
|
|
|
|
$args = func_get_args();
|
|
|
|
$expectedResult = array_pop($args);
|
2016-08-16 15:33:57 +00:00
|
|
|
$result = call_user_func_array([TextData::class, 'UPPERCASE'], $args);
|
2015-05-17 13:00:02 +00:00
|
|
|
$this->assertEquals($expectedResult, $result);
|
|
|
|
}
|
2012-07-31 20:56:11 +00:00
|
|
|
|
|
|
|
public function providerUPPER()
|
|
|
|
{
|
2016-08-16 12:00:19 +00:00
|
|
|
return require 'data/Calculation/TextData/UPPER.php';
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
2012-07-31 20:56:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerPROPER
|
|
|
|
*/
|
2015-05-17 13:00:02 +00:00
|
|
|
public function testPROPER()
|
|
|
|
{
|
|
|
|
$args = func_get_args();
|
|
|
|
$expectedResult = array_pop($args);
|
2016-08-16 15:33:57 +00:00
|
|
|
$result = call_user_func_array([TextData::class, 'PROPERCASE'], $args);
|
2015-05-17 13:00:02 +00:00
|
|
|
$this->assertEquals($expectedResult, $result);
|
|
|
|
}
|
2012-07-31 20:56:11 +00:00
|
|
|
|
|
|
|
public function providerPROPER()
|
|
|
|
{
|
2016-08-16 12:00:19 +00:00
|
|
|
return require 'data/Calculation/TextData/PROPER.php';
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
2012-07-31 20:56:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerLEN
|
|
|
|
*/
|
2015-05-17 13:00:02 +00:00
|
|
|
public function testLEN()
|
|
|
|
{
|
|
|
|
$args = func_get_args();
|
|
|
|
$expectedResult = array_pop($args);
|
2016-08-16 15:33:57 +00:00
|
|
|
$result = call_user_func_array([TextData::class, 'STRINGLENGTH'], $args);
|
2015-05-17 13:00:02 +00:00
|
|
|
$this->assertEquals($expectedResult, $result);
|
|
|
|
}
|
2012-07-31 20:56:11 +00:00
|
|
|
|
|
|
|
public function providerLEN()
|
|
|
|
{
|
2016-08-16 12:00:19 +00:00
|
|
|
return require 'data/Calculation/TextData/LEN.php';
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
2012-07-31 20:56:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerSEARCH
|
|
|
|
*/
|
2015-05-17 13:00:02 +00:00
|
|
|
public function testSEARCH()
|
|
|
|
{
|
|
|
|
$args = func_get_args();
|
|
|
|
$expectedResult = array_pop($args);
|
2016-08-16 15:33:57 +00:00
|
|
|
$result = call_user_func_array([TextData::class, 'SEARCHINSENSITIVE'], $args);
|
2015-05-17 13:00:02 +00:00
|
|
|
$this->assertEquals($expectedResult, $result);
|
|
|
|
}
|
2012-07-31 20:56:11 +00:00
|
|
|
|
|
|
|
public function providerSEARCH()
|
|
|
|
{
|
2016-08-16 12:00:19 +00:00
|
|
|
return require 'data/Calculation/TextData/SEARCH.php';
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
2012-07-31 20:56:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerFIND
|
|
|
|
*/
|
2015-05-17 13:00:02 +00:00
|
|
|
public function testFIND()
|
|
|
|
{
|
|
|
|
$args = func_get_args();
|
|
|
|
$expectedResult = array_pop($args);
|
2016-08-16 15:33:57 +00:00
|
|
|
$result = call_user_func_array([TextData::class, 'SEARCHSENSITIVE'], $args);
|
2015-05-17 13:00:02 +00:00
|
|
|
$this->assertEquals($expectedResult, $result);
|
|
|
|
}
|
2012-07-31 20:56:11 +00:00
|
|
|
|
|
|
|
public function providerFIND()
|
|
|
|
{
|
2016-08-16 12:00:19 +00:00
|
|
|
return require 'data/Calculation/TextData/FIND.php';
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
2012-07-31 20:56:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerREPLACE
|
|
|
|
*/
|
2015-05-17 13:00:02 +00:00
|
|
|
public function testREPLACE()
|
|
|
|
{
|
|
|
|
$args = func_get_args();
|
|
|
|
$expectedResult = array_pop($args);
|
2016-08-16 15:33:57 +00:00
|
|
|
$result = call_user_func_array([TextData::class, 'REPLACE'], $args);
|
2015-05-17 13:00:02 +00:00
|
|
|
$this->assertEquals($expectedResult, $result);
|
|
|
|
}
|
2012-07-31 20:56:11 +00:00
|
|
|
|
|
|
|
public function providerREPLACE()
|
|
|
|
{
|
2016-08-16 12:00:19 +00:00
|
|
|
return require 'data/Calculation/TextData/REPLACE.php';
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
2012-07-31 20:56:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerSUBSTITUTE
|
|
|
|
*/
|
2015-05-17 13:00:02 +00:00
|
|
|
public function testSUBSTITUTE()
|
|
|
|
{
|
|
|
|
$args = func_get_args();
|
|
|
|
$expectedResult = array_pop($args);
|
2016-08-16 15:33:57 +00:00
|
|
|
$result = call_user_func_array([TextData::class, 'SUBSTITUTE'], $args);
|
2015-05-17 13:00:02 +00:00
|
|
|
$this->assertEquals($expectedResult, $result);
|
|
|
|
}
|
2012-07-31 20:56:11 +00:00
|
|
|
|
|
|
|
public function providerSUBSTITUTE()
|
|
|
|
{
|
2016-08-16 12:00:19 +00:00
|
|
|
return require 'data/Calculation/TextData/SUBSTITUTE.php';
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
2012-07-31 20:56:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerTRIM
|
|
|
|
*/
|
2015-05-17 13:00:02 +00:00
|
|
|
public function testTRIM()
|
|
|
|
{
|
|
|
|
$args = func_get_args();
|
|
|
|
$expectedResult = array_pop($args);
|
2016-08-16 15:33:57 +00:00
|
|
|
$result = call_user_func_array([TextData::class, 'TRIMSPACES'], $args);
|
2015-05-17 13:00:02 +00:00
|
|
|
$this->assertEquals($expectedResult, $result);
|
|
|
|
}
|
2012-07-31 20:56:11 +00:00
|
|
|
|
|
|
|
public function providerTRIM()
|
|
|
|
{
|
2016-08-16 12:00:19 +00:00
|
|
|
return require 'data/Calculation/TextData/TRIM.php';
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
2012-07-31 20:56:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerCLEAN
|
|
|
|
*/
|
2015-05-17 13:00:02 +00:00
|
|
|
public function testCLEAN()
|
|
|
|
{
|
|
|
|
$args = func_get_args();
|
|
|
|
$expectedResult = array_pop($args);
|
2016-08-16 15:33:57 +00:00
|
|
|
$result = call_user_func_array([TextData::class, 'TRIMNONPRINTABLE'], $args);
|
2015-05-17 13:00:02 +00:00
|
|
|
$this->assertEquals($expectedResult, $result);
|
|
|
|
}
|
2012-07-31 20:56:11 +00:00
|
|
|
|
|
|
|
public function providerCLEAN()
|
|
|
|
{
|
2016-08-16 12:00:19 +00:00
|
|
|
return require 'data/Calculation/TextData/CLEAN.php';
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
2012-07-31 20:56:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerDOLLAR
|
|
|
|
*/
|
2015-05-17 13:00:02 +00:00
|
|
|
public function testDOLLAR()
|
|
|
|
{
|
|
|
|
$args = func_get_args();
|
|
|
|
$expectedResult = array_pop($args);
|
2016-08-16 15:33:57 +00:00
|
|
|
$result = call_user_func_array([TextData::class, 'DOLLAR'], $args);
|
2015-05-17 13:00:02 +00:00
|
|
|
$this->assertEquals($expectedResult, $result);
|
|
|
|
}
|
2012-07-31 20:56:11 +00:00
|
|
|
|
|
|
|
public function providerDOLLAR()
|
|
|
|
{
|
2016-08-16 12:00:19 +00:00
|
|
|
return require 'data/Calculation/TextData/DOLLAR.php';
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
2012-07-31 20:56:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerFIXED
|
|
|
|
*/
|
2015-05-17 13:00:02 +00:00
|
|
|
public function testFIXED()
|
|
|
|
{
|
|
|
|
$args = func_get_args();
|
|
|
|
$expectedResult = array_pop($args);
|
2016-08-16 15:33:57 +00:00
|
|
|
$result = call_user_func_array([TextData::class, 'FIXEDFORMAT'], $args);
|
2015-05-17 13:00:02 +00:00
|
|
|
$this->assertEquals($expectedResult, $result);
|
|
|
|
}
|
2012-07-31 20:56:11 +00:00
|
|
|
|
|
|
|
public function providerFIXED()
|
|
|
|
{
|
2016-08-16 12:00:19 +00:00
|
|
|
return require 'data/Calculation/TextData/FIXED.php';
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
2012-07-31 20:56:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerT
|
|
|
|
*/
|
2015-05-17 13:00:02 +00:00
|
|
|
public function testT()
|
|
|
|
{
|
|
|
|
$args = func_get_args();
|
|
|
|
$expectedResult = array_pop($args);
|
2016-08-16 15:33:57 +00:00
|
|
|
$result = call_user_func_array([TextData::class, 'RETURNSTRING'], $args);
|
2015-05-17 13:00:02 +00:00
|
|
|
$this->assertEquals($expectedResult, $result);
|
|
|
|
}
|
2012-07-31 20:56:11 +00:00
|
|
|
|
|
|
|
public function providerT()
|
|
|
|
{
|
2016-08-16 12:00:19 +00:00
|
|
|
return require 'data/Calculation/TextData/T.php';
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
2012-07-31 20:56:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerTEXT
|
|
|
|
*/
|
2015-05-17 13:00:02 +00:00
|
|
|
public function testTEXT()
|
|
|
|
{
|
|
|
|
// Enforce decimal and thousands separator values to UK/US, and currency code to USD
|
2016-08-26 06:39:29 +00:00
|
|
|
StringHelper::setDecimalSeparator('.');
|
|
|
|
StringHelper::setThousandsSeparator(',');
|
|
|
|
StringHelper::setCurrencyCode('$');
|
2015-05-17 13:00:02 +00:00
|
|
|
|
|
|
|
$args = func_get_args();
|
|
|
|
$expectedResult = array_pop($args);
|
2016-08-16 15:33:57 +00:00
|
|
|
$result = call_user_func_array([TextData::class, 'TEXTFORMAT'], $args);
|
2015-05-17 13:00:02 +00:00
|
|
|
$this->assertEquals($expectedResult, $result);
|
|
|
|
}
|
2012-07-31 20:56:11 +00:00
|
|
|
|
|
|
|
public function providerTEXT()
|
|
|
|
{
|
2016-08-16 12:00:19 +00:00
|
|
|
return require 'data/Calculation/TextData/TEXT.php';
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
2012-07-31 20:56:11 +00:00
|
|
|
|
2014-08-29 23:12:31 +00:00
|
|
|
/**
|
|
|
|
* @dataProvider providerVALUE
|
|
|
|
*/
|
2015-05-17 13:00:02 +00:00
|
|
|
public function testVALUE()
|
|
|
|
{
|
2016-08-26 06:39:29 +00:00
|
|
|
StringHelper::setDecimalSeparator('.');
|
|
|
|
StringHelper::setThousandsSeparator(' ');
|
|
|
|
StringHelper::setCurrencyCode('$');
|
2015-05-17 13:00:02 +00:00
|
|
|
|
|
|
|
$args = func_get_args();
|
|
|
|
$expectedResult = array_pop($args);
|
2016-08-16 15:33:57 +00:00
|
|
|
$result = call_user_func_array([TextData::class, 'VALUE'], $args);
|
2015-05-17 13:00:02 +00:00
|
|
|
$this->assertEquals($expectedResult, $result, null, 1E-8);
|
|
|
|
}
|
2014-08-29 23:12:31 +00:00
|
|
|
|
|
|
|
public function providerVALUE()
|
|
|
|
{
|
2016-08-16 12:00:19 +00:00
|
|
|
return require 'data/Calculation/TextData/VALUE.php';
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
2012-07-31 20:56:11 +00:00
|
|
|
}
|