mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-03 22:19:19 +00:00
050a42db8e
* Xlsx Reader External Data Validations Flag Missing Fix #2677. This PR supersedes #2679, written by @technghiath, which lacks tests, and probably doesn't solve the problem entirely. The code causing the problem appears to be the last remnant in Xlsx Reader which calls `children` using a namespace prefix rather than a namespace. That is changed, and tests are added where the tag is unexpectedly missing, and also where it uses a non-standard namespace prefix. * Scrutinizer Reports 1 "new" error. It isn't, but fix it anyhow. * Fix One Existing Scrutinizer Problem Only remaining problem in Reader/Xlsx.
59 lines
2.1 KiB
PHP
59 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Cell\DataValidation;
|
|
use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class DataValidationTest extends TestCase
|
|
{
|
|
public function testLoadXlsxDataValidation(): void
|
|
{
|
|
$filename = 'tests/data/Reader/XLSX/dataValidationTest.xlsx';
|
|
$reader = new Xlsx();
|
|
$spreadsheet = $reader->load($filename);
|
|
|
|
$worksheet = $spreadsheet->getActiveSheet();
|
|
|
|
self::assertTrue($worksheet->getCell('B3')->hasDataValidation());
|
|
$spreadsheet->disconnectWorksheets();
|
|
}
|
|
|
|
/**
|
|
* Test for load drop down lists of another sheet.
|
|
* Pull #2150, issue #2149. Also issue #2677.
|
|
*
|
|
* @dataProvider providerExternalSheet
|
|
*/
|
|
public function testDataValidationOfAnotherSheet(string $expectedB14, string $filename): void
|
|
{
|
|
$reader = new Xlsx();
|
|
$spreadsheet = $reader->load($filename);
|
|
|
|
$worksheet = $spreadsheet->getActiveSheet();
|
|
|
|
// same sheet
|
|
$validationCell = $worksheet->getCell('B5');
|
|
self::assertTrue($validationCell->hasDataValidation());
|
|
self::assertSame(DataValidation::TYPE_LIST, $validationCell->getDataValidation()->getType());
|
|
self::assertSame('$A$5:$A$7', $validationCell->getDataValidation()->getFormula1());
|
|
|
|
// another sheet
|
|
$validationCell = $worksheet->getCell('B14');
|
|
self::assertTrue($validationCell->hasDataValidation());
|
|
self::assertSame(DataValidation::TYPE_LIST, $validationCell->getDataValidation()->getType());
|
|
self::assertSame($expectedB14, $validationCell->getDataValidation()->getFormula1());
|
|
$spreadsheet->disconnectWorksheets();
|
|
}
|
|
|
|
public function providerExternalSheet(): array
|
|
{
|
|
return [
|
|
'standard spreadsheet' => ['Feuil2!$A$3:$A$5', 'tests/data/Reader/XLSX/dataValidation2Test.xlsx'],
|
|
'alternate namespace prefix' => ['Feuil2!$A$3:$A$5', 'tests/data/Reader/XLSX/issue.2677.namespace.xlsx'],
|
|
'missing formula' => ['', 'tests/data/Reader/XLSX/issue.2677.removeformula1.xlsx'],
|
|
];
|
|
}
|
|
}
|