File: NQuadsTest.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 (102 lines) | stat: -rw-r--r-- 3,008 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
100
101
102
<?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\JsonLD\JsonLD;
use ML\JsonLD\NQuads;

/**
 * Tests NQuads
 *
 * @author Markus Lanthaler <mail@markus-lanthaler.com>
 */
class NQuadsTest extends \PHPUnit\Framework\TestCase
{
    /**
     * Tests that parsing an invalid NQuad file fails
     */
    public function testInvalidParse()
    {
        $this->expectException('\ML\JsonLD\Exception\InvalidQuadException');
        $nquads = new NQuads();
        $nquads->parse('Invalid NQuads file');
    }

    /**
     * Tests escaping
     */
    public function testEscaping()
    {
        $doc = '<http://example.com>';
        $doc .= ' <http://schema.org/description>';
        $doc .= ' "String with line-break \n and quote (\")" .';
        $doc .= "\n";

        $nquads = new NQuads();
        $parsed = JsonLD::fromRdf($nquads->parse($doc));
        $serialized = $nquads->serialize(JsonLD::toRdf($parsed));

        $this->assertSame($doc, $serialized);
    }

    /**
     * Tests blank node label parsing
     */
    public function testParseBlankNodes()
    {
        $nquads = new NQuads();

        $this->assertNotEmpty($nquads->parse('_:b <http://ex/1> "Test" .'), 'just a letter');

        $this->assertNotEmpty($nquads->parse('_:b1 <http://ex/1> "Test" .'), 'letter and number');

        $this->assertNotEmpty($nquads->parse('_:_b1 <http://ex/1> "Test" .'), 'beginning _');

        $this->assertNotEmpty($nquads->parse('_:b_1 <http://ex/1> "Test" .'), 'containing _');

        $this->assertNotEmpty($nquads->parse('_:b1_ <http://ex/1> "Test" .'), 'ending _');

        $this->assertNotEmpty($nquads->parse('_:b-1 <http://ex/1> "Test" .'), 'containing -');

        $this->assertNotEmpty($nquads->parse('_:b-1 <http://ex/1> "Test" .'), 'ending -');

        $this->assertNotEmpty($nquads->parse('_:b.1 <http://ex/1> "Test" .'), 'containing .');
    }

    /**
     * Tests that parsing fails for blank node labels beginning with "-"
     */
    public function testParseBlankNodeDashAtTheBeginning()
    {
	$this->expectException('\ML\JsonLD\Exception\InvalidQuadException');
        $nquads = new NQuads();
        $nquads->parse('_:-b1 <http://ex/1> "Test" .');
    }

    /**
     * Tests that parsing fails for blank node labels beginning with "."
     */
    public function testParseBlankNodePeriodAtTheBeginning()
    {
	$this->expectException('\ML\JsonLD\Exception\InvalidQuadException');
        $nquads = new NQuads();
        $nquads->parse('_:.b1 <http://ex/1> "Test" .');
    }

    /**
     * Tests that parsing fails for blank node labels ending with "."
     */
    public function testParseBlankNodePeriodAtTheEnd()
    {
	$this->expectException('\ML\JsonLD\Exception\InvalidQuadException');
        $nquads = new NQuads();
        $nquads->parse('_:b1. <http://ex/1> "Test" .');
    }
}