2015-03-27 21:28:26 +00:00
|
|
|
<?php
|
|
|
|
|
2016-08-31 17:18:12 +00:00
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Cell;
|
2015-03-27 21:28:26 +00:00
|
|
|
|
2016-08-31 17:18:12 +00:00
|
|
|
use PhpOffice\PhpSpreadsheet\Cell;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Cell\DataType;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Cell\DefaultValueBinder;
|
|
|
|
use PhpOffice\PhpSpreadsheet\RichText;
|
2016-08-14 04:08:43 +00:00
|
|
|
|
2016-03-22 14:35:50 +00:00
|
|
|
class DefaultValueBinderTest extends \PHPUnit_Framework_TestCase
|
2015-03-27 21:28:26 +00:00
|
|
|
{
|
2015-04-16 00:09:29 +00:00
|
|
|
protected $cellStub;
|
2015-03-27 21:28:26 +00:00
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
2016-08-16 14:24:47 +00:00
|
|
|
if (!defined('PHPSPREADSHEET_ROOT')) {
|
|
|
|
define('PHPSPREADSHEET_ROOT', APPLICATION_PATH . '/');
|
2015-03-27 21:28:26 +00:00
|
|
|
}
|
2016-08-16 15:33:57 +00:00
|
|
|
require_once PHPSPREADSHEET_ROOT . '/Bootstrap.php';
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
2015-03-27 21:28:26 +00:00
|
|
|
|
2015-04-16 00:09:29 +00:00
|
|
|
protected function createCellStub()
|
|
|
|
{
|
|
|
|
// Create a stub for the Cell class.
|
2016-08-14 04:08:43 +00:00
|
|
|
$this->cellStub = $this->getMockBuilder(Cell::class)
|
2015-04-16 00:09:29 +00:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
// Configure the stub.
|
|
|
|
$this->cellStub->expects($this->any())
|
2017-01-05 03:26:20 +00:00
|
|
|
->method('setValueExplicit')
|
|
|
|
->will($this->returnValue(true));
|
2015-04-16 00:09:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider binderProvider
|
2016-12-22 14:43:37 +00:00
|
|
|
*
|
|
|
|
* @param mixed $value
|
2015-04-16 00:09:29 +00:00
|
|
|
*/
|
|
|
|
public function testBindValue($value)
|
2015-05-17 13:00:02 +00:00
|
|
|
{
|
|
|
|
$this->createCellStub();
|
2016-08-14 04:08:43 +00:00
|
|
|
$binder = new DefaultValueBinder();
|
2015-05-17 13:00:02 +00:00
|
|
|
$result = $binder->bindValue($this->cellStub, $value);
|
|
|
|
$this->assertTrue($result);
|
|
|
|
}
|
2015-04-16 00:09:29 +00:00
|
|
|
|
|
|
|
public function binderProvider()
|
|
|
|
{
|
2016-08-16 15:33:57 +00:00
|
|
|
return [
|
|
|
|
[null],
|
|
|
|
[''],
|
|
|
|
['ABC'],
|
|
|
|
['=SUM(A1:B2)'],
|
|
|
|
[true],
|
|
|
|
[false],
|
|
|
|
[123],
|
|
|
|
[-123.456],
|
|
|
|
['123'],
|
|
|
|
['-123.456'],
|
|
|
|
['#REF!'],
|
|
|
|
[new \DateTime()],
|
|
|
|
];
|
2015-04-16 00:09:29 +00:00
|
|
|
}
|
|
|
|
|
2015-03-27 21:28:26 +00:00
|
|
|
/**
|
|
|
|
* @dataProvider providerDataTypeForValue
|
|
|
|
*/
|
2015-05-17 13:00:02 +00:00
|
|
|
public function testDataTypeForValue()
|
|
|
|
{
|
2015-05-28 22:15:46 +00:00
|
|
|
list($args, $expectedResult) = func_get_args();
|
2016-08-16 15:33:57 +00:00
|
|
|
$result = call_user_func_array([DefaultValueBinder::class, 'dataTypeForValue'], $args);
|
2015-05-17 13:00:02 +00:00
|
|
|
$this->assertEquals($expectedResult, $result);
|
|
|
|
}
|
2015-03-27 21:28:26 +00:00
|
|
|
|
|
|
|
public function providerDataTypeForValue()
|
|
|
|
{
|
2016-08-16 12:00:19 +00:00
|
|
|
return require 'data/Cell/DefaultValueBinder.php';
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
2015-03-27 21:28:26 +00:00
|
|
|
|
2015-05-17 13:00:02 +00:00
|
|
|
public function testDataTypeForRichTextObject()
|
|
|
|
{
|
2016-08-14 04:08:43 +00:00
|
|
|
$objRichText = new RichText();
|
2015-04-16 00:09:29 +00:00
|
|
|
$objRichText->createText('Hello World');
|
|
|
|
|
2016-08-14 04:08:43 +00:00
|
|
|
$expectedResult = DataType::TYPE_INLINE;
|
2016-08-26 06:39:29 +00:00
|
|
|
$result = DefaultValueBinder::dataTypeForValue($objRichText);
|
2015-05-17 13:00:02 +00:00
|
|
|
$this->assertEquals($expectedResult, $result);
|
|
|
|
}
|
2015-03-27 21:28:26 +00:00
|
|
|
}
|