source: trunk/client/inc/hpdf5/spipu/html2pdf/src/Tests/CssConverterTest.php@ 424

Last change on this file since 424 was 347, checked in by roby, 4 years ago

Aggiornamento per compatibilità con php7.4

File size: 3.5 KB
Line 
1<?php
2
3namespace Spipu\Html2Pdf\Tests;
4
5use Spipu\Html2Pdf\CssConverter;
6
7/**
8 * Class CssConverterTest
9 */
10class CssConverterTest extends \PHPUnit_Framework_TestCase
11{
12 /**
13 * @var CssConverter
14 */
15 private $cssConverter;
16
17 public function setUp()
18 {
19 $this->cssConverter = new CssConverter();
20 }
21
22 /**
23 * @param string $css
24 * @param string $old
25 * @param array $expected
26 *
27 * @dataProvider convertToMMProvider
28 */
29 public function testConvertToMM($css, $old, $expected)
30 {
31 $result = $this->cssConverter->convertToMM($css, $old);
32
33 $this->assertEquals($expected, $result);
34 }
35
36 public function convertToMMProvider()
37 {
38 return array(
39 array('100mm', null, 100),
40 array('100px', null, 25.4 / 96. * 100),
41 array('100', null, 25.4 / 96. * 100),
42 array('100pt', null, 25.4 / 72. * 100),
43 array('100in', null, 25.4 * 100),
44 array('10%', 100, 10),
45 array('100cm', null, null),
46 );
47 }
48
49 /**
50 * @param string $css
51 * @param array $expected
52 *
53 * @dataProvider convertToRadiusProvider
54 */
55 public function testConvertToRadius($css, $expected)
56 {
57 $result = $this->cssConverter->convertToRadius($css);
58
59 $this->assertEquals(count($expected), count($result));
60
61 for ($i = 0; $i < count($result); $i++) {
62 $this->assertEquals($expected[$i], $result[$i]);
63 }
64 }
65
66 public function convertToRadiusProvider()
67 {
68 return array(
69 array('100mm', array(100)),
70 array('100mm 10mm', array(100, 10)),
71 array('100mm 10mm ', array(100, 10)),
72 array('100mm 10cm 10mm', array(100, 10)),
73 array('1mm 2mm 3mm 4mm', array(1, 2, 3, 4)),
74 );
75 }
76
77 /**
78 * @param string $css
79 * @param boolean $expectedRes
80 * @param array $expectedColor
81 *
82 * @dataProvider convertToColorProvider
83 */
84 public function testConvertToColor($css, $expectedRes, $expectedColor)
85 {
86 $res = true;
87 $resultColor = $this->cssConverter->convertToColor($css, $res);
88
89 $this->assertEquals($expectedRes, $res);
90 $this->assertEquals(count($expectedColor), count($resultColor));
91
92 for ($i = 0; $i < count($resultColor); $i++) {
93 if (is_null($expectedColor[$i])) {
94 $this->assertNull($resultColor[$i]);
95 } else {
96 $this->assertEquals($expectedColor[$i], $resultColor[$i]);
97 }
98 }
99 }
100
101 public function convertToColorProvider()
102 {
103 return array(
104 array('transparent', true, array(null, null, null)),
105 array('aliceblue', true, array( 240, 248, 255)),
106 array('#F0A050', true, array( 240, 160, 80)),
107 array('#FA5', true, array( 255, 170, 85)),
108 array('rgb( 50, 100, 150)', true, array( 50, 100, 150)),
109 array('rgb( 10%, 20%, 30%)', true, array(25.5, 51, 76.5)),
110 array('rgb( 0.2, 0.4, 0.6)', true, array( 51, 102, 153)),
111 array('cmyk(255, 255, 255, 255)', true, array( 100, 100, 100, 100)),
112 array('cmyk(10%, 20%, 30%, 40%)', true, array( 10, 20, 30, 40)),
113 array('cmyk(0.2, 0.4, 0.6, 0.8)', true, array( 20, 40, 60, 80)),
114 array('blakc', false, array( 0, 0, 0)),
115 );
116 }
117}
Note: See TracBrowser for help on using the repository browser.