ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ClauseWithPropertiesAndFactoryTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use PHPUnit\Framework\TestCase;
29
31{
32 protected function getNonEmptyPath(): PathInterface
33 {
34 return new class () extends NullPath {
35 public function steps(): \Generator
36 {
37 yield new NullStep();
38 }
39 };
40 }
41
42 public function testGetBasicClause(): void
43 {
44 $factory = new Factory();
45 $basic_clause = $factory->getBasicClause($this->getNonEmptyPath(), Mode::CONTAINS, 'value');
46
47 $this->assertFalse($basic_clause->isJoin());
48 $this->assertNull($basic_clause->joinProperties());
49 $this->assertNotNull($basic_clause->basicProperties());
50 }
51
53 {
54 $factory = new Factory();
55
56 $this->expectException(\ilMDRepositoryException::class);
57 $basic_clause = $factory->getBasicClause(new NullPath(), Mode::CONTAINS, 'value');
58 }
59
60 public function testGetBasicClauseNotNegated(): void
61 {
62 $factory = new Factory();
63 $basic_clause = $factory->getBasicClause($this->getNonEmptyPath(), Mode::CONTAINS, 'value');
64
65 $this->assertFalse($basic_clause->isNegated());
66 }
67
68 public function testBasicClausePath(): void
69 {
70 $factory = new Factory();
71 $path = $this->getNonEmptyPath();
72 $basic_clause = $factory->getBasicClause($path, Mode::CONTAINS, 'value');
73 $this->assertSame($path, $basic_clause->basicProperties()->path());
74 }
75
76 public function testBasicClauseMode(): void
77 {
78 $factory = new Factory();
79 $basic_clause = $factory->getBasicClause($this->getNonEmptyPath(), Mode::CONTAINS, 'value');
80 $this->assertSame(Mode::CONTAINS, $basic_clause->basicProperties()->mode());
81 }
82
83 public function testBasicClauseNegatedModeTrue(): void
84 {
85 $factory = new Factory();
86 $basic_clause = $factory->getBasicClause(
87 $this->getNonEmptyPath(),
88 Mode::CONTAINS,
89 'value',
90 true
91 );
92 $this->assertTrue($basic_clause->basicProperties()->isModeNegated());
93 }
94
96 {
97 $factory = new Factory();
98 $basic_clause = $factory->getBasicClause(
99 $this->getNonEmptyPath(),
100 Mode::CONTAINS,
101 'value'
102 );
103 $this->assertFalse($basic_clause->basicProperties()->isModeNegated());
104 }
105
106 public function testBasicClauseValue(): void
107 {
108 $factory = new Factory();
109 $basic_clause = $factory->getBasicClause($this->getNonEmptyPath(), Mode::CONTAINS, 'value');
110 $this->assertSame('value', $basic_clause->basicProperties()->value());
111 }
112
113 public function testGetNegatedClause(): void
114 {
115 $factory = new Factory();
116 $join_props = new JoinProperties(Operator::AND, new NullClause(), new NullClause());
117 $basic_props = new BasicProperties(
118 $this->getNonEmptyPath(),
120 'value',
121 false
122 );
123 $clause = new Clause(false, true, $join_props, $basic_props);
124
125 $negated = $factory->getNegatedClause($clause);
126
127 $this->assertTrue($negated->isNegated());
128 $this->assertTrue($negated->isJoin());
129 $this->assertSame($basic_props, $negated->basicProperties());
130 $this->assertSame($join_props, $negated->joinProperties());
131 }
132
133 public function testNegateNegatedClause(): void
134 {
135 $factory = new Factory();
136 $join_props = new JoinProperties(Operator::AND, new NullClause(), new NullClause());
137 $basic_props = new BasicProperties(
138 $this->getNonEmptyPath(),
140 'value',
141 false
142 );
143 $clause = new Clause(true, true, $join_props, $basic_props);
144
145 $negated = $factory->getNegatedClause($clause);
146
147 $this->assertFalse($negated->isNegated());
148 $this->assertTrue($negated->isJoin());
149 $this->assertSame($basic_props, $negated->basicProperties());
150 $this->assertSame($join_props, $negated->joinProperties());
151 }
152
153 public function testGetJoinedClauses(): void
154 {
155 $factory = new Factory();
156 $clause_1 = new NullClause();
157 $clause_2 = new NullClause();
158 $joined_clause = $factory->getJoinedClauses(Operator::OR, $clause_1, $clause_2);
159
160 $this->assertTrue($joined_clause->isJoin());
161 $this->assertNull($joined_clause->basicProperties());
162 $this->assertNotNull($joined_clause->joinProperties());
163 }
164
165 public function testGetJoinedClausesWithOneClause(): void
166 {
167 $factory = new Factory();
168 $clause_1 = new NullClause();
169 $joined_clause = $factory->getJoinedClauses(Operator::OR, $clause_1);
170
171 $this->assertSame($clause_1, $joined_clause);
172 }
173
174
175 public function testGetJoinedClausesNotNegated(): void
176 {
177 $factory = new Factory();
178 $clause_1 = new NullClause();
179 $clause_2 = new NullClause();
180 $joined_clause = $factory->getJoinedClauses(Operator::OR, $clause_1, $clause_2);
181
182 $this->assertFalse($joined_clause->isNegated());
183 }
184
185 public function testJoinedClauseOperator(): void
186 {
187 $factory = new Factory();
188 $clause_1 = new NullClause();
189 $clause_2 = new NullClause();
190 $joined_clause = $factory->getJoinedClauses(Operator::OR, $clause_1, $clause_2);
191
192 $this->assertSame(Operator::OR, $joined_clause->joinProperties()->operator());
193 }
194
195 public function testJoinedClauseSubClausesWithTwo(): void
196 {
197 $factory = new Factory();
198 $clause_1 = new NullClause();
199 $clause_2 = new NullClause();
200 $joined_clause = $factory->getJoinedClauses(Operator::OR, $clause_1, $clause_2);
201
202 $sub_clauses = iterator_to_array($joined_clause->joinProperties()->subClauses());
203 $this->assertSame([$clause_1, $clause_2], $sub_clauses);
204 }
205
207 {
208 $factory = new Factory();
209 $clause_1 = new NullClause();
210 $clause_2 = new NullClause();
211 $clause_3 = new NullClause();
212 $clause_4 = new NullClause();
213 $joined_clause = $factory->getJoinedClauses(
215 $clause_1,
216 $clause_2,
217 $clause_3,
218 $clause_4
219 );
220
221 $sub_clauses = iterator_to_array($joined_clause->joinProperties()->subClauses());
222 $this->assertSame(
223 [$clause_1, $clause_2, $clause_3, $clause_4],
224 $sub_clauses
225 );
226 }
227}
$path
Definition: ltiservices.php:30