File: 0003-Change-font-dir-for-local-build-tests.patch

package info (click to toggle)
php-dompdf 2.0.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,176 kB
  • sloc: php: 22,518; sh: 91; xml: 80; makefile: 52
file content (401 lines) | stat: -rw-r--r-- 14,962 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
From: William Desportes <williamdes@wdes.fr>
Date: Thu, 2 Feb 2023 16:06:40 +0100
Subject: Change fontDir when the tests are run locally

Origin: vendor
Forwarded: not-needed
---
 tests/Canvas/CPDFTest.php         |  6 +++---
 tests/Css/SelectorTest.php        |  2 +-
 tests/Css/ShorthandTest.php       |  2 +-
 tests/Css/StyleTest.php           | 20 ++++++++++----------
 tests/DompdfTest.php              | 18 +++++++++---------
 tests/FrameReflower/ImageTest.php |  2 +-
 tests/Helpers/MockHelper.php      |  4 ++--
 tests/LayoutTest/ImageTest.php    |  4 +++-
 tests/LayoutTest/PageTest.php     |  2 +-
 tests/OptionsTest.php             | 21 +++++++++++++++------
 tests/Renderer/RendererTest.php   |  2 +-
 tests/TestCase.php                | 29 +++++++++++++++++++++++++++++
 12 files changed, 76 insertions(+), 36 deletions(-)

diff --git a/tests/Canvas/CPDFTest.php b/tests/Canvas/CPDFTest.php
index 55f9bc5..5132842 100644
--- a/tests/Canvas/CPDFTest.php
+++ b/tests/Canvas/CPDFTest.php
@@ -14,7 +14,7 @@ class CPDFTest extends TestCase
         global $called;
         $called = 0;
 
-        $dompdf = new Dompdf();
+        $dompdf = $this->getDompdf();
         $canvas = new CPDF([0, 0, 200, 200], "portrait", $dompdf);
         $canvas->new_page();
 
@@ -44,7 +44,7 @@ class CPDFTest extends TestCase
 
     public function testPageText(): void
     {
-        $dompdf = new Dompdf();
+        $dompdf = $this->getDompdf();
         $canvas = new CPDF([0, 0, 200, 200], "portrait", $dompdf);
         $canvas->new_page();
 
@@ -57,7 +57,7 @@ class CPDFTest extends TestCase
 
     public function testPageLine(): void
     {
-        $dompdf = new Dompdf();
+        $dompdf = $this->getDompdf();
         $canvas = new CPDF([0, 0, 200, 200], "portrait", $dompdf);
         $canvas->new_page();
 
diff --git a/tests/Css/SelectorTest.php b/tests/Css/SelectorTest.php
index 7cfc557..e72b729 100644
--- a/tests/Css/SelectorTest.php
+++ b/tests/Css/SelectorTest.php
@@ -13,7 +13,7 @@ class SelectorTest extends TestCase
 {
     private function stylesheet()
     {
-        return new class(new Dompdf()) extends Stylesheet {
+        return new class($this->getDompdf()) extends Stylesheet {
             public function specificity(string $selector, int $origin = self::ORIG_AUTHOR): int
             {
                 return parent::specificity($selector, $origin);
diff --git a/tests/Css/ShorthandTest.php b/tests/Css/ShorthandTest.php
index 015e4da..7c607c6 100644
--- a/tests/Css/ShorthandTest.php
+++ b/tests/Css/ShorthandTest.php
@@ -10,7 +10,7 @@ class ShorthandTest extends TestCase
 {
     protected function style(): Style
     {
-        $dompdf = new Dompdf();
+        $dompdf = $this->getDompdf();
         $sheet = new Stylesheet($dompdf);
         $sheet->set_base_path(__DIR__); // Treat stylesheet as being located in this directory
 
diff --git a/tests/Css/StyleTest.php b/tests/Css/StyleTest.php
index 45929fc..6d9a138 100644
--- a/tests/Css/StyleTest.php
+++ b/tests/Css/StyleTest.php
@@ -31,7 +31,7 @@ class StyleTest extends TestCase
      */
     public function testLengthInPt(string $length, ?float $ref_size, $expected): void
     {
-        $dompdf = new Dompdf();
+        $dompdf = $this->getDompdf();
         $sheet = new Stylesheet($dompdf);
         $s = new Style($sheet);
 
@@ -82,7 +82,7 @@ class StyleTest extends TestCase
      */
     public function testCssImageNoBaseHref(string $value, $expected): void
     {
-        $dompdf = new Dompdf();
+        $dompdf = $this->getDompdf();
         $sheet = new Stylesheet($dompdf);
         $sheet->set_base_path(__DIR__); // Treat stylesheet as being located in this directory
         $s = new Style($sheet);
@@ -98,7 +98,7 @@ class StyleTest extends TestCase
      */
     public function testCssImageWithBaseHref(string $value, $expected): void
     {
-        $dompdf = new Dompdf();
+        $dompdf = $this->getDompdf();
         $dompdf->setProtocol("https://");
         $dompdf->setBaseHost("example.com");
         $dompdf->setBasePath("/");
@@ -117,7 +117,7 @@ class StyleTest extends TestCase
      */
     public function testCssImageWithStylesheetBaseHref(string $value, $expected): void
     {
-        $dompdf = new Dompdf();
+        $dompdf = $this->getDompdf();
         $sheet = new Stylesheet($dompdf);
         $sheet->set_protocol("https://");
         $sheet->set_host("example.com");
@@ -157,7 +157,7 @@ class StyleTest extends TestCase
      */
     public function testContent(string $value, $expected): void
     {
-        $dompdf = new Dompdf();
+        $dompdf = $this->getDompdf();
         $sheet = new Stylesheet($dompdf);
         $style = new Style($sheet);
 
@@ -196,7 +196,7 @@ class StyleTest extends TestCase
     {
         $options = new Options();
         $options->setDefaultPaperSize("A5");
-        $dompdf = new Dompdf($options);
+        $dompdf = $this->getDompdf($options);
         $sheet = new Stylesheet($dompdf);
         $style = new Style($sheet);
 
@@ -236,7 +236,7 @@ class StyleTest extends TestCase
      */
     public function testOpacity(string $value, $expected): void
     {
-        $dompdf = new Dompdf();
+        $dompdf = $this->getDompdf();
         $sheet = new Stylesheet($dompdf);
         $style = new Style($sheet);
 
@@ -266,7 +266,7 @@ class StyleTest extends TestCase
      */
     public function testZIndex(string $value, $expected): void
     {
-        $dompdf = new Dompdf();
+        $dompdf = $this->getDompdf();
         $sheet = new Stylesheet($dompdf);
         $style = new Style($sheet);
 
@@ -287,7 +287,7 @@ class StyleTest extends TestCase
      */
     public function testValueCase(string $cssProp, string $inputValue, string $phpProp, string $expectValue): void
     {
-        $dompdf = new Dompdf();
+        $dompdf = $this->getDompdf();
         $sheet = new Stylesheet($dompdf);
         $style = new Style($sheet);
 
@@ -297,7 +297,7 @@ class StyleTest extends TestCase
 
     public function testWordBreakBreakWord(): void
     {
-        $dompdf = new Dompdf();
+        $dompdf = $this->getDompdf();
         $sheet = new Stylesheet($dompdf);
         $style = new Style($sheet);
 
diff --git a/tests/DompdfTest.php b/tests/DompdfTest.php
index 08a31ed..8e58c10 100644
--- a/tests/DompdfTest.php
+++ b/tests/DompdfTest.php
@@ -16,7 +16,7 @@ class DompdfTest extends TestCase
 {
     public function testConstructor()
     {
-        $dompdf = new Dompdf();
+        $dompdf = $this->getDompdf();
         $this->assertInstanceOf(CPDF::class, $dompdf->getCanvas());
         $this->assertSame("", $dompdf->getProtocol());
         $this->assertSame("", $dompdf->getBaseHost());
@@ -31,7 +31,7 @@ class DompdfTest extends TestCase
 
     public function testSetters()
     {
-        $dompdf = new Dompdf();
+        $dompdf = $this->getDompdf();
         $dompdf->setBaseHost('test1');
         $dompdf->setBasePath('test2');
         $dompdf->setCallbacks(['test' => ['event' => 'test', 'f' => function () {}]]);
@@ -52,14 +52,14 @@ class DompdfTest extends TestCase
         $this->assertEquals('test3', $dompdf->getProtocol());
         $this->assertInstanceOf(FrameTree::class, $dompdf->getTree());
 
-        $dompdf = new Dompdf();
+        $dompdf = $this->getDompdf();
         $dompdf->setHttpContext(['ssl' => ['verify_peer' => false]]);
         $this->assertIsResource($dompdf->getHttpContext());
     }
 
     public function testLoadHtml()
     {
-        $dompdf = new Dompdf();
+        $dompdf = $this->getDompdf();
         $dompdf->loadHtml('<html><body><strong>Hello</strong></body></html>');
         $this->assertEquals('Hello', $dompdf->getDom()->textContent);
 
@@ -70,7 +70,7 @@ class DompdfTest extends TestCase
 
     public function testRender()
     {
-        $dompdf = new Dompdf();
+        $dompdf = $this->getDompdf();
         $dompdf->loadHtml('<html><body><strong>Hello</strong></body></html>');
         $dompdf->render();
 
@@ -95,7 +95,7 @@ class DompdfTest extends TestCase
     {
         $called = 0;
 
-        $dompdf = new Dompdf();
+        $dompdf = $this->getDompdf();
         $dompdf->setCallbacks([
             [
                 "event" => $event,
@@ -118,7 +118,7 @@ class DompdfTest extends TestCase
     {
         $called = 0;
 
-        $dompdf = new Dompdf();
+        $dompdf = $this->getDompdf();
         $dompdf->setCallbacks([
             [
                 "event" => "end_document",
@@ -163,7 +163,7 @@ class DompdfTest extends TestCase
         $options = new Options();
         $options->setDefaultPaperSize("Letter");
 
-        $dompdf = new Dompdf($options);
+        $dompdf = $this->getDompdf($options);
 
         if ($setPaper) {
             $dompdf->setPaper($size, $orientation);
@@ -182,7 +182,7 @@ class DompdfTest extends TestCase
     {
         $text_frame_contents = [];
 
-        $dompdf = new Dompdf();
+        $dompdf = $this->getDompdf();
 
         // Use a callback to inspect the frame tree; otherwise FrameReflower\Page::reflow()
         // will dispose of it before dompdf->render finishes
diff --git a/tests/FrameReflower/ImageTest.php b/tests/FrameReflower/ImageTest.php
index 2603f5d..cfcf8a5 100644
--- a/tests/FrameReflower/ImageTest.php
+++ b/tests/FrameReflower/ImageTest.php
@@ -128,7 +128,7 @@ class ImageTest extends TestCase
         ImageFrameDecorator $parentFrame = null,
         array $containingBlock = [0, 0, 400, 400]
     ): ImageFrameDecorator {
-        $style = new Style(new Stylesheet(new Dompdf()));
+        $style = new Style(new Stylesheet($this->getDompdf()));
 
         foreach ($styleProperties as $prop => $val) {
             $style->set_prop($prop, $val);
diff --git a/tests/Helpers/MockHelper.php b/tests/Helpers/MockHelper.php
index c3fddf5..cba82af 100644
--- a/tests/Helpers/MockHelper.php
+++ b/tests/Helpers/MockHelper.php
@@ -17,9 +17,9 @@ class MockHelper
         // initialize static properties
         // For now we cannot mock methods in a constructor
         // https://github.com/mockery/mockery/issues/534
-        // $style = \Mockery::mock(Style::class, [new Stylesheet(new Dompdf())]);
+        // $style = \Mockery::mock(Style::class, [new Stylesheet($this->getDompdf())]);
 
-        new Style(new Stylesheet(new Dompdf()));
+        new Style(new Stylesheet($this->getDompdf()));
         $style = \Mockery::mock(Style::class);
 
         foreach ($properties as $property => $value) {
diff --git a/tests/LayoutTest/ImageTest.php b/tests/LayoutTest/ImageTest.php
index 7d9353a..99de948 100644
--- a/tests/LayoutTest/ImageTest.php
+++ b/tests/LayoutTest/ImageTest.php
@@ -182,7 +182,9 @@ HTML
         $options = new Options();
 
         // Use callback to inspect frame tree
-        $dompdf = new Dompdf($options);
+        $dompdf = $this->getDompdf($options);
+        $rootDir = realpath(__DIR__ . '/../../');
+        $options->setChroot([$rootDir, '/usr/share/php/dompdf']);
         $dompdf->setBasePath(__DIR__);
         $dompdf->setCallbacks([
             [
diff --git a/tests/LayoutTest/PageTest.php b/tests/LayoutTest/PageTest.php
index f8925d0..838db0b 100644
--- a/tests/LayoutTest/PageTest.php
+++ b/tests/LayoutTest/PageTest.php
@@ -92,7 +92,7 @@ HTML
         $options = new Options();
 
         // Use callback to inspect frame tree
-        $dompdf = new Dompdf($options);
+        $dompdf = $this->getDompdf($options);
         $dompdf->setCallbacks([
             [
                 "event" => "begin_frame",
diff --git a/tests/OptionsTest.php b/tests/OptionsTest.php
index 7eae50a..a237374 100644
--- a/tests/OptionsTest.php
+++ b/tests/OptionsTest.php
@@ -8,12 +8,21 @@ class OptionsTest extends TestCase
 {
     public function testConstructor()
     {
-        $root = realpath(dirname(__DIR__));
-        $option = new Options();
-        $this->assertEquals(sys_get_temp_dir(), $option->getTempDir());
-        $this->assertEquals($root . '/lib/fonts', $option->getFontDir());
-        $this->assertEquals($root . '/lib/fonts', $option->getFontCache());
-        $this->assertEquals([$root], $option->getChroot());
+        $option = $this->getOptions();
+        if (is_dir('/usr/share/php/dompdf/lib/fonts')) {
+            $root = '/usr/share/php/dompdf';
+            $this->assertEquals('/var/cache/php-dompdf/tmp', $option->getTempDir());
+            $this->assertEquals($root . '/lib/fonts', $option->getFontDir());
+            $this->assertEquals('/var/cache/php-dompdf/fonts/', $option->getFontCache());
+            $this->assertEquals([$root], $option->getChroot());
+        }
+        if (! is_dir('/usr/share/php/dompdf/lib/fonts')) {
+            $root = realpath(dirname(__DIR__));
+            $this->assertEquals(sys_get_temp_dir(), $option->getTempDir());
+            $this->assertEquals($root . '/lib/fonts', $option->getFontDir());
+            $this->assertEquals($root . '/lib/fonts', $option->getFontCache());
+            $this->assertEquals([$root], $option->getChroot());
+        }
         $this->assertEmpty($option->getLogOutputFile());
         $this->assertEquals('screen', $option->getDefaultMediaType());
         $this->assertEquals('letter', $option->getDefaultPaperSize());
diff --git a/tests/Renderer/RendererTest.php b/tests/Renderer/RendererTest.php
index d2abf78..06b1dcd 100644
--- a/tests/Renderer/RendererTest.php
+++ b/tests/Renderer/RendererTest.php
@@ -16,7 +16,7 @@ class RendererTest extends TestCase
 
     public function setUp() : void
     {
-        $dompdf = new Dompdf();
+        $dompdf = $this->getDompdf();
         $this->renderer = new Renderer($dompdf);
         $this->resizeBackgroundImageMethod = self::getMethod('_resize_background_image');
     }
diff --git a/tests/TestCase.php b/tests/TestCase.php
index b9ad809..c160bba 100644
--- a/tests/TestCase.php
+++ b/tests/TestCase.php
@@ -3,9 +3,38 @@ namespace Dompdf\Tests;
 
 use PHPUnit\Framework\TestCase as BaseTestCase;
 use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
+use Dompdf\Dompdf;
+use Dompdf\Options;
 
 class TestCase extends BaseTestCase
 {
     use MockeryPHPUnitIntegration;
 
+    protected function getDompdf(Options $options = null): Dompdf
+    {
+        if (is_dir('/usr/share/php/dompdf/lib/fonts')) {
+            return new Dompdf($options);
+        }
+
+        return new Dompdf($this->getOptions($options));
+    }
+
+    protected function getOptions(Options $options = null): Options
+    {
+        $options = $options === null ? new Options() : $options;
+
+        if (is_dir('/usr/share/php/dompdf/lib/fonts')) {
+            return $options;
+        }
+
+        $rootDir = realpath(__DIR__ . '/../');
+        $options = $options
+            ->setChroot(array($rootDir))
+            ->setRootDir($rootDir)
+            ->setTempDir(sys_get_temp_dir())
+            ->setFontDir($rootDir . '/lib/fonts')
+            ->setFontCache($rootDir . '/lib/fonts');
+
+        return $options;
+    }
 }