19 declare(strict_types=1);
73 return new class ($set_root) extends
NullSet {
85 return $this->set_root;
93 public function getScaffoldsForElement(
ElementInterface $element): \Generator
102 return new class ($action, $data_value) extends
NullMarker {
103 public function __construct(
protected Action $action,
protected string $data_value)
107 public function action():
Action 109 return $this->action;
112 public function dataValue():
string 114 return $this->data_value;
128 return $this->test->getMarkerMock($action, $data_value);
139 protected array $my_elements;
143 protected array $steps;
144 protected int $step_index;
148 $this->my_elements = [$this->start_element];
149 $this->steps = iterator_to_array($path->
steps());
150 $this->step_index = -1;
153 protected function filterElements():
void 155 foreach ($this->currentStep()->filters() as $filter) {
156 if ($filter->type() === FilterType::NULL) {
159 if ($filter->type() === FilterType::MDID) {
161 foreach ($this->my_elements as $element) {
162 foreach ($filter->values() as $value) {
163 if ($element->getMDID() === $value) {
164 $elements[] = $element;
169 $this->my_elements = $elements;
174 foreach ($this->my_elements as $element) {
175 foreach ($filter->values() as $value) {
176 if ($element->getData()->value() === $value) {
177 $elements[] = $element;
182 $this->my_elements = $elements;
185 if ($filter->type() === FilterType::INDEX) {
187 foreach ($filter->values() as $value) {
188 $value = (
int) $value;
189 if (0 <= $value && $value < count($this->my_elements)) {
190 $elements[] = $this->my_elements[$value];
193 $this->my_elements = $elements;
198 public function elementsAtFinalStep(): \Generator
200 $current = clone $this;
201 while ($current->hasNextStep()) {
202 $current = $current->nextStep();
204 yield
from $current->my_elements;
209 $element_count = count($this->my_elements);
210 return ($element_count === 0) ?
null : $this->my_elements[$element_count - 1];
215 if (!$this->hasNextStep()) {
218 $clone = clone $this;
219 $clone->my_elements = [];
220 $clone->step_index = $clone->step_index + 1;
221 foreach ($this->my_elements as $element) {
222 array_push($clone->my_elements, ...$element->getSubElements());
224 $clone->filterElements();
230 return (0 <= $this->step_index && $this->step_index < count($this->steps)) ? $this->steps[$this->step_index] :
null;
235 $final_elements = iterator_to_array($this->elementsAtFinalStep());
236 $final_elements_count = count($final_elements);
237 return $final_elements_count > 0 ? $final_elements[$final_elements_count - 1] :
null;
242 if (!$this->hasPreviousStep()) {
245 $clone = clone $this;
246 $clone->my_elements = [];
247 $clone->step_index = $clone->step_index - 1;
248 foreach ($this->my_elements as $element) {
249 $clone->my_elements[] = $element->getSuperElement();
254 public function hasNextStep():
bool 256 return ($this->step_index + 1) < count($this->steps);
259 public function hasPreviousStep():
bool 261 return ($this->step_index - 1) >= -1;
264 public function hasElements():
bool 266 return count($this->my_elements) > 0;
269 public function elements(): \Generator
271 yield
from $this->my_elements;
282 $path_conditions = [];
283 $collected_steps = [];
285 foreach ($path->
steps() as $step) {
288 $condition = array_pop($collected_steps);
289 $target = $collected_steps[count($collected_steps) - 1];
290 $condition_path_steps = [$condition];
292 if (key_exists($condition->name(), $path_conditions)) {
294 foreach ($path_conditions[$condition->name()]->steps() as $cond_step) {
295 $condition_path_steps[] = $cond_step;
298 unset($path_conditions[$condition->name()]);
301 if (key_exists($target->name(), $path_conditions)) {
303 foreach ($path_conditions[$target->name()]->steps() as $cond_step) {
304 $target_steps[] = $cond_step;
306 array_unshift($condition_path_steps, ...$target_steps);
307 unset($path_conditions[$target->name()]);
310 $path_conditions[$target->name()] = $this->
getPathMock(
311 $condition_path_steps,
317 $collected_steps[] = $step;
322 $this->
getPathMock($collected_steps,
false,
false),
328 protected array $path_conditons
334 return $this->clear_path;
337 public function getConditionPathByStepName(
string $name):
PathInterface 339 if (key_exists($name, $this->path_conditons)) {
340 return $this->path_conditons[$name];
342 return $this->test->getPathMock([],
true,
false);
351 $path_conditions_collection,
362 $navigator = $this->navigator_factory->navigator(
363 $this->path_conditions_collection->getConditionPathByStepName($step->
name()),
366 while (!is_null($navigator)) {
367 if (!$navigator->hasElements()) {
370 $navigator = $navigator->nextStep();
377 foreach ($roots as $root) {
378 if (!$this->isPathConditionMet($step, $root)) {
387 foreach ($roots as $root) {
388 if ($this->isPathConditionMet($step, $root)) {
398 foreach ($roots as $root) {
399 if ($this->isPathConditionMet($step, $root)) {
403 yield
from $elements;
417 return $this->test->getPathBuilderMock();
425 protected bool $is_relative;
426 protected bool $leads_to_exactly_one_element;
430 protected array $steps;
434 $this->is_relative =
false;
435 $this->leads_to_exactly_one_element =
false;
438 public function withLeadsToExactlyOneElement(
bool $leads_to_one):
BuilderInterface 440 $builder = clone $this;
441 $builder->leads_to_exactly_one_element = $leads_to_one;
447 $builder = clone $this;
448 $builder->is_relative = $is_relative;
454 $builder = clone $this;
455 $builder->steps[] = $next_step;
461 return $this->test->getPathMock($this->steps, $this->is_relative, $this->leads_to_exactly_one_element);
475 return $this->test->getNavigatorMock($path, $start_element);
490 public function pathConditionChecker(
493 return $this->test->getPathConditionCheckerMock($path_conditions_collection);
498 return $this->test->getPathConditionCollectionMock($path);
505 return new class ($value, $type) extends
NullData {
506 public function __construct(
protected string $my_value,
protected Type $my_type)
510 public function value():
string 512 return $this->my_value;
515 public function type():
Type 517 return $this->my_type;
527 return new class ($name, $data_type, $is_unique) extends
NullDefinition {
529 protected string $my_name,
530 protected Type $data_type,
531 protected bool $is_unique
535 public function name():
string 537 return $this->my_name;
540 public function dataType():
Type 542 return $this->data_type;
545 public function unique():
bool 547 return $this->is_unique;
552 public function getElementMock(
556 bool $is_unique =
false 558 return new class ($this, $mdid, $value, $type, $is_unique) extends
NullElement {
566 protected array $children;
570 protected int|
NoID $mdid,
575 $this->marker =
null;
576 $this->parent =
null;
577 $this->children = [];
578 $this->data = $this->test->getDataMock($value, $type);
579 $this->definition = $this->test->getDefinitionMock(
'', $this->data->type(), $is_unique);
582 public function getMDID():
int|
NoID 589 $child->parent = $this;
590 $this->children[] = $child;
595 foreach ($children as $child) {
596 $this->addChild($child);
600 public function getSubElements(): \Generator
602 yield
from $this->children;
607 return $this->parent;
612 $element = $this->test->getElementMock(NoID::SCAFFOLD, $name, Type::NULL);
613 $this->addChild($element);
624 $this->marker = $factory->
marker($action, $data_value);
625 $element = $this->parent;
626 while (!is_null($element) && !$element->isMarked()) {
627 $current_action = ($element->isScaffold() && $action === Action::CREATE_OR_UPDATE) ? Action::CREATE_OR_UPDATE : Action::NEUTRAL;
628 $element->marker = $factory->
marker($current_action);
629 $element = $element->parent;
635 return $this->definition;
641 return $this->marker;
644 public function isMarked():
bool 646 return !is_null($this->marker);
656 return new class ($steps, $is_relative, $leads_to_one) extends
NullPath {
661 protected array $my_steps,
662 protected bool $is_relative,
663 protected bool $leads_to_one
667 public function leadsToExactlyOneElement():
bool 669 return $this->leads_to_one;
672 public function isRelative():
bool 674 return $this->is_relative;
677 public function steps(): \Generator
679 yield
from $this->my_steps;
689 return new class ($step_name, $filter) extends
NullStep {
696 return $this->step_name;
699 public function filters(): \Generator
701 yield
from $this->my_filter;
708 return new class ($filter_type, $values) extends
NullFilter {
715 return $this->filter_type;
718 public function values(): \Generator
720 yield
from $this->my_values;
726 int $expected_child_count,
727 int|
NoID $expected_id,
728 string $expected_element_data_value,
729 Type $expected_data_type = Type::NULL,
731 string $exptected_marker_value =
'',
732 array $expected_child_values = [],
735 'expected_child_count' => $expected_child_count,
736 'expected_id' => $expected_id,
737 'expected_element_data_value' => $expected_element_data_value,
738 'expected_data_type' => $expected_data_type,
739 'expected_marker_action' => $expected_marker_action,
740 'expected_marker_value' => $exptected_marker_value,
741 'children' => $expected_child_values
745 protected function myAssertElement(
747 array $expected_values
757 $expected_child_count = $expected_values[
'expected_child_count'];
758 $expected_id = $expected_values[
'expected_id'];
759 $expected_element_data_value = $expected_values[
'expected_element_data_value'];
760 $expected_data_type = $expected_values[
'expected_data_type'];
761 $expected_marker_action = $expected_values[
'expected_marker_action'];
762 $expected_marker_value = $expected_values[
'expected_marker_value'];
763 $msg =
'Failed during check of element with data value: ' . $element_to_check->
getData()->value()
764 .
', and with NoID: ' . ($element_to_check->
getMDID() instanceof
NoID ? $element_to_check->
getMDID()->value : $element_to_check->
getMDID());
765 if (is_null($expected_marker_action)) {
766 $this->assertSame(
null, $element_to_check->
getMarker(), $msg);
768 if (!is_null($expected_marker_action)) {
769 $this->assertNotSame(
null, $element_to_check->
getMarker(), $msg);
770 $this->assertSame($expected_marker_action, $element_to_check->
getMarker()->action(), $msg);
771 $this->assertSame($expected_marker_value, $element_to_check->
getMarker()->dataValue(), $msg);
773 $this->assertSame($expected_child_count, count(iterator_to_array($element_to_check->
getSubElements())), $msg);
774 $this->assertSame($expected_id, $element_to_check->
getMDID(), $msg);
775 $this->assertSame($expected_element_data_value, $element_to_check->
getData()->value(), $msg);
776 $this->assertSame($expected_data_type, $element_to_check->
getData()->type(), $msg);
779 protected function myAssertTree(
ElementInterface $root, array $expected_root_values)
786 $expected_values = [$expected_root_values];
787 while (count($elements) > 0) {
788 $this->assertSame(count($elements), count($expected_values),
'Bad test value initializion');
789 $current_element = array_pop($elements);
790 $current_expected_values = array_pop($expected_values);
791 $this->myAssertElement($current_element, $current_expected_values);
792 array_push($elements, ...$current_element->getSubElements());
793 array_push($expected_values, ...$current_expected_values[
'children']);
807 $element_root = $this->getElementMock(NoID::ROOT,
'root', Type::NULL);
808 $element_general = $this->getElementMock(0,
'general', Type::NULL);
809 $element_subsection_1_0 = $this->getElementMock(1,
'subsection_1', Type::NULL);
810 $element_subsection_1_1 = $this->getElementMock(2,
'subsection_1', Type::NULL);
811 $element_target_0 = $this->getElementMock(3,
'target', Type::STRING);
812 $element_target_1 = $this->getElementMock(4,
'target', Type::STRING);
813 $element_target_2 = $this->getElementMock(5,
'target', Type::STRING);
815 $element_root->addChildren($element_general);
816 $element_general->addChildren($element_subsection_1_0, $element_subsection_1_1);
817 $element_subsection_1_0->addChildren($element_target_0);
818 $element_subsection_1_1->addChildren($element_target_1, $element_target_2);
839 $manipulator->prepareDelete($set, $delete_path);
841 $this->fail($e->getMessage());
875 $expected_element_target_1,
876 $expected_element_target_2
888 $expected_element_target_0
900 $expected_element_subsection_1_0,
901 $expected_element_subsection_1_1
913 $expected_element_general
917 $this->myAssertTree($element_root, $expected_element_root);
930 $element_root = $this->getElementMock(NoID::ROOT,
'root', Type::NULL);
931 $element_general = $this->getElementMock(0,
'general', Type::NULL);
932 $element_subsection_1_0 = $this->getElementMock(1,
'subsection_1', Type::NULL);
933 $element_subsection_1_1 = $this->getElementMock(2,
'subsection_1', Type::NULL);
934 $element_target = $this->getElementMock(3,
'target', Type::STRING);
936 $element_root->addChildren($element_general);
937 $element_general->addChildren($element_subsection_1_0, $element_subsection_1_1);
938 $element_subsection_1_0->addChildren($element_target);
961 $manipulator->prepareDelete($set, $delete_path);
963 $this->fail($e->getMessage());
987 $expected_element_target
999 $expected_element_subsection_1_0,
1000 $expected_element_subsection_1_1
1012 $expected_element_general
1016 $this->myAssertTree($element_root, $expected_element_root);
1035 $element_root = $this->getElementMock(NoID::ROOT,
'root', Type::NULL,
true);
1038 $manipulator->prepareCreateOrUpdate($this->
getSetMock($element_root), $path,
'test');
1040 $this->fail($e->getMessage());
1048 Action::CREATE_OR_UPDATE,
1060 $expected_element_general
1064 $this->myAssertTree($element_root, $expected_element_root);
1090 $element_root = $this->getElementMock(NoID::ROOT,
'root', Type::NULL,
true);
1091 $element_general = $this->getElementMock(0,
'general', Type::NULL,
true);
1092 $element_special = $this->getElementMock(1,
'special', Type::NULL,
true);
1094 $element_root->addChildren($element_general, $element_special);
1097 $manipulator->prepareCreateOrUpdate($this->
getSetMock($element_root), $add_path,
'test1',
'test2');
1099 $this->fail($e->getMessage());
1107 Action::CREATE_OR_UPDATE,
1116 Action::CREATE_OR_UPDATE,
1125 Action::CREATE_OR_UPDATE,
1128 $expected_element_tag_0,
1129 $expected_element_tag_1
1147 $expected_element_tags
1159 $expected_element_general,
1160 $expected_element_special
1164 $this->myAssertTree($element_root, $expected_element_root);
1190 $element_root = $this->getElementMock(NoID::ROOT,
'root', Type::NULL,
true);
1191 $element_general = $this->getElementMock(0,
'general', Type::NULL,
true);
1192 $element_special = $this->getElementMock(1,
'special', Type::NULL,
true);
1193 $element_tags = $this->getElementMock(2,
'tags', Type::NULL,
true);
1194 $element_tag_0 = $this->getElementMock(3,
'tag', Type::STRING);
1195 $element_tag_1 = $this->getElementMock(4,
'tag', Type::STRING);
1196 $element_tag_2 = $this->getElementMock(5,
'tag', Type::STRING);
1197 $element_tag_3 = $this->getElementMock(6,
'tag', Type::STRING);
1199 $element_root->addChildren($element_general, $element_special);
1200 $element_general->addChildren($element_tags);
1201 $element_tags->addChildren($element_tag_0, $element_tag_1, $element_tag_2, $element_tag_3);
1204 $manipulator->prepareCreateOrUpdate($this->
getSetMock($element_root), $add_path,
'test1',
'test2');
1206 $this->fail($e->getMessage());
1221 Action::CREATE_OR_UPDATE,
1237 Action::CREATE_OR_UPDATE,
1249 $expected_element_tag_0,
1250 $expected_element_tag_1,
1251 $expected_element_tag_2,
1252 $expected_element_tag_3
1270 $expected_element_tags
1282 $expected_element_general,
1283 $expected_element_special
1287 $this->myAssertTree($element_root, $expected_element_root);
1317 $element_root = $this->getElementMock(NoID::ROOT,
'root', Type::NULL,
true);
1318 $element_general = $this->getElementMock(0,
'general', Type::NULL,
true);
1319 $element_special = $this->getElementMock(1,
'special', Type::NULL,
true);
1320 $element_general_condition = $this->getElementMock(2,
'general_condition', Type::NULL);
1321 $element_tags = $this->getElementMock(3,
'tags', Type::NULL,
true);
1322 $element_tag_0 = $this->getElementMock(4,
'tag', Type::STRING);
1323 $element_tag_1 = $this->getElementMock(5,
'tag', Type::STRING);
1324 $element_tag_2 = $this->getElementMock(6,
'tag', Type::STRING);
1325 $element_tag_3 = $this->getElementMock(7,
'tag', Type::STRING);
1327 $element_root->addChildren($element_general, $element_special);
1328 $element_general->addChildren($element_general_condition, $element_tags);
1329 $element_tags->addChildren($element_tag_0, $element_tag_1, $element_tag_2, $element_tag_3);
1332 $manipulator->prepareCreateOrUpdate($this->
getSetMock($element_root), $add_path,
'test1',
'test2');
1334 $this->fail($e->getMessage());
1349 Action::CREATE_OR_UPDATE,
1365 Action::CREATE_OR_UPDATE,
1377 $expected_element_tag_0,
1378 $expected_element_tag_1,
1379 $expected_element_tag_2,
1380 $expected_element_tag_3
1404 $expected_element_general_condition,
1405 $expected_element_tags
1417 $expected_element_general,
1418 $expected_element_special
1422 $this->myAssertTree($element_root, $expected_element_root);
1451 $element_root = $this->getElementMock(NoID::ROOT,
'root', Type::NULL,
true);
1452 $element_general = $this->getElementMock(0,
'general', Type::NULL,
true);
1453 $element_special = $this->getElementMock(1,
'special', Type::NULL,
true);
1454 $element_general_condition = $this->getElementMock(2,
'general_condition', Type::NULL);
1455 $element_tags = $this->getElementMock(3,
'tags', Type::NULL,
true);
1456 $element_tag_0 = $this->getElementMock(4,
'tag', Type::STRING);
1458 $element_root->addChildren($element_general, $element_special);
1459 $element_general->addChildren($element_general_condition, $element_tags);
1460 $element_tags->addChildren($element_tag_0);
1463 $manipulator->prepareCreateOrUpdate(
1471 $this->fail($e->getMessage());
1479 Action::CREATE_OR_UPDATE,
1488 Action::CREATE_OR_UPDATE,
1497 Action::CREATE_OR_UPDATE,
1513 Action::CREATE_OR_UPDATE,
1522 Action::CREATE_OR_UPDATE,
1525 $expected_element_tags_condition,
1526 $expected_element_tag_1,
1527 $expected_element_tag_2,
1528 $expected_element_tag_3
1540 $expected_element_tag_0
1564 $expected_element_general_condition,
1565 $expected_element_tags,
1566 $expected_element_tags_created
1578 $expected_element_general,
1579 $expected_element_special
1583 $this->myAssertTree($element_root, $expected_element_root);
1612 $element_root = $this->getElementMock(NoID::ROOT,
'root', Type::NULL,
true);
1613 $element_general = $this->getElementMock(0,
'general', Type::NULL,
true);
1614 $element_special = $this->getElementMock(1,
'special', Type::NULL,
true);
1615 $element_general_condition = $this->getElementMock(2,
'general_condition', Type::NULL);
1616 $element_tags = $this->getElementMock(3,
'tags', Type::NULL,
true);
1617 $element_tag_0 = $this->getElementMock(4,
'tag', Type::STRING);
1618 $element_tags_condition = $this->getElementMock(5,
'tags_condition', Type::NULL,
true);
1620 $element_root->addChildren($element_general, $element_special);
1621 $element_general->addChildren($element_general_condition, $element_tags);
1622 $element_tags->addChildren($element_tag_0, $element_tags_condition);
1625 $manipulator->prepareForceCreate(
1633 $this->fail($e->getMessage());
1641 Action::CREATE_OR_UPDATE,
1650 Action::CREATE_OR_UPDATE,
1659 Action::CREATE_OR_UPDATE,
1685 $expected_element_tag_0,
1686 $expected_element_tags_condition,
1687 $expected_element_tag_1,
1688 $expected_element_tag_2,
1689 $expected_element_tag_3
1713 $expected_element_general_condition,
1714 $expected_element_tags
1726 $expected_element_general,
1727 $expected_element_special
1731 $this->myAssertTree($element_root, $expected_element_root);
1756 $element_root = $this->getElementMock(NoID::ROOT,
'root', Type::NULL,
true);
1757 $element_general = $this->getElementMock(0,
'general', Type::NULL,
true);
1758 $element_tags = $this->getElementMock(1,
'tags', Type::NULL,
true);
1759 $element_tag_0 = $this->getElementMock(2,
'tag', Type::STRING);
1761 $element_root->addChildren($element_general);
1762 $element_general->addChildren($element_tags);
1763 $element_tags->addChildren($element_tag_0);
1766 $manipulator->prepareForceCreate(
1774 $this->fail($e->getMessage());
1782 Action::CREATE_OR_UPDATE,
1791 Action::CREATE_OR_UPDATE,
1800 Action::CREATE_OR_UPDATE,
1819 $expected_element_tag_0,
1820 $expected_element_tag_1,
1821 $expected_element_tag_2,
1822 $expected_element_tag_3
1834 $expected_element_tags
1846 $expected_element_general
1850 $this->myAssertTree($element_root, $expected_element_root);
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
__construct()
Constructor setup ILIAS global object public.
custom()
expected output: > ILIAS shows a base horizontal bar chart but customized with e.g.