Skip to content

Commit f0219ff

Browse files
committed
Restore 2 Disabled Tests
1 parent d95bc29 commit f0219ff

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

src/PhpSpreadsheet/Reader/Xlsx.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,7 +1411,7 @@ protected function loadSpreadsheetFromFile(string $filename): Spreadsheet
14111411
);
14121412
if (isset($images[$linkImageKey])) {
14131413
$url = str_replace('xl/drawings/', '', $images[$linkImageKey]);
1414-
$objDrawing->setPath($url);
1414+
$objDrawing->setPath($url, false);
14151415
}
14161416
if ($objDrawing->getPath() === '') {
14171417
continue;
@@ -1500,7 +1500,7 @@ protected function loadSpreadsheetFromFile(string $filename): Spreadsheet
15001500
);
15011501
if (isset($images[$linkImageKey])) {
15021502
$url = str_replace('xl/drawings/', '', $images[$linkImageKey]);
1503-
$objDrawing->setPath($url);
1503+
$objDrawing->setPath($url, false);
15041504
}
15051505
if ($objDrawing->getPath() === '') {
15061506
continue;

src/PhpSpreadsheet/Worksheet/Drawing.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,12 @@ public function setPath($path, $verifyFile = true, $zip = null)
121121
}
122122
// Implicit that it is a URL, rather store info than running check above on value in other places.
123123
$this->isUrl = true;
124-
$imageContents = @file_get_contents($path);
124+
$ctx = null;
125+
// https://github.com/php/php-src/issues/16023
126+
if (substr($path, 0, 6) === 'https:') {
127+
$ctx = stream_context_create(['ssl' => ['crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_3_CLIENT]]);
128+
}
129+
$imageContents = @file_get_contents($path, false, $ctx);
125130
if ($imageContents !== false) {
126131
$filePath = tempnam(sys_get_temp_dir(), 'Drawing');
127132
if ($filePath) {

tests/PhpSpreadsheetTests/Reader/Xlsx/URLImageTest.php

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010

1111
class URLImageTest extends TestCase
1212
{
13-
// https://github.com/readthedocs/readthedocs.org/issues/11615
14-
public function xtestURLImageSource(): void
13+
public function testURLImageSource(): void
1514
{
1615
if (getenv('SKIP_URL_IMAGE_TEST') === '1') {
1716
self::markTestSkipped('Skipped due to setting of environment variable');
@@ -29,20 +28,14 @@ public function xtestURLImageSource(): void
2928
// Check if the source is a URL or a file path
3029
self::assertTrue($drawing->getIsURL());
3130
self::assertSame('https://phpspreadsheet.readthedocs.io/en/latest/topics/images/01-03-filter-icon-1.png', $drawing->getPath());
32-
$imageContents = file_get_contents($drawing->getPath());
33-
self::assertNotFalse($imageContents);
34-
$filePath = tempnam(sys_get_temp_dir(), 'Drawing');
35-
self::assertNotFalse($filePath);
36-
self::assertNotFalse(file_put_contents($filePath, $imageContents));
37-
$mimeType = mime_content_type($filePath);
38-
unlink($filePath);
39-
self::assertNotFalse($mimeType);
40-
$extension = File::mime2ext($mimeType);
41-
self::assertSame('png', $extension);
31+
self::assertSame(IMAGETYPE_PNG, $drawing->getType());
32+
self::assertSame(84, $drawing->getWidth());
33+
self::assertSame(44, $drawing->getHeight());
4234
}
35+
$spreadsheet->disconnectWorksheets();
4336
}
4437

45-
public function xtestURLImageSourceNotFound(): void
38+
public function testURLImageSourceNotFound(): void
4639
{
4740
if (getenv('SKIP_URL_IMAGE_TEST') === '1') {
4841
self::markTestSkipped('Skipped due to setting of environment variable');
@@ -54,6 +47,7 @@ public function xtestURLImageSourceNotFound(): void
5447
$worksheet = $spreadsheet->getActiveSheet();
5548
$collection = $worksheet->getDrawingCollection();
5649
self::assertCount(0, $collection);
50+
$spreadsheet->disconnectWorksheets();
5751
}
5852

5953
public function testURLImageSourceBadProtocol(): void

0 commit comments

Comments
 (0)