-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathQueryObjectQOMTest.php
More file actions
122 lines (106 loc) · 3.54 KB
/
Copy pathQueryObjectQOMTest.php
File metadata and controls
122 lines (106 loc) · 3.54 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
/*
* This file is part of the PHPCR API Tests package
*
* Copyright (c) 2015 Liip and others
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPCR\Tests\Query;
use PHPCR\Query\QOM\QueryObjectModelFactoryInterface;
use PHPCR\Query\QueryInterface;
/**
* test the Query Factory integration.
*
* setLimit, setOffset, bindValue, getBindVariableNames
*
* the details of the QOM model are covered in the QOM subfolder
*/
class QueryObjectQOMTest extends QueryBaseCase
{
/**
* @var QueryObjectModelFactoryInterface
*/
protected $factory;
/**
* @var QueryInterface
*/
protected $query;
public function setUp()
{
parent::setUp();
try {
$this->factory = $this->sharedFixture['qm']->getQOMFactory();
} catch (\Exception $e) {
$this->markTestSkipped('Can not get the QOM factory, skipping tests about QOM query. '.$e->getMessage());
}
$source = $this->factory->selector('data', 'nt:folder');
$constraint = $this->factory->orConstraint(
$this->factory->descendantNode('data', '/tests_general_base'),
$this->factory->sameNode('data', '/tests_general_base')
);
$orderings = array();
$columns = array();
$this->query = $this->factory->createQuery($source, $constraint, $orderings, $columns);
}
public function testExecute()
{
$qr = $this->query->execute();
$this->assertInstanceOf('PHPCR\Query\QueryResultInterface', $qr);
$this->assertCount(5, $qr->getRows());
// we assume content is the same as for sql2
}
/**
* @expectedException \PHPCR\Query\InvalidQueryException
*
* the doc claims there would just be a PHPCR\RepositoryException
* it makes sense that there is a InvalidQueryException
*/
public function testExecuteInvalid()
{
$source = $this->factory->selector('data', 'nonodetype');
$constraint = null;
$orderings = array();
$columns = array();
$query = $this->factory->createQuery($source, $constraint, $orderings, $columns);
$query->execute();
}
public function testGetStatement()
{
$this->assertEquals('SELECT * FROM [nt:folder] AS data '.
'WHERE (ISDESCENDANTNODE(data, [/tests_general_base]) OR ISSAMENODE(data, [/tests_general_base]))', $this->query->getStatement());
}
/**
* Even though the query is defined with QOM, it must return JCR_SQL2 as langugae:
* http://www.day.com/specs/jcr/2.0/6_Query.html#6.9.3%20Getting%20the%20Language.
*/
public function testGetLanguage()
{
$this->assertEquals(\PHPCR\Query\QueryInterface::JCR_SQL2, $this->query->getLanguage());
}
/**
* a transient query has no stored query path.
*
* @expectedException \PHPCR\ItemNotFoundException
*/
public function testGetStoredQueryPathItemNotFound()
{
$this->query->getStoredQueryPath();
}
/* this is level 2 only */
/*
public function testStoreAsNode()
{
$qstr = '//idExample[jcr:mimeType="text/plain"]';
$query = $this->sharedFixture['qm']->createQuery($qstr, 'xpath');
$query->storeAsNode('/test_query/queryNode');
$this->session->save();
}
*/
/*
TODO: trigger the possible exceptions
*/
// stored queries are tested in SQL2 but can be whatever the implementation wants actually
// so no need to test them here again
}