Restore 2 Disabled Tests

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.
This commit is contained in:
oleibman
2024-09-24 17:10:37 -07:00
parent 9d7aaffe8a
commit 1d73598d67
3 changed files with 13 additions and 16 deletions
+2 -2
View File
@@ -1451,7 +1451,7 @@ class Xlsx extends BaseReader
);
if (isset($images[$linkImageKey])) {
$url = str_replace('xl/drawings/', '', $images[$linkImageKey]);
$objDrawing->setPath($url);
$objDrawing->setPath($url, false);
}
if ($objDrawing->getPath() === '') {
continue;
@@ -1544,7 +1544,7 @@ class Xlsx extends BaseReader
);
if (isset($images[$linkImageKey])) {
$url = str_replace('xl/drawings/', '', $images[$linkImageKey]);
$objDrawing->setPath($url);
$objDrawing->setPath($url, false);
}
if ($objDrawing->getPath() === '') {
continue;
+6 -1
View File
@@ -109,7 +109,12 @@ class Drawing extends BaseDrawing
}
// 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) {
@@ -12,8 +12,7 @@ use PHPUnit\Framework\TestCase;
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');
@@ -31,20 +30,13 @@ class URLImageTest extends TestCase
// 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');