UpperTest.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData;
  3. use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
  4. use PhpOffice\PhpSpreadsheet\Settings;
  5. class UpperTest extends AllSetupTeardown
  6. {
  7. /**
  8. * @dataProvider providerUPPER
  9. *
  10. * @param mixed $expectedResult
  11. * @param mixed $str
  12. */
  13. public function testUPPER($expectedResult, $str = 'omitted'): void
  14. {
  15. $this->mightHaveException($expectedResult);
  16. $sheet = $this->getSheet();
  17. if ($str === 'omitted') {
  18. $sheet->getCell('B1')->setValue('=UPPER()');
  19. } else {
  20. $this->setCell('A1', $str);
  21. $sheet->getCell('B1')->setValue('=UPPER(A1)');
  22. }
  23. $result = $sheet->getCell('B1')->getCalculatedValue();
  24. self::assertEquals($expectedResult, $result);
  25. }
  26. public function providerUPPER(): array
  27. {
  28. return require 'tests/data/Calculation/TextData/UPPER.php';
  29. }
  30. /**
  31. * @dataProvider providerLocaleLOWER
  32. *
  33. * @param string $expectedResult
  34. * @param mixed $value
  35. * @param mixed $locale
  36. */
  37. public function testLowerWithLocaleBoolean($expectedResult, $locale, $value): void
  38. {
  39. $newLocale = Settings::setLocale($locale);
  40. if ($newLocale === false) {
  41. self::markTestSkipped('Unable to set locale for locale-specific test');
  42. }
  43. $sheet = $this->getSheet();
  44. $this->setCell('A1', $value);
  45. $sheet->getCell('B1')->setValue('=UPPER(A1)');
  46. $result = $sheet->getCell('B1')->getCalculatedValue();
  47. self::assertEquals($expectedResult, $result);
  48. }
  49. public function providerLocaleLOWER(): array
  50. {
  51. return [
  52. ['VRAI', 'fr_FR', true],
  53. ['WAAR', 'nl_NL', true],
  54. ['TOSI', 'fi', true],
  55. ['ИСТИНА', 'bg', true],
  56. ['FAUX', 'fr_FR', false],
  57. ['ONWAAR', 'nl_NL', false],
  58. ['EPÄTOSI', 'fi', false],
  59. ['ЛОЖЬ', 'bg', false],
  60. ];
  61. }
  62. /**
  63. * @dataProvider providerUpperArray
  64. */
  65. public function testUpperArray(array $expectedResult, string $array): void
  66. {
  67. $calculation = Calculation::getInstance();
  68. $formula = "=UPPER({$array})";
  69. $result = $calculation->_calculateFormulaValue($formula);
  70. self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
  71. }
  72. public function providerUpperArray(): array
  73. {
  74. return [
  75. 'row vector' => [[["LET'S", 'ALL CHANGE', 'CASE']], '{"lEt\'S", "aLl chAngE", "cAsE"}'],
  76. 'column vector' => [[["LET'S"], ['ALL CHANGE'], ['CASE']], '{"lEt\'S"; "aLl chAngE"; "cAsE"}'],
  77. 'matrix' => [[['BUILD ALL', 'YOUR WORKBOOKS'], ['WITH', 'PHPSPREADSHEET']], '{"bUIld aLL", "yOUr WOrkBOOks"; "wiTH", "PhpSpreadsheet"}'],
  78. ];
  79. }
  80. }