ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ManipulatorTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
68 
69 class ManipulatorTest extends TestCase
70 {
71  protected function getSetMock(ElementInterface $set_root): SetInterface
72  {
73  return new class ($set_root) extends NullSet {
74  public function __construct(protected ElementInterface $set_root)
75  {
76  }
77 
78  public function getRessourceID(): RessourceIDInterface
79  {
80  return new NullRessourceID();
81  }
82 
83  public function getRoot(): ElementInterface
84  {
85  return $this->set_root;
86  }
87  };
88  }
89 
91  {
92  return new class () extends NullScaffoldProvider {
93  public function getScaffoldsForElement(ElementInterface $element): \Generator
94  {
95  yield from [];
96  }
97  };
98  }
99 
101  {
102  return new class ($this) extends NullRepository {
103  public function __construct(protected ManipulatorTest $test)
104  {
105  }
106 
107  public function scaffolds(): ScaffoldProviderInterface
108  {
109  return $this->test->getScaffoldProviderMock();
110  }
111  };
112  }
113 
114  public function getMarkerMock(Action $action, string $data_value = ''): MarkerInterface
115  {
116  return new class ($action, $data_value) extends NullMarker {
117  public function __construct(protected Action $action, protected string $data_value)
118  {
119  }
120 
121  public function action(): Action
122  {
123  return $this->action;
124  }
125 
126  public function dataValue(): string
127  {
128  return $this->data_value;
129  }
130  };
131  }
132 
134  {
135  return new class ($this) extends NullMarkerFactory {
136  public function __construct(protected ManipulatorTest $test)
137  {
138  }
139 
140  public function marker(Action $action, string $data_value = ''): MarkerInterface
141  {
142  return $this->test->getMarkerMock($action, $data_value);
143  }
144  };
145  }
146 
147  public function getNavigatorMock(PathInterface $path, ElementInterface $start_element): NavigatorInterface
148  {
149  return new class ($path, $start_element) extends NullNavigator {
153  protected array $my_elements;
157  protected array $steps;
158  protected int $step_index;
159 
160  public function __construct(PathInterface $path, protected ElementInterface $start_element)
161  {
162  $this->my_elements = [$this->start_element];
163  $this->steps = iterator_to_array($path->steps());
164  $this->step_index = -1;
165  }
166 
167  protected function filterElements(): void
168  {
169  foreach ($this->currentStep()->filters() as $filter) {
170  if ($filter->type() === FilterType::NULL) {
171  continue;
172  }
173  if ($filter->type() === FilterType::MDID) {
174  $elements = [];
175  foreach ($this->my_elements as $element) {
176  foreach ($filter->values() as $value) {
177  if ($element->getMDID() === $value) {
178  $elements[] = $element;
179  break;
180  }
181  }
182  }
183  $this->my_elements = $elements;
184  continue;
185  }
186  if ($filter->type() === FilterType::DATA) {
187  $elements = [];
188  foreach ($this->my_elements as $element) {
189  foreach ($filter->values() as $value) {
190  if ($element->getData()->value() === $value) {
191  $elements[] = $element;
192  break;
193  }
194  }
195  }
196  $this->my_elements = $elements;
197  continue;
198  }
199  if ($filter->type() === FilterType::INDEX) {
200  $elements = [];
201  foreach ($filter->values() as $value) {
202  $value = (int) $value;
203  if (0 <= $value && $value < count($this->my_elements)) {
204  $elements[] = $this->my_elements[$value];
205  }
206  }
207  $this->my_elements = $elements;
208  continue;
209  }
210  }
211  }
212 
213  public function elementsAtFinalStep(): \Generator
214  {
215  $current = clone $this;
216  while ($current->hasNextStep()) {
217  $current = $current->nextStep();
218  }
219  yield from $current->my_elements;
220  }
221 
222  public function lastElement(): ?ElementInterface
223  {
224  $element_count = count($this->my_elements);
225  return ($element_count === 0) ? null : $this->my_elements[$element_count - 1];
226  }
227 
228  public function nextStep(): ?NavigatorInterface
229  {
230  if (!$this->hasNextStep()) {
231  return null;
232  }
233  $clone = clone $this;
234  $clone->my_elements = [];
235  $clone->step_index = $clone->step_index + 1;
236  foreach ($this->my_elements as $element) {
237  array_push($clone->my_elements, ...$element->getSubElements());
238  }
239  $clone->filterElements();
240  return $clone;
241  }
242 
243  public function currentStep(): ?StepInterface
244  {
245  return (0 <= $this->step_index && $this->step_index < count($this->steps)) ? $this->steps[$this->step_index] : null;
246  }
247 
248  public function lastElementAtFinalStep(): ?ElementInterface
249  {
250  $final_elements = iterator_to_array($this->elementsAtFinalStep());
251  $final_elements_count = count($final_elements);
252  return $final_elements_count > 0 ? $final_elements[$final_elements_count - 1] : null;
253  }
254 
255  public function previousStep(): ?NavigatorInterface
256  {
257  if (!$this->hasPreviousStep()) {
258  return null;
259  }
260  $clone = clone $this;
261  $clone->my_elements = [];
262  $clone->step_index = $clone->step_index - 1;
263  foreach ($this->my_elements as $element) {
264  $clone->my_elements[] = $element->getSuperElement();
265  }
266  return $clone;
267  }
268 
269  public function hasNextStep(): bool
270  {
271  return ($this->step_index + 1) < count($this->steps);
272  }
273 
274  public function hasPreviousStep(): bool
275  {
276  return ($this->step_index - 1) >= -1;
277  }
278 
279  public function hasElements(): bool
280  {
281  return count($this->my_elements) > 0;
282  }
283 
284  public function elements(): \Generator
285  {
286  yield from $this->my_elements;
287  }
288  };
289  }
290 
291  public function getPathConditionCollectionMock(PathInterface $path): PathConditionsCollectionInterface
292  {
297  $path_conditions = [];
298  $collected_steps = [];
299  $name = '';
300  foreach ($path->steps() as $step) {
301  if ($step->name() === StepToken::SUPER) {
302  $super = $step;
303  $condition = array_pop($collected_steps);
304  $target = $collected_steps[count($collected_steps) - 1];
305  $condition_path_steps = [$condition];
306 
307  if (key_exists($condition->name(), $path_conditions)) {
308  // array_pop($condition_path_steps);
309  foreach ($path_conditions[$condition->name()]->steps() as $cond_step) {
310  $condition_path_steps[] = $cond_step;
311  }
312  // $condition_path_steps[] = $super;
313  unset($path_conditions[$condition->name()]);
314  }
315 
316  if (key_exists($target->name(), $path_conditions)) {
317  $target_steps = [];
318  foreach ($path_conditions[$target->name()]->steps() as $cond_step) {
319  $target_steps[] = $cond_step;
320  }
321  array_unshift($condition_path_steps, ...$target_steps);
322  unset($path_conditions[$target->name()]);
323  }
324 
325  $path_conditions[$target->name()] = $this->getPathMock(
326  $condition_path_steps,
327  true,
328  false
329  );
330  continue;
331  }
332  $collected_steps[] = $step;
333  }
334 
335  return new class (
336  $this,
337  $this->getPathMock($collected_steps, false, false),
338  $path_conditions
339  ) extends NullPathConditionsCollection {
340  public function __construct(
341  protected ManipulatorTest $test,
342  protected PathInterface $clear_path,
343  protected array $path_conditons
344  ) {
345  }
346 
347  public function getPathWithoutConditions(): PathInterface
348  {
349  return $this->clear_path;
350  }
351 
352  public function getConditionPathByStepName(string $name): PathInterface
353  {
354  if (key_exists($name, $this->path_conditons)) {
355  return $this->path_conditons[$name];
356  }
357  return $this->test->getPathMock([], true, false);
358  }
359  };
360  }
361 
363  PathConditionsCollectionInterface $path_conditions_collection
365  return new class (
366  $path_conditions_collection,
367  $this->getNavigatorFactoryMock()
368  ) extends NullPathConditionsChecker {
369  public function __construct(
370  protected PathConditionsCollectionInterface $path_conditions_collection,
371  protected NavigatorFactoryInterface $navigator_factory
372  ) {
373  }
374 
375  public function isPathConditionMet(StepInterface $step, ElementInterface $root): bool
376  {
377  $navigator = $this->navigator_factory->navigator(
378  $this->path_conditions_collection->getConditionPathByStepName($step->name()),
379  $root
380  );
381  while (!is_null($navigator)) {
382  if (!$navigator->hasElements()) {
383  return false;
384  }
385  $navigator = $navigator->nextStep();
386  }
387  return true;
388  }
389 
390  public function allPathConditionsAreMet(StepInterface $step, ElementInterface ...$roots): bool
391  {
392  foreach ($roots as $root) {
393  if (!$this->isPathConditionMet($step, $root)) {
394  return false;
395  }
396  }
397  return true;
398  }
399 
400  public function atLeastOnePathConditionIsMet(StepInterface $step, ElementInterface ...$roots): bool
401  {
402  foreach ($roots as $root) {
403  if ($this->isPathConditionMet($step, $root)) {
404  return true;
405  }
406  }
407  return false;
408  }
409 
410  public function getRootsThatMeetPathCondition(StepInterface $step, ElementInterface ...$roots): \Generator
411  {
412  $elements = [];
413  foreach ($roots as $root) {
414  if ($this->isPathConditionMet($step, $root)) {
415  $elements[] = $root;
416  }
417  }
418  yield from $elements;
419  }
420  };
421  }
422 
424  {
425  return new class ($this) extends NullFactory {
426  public function __construct(protected ManipulatorTest $test)
427  {
428  }
429 
430  public function custom(): BuilderInterface
431  {
432  return $this->test->getPathBuilderMock();
433  }
434  };
435  }
436 
437  public function getPathBuilderMock(): BuilderInterface
438  {
439  return new class ($this) extends NullBuilder {
440  protected bool $is_relative;
441  protected bool $leads_to_exactly_one_element;
445  protected array $steps;
446 
447  public function __construct(protected ManipulatorTest $test)
448  {
449  $this->is_relative = false;
450  $this->leads_to_exactly_one_element = false;
451  }
452 
453  public function withLeadsToExactlyOneElement(bool $leads_to_one): BuilderInterface
454  {
455  $builder = clone $this;
456  $builder->leads_to_exactly_one_element = $leads_to_one;
457  return $builder;
458  }
459 
460  public function withRelative(bool $is_relative): BuilderInterface
461  {
462  $builder = clone $this;
463  $builder->is_relative = $is_relative;
464  return $builder;
465  }
466 
467  public function withNextStepFromStep(StepInterface $next_step, bool $add_as_first = false): BuilderInterface
468  {
469  $builder = clone $this;
470  $builder->steps[] = $next_step;
471  return $builder;
472  }
473 
474  public function get(): PathInterface
475  {
476  return $this->test->getPathMock($this->steps, $this->is_relative, $this->leads_to_exactly_one_element);
477  }
478  };
479  }
480 
482  {
483  return new class ($this) extends NullNavigatorFactory {
484  public function __construct(protected ManipulatorTest $test)
485  {
486  }
487 
488  public function navigator(PathInterface $path, ElementInterface $start_element): NavigatorInterface
489  {
490  return $this->test->getNavigatorMock($path, $start_element);
491  }
492  };
493  }
494 
496  {
497  return new class (
498  $this
499  ) extends NullPathUtilitiesFactory {
500  public function __construct(
501  protected ManipulatorTest $test
502  ) {
503  }
504 
505  public function pathConditionChecker(
506  PathConditionsCollectionInterface $path_conditions_collection
508  return $this->test->getPathConditionCheckerMock($path_conditions_collection);
509  }
510 
511  public function pathConditionsCollection(PathInterface $path): PathConditionsCollectionInterface
512  {
513  return $this->test->getPathConditionCollectionMock($path);
514  }
515  };
516  }
517 
518  public function getDataMock(string $value, Type $type): DataInterface
519  {
520  return new class ($value, $type) extends NullData {
521  public function __construct(protected string $my_value, protected Type $my_type)
522  {
523  }
524 
525  public function value(): string
526  {
527  return $this->my_value;
528  }
529 
530  public function type(): Type
531  {
532  return $this->my_type;
533  }
534  };
535  }
536 
537  public function getDefinitionMock(
538  string $name,
539  Type $data_type,
540  bool $is_unique
542  return new class ($name, $data_type, $is_unique) extends NullDefinition {
543  public function __construct(
544  protected string $my_name,
545  protected Type $data_type,
546  protected bool $is_unique
547  ) {
548  }
549 
550  public function name(): string
551  {
552  return $this->my_name;
553  }
554 
555  public function dataType(): Type
556  {
557  return $this->data_type;
558  }
559 
560  public function unique(): bool
561  {
562  return $this->is_unique;
563  }
564  };
565  }
566 
567  public function getElementMock(
568  int|NoID $mdid,
569  string $value,
570  Type $type,
571  bool $is_unique = false
572  ): ElementInterface {
573  return new class ($this, $mdid, $value, $type, $is_unique) extends NullElement {
574  protected ?ElementInterface $parent;
575  protected ?MarkerInterface $marker;
576  protected DataInterface $data;
577  protected DefinitionInterface $definition;
581  protected array $children;
582 
583  public function __construct(
584  protected ManipulatorTest $test,
585  protected int|NoID $mdid,
586  string $value,
587  Type $type,
588  bool $is_unique
589  ) {
590  $this->marker = null;
591  $this->parent = null;
592  $this->children = [];
593  $this->data = $this->test->getDataMock($value, $type);
594  $this->definition = $this->test->getDefinitionMock('', $this->data->type(), $is_unique);
595  }
596 
597  public function getMDID(): int|NoID
598  {
599  return $this->mdid;
600  }
601 
602  public function addChild(ElementInterface $child): void
603  {
604  $child->parent = $this;
605  $this->children[] = $child;
606  }
607 
608  public function addChildren(ElementInterface ...$children): void
609  {
610  foreach ($children as $child) {
611  $this->addChild($child);
612  }
613  }
614 
615  public function getSubElements(): \Generator
616  {
617  yield from $this->children;
618  }
619 
620  public function getSuperElement(): ?ElementInterface
621  {
622  return $this->parent;
623  }
624 
625  public function addScaffoldToSubElements(ScaffoldProviderInterface $scaffold_provider, string $name): ?ElementInterface
626  {
627  $element = $this->test->getElementMock(NoID::SCAFFOLD, $name, Type::NULL);
628  $this->addChild($element);
629  return $element;
630  }
631 
632  public function getData(): DataInterface
633  {
634  return $this->data;
635  }
636 
637  public function mark(MarkerFactoryInterface $factory, Action $action, string $data_value = ''): void
638  {
639  $this->marker = $factory->marker($action, $data_value);
640  $element = $this->parent;
641  while (!is_null($element) && !$element->isMarked()) {
642  $current_action = ($element->isScaffold() && $action === Action::CREATE_OR_UPDATE) ? Action::CREATE_OR_UPDATE : Action::NEUTRAL;
643  $element->marker = $factory->marker($current_action);
644  $element = $element->parent;
645  }
646  }
647 
648  public function getDefinition(): DefinitionInterface
649  {
650  return $this->definition;
651  }
652 
653 
654  public function getMarker(): ?MarkerInterface
655  {
656  return $this->marker;
657  }
658 
659  public function isMarked(): bool
660  {
661  return !is_null($this->marker);
662  }
663  };
664  }
665 
669  public function getPathMock(array $steps, bool $is_relative, bool $leads_to_one): PathInterface
670  {
671  return new class ($steps, $is_relative, $leads_to_one) extends NullPath {
675  public function __construct(
676  protected array $my_steps,
677  protected bool $is_relative,
678  protected bool $leads_to_one
679  ) {
680  }
681 
682  public function leadsToExactlyOneElement(): bool
683  {
684  return $this->leads_to_one;
685  }
686 
687  public function isRelative(): bool
688  {
689  return $this->is_relative;
690  }
691 
692  public function steps(): \Generator
693  {
694  yield from $this->my_steps;
695  }
696  };
697  }
698 
702  protected function getStepMock(string|StepToken $step_name, array $filter): StepInterface
703  {
704  return new class ($step_name, $filter) extends NullStep {
705  public function __construct(protected string|StepToken $step_name, protected array $my_filter)
706  {
707  }
708 
709  public function name(): string|StepToken
710  {
711  return $this->step_name;
712  }
713 
714  public function filters(): \Generator
715  {
716  yield from $this->my_filter;
717  }
718  };
719  }
720 
721  protected function getFilterMock(FilterType $filter_type, array $values): FilterInterface
722  {
723  return new class ($filter_type, $values) extends NullFilter {
724  public function __construct(protected FilterType $filter_type, protected array $my_values)
725  {
726  }
727 
728  public function type(): FilterType
729  {
730  return $this->filter_type;
731  }
732 
733  public function values(): \Generator
734  {
735  yield from $this->my_values;
736  }
737  };
738  }
739 
740  protected function createExpectedValuesArray(
741  int $expected_child_count,
742  int|NoID $expected_id,
743  string $expected_element_data_value,
744  Type $expected_data_type = Type::NULL,
745  ?Action $expected_marker_action = null,
746  string $exptected_marker_value = '',
747  array $expected_child_values = [],
748  ): array {
749  return [
750  'expected_child_count' => $expected_child_count,
751  'expected_id' => $expected_id,
752  'expected_element_data_value' => $expected_element_data_value,
753  'expected_data_type' => $expected_data_type,
754  'expected_marker_action' => $expected_marker_action,
755  'expected_marker_value' => $exptected_marker_value,
756  'children' => $expected_child_values
757  ];
758  }
759 
760  protected function myAssertElement(
761  ElementInterface $element_to_check,
762  array $expected_values
763  ): void {
772  $expected_child_count = $expected_values['expected_child_count'];
773  $expected_id = $expected_values['expected_id'];
774  $expected_element_data_value = $expected_values['expected_element_data_value'];
775  $expected_data_type = $expected_values['expected_data_type'];
776  $expected_marker_action = $expected_values['expected_marker_action'];
777  $expected_marker_value = $expected_values['expected_marker_value'];
778  $msg = 'Failed during check of element with data value: ' . $element_to_check->getData()->value()
779  . ', and with NoID: ' . ($element_to_check->getMDID() instanceof NoID ? $element_to_check->getMDID()->value : $element_to_check->getMDID());
780  if (is_null($expected_marker_action)) {
781  $this->assertSame(null, $element_to_check->getMarker(), $msg);
782  }
783  if (!is_null($expected_marker_action)) {
784  $this->assertNotSame(null, $element_to_check->getMarker(), $msg);
785  $this->assertSame($expected_marker_action, $element_to_check->getMarker()->action(), $msg);
786  $this->assertSame($expected_marker_value, $element_to_check->getMarker()->dataValue(), $msg);
787  }
788  $this->assertSame($expected_child_count, count(iterator_to_array($element_to_check->getSubElements())), $msg);
789  $this->assertSame($expected_id, $element_to_check->getMDID(), $msg);
790  $this->assertSame($expected_element_data_value, $element_to_check->getData()->value(), $msg);
791  $this->assertSame($expected_data_type, $element_to_check->getData()->type(), $msg);
792  }
793 
794  protected function myAssertTree(ElementInterface $root, array $expected_root_values)
795  {
800  $elements = [$root];
801  $expected_values = [$expected_root_values];
802  while (count($elements) > 0) {
803  $this->assertSame(count($elements), count($expected_values), 'Bad test value initializion');
804  $current_element = array_pop($elements);
805  $current_expected_values = array_pop($expected_values);
806  $this->myAssertElement($current_element, $current_expected_values);
807  array_push($elements, ...$current_element->getSubElements());
808  array_push($expected_values, ...$current_expected_values['children']);
809  }
810  }
811 
812  public function testPrepareDelete_001(): void
813  {
814  $manipulator = new Manipulator(
815  new NullRepository(),
816  $this->getMarkerFactoryMock(),
817  $this->getNavigatorFactoryMock(),
818  $this->getPathFactoryMock(),
820  );
821 
822  $element_root = $this->getElementMock(NoID::ROOT, 'root', Type::NULL);
823  $element_general = $this->getElementMock(0, 'general', Type::NULL);
824  $element_subsection_1_0 = $this->getElementMock(1, 'subsection_1', Type::NULL);
825  $element_subsection_1_1 = $this->getElementMock(2, 'subsection_1', Type::NULL);
826  $element_target_0 = $this->getElementMock(3, 'target', Type::STRING);
827  $element_target_1 = $this->getElementMock(4, 'target', Type::STRING);
828  $element_target_2 = $this->getElementMock(5, 'target', Type::STRING);
829 
830  $element_root->addChildren($element_general);
831  $element_general->addChildren($element_subsection_1_0, $element_subsection_1_1);
832  $element_subsection_1_0->addChildren($element_target_0);
833  $element_subsection_1_1->addChildren($element_target_1, $element_target_2);
834 
835  $set = $this->getSetMock($element_root);
836  $delete_path = $this->getPathMock(
837  [
838  $this->getStepMock('general', [
839  $this->getFilterMock(FilterType::DATA, ['general'])
840  ]),
841  $this->getStepMock('subsection_1', [
842  $this->getFilterMock(FilterType::DATA, ['subsection_1']),
843  $this->getFilterMock(FilterType::MDID, [2])
844  ]),
845  $this->getStepMock('target', [
846  $this->getFilterMock(FilterType::DATA, ['target'])
847  ])
848  ],
849  false,
850  false
851  );
852 
853  try {
854  $manipulator->prepareDelete($set, $delete_path);
855  } catch (\ilMDPathException $e) {
856  $this->fail($e->getMessage());
857  }
858 
859  $expected_element_target_2 = $this->createExpectedValuesArray(
860  0,
861  5,
862  'target',
863  Type::STRING,
865  );
866 
867  $expected_element_target_1 = $this->createExpectedValuesArray(
868  0,
869  4,
870  'target',
871  Type::STRING,
873  );
874 
875  $expected_element_target_0 = $this->createExpectedValuesArray(
876  0,
877  3,
878  'target',
879  Type::STRING
880  );
881 
882  $expected_element_subsection_1_1 = $this->createExpectedValuesArray(
883  2,
884  2,
885  'subsection_1',
886  Type::NULL,
887  Action::NEUTRAL,
888  '',
889  [
890  $expected_element_target_1,
891  $expected_element_target_2
892  ]
893  );
894 
895  $expected_element_subsection_1_0 = $this->createExpectedValuesArray(
896  1,
897  1,
898  'subsection_1',
899  Type::NULL,
900  null,
901  '',
902  [
903  $expected_element_target_0
904  ]
905  );
906 
907  $expected_element_general = $this->createExpectedValuesArray(
908  2,
909  0,
910  'general',
911  Type::NULL,
912  Action::NEUTRAL,
913  '',
914  [
915  $expected_element_subsection_1_0,
916  $expected_element_subsection_1_1
917  ]
918  );
919 
920  $expected_element_root = $this->createExpectedValuesArray(
921  1,
922  NoID::ROOT,
923  'root',
924  Type::NULL,
925  Action::NEUTRAL,
926  '',
927  [
928  $expected_element_general
929  ]
930  );
931 
932  $this->myAssertTree($element_root, $expected_element_root);
933  }
934 
935  public function testPrepareDelete_002(): void
936  {
937  $manipulator = new Manipulator(
938  new NullRepository(),
939  $this->getMarkerFactoryMock(),
940  $this->getNavigatorFactoryMock(),
941  $this->getPathFactoryMock(),
943  );
944 
945  $element_root = $this->getElementMock(NoID::ROOT, 'root', Type::NULL);
946  $element_general = $this->getElementMock(0, 'general', Type::NULL);
947  $element_subsection_1_0 = $this->getElementMock(1, 'subsection_1', Type::NULL);
948  $element_subsection_1_1 = $this->getElementMock(2, 'subsection_1', Type::NULL);
949  $element_target = $this->getElementMock(3, 'target', Type::STRING);
950 
951  $element_root->addChildren($element_general);
952  $element_general->addChildren($element_subsection_1_0, $element_subsection_1_1);
953  $element_subsection_1_0->addChildren($element_target);
954 
955  $set = $this->getSetMock($element_root);
956  $delete_path = $this->getPathMock(
957  [
958  $this->getStepMock('general', [
959  $this->getFilterMock(FilterType::DATA, ['general'])
960  ]),
961  $this->getStepMock('subsection_1', [
962  $this->getFilterMock(FilterType::DATA, ['subsection_1'])
963  ]),
964  $this->getStepMock('i_do_not_exist_one', [
965  $this->getFilterMock(FilterType::DATA, ['i_do_not_exist_one'])
966  ]),
967  $this->getStepMock('i_do_not_exist_two', [
968  $this->getFilterMock(FilterType::DATA, ['i_do_not_exist_two'])
969  ])
970  ],
971  false,
972  false
973  );
974 
975  try {
976  $manipulator->prepareDelete($set, $delete_path);
977  } catch (\ilMDPathException $e) {
978  $this->fail($e->getMessage());
979  }
980 
981  $expected_element_target = $this->createExpectedValuesArray(
982  0,
983  3,
984  'target',
985  Type::STRING
986  );
987 
988  $expected_element_subsection_1_1 = $this->createExpectedValuesArray(
989  0,
990  2,
991  'subsection_1'
992  );
993 
994  $expected_element_subsection_1_0 = $this->createExpectedValuesArray(
995  1,
996  1,
997  'subsection_1',
998  Type::NULL,
999  null,
1000  '',
1001  [
1002  $expected_element_target
1003  ]
1004  );
1005 
1006  $expected_element_general = $this->createExpectedValuesArray(
1007  2,
1008  0,
1009  'general',
1010  Type::NULL,
1011  null,
1012  '',
1013  [
1014  $expected_element_subsection_1_0,
1015  $expected_element_subsection_1_1
1016  ]
1017  );
1018 
1019  $expected_element_root = $this->createExpectedValuesArray(
1020  1,
1021  NoID::ROOT,
1022  'root',
1023  Type::NULL,
1024  null,
1025  '',
1026  [
1027  $expected_element_general
1028  ]
1029  );
1030 
1031  $this->myAssertTree($element_root, $expected_element_root);
1032  }
1033 
1034  public function testPrepareCreateOrUpdate_001(): void
1035  {
1036  $manipulator = new Manipulator(
1037  $this->getRepositoryMock(),
1038  $this->getMarkerFactoryMock(),
1039  $this->getNavigatorFactoryMock(),
1040  $this->getPathFactoryMock(),
1042  );
1043 
1044  $path = $this->getPathMock([
1045  $this->getStepMock('general', [
1046  $this->getFilterMock(FilterType::NULL, [])
1047  ])
1048  ], false, false);
1049 
1050  $element_root = $this->getElementMock(NoID::ROOT, 'root', Type::NULL, true);
1051 
1052  try {
1053  $manipulator->prepareCreateOrUpdate($this->getSetMock($element_root), $path, 'test');
1054  } catch (\ilMDPathException $e) {
1055  $this->fail($e->getMessage());
1056  }
1057 
1058  $expected_element_general = $this->createExpectedValuesArray(
1059  0,
1060  NoID::SCAFFOLD,
1061  'general',
1062  Type::NULL,
1063  Action::CREATE_OR_UPDATE,
1064  'test',
1065  );
1066 
1067  $expected_element_root = $this->createExpectedValuesArray(
1068  1,
1069  NoID::ROOT,
1070  'root',
1071  Type::NULL,
1072  Action::NEUTRAL,
1073  '',
1074  [
1075  $expected_element_general
1076  ]
1077  );
1078 
1079  $this->myAssertTree($element_root, $expected_element_root);
1080  }
1081 
1082  public function testPrepareCreateOrUpdate_002(): void
1083  {
1084  $manipulator = new Manipulator(
1085  $this->getRepositoryMock(),
1086  $this->getMarkerFactoryMock(),
1087  $this->getNavigatorFactoryMock(),
1088  $this->getPathFactoryMock(),
1090  );
1091 
1092  $add_path = $this->getPathMock([
1093  $this->getStepMock('general', [
1094  $this->getFilterMock(FilterType::DATA, ['general'])
1095  ]),
1096  $this->getStepMock('tags', [
1097  $this->getFilterMock(FilterType::DATA, ['tags'])
1098  ]),
1099  $this->getStepMock('tag', [
1100  $this->getFilterMock(FilterType::DATA, ['tag']),
1101  $this->getFilterMock(FilterType::INDEX, [0, 1])
1102  ]),
1103  ], false, false);
1104 
1105  $element_root = $this->getElementMock(NoID::ROOT, 'root', Type::NULL, true);
1106  $element_general = $this->getElementMock(0, 'general', Type::NULL, true);
1107  $element_special = $this->getElementMock(1, 'special', Type::NULL, true);
1108 
1109  $element_root->addChildren($element_general, $element_special);
1110 
1111  try {
1112  $manipulator->prepareCreateOrUpdate($this->getSetMock($element_root), $add_path, 'test1', 'test2');
1113  } catch (\ilMDPathException $e) {
1114  $this->fail($e->getMessage());
1115  }
1116 
1117  $expected_element_tag_1 = $this->createExpectedValuesArray(
1118  0,
1119  NoID::SCAFFOLD,
1120  'tag',
1121  Type::NULL,
1122  Action::CREATE_OR_UPDATE,
1123  'test2',
1124  );
1125 
1126  $expected_element_tag_0 = $this->createExpectedValuesArray(
1127  0,
1128  NoID::SCAFFOLD,
1129  'tag',
1130  Type::NULL,
1131  Action::CREATE_OR_UPDATE,
1132  'test1',
1133  );
1134 
1135  $expected_element_tags = $this->createExpectedValuesArray(
1136  2,
1137  NoID::SCAFFOLD,
1138  'tags',
1139  Type::NULL,
1140  Action::CREATE_OR_UPDATE,
1141  'tags',
1142  [
1143  $expected_element_tag_0,
1144  $expected_element_tag_1
1145  ]
1146  );
1147 
1148  $expected_element_special = $this->createExpectedValuesArray(
1149  0,
1150  1,
1151  'special',
1152  );
1153 
1154  $expected_element_general = $this->createExpectedValuesArray(
1155  1,
1156  0,
1157  'general',
1158  Type::NULL,
1159  Action::NEUTRAL,
1160  '',
1161  [
1162  $expected_element_tags
1163  ]
1164  );
1165 
1166  $expected_element_root = $this->createExpectedValuesArray(
1167  2,
1168  NoID::ROOT,
1169  'root',
1170  Type::NULL,
1171  Action::NEUTRAL,
1172  '',
1173  [
1174  $expected_element_general,
1175  $expected_element_special
1176  ]
1177  );
1178 
1179  $this->myAssertTree($element_root, $expected_element_root);
1180  }
1181 
1182  public function testPrepareCreateOrUpdate_003(): void
1183  {
1184  $manipulator = new Manipulator(
1185  $this->getRepositoryMock(),
1186  $this->getMarkerFactoryMock(),
1187  $this->getNavigatorFactoryMock(),
1188  $this->getPathFactoryMock(),
1190  );
1191 
1192  $add_path = $this->getPathMock([
1193  $this->getStepMock('general', [
1194  $this->getFilterMock(FilterType::DATA, ['general'])
1195  ]),
1196  $this->getStepMock('tags', [
1197  $this->getFilterMock(FilterType::DATA, ['tags'])
1198  ]),
1199  $this->getStepMock('tag', [
1200  $this->getFilterMock(FilterType::DATA, ['tag']),
1201  $this->getFilterMock(FilterType::INDEX, [0, 2])
1202  ]),
1203  ], false, false);
1204 
1205  $element_root = $this->getElementMock(NoID::ROOT, 'root', Type::NULL, true);
1206  $element_general = $this->getElementMock(0, 'general', Type::NULL, true);
1207  $element_special = $this->getElementMock(1, 'special', Type::NULL, true);
1208  $element_tags = $this->getElementMock(2, 'tags', Type::NULL, true);
1209  $element_tag_0 = $this->getElementMock(3, 'tag', Type::STRING);
1210  $element_tag_1 = $this->getElementMock(4, 'tag', Type::STRING);
1211  $element_tag_2 = $this->getElementMock(5, 'tag', Type::STRING);
1212  $element_tag_3 = $this->getElementMock(6, 'tag', Type::STRING);
1213 
1214  $element_root->addChildren($element_general, $element_special);
1215  $element_general->addChildren($element_tags);
1216  $element_tags->addChildren($element_tag_0, $element_tag_1, $element_tag_2, $element_tag_3);
1217 
1218  try {
1219  $manipulator->prepareCreateOrUpdate($this->getSetMock($element_root), $add_path, 'test1', 'test2');
1220  } catch (\ilMDPathException $e) {
1221  $this->fail($e->getMessage());
1222  }
1223 
1224  $expected_element_tag_3 = $this->createExpectedValuesArray(
1225  0,
1226  6,
1227  'tag',
1228  Type::STRING
1229  );
1230 
1231  $expected_element_tag_2 = $this->createExpectedValuesArray(
1232  0,
1233  5,
1234  'tag',
1235  Type::STRING,
1236  Action::CREATE_OR_UPDATE,
1237  'test2'
1238  );
1239 
1240  $expected_element_tag_1 = $this->createExpectedValuesArray(
1241  0,
1242  4,
1243  'tag',
1244  Type::STRING
1245  );
1246 
1247  $expected_element_tag_0 = $this->createExpectedValuesArray(
1248  0,
1249  3,
1250  'tag',
1251  Type::STRING,
1252  Action::CREATE_OR_UPDATE,
1253  'test1'
1254  );
1255 
1256  $expected_element_tags = $this->createExpectedValuesArray(
1257  4,
1258  2,
1259  'tags',
1260  Type::NULL,
1261  Action::NEUTRAL,
1262  '',
1263  [
1264  $expected_element_tag_0,
1265  $expected_element_tag_1,
1266  $expected_element_tag_2,
1267  $expected_element_tag_3
1268  ]
1269  );
1270 
1271  $expected_element_special = $this->createExpectedValuesArray(
1272  0,
1273  1,
1274  'special'
1275  );
1276 
1277  $expected_element_general = $this->createExpectedValuesArray(
1278  1,
1279  0,
1280  'general',
1281  Type::NULL,
1282  Action::NEUTRAL,
1283  '',
1284  [
1285  $expected_element_tags
1286  ]
1287  );
1288 
1289  $expected_element_root = $this->createExpectedValuesArray(
1290  2,
1291  NoID::ROOT,
1292  'root',
1293  Type::NULL,
1294  Action::NEUTRAL,
1295  '',
1296  [
1297  $expected_element_general,
1298  $expected_element_special
1299  ]
1300  );
1301 
1302  $this->myAssertTree($element_root, $expected_element_root);
1303  }
1304 
1305  public function testPrepareCreateOrUpdate_004(): void
1306  {
1307  $manipulator = new Manipulator(
1308  $this->getRepositoryMock(),
1309  $this->getMarkerFactoryMock(),
1310  $this->getNavigatorFactoryMock(),
1311  $this->getPathFactoryMock(),
1313  );
1314 
1315  $add_path = $this->getPathMock([
1316  $this->getStepMock('general', [
1317  $this->getFilterMock(FilterType::DATA, ['general'])
1318  ]),
1319  $this->getStepMock('general_condition', [
1320  $this->getFilterMock(FilterType::DATA, ['general_condition'])
1321  ]),
1322  $this->getStepMock(StepToken::SUPER, []),
1323  $this->getStepMock('tags', [
1324  $this->getFilterMock(FilterType::DATA, ['tags'])
1325  ]),
1326  $this->getStepMock('tag', [
1327  $this->getFilterMock(FilterType::DATA, ['tag']),
1328  $this->getFilterMock(FilterType::INDEX, [0, 2])
1329  ]),
1330  ], false, false);
1331 
1332  $element_root = $this->getElementMock(NoID::ROOT, 'root', Type::NULL, true);
1333  $element_general = $this->getElementMock(0, 'general', Type::NULL, true);
1334  $element_special = $this->getElementMock(1, 'special', Type::NULL, true);
1335  $element_general_condition = $this->getElementMock(2, 'general_condition', Type::NULL);
1336  $element_tags = $this->getElementMock(3, 'tags', Type::NULL, true);
1337  $element_tag_0 = $this->getElementMock(4, 'tag', Type::STRING);
1338  $element_tag_1 = $this->getElementMock(5, 'tag', Type::STRING);
1339  $element_tag_2 = $this->getElementMock(6, 'tag', Type::STRING);
1340  $element_tag_3 = $this->getElementMock(7, 'tag', Type::STRING);
1341 
1342  $element_root->addChildren($element_general, $element_special);
1343  $element_general->addChildren($element_general_condition, $element_tags);
1344  $element_tags->addChildren($element_tag_0, $element_tag_1, $element_tag_2, $element_tag_3);
1345 
1346  try {
1347  $manipulator->prepareCreateOrUpdate($this->getSetMock($element_root), $add_path, 'test1', 'test2');
1348  } catch (\ilMDPathException $e) {
1349  $this->fail($e->getMessage());
1350  }
1351 
1352  $expected_element_tag_3 = $this->createExpectedValuesArray(
1353  0,
1354  7,
1355  'tag',
1356  Type::STRING
1357  );
1358 
1359  $expected_element_tag_2 = $this->createExpectedValuesArray(
1360  0,
1361  6,
1362  'tag',
1363  Type::STRING,
1364  Action::CREATE_OR_UPDATE,
1365  'test2'
1366  );
1367 
1368  $expected_element_tag_1 = $this->createExpectedValuesArray(
1369  0,
1370  5,
1371  'tag',
1372  Type::STRING
1373  );
1374 
1375  $expected_element_tag_0 = $this->createExpectedValuesArray(
1376  0,
1377  4,
1378  'tag',
1379  Type::STRING,
1380  Action::CREATE_OR_UPDATE,
1381  'test1'
1382  );
1383 
1384  $expected_element_tags = $this->createExpectedValuesArray(
1385  4,
1386  3,
1387  'tags',
1388  Type::NULL,
1389  Action::NEUTRAL,
1390  '',
1391  [
1392  $expected_element_tag_0,
1393  $expected_element_tag_1,
1394  $expected_element_tag_2,
1395  $expected_element_tag_3
1396  ]
1397  );
1398 
1399  $expected_element_general_condition = $this->createExpectedValuesArray(
1400  0,
1401  2,
1402  'general_condition'
1403  );
1404 
1405  $expected_element_special = $this->createExpectedValuesArray(
1406  0,
1407  1,
1408  'special'
1409  );
1410 
1411  $expected_element_general = $this->createExpectedValuesArray(
1412  2,
1413  0,
1414  'general',
1415  Type::NULL,
1416  Action::NEUTRAL,
1417  '',
1418  [
1419  $expected_element_general_condition,
1420  $expected_element_tags
1421  ]
1422  );
1423 
1424  $expected_element_root = $this->createExpectedValuesArray(
1425  2,
1426  NoID::ROOT,
1427  'root',
1428  Type::NULL,
1429  Action::NEUTRAL,
1430  '',
1431  [
1432  $expected_element_general,
1433  $expected_element_special
1434  ]
1435  );
1436 
1437  $this->myAssertTree($element_root, $expected_element_root);
1438  }
1439 
1440  public function testPrepareCreateOrUpdate_005(): void
1441  {
1442  $manipulator = new Manipulator(
1443  $this->getRepositoryMock(),
1444  $this->getMarkerFactoryMock(),
1445  $this->getNavigatorFactoryMock(),
1446  $this->getPathFactoryMock(),
1448  );
1449 
1450  $add_path = $this->getPathMock([
1451  $this->getStepMock('general', [
1452  $this->getFilterMock(FilterType::DATA, ['general'])
1453  ]),
1454  $this->getStepMock('tags', [
1455  $this->getFilterMock(FilterType::DATA, ['tags'])
1456  ]),
1457  $this->getStepMock('tags_condition', [
1458  $this->getFilterMock(FilterType::DATA, ['tags_condition'])
1459  ]),
1460  $this->getStepMock(StepToken::SUPER, []),
1461  $this->getStepMock('tag', [
1462  $this->getFilterMock(FilterType::DATA, ['tag'])
1463  ]),
1464  ], false, false);
1465 
1466  $element_root = $this->getElementMock(NoID::ROOT, 'root', Type::NULL, true);
1467  $element_general = $this->getElementMock(0, 'general', Type::NULL, true);
1468  $element_special = $this->getElementMock(1, 'special', Type::NULL, true);
1469  $element_general_condition = $this->getElementMock(2, 'general_condition', Type::NULL);
1470  $element_tags = $this->getElementMock(3, 'tags', Type::NULL, true);
1471  $element_tag_0 = $this->getElementMock(4, 'tag', Type::STRING);
1472 
1473  $element_root->addChildren($element_general, $element_special);
1474  $element_general->addChildren($element_general_condition, $element_tags);
1475  $element_tags->addChildren($element_tag_0);
1476 
1477  try {
1478  $manipulator->prepareCreateOrUpdate(
1479  $this->getSetMock($element_root),
1480  $add_path,
1481  'test1',
1482  'test2',
1483  'test3'
1484  );
1485  } catch (\ilMDPathException $e) {
1486  $this->fail($e->getMessage());
1487  }
1488 
1489  $expected_element_tag_3 = $this->createExpectedValuesArray(
1490  0,
1491  NoID::SCAFFOLD,
1492  'tag',
1493  Type::NULL,
1494  Action::CREATE_OR_UPDATE,
1495  'test3'
1496  );
1497 
1498  $expected_element_tag_2 = $this->createExpectedValuesArray(
1499  0,
1500  NoID::SCAFFOLD,
1501  'tag',
1502  Type::NULL,
1503  Action::CREATE_OR_UPDATE,
1504  'test2'
1505  );
1506 
1507  $expected_element_tag_1 = $this->createExpectedValuesArray(
1508  0,
1509  NoID::SCAFFOLD,
1510  'tag',
1511  Type::NULL,
1512  Action::CREATE_OR_UPDATE,
1513  'test1'
1514  );
1515 
1516  $expected_element_tag_0 = $this->createExpectedValuesArray(
1517  0,
1518  4,
1519  'tag',
1520  Type::STRING
1521  );
1522 
1523  $expected_element_tags_condition = $this->createExpectedValuesArray(
1524  0,
1525  NoID::SCAFFOLD,
1526  'tags_condition',
1527  Type::NULL,
1528  Action::CREATE_OR_UPDATE,
1529  'tags_condition'
1530  );
1531 
1532  $expected_element_tags_created = $this->createExpectedValuesArray(
1533  4,
1534  NoID::SCAFFOLD,
1535  'tags',
1536  Type::NULL,
1537  Action::CREATE_OR_UPDATE,
1538  'tags',
1539  [
1540  $expected_element_tags_condition,
1541  $expected_element_tag_1,
1542  $expected_element_tag_2,
1543  $expected_element_tag_3
1544  ]
1545  );
1546 
1547  $expected_element_tags = $this->createExpectedValuesArray(
1548  1,
1549  3,
1550  'tags',
1551  Type::NULL,
1552  null,
1553  '',
1554  [
1555  $expected_element_tag_0
1556  ]
1557  );
1558 
1559  $expected_element_general_condition = $this->createExpectedValuesArray(
1560  0,
1561  2,
1562  'general_condition'
1563  );
1564 
1565  $expected_element_special = $this->createExpectedValuesArray(
1566  0,
1567  1,
1568  'special'
1569  );
1570 
1571  $expected_element_general = $this->createExpectedValuesArray(
1572  3,
1573  0,
1574  'general',
1575  Type::NULL,
1576  Action::NEUTRAL,
1577  '',
1578  [
1579  $expected_element_general_condition,
1580  $expected_element_tags,
1581  $expected_element_tags_created
1582  ]
1583  );
1584 
1585  $expected_element_root = $this->createExpectedValuesArray(
1586  2,
1587  NoID::ROOT,
1588  'root',
1589  Type::NULL,
1590  Action::NEUTRAL,
1591  '',
1592  [
1593  $expected_element_general,
1594  $expected_element_special
1595  ]
1596  );
1597 
1598  $this->myAssertTree($element_root, $expected_element_root);
1599  }
1600 
1601  public function testPrepareForceCreate01(): void
1602  {
1603  $manipulator = new Manipulator(
1604  $this->getRepositoryMock(),
1605  $this->getMarkerFactoryMock(),
1606  $this->getNavigatorFactoryMock(),
1607  $this->getPathFactoryMock(),
1609  );
1610 
1611  $add_path = $this->getPathMock([
1612  $this->getStepMock('general', [
1613  $this->getFilterMock(FilterType::DATA, ['general'])
1614  ]),
1615  $this->getStepMock('tags', [
1616  $this->getFilterMock(FilterType::DATA, ['tags'])
1617  ]),
1618  $this->getStepMock('tags_condition', [
1619  $this->getFilterMock(FilterType::DATA, ['tags_condition'])
1620  ]),
1621  $this->getStepMock(StepToken::SUPER, []),
1622  $this->getStepMock('tag', [
1623  $this->getFilterMock(FilterType::DATA, ['tag'])
1624  ]),
1625  ], false, false);
1626 
1627  $element_root = $this->getElementMock(NoID::ROOT, 'root', Type::NULL, true);
1628  $element_general = $this->getElementMock(0, 'general', Type::NULL, true);
1629  $element_special = $this->getElementMock(1, 'special', Type::NULL, true);
1630  $element_general_condition = $this->getElementMock(2, 'general_condition', Type::NULL);
1631  $element_tags = $this->getElementMock(3, 'tags', Type::NULL, true);
1632  $element_tag_0 = $this->getElementMock(4, 'tag', Type::STRING);
1633  $element_tags_condition = $this->getElementMock(5, 'tags_condition', Type::NULL, true);
1634 
1635  $element_root->addChildren($element_general, $element_special);
1636  $element_general->addChildren($element_general_condition, $element_tags);
1637  $element_tags->addChildren($element_tag_0, $element_tags_condition);
1638 
1639  try {
1640  $manipulator->prepareForceCreate(
1641  $this->getSetMock($element_root),
1642  $add_path,
1643  'test1',
1644  'test2',
1645  'test3'
1646  );
1647  } catch (\ilMDPathException $e) {
1648  $this->fail($e->getMessage());
1649  }
1650 
1651  $expected_element_tag_3 = $this->createExpectedValuesArray(
1652  0,
1653  NoID::SCAFFOLD,
1654  'tag',
1655  Type::NULL,
1656  Action::CREATE_OR_UPDATE,
1657  'test3'
1658  );
1659 
1660  $expected_element_tag_2 = $this->createExpectedValuesArray(
1661  0,
1662  NoID::SCAFFOLD,
1663  'tag',
1664  Type::NULL,
1665  Action::CREATE_OR_UPDATE,
1666  'test2'
1667  );
1668 
1669  $expected_element_tag_1 = $this->createExpectedValuesArray(
1670  0,
1671  NoID::SCAFFOLD,
1672  'tag',
1673  Type::NULL,
1674  Action::CREATE_OR_UPDATE,
1675  'test1'
1676  );
1677 
1678  $expected_element_tag_0 = $this->createExpectedValuesArray(
1679  0,
1680  4,
1681  'tag',
1682  Type::STRING
1683  );
1684 
1685  $expected_element_tags_condition = $this->createExpectedValuesArray(
1686  0,
1687  5,
1688  'tags_condition',
1689  Type::NULL
1690  );
1691 
1692  $expected_element_tags = $this->createExpectedValuesArray(
1693  5,
1694  3,
1695  'tags',
1696  Type::NULL,
1697  Action::NEUTRAL,
1698  '',
1699  [
1700  $expected_element_tag_0,
1701  $expected_element_tags_condition,
1702  $expected_element_tag_1,
1703  $expected_element_tag_2,
1704  $expected_element_tag_3
1705  ]
1706  );
1707 
1708  $expected_element_general_condition = $this->createExpectedValuesArray(
1709  0,
1710  2,
1711  'general_condition'
1712  );
1713 
1714  $expected_element_special = $this->createExpectedValuesArray(
1715  0,
1716  1,
1717  'special'
1718  );
1719 
1720  $expected_element_general = $this->createExpectedValuesArray(
1721  2,
1722  0,
1723  'general',
1724  Type::NULL,
1725  Action::NEUTRAL,
1726  '',
1727  [
1728  $expected_element_general_condition,
1729  $expected_element_tags
1730  ]
1731  );
1732 
1733  $expected_element_root = $this->createExpectedValuesArray(
1734  2,
1735  NoID::ROOT,
1736  'root',
1737  Type::NULL,
1738  Action::NEUTRAL,
1739  '',
1740  [
1741  $expected_element_general,
1742  $expected_element_special
1743  ]
1744  );
1745 
1746  $this->myAssertTree($element_root, $expected_element_root);
1747  }
1748 
1749  public function testPrepareForceCreate02(): void
1750  {
1751  $manipulator = new Manipulator(
1752  $this->getRepositoryMock(),
1753  $this->getMarkerFactoryMock(),
1754  $this->getNavigatorFactoryMock(),
1755  $this->getPathFactoryMock(),
1757  );
1758 
1759  $add_path = $this->getPathMock([
1760  $this->getStepMock('general', [
1761  $this->getFilterMock(FilterType::DATA, ['general'])
1762  ]),
1763  $this->getStepMock('tags', [
1764  $this->getFilterMock(FilterType::DATA, ['tags'])
1765  ]),
1766  $this->getStepMock('tag', [
1767  $this->getFilterMock(FilterType::DATA, ['tag'])
1768  ]),
1769  ], false, false);
1770 
1771  $element_root = $this->getElementMock(NoID::ROOT, 'root', Type::NULL, true);
1772  $element_general = $this->getElementMock(0, 'general', Type::NULL, true);
1773  $element_tags = $this->getElementMock(1, 'tags', Type::NULL, true);
1774  $element_tag_0 = $this->getElementMock(2, 'tag', Type::STRING);
1775 
1776  $element_root->addChildren($element_general);
1777  $element_general->addChildren($element_tags);
1778  $element_tags->addChildren($element_tag_0);
1779 
1780  try {
1781  $manipulator->prepareForceCreate(
1782  $this->getSetMock($element_root),
1783  $add_path,
1784  'test1',
1785  'test2',
1786  'test3'
1787  );
1788  } catch (\ilMDPathException $e) {
1789  $this->fail($e->getMessage());
1790  }
1791 
1792  $expected_element_tag_3 = $this->createExpectedValuesArray(
1793  0,
1794  NoID::SCAFFOLD,
1795  'tag',
1796  Type::NULL,
1797  Action::CREATE_OR_UPDATE,
1798  'test3'
1799  );
1800 
1801  $expected_element_tag_2 = $this->createExpectedValuesArray(
1802  0,
1803  NoID::SCAFFOLD,
1804  'tag',
1805  Type::NULL,
1806  Action::CREATE_OR_UPDATE,
1807  'test2'
1808  );
1809 
1810  $expected_element_tag_1 = $this->createExpectedValuesArray(
1811  0,
1812  NoID::SCAFFOLD,
1813  'tag',
1814  Type::NULL,
1815  Action::CREATE_OR_UPDATE,
1816  'test1'
1817  );
1818 
1819  $expected_element_tag_0 = $this->createExpectedValuesArray(
1820  0,
1821  2,
1822  'tag',
1823  Type::STRING
1824  );
1825 
1826  $expected_element_tags = $this->createExpectedValuesArray(
1827  4,
1828  1,
1829  'tags',
1830  Type::NULL,
1831  Action::NEUTRAL,
1832  '',
1833  [
1834  $expected_element_tag_0,
1835  $expected_element_tag_1,
1836  $expected_element_tag_2,
1837  $expected_element_tag_3
1838  ]
1839  );
1840 
1841  $expected_element_general = $this->createExpectedValuesArray(
1842  1,
1843  0,
1844  'general',
1845  Type::NULL,
1846  Action::NEUTRAL,
1847  '',
1848  [
1849  $expected_element_tags
1850  ]
1851  );
1852 
1853  $expected_element_root = $this->createExpectedValuesArray(
1854  1,
1855  NoID::ROOT,
1856  'root',
1857  Type::NULL,
1858  Action::NEUTRAL,
1859  '',
1860  [
1861  $expected_element_general
1862  ]
1863  );
1864 
1865  $this->myAssertTree($element_root, $expected_element_root);
1866  }
1867 }
steps()
Get all steps in the path.
FilterType
Values should always be all lowercase.
Definition: FilterType.php:26
getMarkerMock(Action $action, string $data_value='')
getSetMock(ElementInterface $set_root)
$path
Definition: ltiservices.php:32
marker(Action $action, string $data_value='')
__construct()
Constructor setup ILIAS global object public.
Definition: class.ilias.php:62
getPathMock(array $steps, bool $is_relative, bool $leads_to_one)
name()
Steps are identified by the names of LOM elements, or a token to specify a step to the super-element...
StepToken
The string representation of these tokens must not occur as names of metadata elements.
Definition: StepToken.php:27
getPathConditionCheckerMock(PathConditionsCollectionInterface $path_conditions_collection)
getDefinitionMock(string $name, Type $data_type, bool $is_unique)
getStepMock(string|StepToken $step_name, array $filter)
getFilterMock(FilterType $filter_type, array $values)
createExpectedValuesArray(int $expected_child_count, int|NoID $expected_id, string $expected_element_data_value, Type $expected_data_type=Type::NULL, ?Action $expected_marker_action=null, string $exptected_marker_value='', array $expected_child_values=[],)