Passed
Push — develop ( 0f8292...86c635 )
by Adrien
26:53
created

HtmlTest::testBackgroundColorInRanding()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 0
dl 0
loc 16
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheetTests\Reader;
4
5
use PhpOffice\PhpSpreadsheet\Reader\Html;
6
use PHPUnit\Framework\TestCase;
7
8
class HtmlTest extends TestCase
9
{
10
    public function testCsvWithAngleBracket()
11
    {
12
        $filename = __DIR__ . '/../../data/Reader/HTML/csv_with_angle_bracket.csv';
13
        $reader = new Html();
14
        self::assertFalse($reader->canRead($filename));
15
    }
16
17
    public function providerCanReadVerySmallFile()
18
    {
19
        $padding = str_repeat('a', 2048);
20
21
        return [
22
            [true, ' <html> ' . $padding . ' </html> '],
23
            [true, ' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html>' . $padding . '</html>'],
24
            [true, '<html></html>'],
25
            [false, ''],
26
        ];
27
    }
28
29
    /**
30
     * @dataProvider providerCanReadVerySmallFile
31
     *
32
     * @param bool $expected
33
     * @param string $content
34
     */
35
    public function testCanReadVerySmallFile($expected, $content)
36
    {
37
        $filename = tempnam(sys_get_temp_dir(), 'html');
38
        file_put_contents($filename, $content);
39
40
        $reader = new Html();
41
        $actual = $reader->canRead($filename);
42
        unlink($filename);
43
44
        self::assertSame($expected, $actual);
45
    }
46
47
    public function testBackgroundColorInRanding()
48
    {
49
        $html = '<table>
50
                    <tr>
51
                        <td style="background-color: #000000;color: #FFFFFF">Blue background</td>
52
                    </tr>
53
                </table>';
54
        $filename = tempnam(sys_get_temp_dir(), 'html');
55
        file_put_contents($filename, $html);
56
        $reader = new Html();
57
        $spreadsheet = $reader->load($filename);
58
        $firstSheet = $spreadsheet->getSheet(0);
59
        $style = $firstSheet->getCell('A1')->getStyle();
60
61
        self::assertEquals('FFFFFF', $style->getFont()->getColor()->getRGB());
62
        unlink($filename);
63
    }
64
}
65