LowerTest.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 LowerTest extends AllSetupTeardown
  6. {
  7. /**
  8. * @dataProvider providerLOWER
  9. *
  10. * @param mixed $expectedResult
  11. * @param mixed $str
  12. */
  13. public function testLOWER($expectedResult, $str = 'omitted'): void
  14. {
  15. $this->mightHaveException($expectedResult);
  16. $sheet = $this->getSheet();
  17. if ($str === 'omitted') {
  18. $sheet->getCell('B1')->setValue('=LOWER()');
  19. } else {
  20. $this->setCell('A1', $str);
  21. $sheet->getCell('B1')->setValue('=LOWER(A1)');
  22. }
  23. $result = $sheet->getCell('B1')->getCalculatedValue();
  24. self::assertEquals($expectedResult, $result);
  25. }
  26. public function providerLOWER(): array
  27. {
  28. return require 'tests/data/Calculation/TextData/LOWER.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('=LOWER(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 providerLowerArray
  64. */
  65. public function testLowerArray(array $expectedResult, string $array): void
  66. {
  67. $calculation = Calculation::getInstance();
  68. $formula = "=LOWER({$array})";
  69. $result = $calculation->_calculateFormulaValue($formula);
  70. self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
  71. }
  72. public function providerLowerArray(): 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. }