No Description

AdvancedValueBinderTest.php 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. class AdvancedValueBinderTest extends PHPUnit_Framework_TestCase
  3. {
  4. public function setUp()
  5. {
  6. if (!defined('PHPEXCEL_ROOT')) {
  7. define('PHPEXCEL_ROOT', APPLICATION_PATH . '/');
  8. }
  9. require_once(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
  10. }
  11. public function provider()
  12. {
  13. if (!class_exists('PHPExcel_Style_NumberFormat')) {
  14. $this->setUp();
  15. }
  16. $currencyUSD = PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_USD_SIMPLE;
  17. $currencyEURO = str_replace('$', '€', PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_USD_SIMPLE);
  18. return array(
  19. array('10%', 0.1, PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE_00, ',', '.', '$'),
  20. array('$10.11', 10.11, $currencyUSD, ',', '.', '$'),
  21. array('$1,010.12', 1010.12, $currencyUSD, ',', '.', '$'),
  22. array('$20,20', 20.2, $currencyUSD, '.', ',', '$'),
  23. array('$2.020,20', 2020.2, $currencyUSD, '.', ',', '$'),
  24. array('€2.020,20', 2020.2, $currencyEURO, '.', ',', '€'),
  25. array('€ 2.020,20', 2020.2, $currencyEURO, '.', ',', '€'),
  26. array('€2,020.22', 2020.22, $currencyEURO, ',', '.', '€'),
  27. );
  28. }
  29. /**
  30. * @dataProvider provider
  31. */
  32. public function testCurrency($value, $valueBinded, $format, $thousandsSeparator, $decimalSeparator, $currencyCode)
  33. {
  34. $sheet = $this->getMock(
  35. 'PHPExcel_Worksheet',
  36. array('getStyle', 'getNumberFormat', 'setFormatCode','getCellCacheController')
  37. );
  38. $cache = $this->getMockBuilder('PHPExcel_CachedObjectStorage_Memory')
  39. ->disableOriginalConstructor()
  40. ->getMock();
  41. $cache->expects($this->any())
  42. ->method('getParent')
  43. ->will($this->returnValue($sheet));
  44. $sheet->expects($this->once())
  45. ->method('getStyle')
  46. ->will($this->returnSelf());
  47. $sheet->expects($this->once())
  48. ->method('getNumberFormat')
  49. ->will($this->returnSelf());
  50. $sheet->expects($this->once())
  51. ->method('setFormatCode')
  52. ->with($format)
  53. ->will($this->returnSelf());
  54. $sheet->expects($this->any())
  55. ->method('getCellCacheController')
  56. ->will($this->returnValue($cache));
  57. PHPExcel_Shared_String::setCurrencyCode($currencyCode);
  58. PHPExcel_Shared_String::setDecimalSeparator($decimalSeparator);
  59. PHPExcel_Shared_String::setThousandsSeparator($thousandsSeparator);
  60. $cell = new PHPExcel_Cell(NULL, PHPExcel_Cell_DataType::TYPE_STRING, $sheet);
  61. $binder = new PHPExcel_Cell_AdvancedValueBinder();
  62. $binder->bindValue($cell, $value);
  63. $this->assertEquals($valueBinded, $cell->getValue());
  64. }
  65. }