mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-17 21:46:37 +00:00
beb0ac856a
For the second time in recent months, some tests are failing/erring because https file_get_contents is not working on github (cannot reproduce locally on Windows or Linux). Filed an issue with Php when this first happened, and their suggested code change worked till now. If they come up with another successful code change, I will implement it and restore these tests.
66 lines
2.6 KiB
PHP
66 lines
2.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Reader\Html;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Exception as SpreadsheetException;
|
|
use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class HtmlImage2Test extends TestCase
|
|
{
|
|
public function xtestCanInsertImageGoodProtocol(): void
|
|
{
|
|
if (getenv('SKIP_URL_IMAGE_TEST') === '1') {
|
|
self::markTestSkipped('Skipped due to setting of environment variable');
|
|
}
|
|
$imagePath = 'https://phpspreadsheet.readthedocs.io/en/latest/topics/images/01-03-filter-icon-1.png';
|
|
$html = '<table>
|
|
<tr>
|
|
<td><img src="' . $imagePath . '" alt="test image voilà"></td>
|
|
</tr>
|
|
</table>';
|
|
$filename = HtmlHelper::createHtml($html);
|
|
$spreadsheet = HtmlHelper::loadHtmlIntoSpreadsheet($filename, true);
|
|
$firstSheet = $spreadsheet->getSheet(0);
|
|
|
|
/** @var Drawing $drawing */
|
|
$drawing = $firstSheet->getDrawingCollection()[0];
|
|
self::assertEquals($imagePath, $drawing->getPath());
|
|
self::assertEquals('A1', $drawing->getCoordinates());
|
|
}
|
|
|
|
public function xtestCantInsertImageNotFound(): void
|
|
{
|
|
if (getenv('SKIP_URL_IMAGE_TEST') === '1') {
|
|
self::markTestSkipped('Skipped due to setting of environment variable');
|
|
}
|
|
$imagePath = 'https://phpspreadsheet.readthedocs.io/en/latest/topics/images/xxx01-03-filter-icon-1.png';
|
|
$html = '<table>
|
|
<tr>
|
|
<td><img src="' . $imagePath . '" alt="test image voilà"></td>
|
|
</tr>
|
|
</table>';
|
|
$filename = HtmlHelper::createHtml($html);
|
|
$spreadsheet = HtmlHelper::loadHtmlIntoSpreadsheet($filename, true);
|
|
$firstSheet = $spreadsheet->getSheet(0);
|
|
$drawingCollection = $firstSheet->getDrawingCollection();
|
|
self::assertCount(0, $drawingCollection);
|
|
}
|
|
|
|
public function testCannotInsertImageBadProtocol(): void
|
|
{
|
|
$this->expectException(SpreadsheetException::class);
|
|
$this->expectExceptionMessage('Invalid protocol for linked drawing');
|
|
$imagePath = 'httpx://phpspreadsheet.readthedocs.io/en/latest/topics/images/01-03-filter-icon-1.png';
|
|
$html = '<table>
|
|
<tr>
|
|
<td><img src="' . $imagePath . '" alt="test image voilà"></td>
|
|
</tr>
|
|
</table>';
|
|
$filename = HtmlHelper::createHtml($html);
|
|
HtmlHelper::loadHtmlIntoSpreadsheet($filename, true);
|
|
}
|
|
}
|