File: FileGetContentsLoaderTest.php

package info (click to toggle)
php-ml-json-ld 1.2.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 628 kB
  • sloc: php: 4,521; makefile: 21
file content (99 lines) | stat: -rw-r--r-- 2,817 bytes parent folder | download | duplicates (2)
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
<?php

/*
 * (c) Markus Lanthaler <mail@markus-lanthaler.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace ML\JsonLD\Test;

use ML\IRI\IRI;
use ML\JsonLD\FileGetContentsLoader;

/**
 * Test the parsing of a JSON-LD document into a Document.
 */
class FileGetContentsLoaderTest extends \PHPUnit\Framework\TestCase
{

    protected $iri;

    protected $loader;

    public function setUp(): void
    {
        parent::setUp();

        $this->iri = new IRI('https://www.example.com');
        $this->loader = new FileGetContentsLoader;
    }

    public function tearDown(): void
    {
        unset($iri);
        unset($this->loader);

        parent::tearDown();
    }

    public function testParseLinkHeadersExactsValues()
    {
        $headers = array(
            '<https://www.example.com>; param1=foo; param2="bar";',
        );

        $parsed = $this->loader->parseLinkHeaders($headers, $this->iri);

        $this->assertEquals('https://www.example.com', $parsed[0]['uri']);
        $this->assertEquals('foo', $parsed[0]['param1']);
        $this->assertEquals('bar', $parsed[0]['param2']);
    }

    public function testParseLinkHeadersTrimsValues()
    {
        $headers = array(
            '< https://www.example.com  >; param1= foo ; param2=" bar ";',
        );

        $parsed = $this->loader->parseLinkHeaders($headers, $this->iri);

        $this->assertEquals('https://www.example.com', $parsed[0]['uri']);
        $this->assertEquals('foo', $parsed[0]['param1']);
        $this->assertEquals('bar', $parsed[0]['param2']);
    }

    public function testParseLinkHeadersWithMultipleHeaders()
    {
        $headers = array(
            '<https://www.example.com>; param1=foo; param2=bar;',
            '<https://www.example.org>; param1=fizz; param2=buzz;',
        );

        $parsed = $this->loader->parseLinkHeaders($headers, $this->iri);

        $this->assertCount(2, $parsed);
    }

    public function testParseLinkHeadersWithMultipleLinks()
    {
        $headers = array(
            '<https://www.example.com>; param1=foo; param2=bar;, '
                . '<https://www.example.org>; param1=fizz; param2=buzz;'
        );

        $parsed = $this->loader->parseLinkHeaders($headers, $this->iri);

        $this->assertCount(2, $parsed);
        $this->assertEquals('https://www.example.com', $parsed[0]['uri']);
        $this->assertEquals('https://www.example.org', $parsed[1]['uri']);
    }

    public function testParseLinkHeadersConvertsRelativeLinksToAbsolute()
    {
        $headers = array('</foo/bar>;');
        $parsed = $this->loader->parseLinkHeaders($headers, $this->iri);
        $this->assertEquals('https://www.example.com/foo/bar', $parsed[0]['uri']);
    }
}