ILIAS  trunk Revision v11.0_alpha-2662-g519ff7d528f
InfosTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
27 use ILIAS\MetaData\Vocabularies\Standard\NullRepository as NullStandardRepository;
33 
34 class InfosTest extends TestCase
35 {
36  protected function getVocabulary(
37  Type $type,
38  bool $active = true,
41  return new class ($type, $active, $slot) extends NullVocabulary {
42  public function __construct(
43  protected Type $type,
44  protected bool $active,
45  protected SlotIdentifier $slot
46  ) {
47  }
48 
49  public function slot(): SlotIdentifier
50  {
51  return $this->slot;
52  }
53 
54  public function type(): Type
55  {
56  return $this->type;
57  }
58 
59  public function isActive(): bool
60  {
61  return $this->active;
62  }
63  };
64  }
65 
66  protected function getControlledRepo(
68  int $active_count = 0
69  ): ControlledRepository {
70  return new class ($slot, $active_count) extends NullControlledRepository {
71  public function __construct(
72  protected SlotIdentifier $slot,
73  protected int $active_count
74  ) {
75  }
76 
77  public function countActiveVocabulariesForSlot(SlotIdentifier $slot): int
78  {
79  if ($slot === $this->slot) {
80  return $this->active_count;
81  }
82  return 0;
83  }
84  };
85  }
86 
87  protected function getStandardRepo(
89  bool $active = false
90  ): StandardRepository {
91  return new class ($slot, $active) extends NullStandardRepository {
92  public function __construct(
93  protected SlotIdentifier $slot,
94  protected bool $active
95  ) {
96  }
97 
98  public function isVocabularyActive(SlotIdentifier $slot): bool
99  {
100  if ($slot === $this->slot) {
101  return $this->active;
102  }
103  return false;
104  }
105  };
106  }
107 
108  public static function activeCountProvider(): array
109  {
110  return [
111  [5, true, true, true],
112  [5, true, false, true],
113  [1, false, true, false],
114  [1, false, false, true],
115  [0, true, true, false],
116  [0, true, false, true],
117  [0, false, false, false]
118  ];
119  }
120 
121  #[\PHPUnit\Framework\Attributes\DataProvider('activeCountProvider')]
123  int $active_controlled_vocabs,
124  bool $is_standard_vocab_active,
125  bool $is_vocab_active,
126  bool $are_other_vocabs_active
127  ): void {
128  $infos = new Infos(
129  $this->getControlledRepo(SlotIdentifier::TECHNICAL_FORMAT, $active_controlled_vocabs),
130  $this->getStandardRepo(SlotIdentifier::TECHNICAL_FORMAT, $is_standard_vocab_active)
131  );
132  $vocab = $this->getVocabulary(
133  Type::STANDARD,
134  $is_vocab_active,
135  SlotIdentifier::TECHNICAL_FORMAT
136  );
137 
138  $this->assertSame(
139  $are_other_vocabs_active,
140  $infos->isDeactivatable($vocab)
141  );
142  }
143 
144  public function testIsDeactivatableControlledString(): void
145  {
146  $infos = new Infos($this->getControlledRepo(), $this->getStandardRepo());
147  $vocab = $this->getVocabulary(Type::CONTROLLED_STRING);
148 
149  $this->assertTrue($infos->isDeactivatable($vocab));
150  }
151 
152  #[\PHPUnit\Framework\Attributes\DataProvider('activeCountProvider')]
154  int $active_controlled_vocabs,
155  bool $is_standard_vocab_active,
156  bool $is_vocab_active,
157  bool $are_other_vocabs_active
158  ): void {
159  $infos = new Infos(
160  $this->getControlledRepo(SlotIdentifier::TECHNICAL_FORMAT, $active_controlled_vocabs),
161  $this->getStandardRepo(SlotIdentifier::TECHNICAL_FORMAT, $is_standard_vocab_active)
162  );
163  $vocab = $this->getVocabulary(
164  Type::CONTROLLED_VOCAB_VALUE,
165  $is_vocab_active,
166  SlotIdentifier::TECHNICAL_FORMAT
167  );
168 
169  $this->assertSame(
170  $are_other_vocabs_active,
171  $infos->isDeactivatable($vocab)
172  );
173  }
174 
175  public function testIsDeactivatableCopyright(): void
176  {
177  $infos = new Infos($this->getControlledRepo(), $this->getStandardRepo());
179 
180  $this->assertFalse($infos->isDeactivatable($vocab));
181  }
182 
183  public function testCanDisallowCustomInputStandard(): void
184  {
185  $infos = new Infos($this->getControlledRepo(), $this->getStandardRepo());
186  $vocab = $this->getVocabulary(Type::STANDARD);
187 
188  $this->assertFalse($infos->canDisallowCustomInput($vocab));
189  }
190 
192  {
193  $infos = new Infos($this->getControlledRepo(), $this->getStandardRepo());
194  $vocab = $this->getVocabulary(Type::CONTROLLED_STRING);
195 
196  $this->assertTrue($infos->canDisallowCustomInput($vocab));
197  }
198 
200  {
201  $infos = new Infos($this->getControlledRepo(), $this->getStandardRepo());
202  $vocab = $this->getVocabulary(Type::CONTROLLED_VOCAB_VALUE);
203 
204  $this->assertFalse($infos->canDisallowCustomInput($vocab));
205  }
206 
207  public function testCanDisallowCustomInputCopyright(): void
208  {
209  $infos = new Infos($this->getControlledRepo(), $this->getStandardRepo());
211 
212  $this->assertFalse($infos->canDisallowCustomInput($vocab));
213  }
214 
215  public function testIsCustomInputApplicableStandard(): void
216  {
217  $infos = new Infos($this->getControlledRepo(), $this->getStandardRepo());
218  $vocab = $this->getVocabulary(Type::STANDARD);
219 
220  $this->assertFalse($infos->isCustomInputApplicable($vocab));
221  }
222 
224  {
225  $infos = new Infos($this->getControlledRepo(), $this->getStandardRepo());
226  $vocab = $this->getVocabulary(Type::CONTROLLED_STRING);
227 
228  $this->assertTrue($infos->isCustomInputApplicable($vocab));
229  }
230 
232  {
233  $infos = new Infos($this->getControlledRepo(), $this->getStandardRepo());
234  $vocab = $this->getVocabulary(Type::CONTROLLED_VOCAB_VALUE);
235 
236  $this->assertFalse($infos->isCustomInputApplicable($vocab));
237  }
238 
239  public function testIsCustomInputApplicableCopyright(): void
240  {
241  $infos = new Infos($this->getControlledRepo(), $this->getStandardRepo());
243 
244  $this->assertTrue($infos->isCustomInputApplicable($vocab));
245  }
246 
247  public function testCanBeDeletedStandard(): void
248  {
249  $infos = new Infos($this->getControlledRepo(), $this->getStandardRepo());
250  $vocab = $this->getVocabulary(Type::STANDARD);
251 
252  $this->assertFalse($infos->canBeDeleted($vocab));
253  }
254 
255  public function testCanBeDeletedControlledString(): void
256  {
257  $infos = new Infos($this->getControlledRepo(), $this->getStandardRepo());
258  $vocab = $this->getVocabulary(Type::CONTROLLED_STRING);
259 
260  $this->assertTrue($infos->canBeDeleted($vocab));
261  }
262 
263  #[\PHPUnit\Framework\Attributes\DataProvider('activeCountProvider')]
265  int $active_controlled_vocabs,
266  bool $is_standard_vocab_active,
267  bool $is_vocab_active,
268  bool $are_other_vocabs_active
269  ): void {
270  $infos = new Infos(
271  $this->getControlledRepo(SlotIdentifier::TECHNICAL_FORMAT, $active_controlled_vocabs),
272  $this->getStandardRepo(SlotIdentifier::TECHNICAL_FORMAT, $is_standard_vocab_active)
273  );
274  $vocab = $this->getVocabulary(
275  Type::CONTROLLED_VOCAB_VALUE,
276  $is_vocab_active,
277  SlotIdentifier::TECHNICAL_FORMAT
278  );
279 
280  $this->assertSame(
281  $are_other_vocabs_active,
282  $infos->canBeDeleted($vocab)
283  );
284  }
285 
286  public function testCanBeDeletedCopyright(): void
287  {
288  $infos = new Infos($this->getControlledRepo(), $this->getStandardRepo());
290 
291  $this->assertFalse($infos->canBeDeleted($vocab));
292  }
293 }
getStandardRepo(SlotIdentifier $slot=SlotIdentifier::NULL, bool $active=false)
Definition: InfosTest.php:87
testIsDeactivatableControlledVocabValue(int $active_controlled_vocabs, bool $is_standard_vocab_active, bool $is_vocab_active, bool $are_other_vocabs_active)
Definition: InfosTest.php:153
getControlledRepo(SlotIdentifier $slot=SlotIdentifier::NULL, int $active_count=0)
Definition: InfosTest.php:66
__construct()
Constructor setup ILIAS global object public.
Definition: class.ilias.php:76
$vocab
testCanBeDeletedControlledVocabValue(int $active_controlled_vocabs, bool $is_standard_vocab_active, bool $is_vocab_active, bool $are_other_vocabs_active)
Definition: InfosTest.php:264
getVocabulary(Type $type, bool $active=true, SlotIdentifier $slot=SlotIdentifier::NULL)
Definition: InfosTest.php:36
testIsDeactivatableStandard(int $active_controlled_vocabs, bool $is_standard_vocab_active, bool $is_vocab_active, bool $are_other_vocabs_active)
Definition: InfosTest.php:122