Passed
Push — master ( 67a964...2aff1a )
by Konrad
04:08
created

InsertIntoQueryTest   A

Complexity

Total Complexity 23

Size/Duplication

Total Lines 631
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 1
Metric Value
eloc 303
dl 0
loc 631
rs 10
c 4
b 0
f 1
wmc 23

22 Methods

Rating   Name   Duplication   Size   Complexity  
A testInsertIntoDate() 0 45 1
A testInsertIntoWhere() 0 21 1
A testInsertIntoListMoreComplex() 0 69 1
A testInsertInto2GraphsSameTriples() 0 34 1
A testInsertIntoObjectWithDatatype() 0 21 1
A testInsertIntoBlankNode2() 0 35 1
A testInsertInto() 0 9 1
A testMultipleInsertQueriesInDifferentGraphs() 0 14 1
A testInsertIntoBlankNode1() 0 20 1
A testInsertIntoConstruct() 0 10 1
A testInsertIntoPrefixedUri() 0 22 1
A testInsertIntoNumbers() 0 40 1
A testMultipleInsertsSameStore() 0 42 1
A setUp() 0 5 1
A testInsertIntoBlankNode3() 0 43 1
A testInsertIntoUriTriple() 0 18 1
A testInsertIntoLongValue() 0 12 1
A testInsertIntoShortenedUri() 0 18 1
A testInsertIntoList() 0 40 1
A testInsertIntoObjectWithLanguage() 0 21 1
A testValueEscape() 0 7 1
A testAdditionOfManyTriples() 0 15 2
1
<?php
2
3
/*
4
 * This file is part of the sweetrdf/InMemoryStoreSqlite package and licensed under
5
 * the terms of the GPL-3 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\NamespaceHelper;
18
use sweetrdf\InMemoryStoreSqlite\Store\InMemoryStoreSqlite;
19
use Tests\TestCase;
20
21
/**
22
 * Tests for query method - focus on INSERT INTO queries.
23
 */
24
class InsertIntoQueryTest extends TestCase
25
{
26
    protected function setUp(): void
27
    {
28
        parent::setUp();
29
30
        $this->subjectUnderTest = InMemoryStoreSqlite::createInstance();
31
    }
32
33
    public function testInsertInto()
34
    {
35
        // test data
36
        $this->subjectUnderTest->query('INSERT INTO <http://ex/> {
37
            <http://s> <http://p1> "baz" .
38
        }');
39
40
        $res = $this->subjectUnderTest->query('SELECT * FROM <http://ex/> {?s ?p ?o.}');
41
        $this->assertEquals(1, \count($res['result']['rows']));
42
    }
43
44
    public function testInsertIntoUriTriple()
45
    {
46
        // test data
47
        $this->subjectUnderTest->query('INSERT INTO <http://ex> { <http://s> <http://p> <http://o> .}');
48
49
        $res = $this->subjectUnderTest->query('SELECT * FROM <http://ex> {?s ?p ?o.}');
50
        $this->assertEquals(
51
            [
52
                [
53
                    's' => 'http://s',
54
                    's type' => 'uri',
55
                    'p' => 'http://p',
56
                    'p type' => 'uri',
57
                    'o' => 'http://o',
58
                    'o type' => 'uri',
59
                ],
60
            ],
61
            $res['result']['rows']
62
        );
63
    }
64
65
    public function testInsertIntoShortenedUri()
66
    {
67
        // test data
68
        $this->subjectUnderTest->query('INSERT INTO <http://ex> { <#make> <#me> <#happy> .}');
69
70
        $res = $this->subjectUnderTest->query('SELECT * FROM <http://ex> {?s ?p ?o.}');
71
        $this->assertEquals(
72
            [
73
                [
74
                    's' => NamespaceHelper::BASE_NAMESPACE.'#make',
75
                    's type' => 'uri',
76
                    'p' => NamespaceHelper::BASE_NAMESPACE.'#me',
77
                    'p type' => 'uri',
78
                    'o' => NamespaceHelper::BASE_NAMESPACE.'#happy',
79
                    'o type' => 'uri',
80
                ],
81
            ],
82
            $res['result']['rows']
83
        );
84
    }
85
86
    public function testInsertIntoPrefixedUri()
87
    {
88
        // test data
89
        $query = '
90
            PREFIX ex: <http://ex/>
91
            INSERT INTO <http://ex> { <http://s> rdf:type ex:Person .}
92
        ';
93
        $this->subjectUnderTest->query($query);
94
95
        $res = $this->subjectUnderTest->query('SELECT * FROM <http://ex> {?s ?p ?o.}');
96
        $this->assertEquals(
97
            [
98
                [
99
                    's' => 'http://s',
100
                    's type' => 'uri',
101
                    'p' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type',
102
                    'p type' => 'uri',
103
                    'o' => 'http://ex/Person',
104
                    'o type' => 'uri',
105
                ],
106
            ],
107
            $res['result']['rows']
108
        );
109
    }
110
111
    public function testInsertIntoNumbers()
112
    {
113
        // test data
114
        $this->subjectUnderTest->query('INSERT INTO <http://ex> {
115
            <http://s> <http://foo> 1 .
116
            <http://s> <http://foo> 2.0 .
117
            <http://s> <http://foo> "3" .
118
        }');
119
120
        $res = $this->subjectUnderTest->query('SELECT * FROM <http://ex> {?s ?p ?o.}');
121
        $this->assertEquals(
122
            [
123
                [
124
                    's' => 'http://s',
125
                    's type' => 'uri',
126
                    'p' => 'http://foo',
127
                    'p type' => 'uri',
128
                    'o' => '1',
129
                    'o type' => 'literal',
130
                    'o datatype' => 'http://www.w3.org/2001/XMLSchema#integer',
131
                ],
132
                [
133
                    's' => 'http://s',
134
                    's type' => 'uri',
135
                    'p' => 'http://foo',
136
                    'p type' => 'uri',
137
                    'o' => '2.0',
138
                    'o type' => 'literal',
139
                    'o datatype' => 'http://www.w3.org/2001/XMLSchema#decimal',
140
                ],
141
                [
142
                    's' => 'http://s',
143
                    's type' => 'uri',
144
                    'p' => 'http://foo',
145
                    'p type' => 'uri',
146
                    'o' => '3',
147
                    'o type' => 'literal',
148
                ],
149
            ],
150
            $res['result']['rows']
151
        );
152
    }
153
154
    public function testInsertIntoObjectWithDatatype()
155
    {
156
        // test data
157
        $this->subjectUnderTest->query('INSERT INTO <http://ex> {
158
            <http://s> <http://foo> "4"^^xsd:integer .
159
        }');
160
161
        $res = $this->subjectUnderTest->query('SELECT * FROM <http://ex> {?s ?p ?o.}');
162
        $this->assertEquals(
163
            [
164
                [
165
                    's' => 'http://s',
166
                    's type' => 'uri',
167
                    'p' => 'http://foo',
168
                    'p type' => 'uri',
169
                    'o' => '4',
170
                    'o type' => 'literal',
171
                    'o datatype' => 'http://www.w3.org/2001/XMLSchema#integer',
172
                ],
173
            ],
174
            $res['result']['rows']
175
        );
176
    }
177
178
    public function testInsertIntoObjectWithLanguage()
179
    {
180
        // test data
181
        $this->subjectUnderTest->query('INSERT INTO <http://ex> {
182
            <http://s> <http://foo> "5"@en .
183
        }');
184
185
        $res = $this->subjectUnderTest->query('SELECT * FROM <http://ex> {?s ?p ?o.}');
186
        $this->assertEquals(
187
            [
188
                [
189
                    's' => 'http://s',
190
                    's type' => 'uri',
191
                    'p' => 'http://foo',
192
                    'p type' => 'uri',
193
                    'o' => '5',
194
                    'o type' => 'literal',
195
                    'o lang' => 'en',
196
                ],
197
            ],
198
            $res['result']['rows']
199
        );
200
    }
201
202
    public function testInsertIntoBlankNode1()
203
    {
204
        // test data
205
        $this->subjectUnderTest->query('INSERT INTO <http://ex> {
206
            _:foo <http://foo> "6" .
207
        }');
208
209
        $res = $this->subjectUnderTest->query('SELECT * FROM <http://ex> {?s ?p ?o.}');
210
        $this->assertEquals(
211
            [
212
                [
213
                    's' => $res['result']['rows'][0]['s'], // blank node ID is dynamic
214
                    's type' => 'bnode',
215
                    'p' => 'http://foo',
216
                    'p type' => 'uri',
217
                    'o' => '6',
218
                    'o type' => 'literal',
219
                ],
220
            ],
221
            $res['result']['rows']
222
        );
223
    }
224
225
    public function testInsertIntoBlankNode2()
226
    {
227
        // test data
228
        $this->subjectUnderTest->query('INSERT INTO <http://ex/> {
229
            <http://s> <http://p1> [
230
                <http://foo> <http://bar>
231
            ] .
232
        }');
233
234
        $res = $this->subjectUnderTest->query('SELECT * FROM <http://ex/> {?s ?p ?o.}');
235
236
        // because bnode ID is random, we check only its structure
237
        $this->assertTrue(isset($res['result']['rows'][0]));
238
        $this->assertEquals(1, preg_match('/_:[a-z0-9]+_[a-z0-9]+/', $res['result']['rows'][0]['o']));
239
240
        $this->assertEquals(
241
            [
242
                [
243
                    's' => 'http://s',
244
                    's type' => 'uri',
245
                    'p' => 'http://p1',
246
                    'p type' => 'uri',
247
                    'o' => $res['result']['rows'][0]['o'],
248
                    'o type' => 'bnode',
249
                ],
250
                [
251
                    's' => $res['result']['rows'][0]['o'],
252
                    's type' => 'bnode',
253
                    'p' => 'http://foo',
254
                    'p type' => 'uri',
255
                    'o' => 'http://bar',
256
                    'o type' => 'uri',
257
                ],
258
            ],
259
            $res['result']['rows']
260
        );
261
    }
262
263
    public function testInsertIntoBlankNode3()
264
    {
265
        // test data
266
        $this->subjectUnderTest->query('
267
            PREFIX ex: <http://ex/>
268
            INSERT INTO <http://ex/> {
269
                ex:3 ex:action [
270
                    ex:query  <agg-avg-01.rq> ;
271
                    ex:data   <agg-numeric.ttl>
272
                ] .
273
            }
274
        ');
275
276
        $res = $this->subjectUnderTest->query('SELECT * FROM <http://ex/> {?s ?p ?o.}');
277
278
        $this->assertEquals(
279
            [
280
                [
281
                    's' => 'http://ex/3',
282
                    's type' => 'uri',
283
                    'p' => 'http://ex/action',
284
                    'p type' => 'uri',
285
                    'o' => $res['result']['rows'][0]['o'],
286
                    'o type' => 'bnode',
287
                ],
288
                [
289
                    's' => $res['result']['rows'][0]['o'],
290
                    's type' => 'bnode',
291
                    'p' => 'http://ex/query',
292
                    'p type' => 'uri',
293
                    'o' => NamespaceHelper::BASE_NAMESPACE.'agg-avg-01.rq',
294
                    'o type' => 'uri',
295
                ],
296
                [
297
                    's' => $res['result']['rows'][0]['o'],
298
                    's type' => 'bnode',
299
                    'p' => 'http://ex/data',
300
                    'p type' => 'uri',
301
                    'o' => NamespaceHelper::BASE_NAMESPACE.'agg-numeric.ttl',
302
                    'o type' => 'uri',
303
                ],
304
            ],
305
            $res['result']['rows']
306
        );
307
    }
308
309
    public function testInsertIntoDate()
310
    {
311
        // test data
312
        $this->subjectUnderTest->query('INSERT INTO <http://ex/> {
313
            <http://s> <http://p1> "2009-05-28T18:03:38+09:00" .
314
            <http://s> <http://p1> "2009-05-28T18:03:38+09:00GMT" .
315
            <http://s> <http://p1> "21 August 2007" .
316
        }');
317
318
        $res = $this->subjectUnderTest->query('SELECT * FROM <http://ex/> {?s ?p ?o.}');
319
320
        $this->assertEquals(
321
            [
322
                'query_type' => 'select',
323
                'result' => [
324
                    'variables' => ['s', 'p', 'o'],
325
                    'rows' => [
326
                        [
327
                            's' => 'http://s',
328
                            's type' => 'uri',
329
                            'p' => 'http://p1',
330
                            'p type' => 'uri',
331
                            'o' => '2009-05-28T18:03:38+09:00',
332
                            'o type' => 'literal',
333
                        ],
334
                        [
335
                            's' => 'http://s',
336
                            's type' => 'uri',
337
                            'p' => 'http://p1',
338
                            'p type' => 'uri',
339
                            'o' => '2009-05-28T18:03:38+09:00GMT',
340
                            'o type' => 'literal',
341
                        ],
342
                        [
343
                            's' => 'http://s',
344
                            's type' => 'uri',
345
                            'p' => 'http://p1',
346
                            'p type' => 'uri',
347
                            'o' => '21 August 2007',
348
                            'o type' => 'literal',
349
                        ],
350
                    ],
351
                ],
352
            ],
353
            $res
354
        );
355
    }
356
357
    public function testInsertIntoList()
358
    {
359
        // test data
360
        $this->subjectUnderTest->query('INSERT INTO <http://ex/> {
361
            <http://s> <http://p1> 1, 2, 3 .
362
        }');
363
364
        $res = $this->subjectUnderTest->query('SELECT * FROM <http://ex/> {?s ?p ?o.}');
365
366
        $this->assertEquals(
367
            [
368
                [
369
                    's' => 'http://s',
370
                    's type' => 'uri',
371
                    'p' => 'http://p1',
372
                    'p type' => 'uri',
373
                    'o' => '1',
374
                    'o type' => 'literal',
375
                    'o datatype' => 'http://www.w3.org/2001/XMLSchema#integer',
376
                ],
377
                [
378
                    's' => 'http://s',
379
                    's type' => 'uri',
380
                    'p' => 'http://p1',
381
                    'p type' => 'uri',
382
                    'o' => '2',
383
                    'o type' => 'literal',
384
                    'o datatype' => 'http://www.w3.org/2001/XMLSchema#integer',
385
                ],
386
                [
387
                    's' => 'http://s',
388
                    's type' => 'uri',
389
                    'p' => 'http://p1',
390
                    'p type' => 'uri',
391
                    'o' => '3',
392
                    'o type' => 'literal',
393
                    'o datatype' => 'http://www.w3.org/2001/XMLSchema#integer',
394
                ],
395
            ],
396
            $res['result']['rows']
397
        );
398
    }
399
400
    /**
401
     * Demonstrates that store can't save long values.
402
     */
403
    public function testInsertIntoLongValue()
404
    {
405
        // create long URI (ca. 250 chars)
406
        $longURI = 'http://'.hash('sha512', 'long')
407
            .hash('sha512', 'URI');
408
409
        $this->expectException(Exception::class);
410
411
        // test data
412
        $this->subjectUnderTest->query('INSERT INTO <http://graph> {
413
            <'.$longURI.'/s> <'.$longURI.'/p> <'.$longURI.'/o> ;
414
                             <'.$longURI.'/p2> <'.$longURI.'/o2> .
415
        ');
416
    }
417
418
    public function testInsertIntoListMoreComplex()
419
    {
420
        // test data
421
        $this->subjectUnderTest->query('INSERT INTO <http://ex/> {
422
            _:b0  rdf:first  1 ;
423
                  rdf:rest   _:b1 .
424
            _:b1  rdf:first  2 ;
425
                  rdf:rest   _:b2 .
426
            _:b2  rdf:first  3 ;
427
                  rdf:rest   rdf:nil .
428
        }');
429
430
        $res = $this->subjectUnderTest->query('SELECT * FROM <http://ex/> {?s ?p ?o.}');
431
432
        $this->assertEquals(
433
            [
434
                [
435
                    's' => $res['result']['rows'][0]['s'],
436
                    's type' => 'bnode',
437
                    'p' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#first',
438
                    'p type' => 'uri',
439
                    'o' => '1',
440
                    'o type' => 'literal',
441
                    'o datatype' => 'http://www.w3.org/2001/XMLSchema#integer',
442
                ],
443
                [
444
                    's' => $res['result']['rows'][1]['s'],
445
                    's type' => 'bnode',
446
                    'p' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#rest',
447
                    'p type' => 'uri',
448
                    'o' => $res['result']['rows'][1]['o'],
449
                    'o type' => 'bnode',
450
                ],
451
                [
452
                    's' => $res['result']['rows'][2]['s'],
453
                    's type' => 'bnode',
454
                    'p' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#first',
455
                    'p type' => 'uri',
456
                    'o' => '2',
457
                    'o type' => 'literal',
458
                    'o datatype' => 'http://www.w3.org/2001/XMLSchema#integer',
459
                ],
460
                [
461
                    's' => $res['result']['rows'][3]['s'],
462
                    's type' => 'bnode',
463
                    'p' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#rest',
464
                    'p type' => 'uri',
465
                    'o' => $res['result']['rows'][3]['o'],
466
                    'o type' => 'bnode',
467
                ],
468
                [
469
                    's' => $res['result']['rows'][4]['s'],
470
                    's type' => 'bnode',
471
                    'p' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#first',
472
                    'p type' => 'uri',
473
                    'o' => '3',
474
                    'o type' => 'literal',
475
                    'o datatype' => 'http://www.w3.org/2001/XMLSchema#integer',
476
                ],
477
                [
478
                    's' => $res['result']['rows'][5]['s'],
479
                    's type' => 'bnode',
480
                    'p' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#rest',
481
                    'p type' => 'uri',
482
                    'o' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#nil',
483
                    'o type' => 'uri',
484
                ],
485
            ],
486
            $res['result']['rows']
487
        );
488
    }
489
490
    public function testInsertIntoConstruct()
491
    {
492
        // test data
493
        $this->subjectUnderTest->query('INSERT INTO <http://ex/> CONSTRUCT {
494
            <http://baz> <http://location> "Leipzig" .
495
            <http://baz2> <http://location> "Grimma" .
496
        }');
497
498
        $res = $this->subjectUnderTest->query('SELECT * FROM <http://ex/> {?s ?p ?o.}');
499
        $this->assertEquals(2, \count($res['result']['rows']));
500
    }
501
502
    public function testInsertIntoWhere()
503
    {
504
        // test data
505
        $this->subjectUnderTest->query('INSERT INTO <http://ex/> CONSTRUCT {
506
            <http://baz> <http://location> "Leipzig" .
507
            <http://baz2> <http://location> "Grimma" .
508
        } WHERE {
509
            ?s <http://location> "Leipzig" .
510
        }');
511
512
        // we expect that 1 element gets added to the store, because of the WHERE clause.
513
        // but store added none.
514
        $res = $this->subjectUnderTest->query('SELECT * FROM <http://ex/> {?s ?p ?o.}');
515
        $this->assertEquals(2, \count($res['result']['rows']));
516
517
        $this->markTestSkipped(
518
            'Store does not check the WHERE clause when inserting data.'
519
            .' Too many triples were added.'
520
            .\PHP_EOL
521
            .\PHP_EOL.'FYI: https://www.w3.org/Submission/SPARQL-Update/#sec_examples and '
522
            .\PHP_EOL.'https://github.com/semsol/arc2/wiki/SPARQL-#insert-example'
523
        );
524
    }
525
526
    public function testInsertInto2GraphsSameTriples()
527
    {
528
        /*
529
         * Test behavior if same triple get inserted into two different graphs:
530
         * 1. add
531
         * 2. check additions
532
         * 3. delete graph2 content
533
         * 4. check again
534
         */
535
536
        $triple = '<http://foo> <http://location> "Leipzig" .';
537
        $this->subjectUnderTest->query('INSERT INTO <http://graph1/> {'.$triple.'}');
538
        $this->subjectUnderTest->query('INSERT INTO <http://graph2/> {'.$triple.'}');
539
540
        // check additions (graph1)
541
        $res = $this->subjectUnderTest->query('SELECT * FROM <http://graph1/> {?s ?p ?o.}');
542
        $this->assertEquals(1, \count($res['result']['rows']));
543
544
        // check additions (graph2)
545
        $res = $this->subjectUnderTest->query('SELECT * FROM <http://graph2/> {?s ?p ?o.}');
546
        $this->assertEquals(1, \count($res['result']['rows']));
547
548
        /*
549
         * test isolation by removing the triple from graph2
550
         */
551
        $this->subjectUnderTest->query('DELETE FROM <http://graph2/>');
552
553
        // check triples (graph1)
554
        $res = $this->subjectUnderTest->query('SELECT * FROM <http://graph1/> {?s ?p ?o.}');
555
        $this->assertEquals(1, \count($res['result']['rows']));
556
557
        // check triples (graph2)
558
        $res = $this->subjectUnderTest->query('SELECT * FROM <http://graph2/> {?s ?p ?o.}');
559
        $this->assertEquals(0, \count($res['result']['rows']));
560
    }
561
562
    /**
563
     * Tests old behavior of ARC2 store: its SQLite in-memory implementation was not able
564
     * to recognize all triples added by separate query calls.
565
     */
566
    public function testMultipleInsertsSameStore()
567
    {
568
        // add triples in separate query calls
569
        $this->subjectUnderTest->query('INSERT INTO <http://ex/> {<http://a> <http://b> <http://c> . }');
570
        $this->subjectUnderTest->query('INSERT INTO <http://ex/> {<http://a2> <http://b2> "c2"@de. }');
571
        $this->subjectUnderTest->query('INSERT INTO <http://ex/> {<http://a3> <http://b3> "c3"^^xsd:string . }');
572
573
        // check result
574
        $res = $this->subjectUnderTest->query('SELECT * FROM <http://ex/> WHERE {?s ?p ?o.}');
575
576
        $this->assertEquals(3, \count($res['result']['rows']));
577
578
        $this->assertEquals(
579
            [
580
                [
581
                    's' => 'http://a',
582
                    's type' => 'uri',
583
                    'p' => 'http://b',
584
                    'p type' => 'uri',
585
                    'o' => 'http://c',
586
                    'o type' => 'uri',
587
                ],
588
                [
589
                    's' => 'http://a2',
590
                    's type' => 'uri',
591
                    'p' => 'http://b2',
592
                    'p type' => 'uri',
593
                    'o' => 'c2',
594
                    'o type' => 'literal',
595
                    'o lang' => 'de',
596
                ],
597
                [
598
                    's' => 'http://a3',
599
                    's type' => 'uri',
600
                    'p' => 'http://b3',
601
                    'p type' => 'uri',
602
                    'o' => 'c3',
603
                    'o type' => 'literal',
604
                    'o datatype' => 'http://www.w3.org/2001/XMLSchema#string',
605
                ],
606
            ],
607
            $res['result']['rows']
608
        );
609
    }
610
611
    public function testMultipleInsertQueriesInDifferentGraphs()
612
    {
613
        $this->subjectUnderTest->query('INSERT INTO <http://graph1/> {<http://foo/1> <http://foo/2> <http://foo/3> . }');
614
        $this->subjectUnderTest->query('INSERT INTO <http://graph2/> {<http://foo/4> <http://foo/5> <http://foo/6> . }');
615
        $this->subjectUnderTest->query('INSERT INTO <http://graph2/> {<http://foo/a> <http://foo/b> <http://foo/c> . }');
616
617
        $res = $this->subjectUnderTest->query('SELECT * FROM <http://graph1/> WHERE {?s ?p ?o.}');
618
        $this->assertEquals(1, \count($res['result']['rows']));
619
620
        $res = $this->subjectUnderTest->query('SELECT * FROM <http://graph2/> WHERE {?s ?p ?o.}');
621
        $this->assertEquals(2, \count($res['result']['rows']));
622
623
        $res = $this->subjectUnderTest->query('SELECT * WHERE {?s ?p ?o.}');
624
        $this->assertEquals(3, \count($res['result']['rows']));
625
    }
626
627
    public function testValueEscape()
628
    {
629
        $this->subjectUnderTest->query('INSERT INTO <http://graph1/> {<http://foo/1> <http://foo/2> \'"foobar";\' . }');
630
        $this->subjectUnderTest->query('INSERT INTO <http://graph1/> {<http://foo/1> <http://foo/2> "\'foobar2\'" . }');
631
632
        $res = $this->subjectUnderTest->query('SELECT * FROM <http://graph1/> WHERE {?s ?p ?o.}');
633
        $this->assertEquals(2, \count($res['result']['rows']));
634
    }
635
636
    /**
637
     * Adds bulk of triples to test behavior.
638
     * May take at least one second to finish.
639
     */
640
    public function testAdditionOfManyTriples()
641
    {
642
        $amount = 3000;
643
644
        // add triples in separate query calls
645
        for ($i = 0; $i < $amount; ++$i) {
646
            $this->subjectUnderTest->query('INSERT INTO <http://ex/> {
647
                <http://a> <http://b> <http://c'.$i.'> .
648
            }');
649
        }
650
651
        // check result
652
        $res = $this->subjectUnderTest->query('SELECT * FROM <http://ex/> WHERE {?s ?p ?o.}');
653
654
        $this->assertEquals($amount, \count($res['result']['rows']));
655
    }
656
}
657