Skip to content

Commit

Permalink
Restore 2 Disabled Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
oleibman committed Sep 25, 2024
1 parent d95bc29 commit f0219ff
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/PhpSpreadsheet/Reader/Xlsx.php
Original file line number Diff line number Diff line change
Expand Up @@ -1411,7 +1411,7 @@ protected function loadSpreadsheetFromFile(string $filename): Spreadsheet
);
if (isset($images[$linkImageKey])) {
$url = str_replace('xl/drawings/', '', $images[$linkImageKey]);
$objDrawing->setPath($url);
$objDrawing->setPath($url, false);
}
if ($objDrawing->getPath() === '') {
continue;
Expand Down Expand Up @@ -1500,7 +1500,7 @@ protected function loadSpreadsheetFromFile(string $filename): Spreadsheet
);
if (isset($images[$linkImageKey])) {
$url = str_replace('xl/drawings/', '', $images[$linkImageKey]);
$objDrawing->setPath($url);
$objDrawing->setPath($url, false);
}
if ($objDrawing->getPath() === '') {
continue;
Expand Down
7 changes: 6 additions & 1 deletion src/PhpSpreadsheet/Worksheet/Drawing.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,12 @@ public function setPath($path, $verifyFile = true, $zip = null)
}
// 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 (substr($path, 0, 6) === '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) {
Expand Down
20 changes: 7 additions & 13 deletions tests/PhpSpreadsheetTests/Reader/Xlsx/URLImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@

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');
Expand All @@ -29,20 +28,14 @@ public function xtestURLImageSource(): void
// 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');
Expand All @@ -54,6 +47,7 @@ public function xtestURLImageSourceNotFound(): void
$worksheet = $spreadsheet->getActiveSheet();
$collection = $worksheet->getDrawingCollection();
self::assertCount(0, $collection);
$spreadsheet->disconnectWorksheets();
}

public function testURLImageSourceBadProtocol(): void
Expand Down

0 comments on commit f0219ff

Please sign in to comment.