|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx; |
| 6 | + |
| 7 | +use PhpOffice\PhpSpreadsheet\Cell\DataValidator; |
| 8 | +use PhpOffice\PhpSpreadsheet\Reader\Xlsx; |
| 9 | + |
| 10 | +class Issue3863Test extends \PHPUnit\Framework\TestCase |
| 11 | +{ |
| 12 | + private static string $testbook = 'tests/data/Reader/XLSX/issue.3863.xlsx'; |
| 13 | + |
| 14 | + public function testPreliminaries(): void |
| 15 | + { |
| 16 | + $file = 'zip://'; |
| 17 | + $file .= self::$testbook; |
| 18 | + $file .= '#xl/worksheets/sheet1.xml'; |
| 19 | + $data = file_get_contents($file); |
| 20 | + if ($data === false) { |
| 21 | + self::fail('Unable to read file'); |
| 22 | + } else { |
| 23 | + // Only 1 Data Validation and it does not specify operator |
| 24 | + self::assertStringContainsString('<dataValidations count="1"><dataValidation type="whole" allowBlank="1" showInputMessage="1" showErrorMessage="1" sqref="A1" xr:uid="{D0F98CC5-7234-4ADF-BD42-F33321DCD3CA}"><formula1>5</formula1><formula2>10</formula2></dataValidation></dataValidations>', $data); |
| 25 | + } |
| 26 | + } |
| 27 | + |
| 28 | + public function testValidData(): void |
| 29 | + { |
| 30 | + $reader = new Xlsx(); |
| 31 | + $spreadsheet = $reader->load(self::$testbook); |
| 32 | + $sheet = $spreadsheet->getActiveSheet(); |
| 33 | + self::assertSame('between', $sheet->getCell('A1')->getDataValidation()->getOperator()); |
| 34 | + $validator = new DataValidator(); |
| 35 | + self::assertTrue($validator->isValid($sheet->getCell('A1'))); |
| 36 | + $sheet->getCell('A1')->setValue(3); |
| 37 | + self::assertFalse($validator->isValid($sheet->getCell('A1'))); |
| 38 | + $sheet->getCell('A1')->setValue(7); |
| 39 | + self::assertTrue($validator->isValid($sheet->getCell('A1'))); |
| 40 | + $spreadsheet->disconnectWorksheets(); |
| 41 | + } |
| 42 | +} |
0 commit comments