ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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  $util = new class () extends NullUtilities {
37  public function txt(string $key): string
38  {
39  return 'translated ' . $key;
40  }
41  };
42 
43  return new Elements($util);
44  }
45 
46  protected function getBaseElement(
47  string $name,
48  ?BaseElementInterface $super
50  return new class ($name, $super) extends NullBaseElement {
51  public function __construct(
52  protected string $name,
53  protected ?BaseElementInterface $super
54  ) {
55  }
56 
57  public function getDefinition(): DefinitionInterface
58  {
59  return new class ($this->name) extends NullDefinition {
60  public function __construct(protected string $name)
61  {
62  }
63 
64  public function name(): string
65  {
66  return $this->name;
67  }
68  };
69  }
70 
71  public function getSuperElement(): ?BaseElementInterface
72  {
73  return $this->super;
74  }
75 
76  public function isRoot(): bool
77  {
78  return is_null($this->super);
79  }
80  };
81  }
82 
84  {
85  $root = $this->getBaseElement('root', null);
86  $high = $this->getBaseElement('high', $root);
87  $middle = $this->getBaseElement('lifeCycle', $high);
88  return $this->getBaseElement('lowElement', $middle);
89  }
90 
91  public function testName(): void
92  {
93  $elements = $this->getElements();
94  $low = $this->getTreeOfBaseElements();
95  $this->assertSame(
96  'translated meta_low_element',
97  $elements->name($low)
98  );
99  $this->assertSame(
100  'translated meta_low_element_plural',
101  $elements->name($low, true)
102  );
103  $lifecycle = $low->getSuperElement();
104  $this->assertSame(
105  'translated meta_lifecycle',
106  $elements->name($lifecycle)
107  );
108  $this->assertSame(
109  'translated meta_lifecycle_plural',
110  $elements->name($lifecycle, true)
111  );
112  }
113 
114  public function testNameWithParents(): void
115  {
116  $elements = $this->getElements();
117  $low = $this->getTreeOfBaseElements();
118  $this->assertSame(
119  'translated meta_high: translated meta_lifecycle: translated meta_low_element',
120  $elements->nameWithParents($low)
121  );
122  $this->assertSame(
123  'translated meta_high: translated meta_lifecycle: translated meta_low_element_plural',
124  $elements->nameWithParents($low, null, true)
125  );
126  }
127 
128  public function testNameWithParentsForRoot(): void
129  {
130  $elements = $this->getElements();
131  $root = $this->getBaseElement('root', null);
132  $this->assertSame(
133  'translated meta_root',
134  $elements->nameWithParents($root)
135  );
136  $this->assertSame(
137  'translated meta_root_plural',
138  $elements->nameWithParents($root, null, true)
139  );
140  $this->assertSame(
141  'translated meta_root',
142  $elements->nameWithParents($root, null, false, true)
143  );
144  }
145 
146  public function testNameWithParentsAndSkipInitial(): void
147  {
148  $elements = $this->getElements();
149  $low = $this->getTreeOfBaseElements();
150  $this->assertSame(
151  'translated meta_high: translated meta_lifecycle',
152  $elements->nameWithParents($low, null, false, true)
153  );
154  $this->assertSame(
155  'translated meta_high: translated meta_lifecycle',
156  $elements->nameWithParents($low, null, true, true)
157  );
158  }
159 
160  public function testNameWithParentsAndCutOff(): void
161  {
162  $elements = $this->getElements();
163  $low = $this->getTreeOfBaseElements();
164  $lifecycle = $low->getSuperElement();
165  $high = $lifecycle->getSuperElement();
166  $this->assertSame(
167  'translated meta_lifecycle: translated meta_low_element',
168  $elements->nameWithParents($low, $high)
169  );
170  $this->assertSame(
171  'translated meta_lifecycle: translated meta_low_element_plural',
172  $elements->nameWithParents($low, $high, true)
173  );
174  $this->assertSame(
175  'translated meta_low_element',
176  $elements->nameWithParents($low, $lifecycle)
177  );
178  $this->assertSame(
179  'translated meta_lifecycle',
180  $elements->nameWithParents($low, $high, true, true)
181  );
182  $this->assertSame(
183  'translated meta_low_element_plural',
184  $elements->nameWithParents($low, $lifecycle, true, true)
185  );
186  }
187 }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
__construct()
Constructor setup ILIAS global object public.
Definition: class.ilias.php:76
$lifecycle
getBaseElement(string $name, ?BaseElementInterface $super)