Failed Conditions
Pull Request — master (#4274)
by Owen
13:07
created

HtmlImage2Test::xtestCantInsertImageNotFound()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 10
c 0
b 0
f 0
dl 0
loc 16
rs 9.9332
cc 2
nc 2
nop 0
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
class HtmlImage2Test extends TestCase
12
{
13
    public function xtestCanInsertImageGoodProtocol(): void
14
    {
15
        if (getenv('SKIP_URL_IMAGE_TEST') === '1') {
16
            self::markTestSkipped('Skipped due to setting of environment variable');
17
        }
18
        $imagePath = 'https://phpspreadsheet.readthedocs.io/en/latest/topics/images/01-03-filter-icon-1.png';
19
        $html = '<table>
20
                    <tr>
21
                        <td><img src="' . $imagePath . '" alt="test image voilà"></td>
22
                    </tr>
23
                </table>';
24
        $filename = HtmlHelper::createHtml($html);
25
        $spreadsheet = HtmlHelper::loadHtmlIntoSpreadsheet($filename, true);
26
        $firstSheet = $spreadsheet->getSheet(0);
27
28
        /** @var Drawing $drawing */
29
        $drawing = $firstSheet->getDrawingCollection()[0];
30
        self::assertEquals($imagePath, $drawing->getPath());
31
        self::assertEquals('A1', $drawing->getCoordinates());
32
    }
33
34
    public function xtestCantInsertImageNotFound(): void
35
    {
36
        if (getenv('SKIP_URL_IMAGE_TEST') === '1') {
37
            self::markTestSkipped('Skipped due to setting of environment variable');
38
        }
39
        $imagePath = 'https://phpspreadsheet.readthedocs.io/en/latest/topics/images/xxx01-03-filter-icon-1.png';
40
        $html = '<table>
41
                    <tr>
42
                        <td><img src="' . $imagePath . '" alt="test image voilà"></td>
43
                    </tr>
44
                </table>';
45
        $filename = HtmlHelper::createHtml($html);
46
        $spreadsheet = HtmlHelper::loadHtmlIntoSpreadsheet($filename, true);
47
        $firstSheet = $spreadsheet->getSheet(0);
48
        $drawingCollection = $firstSheet->getDrawingCollection();
49
        self::assertCount(0, $drawingCollection);
50
    }
51
52
    public function testCannotInsertImageBadProtocol(): void
53
    {
54
        $this->expectException(SpreadsheetException::class);
55
        $this->expectExceptionMessage('Invalid protocol for linked drawing');
56
        $imagePath = 'httpx://phpspreadsheet.readthedocs.io/en/latest/topics/images/01-03-filter-icon-1.png';
57
        $html = '<table>
58
                    <tr>
59
                        <td><img src="' . $imagePath . '" alt="test image voilà"></td>
60
                    </tr>
61
                </table>';
62
        $filename = HtmlHelper::createHtml($html);
63
        HtmlHelper::loadHtmlIntoSpreadsheet($filename, true);
64
    }
65
}
66