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