KnownNotWorkingSparqlQueriesTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 149
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
c 1
b 0
f 0
dl 0
loc 149
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testSelectAlias() 0 9 1
A testSelectSubSelect() 0 15 1
A setUp() 0 5 1
A testSelectSameTerm() 0 5 1
A testSelectFilterLangMatchesWithStar() 0 26 1
1
<?php
2
3
/**
4
 * This file is part of the sweetrdf/InMemoryStoreSqlite package and licensed under
5
 * the terms of the GPL-2 license.
6
 *
7
 * (c) Konrad Abicht <[email protected]>
8
 * (c) Benjamin Nowack
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Tests\Integration\Store\InMemoryStoreSqlite\Query;
15
16
use Exception;
17
use sweetrdf\InMemoryStoreSqlite\Store\InMemoryStoreSqlite;
18
use Tests\TestCase;
19
20
/**
21
 * Tests for query method - focus on queries which are known to fail.
22
 */
23
class KnownNotWorkingSparqlQueriesTest extends TestCase
24
{
25
    protected function setUp(): void
26
    {
27
        parent::setUp();
28
29
        $this->subjectUnderTest = InMemoryStoreSqlite::createInstance();
30
    }
31
32
    /**
33
     * Variable alias not working.
34
     */
35
    public function testSelectAlias()
36
    {
37
        // test data
38
        $this->subjectUnderTest->query('INSERT INTO <http://example.com/> {
39
            <http://s> <http://p1> "baz" .
40
        }');
41
42
        $this->expectException(Exception::class);
43
        $this->subjectUnderTest->query('
44
            SELECT (?s AS ?s_alias) ?o FROM <http://example.com/> WHERE {?s <http://p1> ?o.}
45
        ');
46
    }
47
48
    /**
49
     * FILTER: langMatches with *.
50
     *
51
     * Based on the specification (https://www.w3.org/TR/rdf-sparql-query/#func-langMatches)
52
     * langMatches with * has to return all entries with no language set.
53
     */
54
    public function testSelectFilterLangMatchesWithStar()
55
    {
56
        // test data
57
        $this->subjectUnderTest->query('INSERT INTO <http://example.com/> {
58
            <http://s> <http://p1> "foo" .
59
            <http://s> <http://p1> "in de"@de .
60
            <http://s> <http://p1> "in en"@en .
61
        }');
62
63
        $res = $this->subjectUnderTest->query('
64
            SELECT ?s ?o WHERE {
65
                ?s <http://p1> ?o .
66
                FILTER langMatches (lang(?o), "*")
67
            }
68
        ');
69
        $this->assertEquals(
70
            [
71
                'query_type' => 'select',
72
                'result' => [
73
                    'variables' => [
74
                        's', 'o',
75
                    ],
76
                    'rows' => [],
77
                ],
78
            ],
79
            $res
80
        );
81
    }
82
83
    /**
84
     * sameTerm.
85
     */
86
    public function testSelectSameTerm()
87
    {
88
        $this->markTestSkipped(
89
            'Solving sameterm does not work properly. The result contains elements multiple times. '
90
            .\PHP_EOL.'Expected behavior is described here: https://www.w3.org/TR/rdf-sparql-query/#func-sameTerm'
91
        );
92
93
        /*
94
95
        demo code:
96
97
        // test data
98
        $this->subjectUnderTest->query('INSERT INTO <http://example.com/> {
99
            <http://container1> <http://weight> "100" .
100
            <http://container2> <http://weight> "100" .
101
        }');
102
103
        $res = $this->subjectUnderTest->query('SELECT ?c1 ?c2 WHERE {
104
            ?c1 ?weight ?w1.
105
106
            ?c2 ?weight ?w2.
107
108
            FILTER (sameTerm(?w1, ?w2))
109
        }');
110
        $this->assertEquals(
111
            [
112
                'query_type' => 'select',
113
                'result' => [
114
                    'variables' => [
115
                        'c1', 'c2',
116
                    ],
117
                    'rows' => [
118
                        [
119
                            'c1' => 'http://container1',
120
                            'c1 type' => 'uri',
121
                            'c2' => 'http://container1',
122
                            'c2 type' => 'uri',
123
                        ],
124
                        [
125
                            'c1' => 'http://container2',
126
                            'c1 type' => 'uri',
127
                            'c2' => 'http://container1',
128
                            'c2 type' => 'uri',
129
                        ],
130
                        [
131
                            'c1' => 'http://container1',
132
                            'c1 type' => 'uri',
133
                            'c2' => 'http://container2',
134
                            'c2 type' => 'uri',
135
                        ],
136
                        [
137
                            'c1' => 'http://container2',
138
                            'c1 type' => 'uri',
139
                            'c2' => 'http://container2',
140
                            'c2 type' => 'uri',
141
                        ],
142
                    ],
143
                ],
144
            ],
145
            $res,
146
            '',
147
            0,
148
            10,
149
            true
150
        );
151
        */
152
    }
153
154
    /**
155
     * Sub Select.
156
     */
157
    public function testSelectSubSelect()
158
    {
159
        // test data
160
        $this->subjectUnderTest->query('INSERT INTO <http://example.com/> {
161
            <http://person1> <http://id> "1" .
162
            <http://person3> <http://id> "3" .
163
            <http://person2> <http://id> "2" .
164
165
            <http://person1> <http://knows> <http://person2> .
166
            <http://person2> <http://knows> <http://person3> .
167
            <http://person3> <http://knows> <http://person2> .
168
        }');
169
170
        $this->expectException(Exception::class);
171
        $this->subjectUnderTest->query('
172
            SELECT * WHERE {
173
                {
174
                    SELECT ?p WHERE {
175
                        ?p <http://id> "1" .
176
                    }
177
                }
178
                ?p <http://knows> ?who .
179
            }
180
        ');
181
    }
182
}
183