mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-02 13:41:21 +00:00
37b6ca4979
Its defaults are to unescape within single quotes, and escape within double quotes and here-docs. Right now, it leaves everything as-is, which means our code is inconsistent and need not be. Further, although dealing with complex regular expressions will never be easy, I find it much easier to figure out what's going on when superfluous back-slashes are removed. These changes were all made automatically using the "fix" script, so should be reliable. They, of course, pass all unit tests.
65 lines
2.4 KiB
PHP
65 lines
2.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Writer\Html;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Shared\File;
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup;
|
|
use PhpOffice\PhpSpreadsheet\Writer\Exception as WriterException;
|
|
use PhpOffice\PhpSpreadsheet\Writer\Html;
|
|
use PhpOffice\PhpSpreadsheet\Writer\Pdf\Mpdf;
|
|
use PhpOffice\PhpSpreadsheetTests\Functional;
|
|
|
|
class InvalidFileNameTest extends Functional\AbstractFunctional
|
|
{
|
|
public function testEmptyFileName(): void
|
|
{
|
|
$this->expectException(WriterException::class);
|
|
$spreadsheet = new Spreadsheet();
|
|
$spreadsheet->getActiveSheet()->getCell('A1')->setValue('Cell 1');
|
|
$writer = new Html($spreadsheet);
|
|
$writer->save('');
|
|
}
|
|
|
|
public function testEmptyFileNamePdf(): void
|
|
{
|
|
$this->expectException(WriterException::class);
|
|
$spreadsheet = new Spreadsheet();
|
|
$spreadsheet->getActiveSheet()->getCell('A1')->setValue('Cell 1');
|
|
$writer = new Mpdf($spreadsheet);
|
|
$writer->save('');
|
|
}
|
|
|
|
public function testNotEmptyTempdirNamePdf(): void
|
|
{
|
|
$spreadsheet = new Spreadsheet();
|
|
$spreadsheet->getActiveSheet()->getCell('A1')->setValue('Cell 1');
|
|
$writer = new Mpdf($spreadsheet);
|
|
$writer->setFont('Helvetica');
|
|
self::assertEquals('Helvetica', $writer->getFont());
|
|
$writer->setPaperSize(PageSetup::PAPERSIZE_LEDGER);
|
|
self::assertEquals($writer->getPaperSize(), PageSetup::PAPERSIZE_LEDGER);
|
|
self::assertEquals(File::sysGetTempDir() . '/phpsppdf', $writer->getTempDir());
|
|
$writer->setTempDir(File::sysGetTempDir());
|
|
self::assertEquals(File::sysGetTempDir(), $writer->getTempDir());
|
|
}
|
|
|
|
public function testEmptyTempdirNamePdf(): void
|
|
{
|
|
$this->expectException(WriterException::class);
|
|
$spreadsheet = new Spreadsheet();
|
|
$spreadsheet->getActiveSheet()->getCell('A1')->setValue('Cell 1');
|
|
$writer = new Mpdf($spreadsheet);
|
|
$writer->setTempDir('');
|
|
}
|
|
|
|
public function testWinFileNames(): void
|
|
{
|
|
self::assertEquals('file:///C:/temp/filename.xlsx', Html::winFileToUrl('C:\temp\filename.xlsx'));
|
|
self::assertEquals('/tmp/filename.xlsx', Html::winFileToUrl('/tmp/filename.xlsx'));
|
|
self::assertEquals('a:bfile', Html::winFileToUrl('a:bfile'));
|
|
}
|
|
}
|