No Description

DefaultValueBinderTest.php 2.2KB

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