mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-05 06:58:15 +00:00
Merge pull request #4170 from oleibman/urlreinstate
Restore 2 Disabled Tests
This commit is contained in:
@@ -1451,7 +1451,7 @@ class Xlsx extends BaseReader
|
||||
);
|
||||
if (isset($images[$linkImageKey])) {
|
||||
$url = str_replace('xl/drawings/', '', $images[$linkImageKey]);
|
||||
$objDrawing->setPath($url);
|
||||
$objDrawing->setPath($url, false);
|
||||
}
|
||||
if ($objDrawing->getPath() === '') {
|
||||
continue;
|
||||
@@ -1544,7 +1544,7 @@ class Xlsx extends BaseReader
|
||||
);
|
||||
if (isset($images[$linkImageKey])) {
|
||||
$url = str_replace('xl/drawings/', '', $images[$linkImageKey]);
|
||||
$objDrawing->setPath($url);
|
||||
$objDrawing->setPath($url, false);
|
||||
}
|
||||
if ($objDrawing->getPath() === '') {
|
||||
continue;
|
||||
|
||||
@@ -109,7 +109,12 @@ class Drawing extends BaseDrawing
|
||||
}
|
||||
// Implicit that it is a URL, rather store info than running check above on value in other places.
|
||||
$this->isUrl = true;
|
||||
$imageContents = @file_get_contents($path);
|
||||
$ctx = null;
|
||||
// https://github.com/php/php-src/issues/16023
|
||||
if (str_starts_with($path, 'https:')) {
|
||||
$ctx = stream_context_create(['ssl' => ['crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_3_CLIENT]]);
|
||||
}
|
||||
$imageContents = @file_get_contents($path, false, $ctx);
|
||||
if ($imageContents !== false) {
|
||||
$filePath = tempnam(sys_get_temp_dir(), 'Drawing');
|
||||
if ($filePath) {
|
||||
|
||||
@@ -12,8 +12,7 @@ use PHPUnit\Framework\TestCase;
|
||||
|
||||
class URLImageTest extends TestCase
|
||||
{
|
||||
// https://github.com/readthedocs/readthedocs.org/issues/11615
|
||||
public function xtestURLImageSource(): void
|
||||
public function testURLImageSource(): void
|
||||
{
|
||||
if (getenv('SKIP_URL_IMAGE_TEST') === '1') {
|
||||
self::markTestSkipped('Skipped due to setting of environment variable');
|
||||
@@ -31,20 +30,14 @@ class URLImageTest extends TestCase
|
||||
// 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());
|
||||
$imageContents = file_get_contents($drawing->getPath());
|
||||
self::assertNotFalse($imageContents);
|
||||
$filePath = tempnam(sys_get_temp_dir(), 'Drawing');
|
||||
self::assertNotFalse($filePath);
|
||||
self::assertNotFalse(file_put_contents($filePath, $imageContents));
|
||||
$mimeType = mime_content_type($filePath);
|
||||
unlink($filePath);
|
||||
self::assertNotFalse($mimeType);
|
||||
$extension = File::mime2ext($mimeType);
|
||||
self::assertSame('png', $extension);
|
||||
self::assertSame(IMAGETYPE_PNG, $drawing->getType());
|
||||
self::assertSame(84, $drawing->getWidth());
|
||||
self::assertSame(44, $drawing->getHeight());
|
||||
}
|
||||
$spreadsheet->disconnectWorksheets();
|
||||
}
|
||||
|
||||
public function xtestURLImageSourceNotFound(): void
|
||||
public function testURLImageSourceNotFound(): void
|
||||
{
|
||||
if (getenv('SKIP_URL_IMAGE_TEST') === '1') {
|
||||
self::markTestSkipped('Skipped due to setting of environment variable');
|
||||
@@ -56,6 +49,7 @@ class URLImageTest extends TestCase
|
||||
$worksheet = $spreadsheet->getActiveSheet();
|
||||
$collection = $worksheet->getDrawingCollection();
|
||||
self::assertCount(0, $collection);
|
||||
$spreadsheet->disconnectWorksheets();
|
||||
}
|
||||
|
||||
public function testURLImageSourceBadProtocol(): void
|
||||
|
||||
Reference in New Issue
Block a user