DefaultValueBinderTest.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. require_once 'testDataFileIterator.php';
  3. class DefaultValueBinderTest extends PHPUnit_Framework_TestCase
  4. {
  5. protected $cellStub;
  6. public function setUp()
  7. {
  8. if (!defined('PHPEXCEL_ROOT')) {
  9. define('PHPEXCEL_ROOT', APPLICATION_PATH . '/');
  10. }
  11. require_once(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
  12. }
  13. protected function createCellStub()
  14. {
  15. // Create a stub for the Cell class.
  16. $this->cellStub = $this->getMockBuilder('PHPExcel_Cell')
  17. ->disableOriginalConstructor()
  18. ->getMock();
  19. // Configure the stub.
  20. $this->cellStub->expects($this->any())
  21. ->method('setValueExplicit')
  22. ->will($this->returnValue(true));
  23. }
  24. /**
  25. * @dataProvider binderProvider
  26. */
  27. public function testBindValue($value)
  28. {
  29. $this->createCellStub();
  30. $binder = new PHPExcel_Cell_DefaultValueBinder();
  31. $result = $binder->bindValue($this->cellStub, $value);
  32. $this->assertTrue($result);
  33. }
  34. public function binderProvider()
  35. {
  36. return array(
  37. array(null),
  38. array(''),
  39. array('ABC'),
  40. array('=SUM(A1:B2)'),
  41. array(true),
  42. array(false),
  43. array(123),
  44. array(-123.456),
  45. array('123'),
  46. array('-123.456'),
  47. array('#REF!'),
  48. array(new DateTime()),
  49. );
  50. }
  51. /**
  52. * @dataProvider providerDataTypeForValue
  53. */
  54. public function testDataTypeForValue()
  55. {
  56. $args = func_get_args();
  57. $expectedResult = array_pop($args);
  58. $result = call_user_func_array(array('PHPExcel_Cell_DefaultValueBinder','dataTypeForValue'), $args);
  59. $this->assertEquals($expectedResult, $result);
  60. }
  61. public function providerDataTypeForValue()
  62. {
  63. return new testDataFileIterator('rawTestData/Cell/DefaultValueBinder.data');
  64. }
  65. public function testDataTypeForRichTextObject()
  66. {
  67. $objRichText = new PHPExcel_RichText();
  68. $objRichText->createText('Hello World');
  69. $expectedResult = PHPExcel_Cell_DataType::TYPE_INLINE;
  70. $result = call_user_func(array('PHPExcel_Cell_DefaultValueBinder','dataTypeForValue'), $objRichText);
  71. $this->assertEquals($expectedResult, $result);
  72. }
  73. }