mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-19 14:36:48 +00:00
beb0ac856a
For the second time in recent months, some tests are failing/erring because https file_get_contents is not working on github (cannot reproduce locally on Windows or Linux). Filed an issue with Php when this first happened, and their suggested code change worked till now. If they come up with another successful code change, I will implement it and restore these tests.
65 lines
2.6 KiB
PHP
65 lines
2.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Exception as SpreadsheetException;
|
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
|
use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
|
|
use PhpOffice\PhpSpreadsheetTests\Reader\Utility\File;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class URLImageTest extends TestCase
|
|
{
|
|
public function xtestURLImageSource(): void
|
|
{
|
|
if (getenv('SKIP_URL_IMAGE_TEST') === '1') {
|
|
self::markTestSkipped('Skipped due to setting of environment variable');
|
|
}
|
|
$filename = realpath(__DIR__ . '/../../../data/Reader/XLSX/urlImage.xlsx');
|
|
self::assertNotFalse($filename);
|
|
$reader = IOFactory::createReader('Xlsx');
|
|
$spreadsheet = $reader->load($filename);
|
|
$worksheet = $spreadsheet->getActiveSheet();
|
|
$collection = $worksheet->getDrawingCollection();
|
|
self::assertCount(1, $collection);
|
|
|
|
foreach ($collection as $drawing) {
|
|
self::assertInstanceOf(Drawing::class, $drawing);
|
|
// Check if the source is a URL or a file path
|
|
self::assertTrue($drawing->getIsURL());
|
|
self::assertSame('https://phpspreadsheet.readthedocs.io/en/latest/topics/images/01-03-filter-icon-1.png', $drawing->getPath());
|
|
self::assertSame(IMAGETYPE_PNG, $drawing->getType());
|
|
self::assertSame(84, $drawing->getWidth());
|
|
self::assertSame(44, $drawing->getHeight());
|
|
}
|
|
$spreadsheet->disconnectWorksheets();
|
|
}
|
|
|
|
public function xtestURLImageSourceNotFound(): void
|
|
{
|
|
if (getenv('SKIP_URL_IMAGE_TEST') === '1') {
|
|
self::markTestSkipped('Skipped due to setting of environment variable');
|
|
}
|
|
$filename = realpath(__DIR__ . '/../../../data/Reader/XLSX/urlImage.notfound.xlsx');
|
|
self::assertNotFalse($filename);
|
|
$reader = IOFactory::createReader('Xlsx');
|
|
$spreadsheet = $reader->load($filename);
|
|
$worksheet = $spreadsheet->getActiveSheet();
|
|
$collection = $worksheet->getDrawingCollection();
|
|
self::assertCount(0, $collection);
|
|
$spreadsheet->disconnectWorksheets();
|
|
}
|
|
|
|
public function testURLImageSourceBadProtocol(): void
|
|
{
|
|
$filename = realpath(__DIR__ . '/../../../data/Reader/XLSX/urlImage.bad.dontuse');
|
|
self::assertNotFalse($filename);
|
|
$this->expectException(SpreadsheetException::class);
|
|
$this->expectExceptionMessage('Invalid protocol for linked drawing');
|
|
$reader = IOFactory::createReader('Xlsx');
|
|
$reader->load($filename);
|
|
}
|
|
}
|