Skip to content

Commit

Permalink
Merge pull request #4170 from oleibman/urlreinstate
Browse files Browse the repository at this point in the history
Restore 2 Disabled Tests
  • Loading branch information
oleibman authored Sep 25, 2024
2 parents 9d7aaff + 512c21e commit 498afe2
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 @@ -1451,7 +1451,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 @@ -1544,7 +1544,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 @@ -109,7 +109,12 @@ public function setPath(string $path, bool $verifyFile = true, ?ZipArchive $zip
}
// 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) {
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 @@ -12,8 +12,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 @@ -31,20 +30,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 @@ -56,6 +49,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 498afe2

Please sign in to comment.