-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathUpdateParserSpec.php
119 lines (104 loc) · 3.91 KB
/
UpdateParserSpec.php
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
<?php
/*
* This file is part of the PHPCR Shell package
*
* (c) Daniel Leech <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace spec\PHPCR\Shell\Query;
use PHPCR\Query\QOM\ChildNodeJoinConditionInterface;
use PHPCR\Query\QOM\ComparisonInterface;
use PHPCR\Query\QOM\JoinInterface;
use PHPCR\Query\QOM\LiteralInterface;
use PHPCR\Query\QOM\PropertyValueInterface;
use PHPCR\Query\QOM\QueryObjectModelConstantsInterface;
use PHPCR\Query\QOM\QueryObjectModelFactoryInterface;
use PHPCR\Query\QOM\SelectorInterface;
use PHPCR\Query\QueryInterface;
use PhpSpec\ObjectBehavior;
class UpdateParserSpec extends ObjectBehavior
{
public function let(
QueryObjectModelFactoryInterface $qomf
) {
$this->beConstructedWith(
$qomf
);
}
public function it_is_initializable()
{
$this->shouldHaveType('PHPCR\Shell\Query\UpdateParser');
}
public function it_should_provide_a_qom_object_for_selecting(
QueryObjectModelFactoryInterface $qomf,
ChildNodeJoinConditionInterface $joinCondition,
JoinInterface $join,
SelectorInterface $parentSelector,
SelectorInterface $childSelector,
PropertyValueInterface $childValue,
LiteralInterface $literalValue,
ComparisonInterface $comparison,
QueryInterface $query
) {
$qomf->selector('parent', 'mgnl:page')->willReturn($parentSelector);
$qomf->selector('child', 'mgnl:metaData')->willReturn($childSelector);
$qomf->childNodeJoinCondition('child', 'parent')->willReturn($joinCondition);
$qomf->join($parentSelector, $childSelector, QueryObjectModelConstantsInterface::JCR_JOIN_TYPE_INNER, $joinCondition)->willReturn($join);
$qomf->propertyValue('child', 'mgnl:template')->willReturn($childValue);
$qomf->literal('standard-templating-kit:stkNews')->willReturn($literalValue);
$qomf->comparison($childValue, QueryObjectModelConstantsInterface::JCR_OPERATOR_EQUAL_TO, $literalValue)->willReturn($comparison);
$qomf->createQuery($join, $comparison)->willReturn($query);
$sql = <<<'EOT'
UPDATE [mgnl:page] AS parent
INNER JOIN [mgnl:metaData] AS child ON ISCHILDNODE(child,parent)
SET
parent.foo = 'PHPCR\FOO\Bar',
parent.bar = 'foo'
WHERE
child.[mgnl:template] = 'standard-templating-kit:stkNews'
EOT;
$res = $this->parseUpdate($sql);
$res->offsetGet(0)->shouldHaveType(QueryInterface::class);
$res->offsetGet(1)->shouldReturn([
[
'selector' => 'parent',
'name' => 'foo',
'value' => 'PHPCR\\FOO\\Bar',
],
[
'selector' => 'parent',
'name' => 'bar',
'value' => 'foo',
],
]);
}
public function it_should_parse_functions(
QueryObjectModelFactoryInterface $qomf,
SelectorInterface $source,
QueryInterface $query
) {
$qomf->selector('a', 'dtl:article')->willReturn($source);
$qomf->createQuery($source, null)->willReturn($query);
$sql = <<<'EOT'
UPDATE [dtl:article] AS a SET a.tags = array_replace(a.tags, 'asd', 'dsa')
EOT;
$res = $this->parseUpdate($sql);
$res->offsetGet(0)->shouldHaveType('PHPCR\Query\QueryInterface');
}
public function it_should_parse_apply(
QueryObjectModelFactoryInterface $qomf,
SelectorInterface $source,
QueryInterface $query
) {
$qomf->selector('a', 'dtl:article')->willReturn($source);
$qomf->createQuery($source, null)->willReturn($query);
$sql = <<<'EOT'
UPDATE [dtl:article] AS a APPLY nodetype_add('nt:barbar')
EOT;
$res = $this->parseUpdate($sql);
$res->offsetGet(0)->shouldHaveType('PHPCR\Query\QueryInterface');
}
}