1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Reader\Html; |
6
|
|
|
|
7
|
|
|
use PhpOffice\PhpSpreadsheet\Exception as SpreadsheetException; |
8
|
|
|
use PhpOffice\PhpSpreadsheet\Worksheet\Drawing; |
9
|
|
|
use PHPUnit\Framework\TestCase; |
10
|
|
|
|
11
|
|
|
// not sure why succeeding now |
12
|
|
|
class HtmlImage2Test extends TestCase |
13
|
|
|
{ |
14
|
|
|
public function testCanInsertImageGoodProtocolxx(): void |
15
|
|
|
{ |
16
|
|
|
if (getenv('SKIP_URL_IMAGE_TEST') === '1') { |
17
|
|
|
self::markTestSkipped('Skipped due to setting of environment variable'); |
18
|
|
|
} |
19
|
|
|
$imagePath = 'https://phpspreadsheet.readthedocs.io/en/latest/topics/images/01-03-filter-icon-1.png'; |
20
|
|
|
$html = '<table> |
21
|
|
|
<tr> |
22
|
|
|
<td><img src="' . $imagePath . '" alt="test image voilà"></td> |
23
|
|
|
</tr> |
24
|
|
|
</table>'; |
25
|
|
|
$filename = HtmlHelper::createHtml($html); |
26
|
|
|
$spreadsheet = HtmlHelper::loadHtmlIntoSpreadsheet($filename, true); |
27
|
|
|
$firstSheet = $spreadsheet->getSheet(0); |
28
|
|
|
|
29
|
|
|
/** @var Drawing $drawing */ |
30
|
|
|
$drawing = $firstSheet->getDrawingCollection()[0]; |
31
|
|
|
self::assertEquals($imagePath, $drawing->getPath()); |
32
|
|
|
self::assertEquals('A1', $drawing->getCoordinates()); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function xtestCantInsertImageNotFound(): void |
36
|
|
|
{ |
37
|
|
|
if (getenv('SKIP_URL_IMAGE_TEST') === '1') { |
38
|
|
|
self::markTestSkipped('Skipped due to setting of environment variable'); |
39
|
|
|
} |
40
|
|
|
$imagePath = 'https://phpspreadsheet.readthedocs.io/en/latest/topics/images/xxx01-03-filter-icon-1.png'; |
41
|
|
|
$html = '<table> |
42
|
|
|
<tr> |
43
|
|
|
<td><img src="' . $imagePath . '" alt="test image voilà"></td> |
44
|
|
|
</tr> |
45
|
|
|
</table>'; |
46
|
|
|
$filename = HtmlHelper::createHtml($html); |
47
|
|
|
$spreadsheet = HtmlHelper::loadHtmlIntoSpreadsheet($filename, true); |
48
|
|
|
$firstSheet = $spreadsheet->getSheet(0); |
49
|
|
|
$drawingCollection = $firstSheet->getDrawingCollection(); |
50
|
|
|
self::assertCount(0, $drawingCollection); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function testCannotInsertImageBadProtocol(): void |
54
|
|
|
{ |
55
|
|
|
$this->expectException(SpreadsheetException::class); |
56
|
|
|
$this->expectExceptionMessage('Invalid protocol for linked drawing'); |
57
|
|
|
$imagePath = 'httpx://phpspreadsheet.readthedocs.io/en/latest/topics/images/01-03-filter-icon-1.png'; |
58
|
|
|
$html = '<table> |
59
|
|
|
<tr> |
60
|
|
|
<td><img src="' . $imagePath . '" alt="test image voilà"></td> |
61
|
|
|
</tr> |
62
|
|
|
</table>'; |
63
|
|
|
$filename = HtmlHelper::createHtml($html); |
64
|
|
|
HtmlHelper::loadHtmlIntoSpreadsheet($filename, true); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|