ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
BuilderTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
30 
31 class BuilderTest extends TestCase
32 {
33  protected function getBuilder(): Builder
34  {
35  $internal_builder = new class ('') extends NullInternalBuilder {
36  public function __construct(public string $path)
37  {
38  }
39 
40  public function withNextStep(string $name, bool $add_as_first = false): BuilderInterface
41  {
42  return new self($this->path . ':' . $name);
43  }
44 
45  public function withNextStepToSuperElement(bool $add_as_first = false): BuilderInterface
46  {
47  return new self($this->path . ':^');
48  }
49 
50  public function withAdditionalFilterAtCurrentStep(
51  FilterType $type,
52  string ...$values
53  ): BuilderInterface {
54  $filter = '{' . $type->value . ';' . implode(',', $values) . '}';
55  return new self($this->path . $filter);
56  }
57 
58  public function get(): PathInterface
59  {
60  return new class ($this->path) extends NullPath {
61  public function __construct(public string $path_string)
62  {
63  }
64  };
65  }
66  };
67 
68  return new class ($internal_builder) extends Builder {
69  public function __construct(BuilderInterface $internal_builder)
70  {
71  parent::__construct($internal_builder);
72  }
73 
74  public function exposePath(): string
75  {
76  return $this->internal_builder->path;
77  }
78  };
79  }
80 
81  public function testWithNextStep(): void
82  {
83  $builder = $this->getBuilder();
84  $builder1 = $builder->withNextStep('step');
85 
86  $this->assertSame(
87  '',
88  $builder->exposePath()
89  );
90  $this->assertSame(
91  ':step',
92  $builder1->exposePath()
93  );
94  }
95 
96  public function testWithNextStepToSuperElement(): void
97  {
98  $builder = $this->getBuilder();
99  $builder1 = $builder->withNextStepToSuperElement();
100 
101  $this->assertSame(
102  '',
103  $builder->exposePath()
104  );
105  $this->assertSame(
106  ':^',
107  $builder1->exposePath()
108  );
109  }
110 
112  {
113  $builder = $this->getBuilder();
114  $builder1 = $builder->withAdditionalFilterAtCurrentStep(FilterType::DATA, 'v1', 'v2');
115 
116  $this->assertSame(
117  '',
118  $builder->exposePath()
119  );
120  $this->assertSame(
121  '{data;v1,v2}',
122  $builder1->exposePath()
123  );
124  }
125 
126  public function testGet(): void
127  {
128  $builder = $this->getBuilder()
129  ->withNextStep('step1')
130  ->withNextStepToSuperElement()
131  ->withNextStep('step2')
132  ->withAdditionalFilterAtCurrentStep(FilterType::MDID, '12');
133  $builder3 = $builder
134  ->withNextStep('step3')
135  ->withNextStepToSuperElement();
136 
137  $this->assertSame(
138  ':step1:^:step2{id;12}',
139  $builder->get()->path_string
140  );
141  $this->assertSame(
142  ':step1:^:step2{id;12}:step3:^',
143  $builder3->get()->path_string
144  );
145  }
146 }
FilterType
Values should always be all lowercase.
Definition: FilterType.php:26
$path
Definition: ltiservices.php:32
__construct(PathFactory $path_factory)
Definition: Paths.php:31
__construct(VocabulariesInterface $vocabularies)