mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-08-24 18:08:18 +00:00
b67404229a
* Allow Skipping One Unit Test Alone in the test suite, URLImageTest needs to access the internet. It's a little fragile (the site that it's looking for may go away or change), but no real problem. However, on my system, it runs afoul of my proxy. Rather than jumping through hoops when I run the test suite (which happens very often), I am changing the test to skip if an environment variable is set to a specific value. This should not adversely affect anyone, and the test will still run in github, but it will help me a lot. * Scrutinizer It complained that my one new if statement made the module too complex. There actually were a number of if-then-else situations that could be handled just as well with assertions. I have changed it accordingly.
43 lines
1.7 KiB
PHP
43 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx;
|
|
|
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
|
use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
|
|
use PhpOffice\PhpSpreadsheetTests\Reader\Utility\File;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class URLImageTest extends TestCase
|
|
{
|
|
public function testURLImageSource(): void
|
|
{
|
|
if (getenv('SKIP_URL_IMAGE_TEST') === '1') {
|
|
self::markTestSkipped('Skipped due to setting of environment variable');
|
|
}
|
|
$filename = realpath(__DIR__ . '/../../../data/Reader/XLSX/urlImage.xlsx');
|
|
self::assertNotFalse($filename);
|
|
$reader = IOFactory::createReader('Xlsx');
|
|
$spreadsheet = $reader->load($filename);
|
|
$worksheet = $spreadsheet->getActiveSheet();
|
|
$collection = $worksheet->getDrawingCollection();
|
|
self::assertCount(1, $collection);
|
|
|
|
foreach ($collection as $drawing) {
|
|
self::assertInstanceOf(Drawing::class, $drawing);
|
|
// Check if the source is a URL or a file path
|
|
self::assertTrue($drawing->getIsURL());
|
|
self::assertSame('https://www.globalipmanager.com/DataFiles/Pics/20/Berniaga.comahp2.jpg', $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('jpeg', $extension);
|
|
}
|
|
}
|
|
}
|