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
|
|
|
|
2017-05-17 22:02:17 +00:00
|
|
|
use DateTime;
|
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;
|
2017-05-17 22:02:17 +00:00
|
|
|
use PHPUnit_Framework_TestCase;
|
2016-08-14 04:08:43 +00:00
|
|
|
|
2017-05-17 22:02:17 +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
|
|
|
|
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!'],
|
2017-05-17 22:02:17 +00:00
|
|
|
[new DateTime()],
|
2016-08-16 15:33:57 +00:00
|
|
|
];
|
2015-04-16 00:09:29 +00:00
|
|
|
}
|
|
|
|
|
2015-03-27 21:28:26 +00:00
|
|
|
/**
|
|
|
|
* @dataProvider providerDataTypeForValue
|
2017-01-23 05:49:10 +00:00
|
|
|
*
|
|
|
|
* @param mixed $expectedResult
|
2015-03-27 21:28:26 +00:00
|
|
|
*/
|
2017-01-23 05:49:10 +00:00
|
|
|
public function testDataTypeForValue($expectedResult, ...$args)
|
2015-05-17 13:00:02 +00:00
|
|
|
{
|
2017-01-23 05:49:10 +00:00
|
|
|
$result = DefaultValueBinder::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
|
|
|
}
|