DataValidationBooleanValue.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx;
  3. use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
  4. use PHPUnit\Framework\TestCase;
  5. class DataValidationBooleanValue extends TestCase
  6. {
  7. public static function testPr2225TrueFalse(): void
  8. {
  9. //This file is created with LibreOffice
  10. $xlsxFile = 'tests/data/Reader/XLSX/pr2225-datavalidation-truefalse.xlsx';
  11. $reader = new Xlsx();
  12. $spreadsheet = $reader->load($xlsxFile);
  13. $a1 = $spreadsheet->getActiveSheet()->getDataValidation('A1');
  14. $a2 = $spreadsheet->getActiveSheet()->getDataValidation('A2');
  15. //<dataValidation allowBlank="false" showDropDown="false" showErrorMessage="true" showInputMessage="true" sqref="A1" type="list">
  16. //<dataValidation allowBlank="true" showDropDown="true" showErrorMessage="false" showInputMessage="false" sqref="A2" type="list">
  17. self::assertFalse($a1->getAllowBlank(), 'A1 validation does not allow blanks, flag should be false');
  18. self::assertTrue($a1->getShowDropDown(), 'A1 is set to show the drop down in Excel, which is false in the file');
  19. self::assertTrue($a1->getShowErrorMessage(), 'A1 Shows error message, flag should be true');
  20. self::assertTrue($a1->getShowInputMessage(), 'A1 Shows input message, flag should be true');
  21. self::assertTrue($a2->getAllowBlank(), 'A2 validation allows blanks, flag should be true');
  22. self::assertFalse($a2->getShowDropDown(), 'A2 is set to not show the drop down in Excel, which is true in the file');
  23. self::assertFalse($a2->getShowErrorMessage(), 'A2 does not show error message, flag should be false');
  24. self::assertFalse($a2->getShowInputMessage(), 'A2 does not show input message, flag should be false');
  25. }
  26. //This file was created with Google Sheets export to XLSX
  27. public static function testPr2225OneZero(): void
  28. {
  29. $xlsxFile = 'tests/data/Reader/XLSX/pr2225-datavalidation-onezero.xlsx';
  30. $reader = new Xlsx();
  31. $spreadsheet = $reader->load($xlsxFile);
  32. $a1 = $spreadsheet->getActiveSheet()->getDataValidation('A1');
  33. $a2 = $spreadsheet->getActiveSheet()->getDataValidation('A2');
  34. //<dataValidation allowBlank="1" showErrorMessage="1" showInputMessage="1" sqref="A1" type="list">
  35. //<dataValidation allowBlank="1" showDropDown="0" sqref="A2" type="list">
  36. self::assertTrue($a1->getAllowBlank(), 'A1 validation allows blanks, flag should be true');
  37. self::assertTrue($a1->getShowDropDown(), 'A1 is set to show the drop down in Excel, which is false in the file');
  38. self::assertTrue($a1->getShowErrorMessage(), 'A1 Shows error message, flag should be true');
  39. self::assertTrue($a1->getShowInputMessage(), 'A1 Shows input message, flag should be true');
  40. self::assertTrue($a2->getAllowBlank(), 'A2 validation allows blanks, flag should be true');
  41. self::assertFalse($a2->getShowDropDown(), 'A2 is set to not show the drop down in Excel, which is true in the file');
  42. self::assertFalse($a2->getShowErrorMessage(), 'A2 does not show error message, flag should be false');
  43. self::assertFalse($a2->getShowInputMessage(), 'A2 does not show input message, flag should be false');
  44. }
  45. }