ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ElementsTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
31 
32 class ElementsTest extends TestCase
33 {
34  protected function getElements(): Elements
35  {
36  $format = $this->createMock(DateFormat::class);
37  $util = new class ($format) extends NullUtilities {
38  public function txt(string $key): string
39  {
40  return 'translated ' . $key;
41  }
42  };
43 
44  return new Elements($util);
45  }
46 
47  protected function getBaseElement(
48  string $name,
49  ?BaseElementInterface $super
51  return new class ($name, $super) extends NullBaseElement {
52  public function __construct(
53  protected string $name,
54  protected ?BaseElementInterface $super
55  ) {
56  }
57 
58  public function getDefinition(): DefinitionInterface
59  {
60  return new class ($this->name) extends NullDefinition {
61  public function __construct(protected string $name)
62  {
63  }
64 
65  public function name(): string
66  {
67  return $this->name;
68  }
69  };
70  }
71 
72  public function getSuperElement(): ?BaseElementInterface
73  {
74  return $this->super;
75  }
76 
77  public function isRoot(): bool
78  {
79  return is_null($this->super);
80  }
81  };
82  }
83 
85  {
86  $root = $this->getBaseElement('root', null);
87  $high = $this->getBaseElement('high', $root);
88  $middle = $this->getBaseElement('lifeCycle', $high);
89  return $this->getBaseElement('lowElement', $middle);
90  }
91 
92  public function testName(): void
93  {
94  $elements = $this->getElements();
95  $low = $this->getTreeOfBaseElements();
96  $this->assertSame(
97  'translated meta_low_element',
98  $elements->name($low)
99  );
100  $this->assertSame(
101  'translated meta_low_element_plural',
102  $elements->name($low, true)
103  );
104  $lifecycle = $low->getSuperElement();
105  $this->assertSame(
106  'translated meta_lifecycle',
107  $elements->name($lifecycle)
108  );
109  $this->assertSame(
110  'translated meta_lifecycle_plural',
111  $elements->name($lifecycle, true)
112  );
113  }
114 
115  public function testNameWithParents(): void
116  {
117  $elements = $this->getElements();
118  $low = $this->getTreeOfBaseElements();
119  $this->assertSame(
120  'translated meta_high: translated meta_lifecycle: translated meta_low_element',
121  $elements->nameWithParents($low)
122  );
123  $this->assertSame(
124  'translated meta_high: translated meta_lifecycle: translated meta_low_element_plural',
125  $elements->nameWithParents($low, null, true)
126  );
127  }
128 
129  public function testNameWithParentsForRoot(): void
130  {
131  $elements = $this->getElements();
132  $root = $this->getBaseElement('root', null);
133  $this->assertSame(
134  'translated meta_root',
135  $elements->nameWithParents($root)
136  );
137  $this->assertSame(
138  'translated meta_root_plural',
139  $elements->nameWithParents($root, null, true)
140  );
141  $this->assertSame(
142  'translated meta_root',
143  $elements->nameWithParents($root, null, false, true)
144  );
145  }
146 
147  public function testNameWithParentsAndSkipInitial(): void
148  {
149  $elements = $this->getElements();
150  $low = $this->getTreeOfBaseElements();
151  $this->assertSame(
152  'translated meta_high: translated meta_lifecycle',
153  $elements->nameWithParents($low, null, false, true)
154  );
155  $this->assertSame(
156  'translated meta_high: translated meta_lifecycle',
157  $elements->nameWithParents($low, null, true, true)
158  );
159  }
160 
161  public function testNameWithParentsAndCutOff(): void
162  {
163  $elements = $this->getElements();
164  $low = $this->getTreeOfBaseElements();
165  $lifecycle = $low->getSuperElement();
166  $high = $lifecycle->getSuperElement();
167  $this->assertSame(
168  'translated meta_lifecycle: translated meta_low_element',
169  $elements->nameWithParents($low, $high)
170  );
171  $this->assertSame(
172  'translated meta_lifecycle: translated meta_low_element_plural',
173  $elements->nameWithParents($low, $high, true)
174  );
175  $this->assertSame(
176  'translated meta_low_element',
177  $elements->nameWithParents($low, $lifecycle)
178  );
179  $this->assertSame(
180  'translated meta_lifecycle',
181  $elements->nameWithParents($low, $high, true, true)
182  );
183  $this->assertSame(
184  'translated meta_low_element_plural',
185  $elements->nameWithParents($low, $lifecycle, true, true)
186  );
187  }
188 }
__construct()
Constructor setup ILIAS global object public.
Definition: class.ilias.php:62
string $key
Consumer key/client ID value.
Definition: System.php:193
$lifecycle
getBaseElement(string $name, ?BaseElementInterface $super)