File: CacheTest.php

package info (click to toggle)
php-dompdf 3.0.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 5,548 kB
  • sloc: php: 26,160; sh: 109; xml: 100; makefile: 42
file content (37 lines) | stat: -rw-r--r-- 1,237 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
<?php
namespace Dompdf\Tests\Image;

use Dompdf\Helpers;
use Dompdf\Image;
use Dompdf\Options;
use Dompdf\Tests\TestCase;

class CacheTest extends TestCase
{
    public static function imageUrlProvider(): array
    {
        return [
            ["../_files/jamaica.jpg", "file://" . realpath(__DIR__ . "/../_files/jamaica.jpg")],
            ["data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20100%20100%22%3E%3Cimage%20x%3D%2250%22%20y%3D%22150%22%20width%3D%22100%22%20height%3D%22100%22%20xlink%3Ahref%3D%22https%3A%2F%2Fexample.com%2Fimage.gif%22%2F%3E%3C%2Fsvg%3E", Image\Cache::$broken_image],
        ];
    }

    /**
     * @dataProvider imageUrlProvider
     */
    #[\PHPUnit\Framework\Attributes\DataProvider('imageUrlProvider')]
    public function testUrlResolution(string $url, string $expected): void
    {
        $protocol = "";
        $host = "";
        $base_path = __DIR__;
        $options = new Options([
            "chroot" => [
                __DIR__ . "/../_files"
            ]
        ]);

        $cache = Image\Cache::resolve_url($url, $protocol, $host, $base_path, $options);
        $this->assertEquals($expected, $cache[0]);
    }
}