-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into condxlsborder
- Loading branch information
Showing
12 changed files
with
160 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpOffice\PhpSpreadsheetTests\Reader\Csv; | ||
|
||
use PhpOffice\PhpSpreadsheet\IOFactory; | ||
use PhpOffice\PhpSpreadsheet\Reader\Csv as CsvReader; | ||
use PhpOffice\PhpSpreadsheet\Shared\File; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class NotHtmlTest extends TestCase | ||
{ | ||
private string $tempFile = ''; | ||
|
||
protected function tearDown(): void | ||
{ | ||
if ($this->tempFile !== '') { | ||
unlink($this->tempFile); | ||
$this->tempFile = ''; | ||
} | ||
} | ||
|
||
public function testHtmlCantRead(): void | ||
{ | ||
// This test has a file which IOFactory will identify as Csv. | ||
// So file can be read using either Csv Reader or IOFactory. | ||
$this->tempFile = $filename = File::temporaryFilename(); | ||
$cells = [ | ||
['1', '<a href="http://example.com">example</a>', '3'], | ||
['4', '5', '6'], | ||
]; | ||
$handle = fopen($filename, 'wb'); | ||
self::assertNotFalse($handle); | ||
foreach ($cells as $row) { | ||
fwrite($handle, "{$row[0]},{$row[1]},{$row[2]}\n"); | ||
} | ||
fclose($handle); | ||
// Php8.3- identify file as text/html. | ||
// Php8.4+ identify file as text/csv, and this type of change | ||
// has been known to be retrofitted to prior versions. | ||
$mime = mime_content_type($filename); | ||
if ($mime !== 'text/csv') { | ||
self::assertSame('text/html', $mime); | ||
} | ||
self::assertSame('Csv', IOFactory::identify($filename)); | ||
$reader = new CsvReader(); | ||
$spreadsheet = $reader->load($filename); | ||
$sheet = $spreadsheet->getActiveSheet(); | ||
self::assertSame($cells, $sheet->toArray()); | ||
$spreadsheet->disconnectWorksheets(); | ||
} | ||
|
||
public function testHtmlCanRead(): void | ||
{ | ||
// This test has a file which IOFactory will identify as Html. | ||
// So file has to be read using Csv Reader, not IOFactory. | ||
$this->tempFile = $filename = File::temporaryFilename(); | ||
$cells = [ | ||
['<a href="http://example.com">example</a>', '<div>hello', '3'], | ||
['4', '5', '</div>'], | ||
]; | ||
$handle = fopen($filename, 'wb'); | ||
self::assertNotFalse($handle); | ||
foreach ($cells as $row) { | ||
fwrite($handle, "{$row[0]},{$row[1]},{$row[2]}\n"); | ||
} | ||
fclose($handle); | ||
// Php8.3- identify file as text/html. | ||
// Php8.4+ identify file as text/csv, and this type of change | ||
// has been known to be retrofitted to prior versions. | ||
$mime = mime_content_type($filename); | ||
if ($mime !== 'text/csv') { | ||
self::assertSame('text/html', $mime); | ||
} | ||
self::assertSame('Html', IOFactory::identify($filename)); | ||
$reader = new CsvReader(); | ||
$spreadsheet = $reader->load($filename); | ||
$sheet = $spreadsheet->getActiveSheet(); | ||
self::assertSame($cells, $sheet->toArray()); | ||
$spreadsheet->disconnectWorksheets(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx; | ||
|
||
use PhpOffice\PhpSpreadsheet\IOFactory; | ||
use PhpOffice\PhpSpreadsheet\Reader\IReader; | ||
use PhpOffice\PhpSpreadsheet\Reader\Xlsx as XlsxReader; | ||
|
||
class Issue3982Test extends \PHPUnit\Framework\TestCase | ||
{ | ||
private static string $testbook = 'tests/data/Reader/XLSX/issue.3982.xlsx'; | ||
|
||
public function testLoadAllRows(): void | ||
{ | ||
$spreadsheet = IOFactory::load(self::$testbook); | ||
$sheet = $spreadsheet->getActiveSheet(); | ||
$data = $sheet->toArray(null, true, false, true); | ||
self::assertCount(1048576, $data); | ||
$spreadsheet->disconnectWorksheets(); | ||
} | ||
|
||
public function testIgnoreCellsWithNoRows(): void | ||
{ | ||
$spreadsheet = IOFactory::load(self::$testbook, IReader::IGNORE_ROWS_WITH_NO_CELLS); | ||
$sheet = $spreadsheet->getActiveSheet(); | ||
$data = $sheet->toArray(null, true, false, true); | ||
self::assertSame([1, 2, 3, 4, 5, 6], array_keys($data)); | ||
$spreadsheet->disconnectWorksheets(); | ||
} | ||
|
||
public function testDefaultSetting(): void | ||
{ | ||
$reader = new XlsxReader(); | ||
self::assertFalse($reader->getIgnoreRowsWithNoCells()); | ||
self::assertFalse($reader->getReadDataOnly()); | ||
self::assertFalse($reader->getIncludeCharts()); | ||
self::assertTrue($reader->getReadEmptyCells()); | ||
} | ||
} |
Binary file not shown.