Skip to content

Commit

Permalink
Restore 2 Disabled Tests
Browse files Browse the repository at this point in the history
For some https requests for file_get_contents, "context" needs to be added to function call. It is not clear why this has changed recently.
  • Loading branch information
oleibman committed Sep 25, 2024
1 parent 9d7aaff commit 1d73598
Show file tree
Hide file tree
Showing 3 changed files with 13 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]]);

Check failure on line 115 in src/PhpSpreadsheet/Worksheet/Drawing.php

View workflow job for this annotation

GitHub Actions / phpcs

Expected at least 1 space before "=>"; 0 found

Check failure on line 115 in src/PhpSpreadsheet/Worksheet/Drawing.php

View workflow job for this annotation

GitHub Actions / phpcs

Expected at least 1 space after "=>"; 0 found
}
$imageContents = @file_get_contents($path, false, $ctx);
if ($imageContents !== false) {
$filePath = tempnam(sys_get_temp_dir(), 'Drawing');
if ($filePath) {
Expand Down
18 changes: 5 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,13 @@ 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());
}
}

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 Down

0 comments on commit 1d73598

Please sign in to comment.