PhpSpreadsheet/tests/PhpSpreadsheetTests/Calculation/TextDataTest.php

361 lines
9.4 KiB
PHP
Raw Normal View History

2012-07-31 20:56:11 +00:00
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation;
2012-07-31 20:56:11 +00:00
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\TextData;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
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()
{
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);
$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()
{
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);
$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()
{
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);
$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()
{
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);
$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()
{
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);
$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()
{
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);
$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()
{
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);
$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()
{
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);
$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()
{
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);
$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()
{
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);
$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()
{
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);
$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()
{
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);
$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()
{
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);
$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()
{
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);
$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()
{
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);
$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()
{
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);
$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()
{
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);
$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()
{
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);
$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()
{
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);
$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()
{
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
StringHelper::setDecimalSeparator('.');
StringHelper::setThousandsSeparator(',');
StringHelper::setCurrencyCode('$');
2015-05-17 13:00:02 +00:00
$args = func_get_args();
$expectedResult = array_pop($args);
$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()
{
return require 'data/Calculation/TextData/TEXT.php';
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
/**
* @dataProvider providerVALUE
*/
2015-05-17 13:00:02 +00:00
public function testVALUE()
{
StringHelper::setDecimalSeparator('.');
StringHelper::setThousandsSeparator(' ');
StringHelper::setCurrencyCode('$');
2015-05-17 13:00:02 +00:00
$args = func_get_args();
$expectedResult = array_pop($args);
$result = call_user_func_array([TextData::class, 'VALUE'], $args);
2015-05-17 13:00:02 +00:00
$this->assertEquals($expectedResult, $result, null, 1E-8);
}
public function providerVALUE()
{
return require 'data/Calculation/TextData/VALUE.php';
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
}