Skip to content

Commit c251ef5

Browse files
committed
Restore 2 Disabled Tests
1 parent a9693d1 commit c251ef5

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
@@ -1432,7 +1432,7 @@ protected function loadSpreadsheetFromFile(string $filename): Spreadsheet
14321432
);
14331433
if (isset($images[$linkImageKey])) {
14341434
$url = str_replace('xl/drawings/', '', $images[$linkImageKey]);
1435-
$objDrawing->setPath($url);
1435+
$objDrawing->setPath($url, false);
14361436
}
14371437
if ($objDrawing->getPath() === '') {
14381438
continue;
@@ -1525,7 +1525,7 @@ protected function loadSpreadsheetFromFile(string $filename): Spreadsheet
15251525
);
15261526
if (isset($images[$linkImageKey])) {
15271527
$url = str_replace('xl/drawings/', '', $images[$linkImageKey]);
1528-
$objDrawing->setPath($url);
1528+
$objDrawing->setPath($url, false);
15291529
}
15301530
if ($objDrawing->getPath() === '') {
15311531
continue;

src/PhpSpreadsheet/Worksheet/Drawing.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,12 @@ public function setPath(string $path, bool $verifyFile = true, ?ZipArchive $zip
109109
}
110110
// Implicit that it is a URL, rather store info than running check above on value in other places.
111111
$this->isUrl = true;
112-
$imageContents = @file_get_contents($path);
112+
$ctx = null;
113+
// https://github.com/php/php-src/issues/16023
114+
if (str_starts_with($path, 'https:')) {
115+
$ctx = stream_context_create(['ssl' => ['crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_3_CLIENT]]);
116+
}
117+
$imageContents = @file_get_contents($path, false, $ctx);
113118
if ($imageContents !== false) {
114119
$filePath = tempnam(sys_get_temp_dir(), 'Drawing');
115120
if ($filePath) {

tests/PhpSpreadsheetTests/Reader/Xlsx/URLImageTest.php

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

1313
class URLImageTest extends TestCase
1414
{
15-
// https://github.com/readthedocs/readthedocs.org/issues/11615
16-
public function xtestURLImageSource(): void
15+
public function testURLImageSource(): void
1716
{
1817
if (getenv('SKIP_URL_IMAGE_TEST') === '1') {
1918
self::markTestSkipped('Skipped due to setting of environment variable');
@@ -31,20 +30,14 @@ public function xtestURLImageSource(): void
3130
// Check if the source is a URL or a file path
3231
self::assertTrue($drawing->getIsURL());
3332
self::assertSame('https://phpspreadsheet.readthedocs.io/en/latest/topics/images/01-03-filter-icon-1.png', $drawing->getPath());
34-
$imageContents = file_get_contents($drawing->getPath());
35-
self::assertNotFalse($imageContents);
36-
$filePath = tempnam(sys_get_temp_dir(), 'Drawing');
37-
self::assertNotFalse($filePath);
38-
self::assertNotFalse(file_put_contents($filePath, $imageContents));
39-
$mimeType = mime_content_type($filePath);
40-
unlink($filePath);
41-
self::assertNotFalse($mimeType);
42-
$extension = File::mime2ext($mimeType);
43-
self::assertSame('png', $extension);
33+
self::assertSame(IMAGETYPE_PNG, $drawing->getType());
34+
self::assertSame(84, $drawing->getWidth());
35+
self::assertSame(44, $drawing->getHeight());
4436
}
37+
$spreadsheet->disconnectWorksheets();
4538
}
4639

47-
public function xtestURLImageSourceNotFound(): void
40+
public function testURLImageSourceNotFound(): void
4841
{
4942
if (getenv('SKIP_URL_IMAGE_TEST') === '1') {
5043
self::markTestSkipped('Skipped due to setting of environment variable');
@@ -56,6 +49,7 @@ public function xtestURLImageSourceNotFound(): void
5649
$worksheet = $spreadsheet->getActiveSheet();
5750
$collection = $worksheet->getDrawingCollection();
5851
self::assertCount(0, $collection);
52+
$spreadsheet->disconnectWorksheets();
5953
}
6054

6155
public function testURLImageSourceBadProtocol(): void

0 commit comments

Comments
 (0)