Files
PhpSpreadsheet/tests/PhpSpreadsheetTests/Reader/Xlsx/Issue2362Test.php
oleibman f831f48b71 ZipArchive and "Inconsistent" Zip File (#2376)
* ZipArchive and "Inconsistent" Zip File

Fix #2362. I added test for zip file inconsistency when dealing with a particularly nasty PHP/libzip bug affecting zero-length files. However, we also now verify that the file starts with a valid zip signature, so the consistency test is not really needed, and, from what I've read on the web, isn't particularly useful. The file with a problem, for example, opens just fine with Excel and zip, despite Php reporting it as inconsistent (when asked to check consistency). So, remove the consistency check.

* Update Issue2362Test.php

Latest Phpstan does not allow cast from 'mixed' to 'string'.

* Update Issue2362Test.php
2021-11-12 01:18:57 -08:00

44 lines
1.4 KiB
PHP

<?php
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\RichText\RichText;
use PHPUnit\Framework\TestCase;
use ZipArchive;
class Issue2362Test extends TestCase
{
public function testPreliminaries(): void
{
// ZipArchive says file is 'inconsistent',
// but Excel has no problem with it.
$filename = 'tests/data/Reader/XLSX/issue.2362.xlsx';
$zip = new ZipArchive();
$res = $zip->open($filename, ZipArchive::CHECKCONS);
self::assertSame(ZipArchive::ER_INCONS, $res);
}
public function testIssue2362(): void
{
$filename = 'tests/data/Reader/XLSX/issue.2362.xlsx';
$reader = IOFactory::createReader('Xlsx');
$spreadsheet = $reader->load($filename);
$sheet = $spreadsheet->getActiveSheet();
$value = $sheet->getCell('A1')->getValue();
if ($value instanceof RichText) {
self::assertSame('Дата', (string) $value);
} else {
self::fail('A1 is not RichText');
}
$value = $sheet->getCell('D21')->getValue();
if ($value instanceof RichText) {
self::assertSame('391800, Рязанская область, г. Скопин, ул. Ленина, д. 40', (string) $value);
} else {
self::fail('D21 is not RichText');
}
$spreadsheet->disconnectWorksheets();
}
}