19declare(strict_types=1);
23use PHPUnit\Framework\TestCase;
56 return new class ($selection_active) extends
NullSettings {
57 public function __construct(
protected bool $selection_active)
63 return $this->selection_active;
70 return new class () extends NullPathFactory {
74 protected string $path =
'';
76 public function withNextStep(
string $name,
bool $add_as_first =
false):
BuilderInterface
79 $clone->path .=
'>' . $name;
108 public function id():
int
121 array $outdated_entry_ids,
122 int $default_entry_id
123 ): CopyrightRepository {
125 foreach ($entry_ids as
$id) {
129 return new class ($entries, $outdated_entry_ids, $default_entry_id) extends
NullRepository {
131 protected array $entries,
132 protected array $outdated_entry_ids,
133 protected int $default_entry_id
137 public function getAllEntries(): \Generator
139 yield
from $this->entries;
142 public function getActiveEntries(): \Generator
144 foreach ($this->entries as $entry) {
145 if (!in_array($entry->id(), $this->outdated_entry_ids)) {
151 public function getDefaultEntry(): EntryInterface
153 foreach ($this->entries as $entry) {
154 if ($entry->id() === $this->default_entry_id) {
158 throw new \ilMDServicesException(
'Default entry id not found.');
161 public function getEntry(
int $id): EntryInterface
163 foreach ($this->entries as $entry) {
164 if ($entry->id() ===
$id) {
168 throw new \ilMDServicesException(
'Entry id not found.');
176 public function isIdentifierValid(
string $identifier):
bool
178 return str_contains($identifier,
'valid_');
181 public function parseEntryIDFromIdentifier(
string $identifier):
int
183 if ($this->isIdentifierValid($identifier)) {
184 return (
int) str_replace(
'valid_',
'', $identifier);
193 return new class () extends NullSearchClauseFactory {
194 public function getBasicClause(
198 bool $is_mode_negated =
false
200 $search_data =
'"' .
$path->toString() .
'" ' .
201 ($is_mode_negated ?
'not ' :
'') .
202 $mode->value .
' "' . $value .
'"';
203 return new class ($search_data) extends
NullClause {
204 public function __construct(
public string $exposed_search_data)
210 public function getJoinedClauses(
216 foreach ([$first_clause, ...$further_clauses] as $clause) {
217 $clauses_data[] = $clause->exposed_search_data;
219 $search_data = implode(
' ' . $operator->value .
' ', $clauses_data);
220 return new class ($search_data) extends
NullClause {
221 public function __construct(
public string $exposed_search_data)
231 return new class ($raw_copyright) extends
NullReader {
232 public function __construct(
protected string $raw_copyright)
238 if (
$path->toString() !==
'>rights>description>string') {
239 throw new \ilMDServicesException(
'Wrong Path!');
241 return new class ($this->raw_copyright) extends
NullData {
242 public function __construct(
protected string $raw_copyright)
246 public function value():
string
248 return $this->raw_copyright;
258 public array $prepared_creates_or_updates = [];
262 $clone = clone $this;
263 $clone->prepared_creates_or_updates[] = [
264 'path' =>
$path->toString(),
278 $this->getPathFactory(),
280 $this->getIdentifierHandler(),
282 $this->getClauseFactory()
286 return new class ((string) $entry->id()) extends
NullCopyright {
287 public function __construct(
public string $exposed_id)
296 public function __construct(
public string $exposed_id)
306 $helper = $this->getCopyrightHelper(
307 $this->getSettings(
true),
308 $this->getCopyrightRepository([], [], 0)
311 $this->assertTrue($helper->isCopyrightSelectionActive());
316 $helper = $this->getCopyrightHelper(
317 $this->getSettings(
false),
318 $this->getCopyrightRepository([], [], 0)
321 $this->assertFalse($helper->isCopyrightSelectionActive());
326 $helper = $this->getCopyrightHelper(
327 $this->getSettings(
true),
328 $this->getCopyrightRepository([13, 77, 932, 5], [77], 13)
330 $reader = $this->getReader(
'valid_5');
332 $this->assertTrue($helper->hasPresetCopyright($reader));
337 $helper = $this->getCopyrightHelper(
338 $this->getSettings(
true),
339 $this->getCopyrightRepository([13, 77, 932, 5], [77], 13)
341 $reader = $this->getReader(
'');
343 $this->assertTrue($helper->hasPresetCopyright($reader));
348 $helper = $this->getCopyrightHelper(
349 $this->getSettings(
true),
350 $this->getCopyrightRepository([13, 77, 932, 5], [77], 13)
352 $reader = $this->getReader(
'something else');
354 $this->assertFalse($helper->hasPresetCopyright($reader));
359 $helper = $this->getCopyrightHelper(
360 $this->getSettings(
false),
361 $this->getCopyrightRepository([13, 77, 932, 5], [77], 13)
363 $reader = $this->getReader(
'valid_5');
365 $this->assertFalse($helper->hasPresetCopyright($reader));
370 $helper = $this->getCopyrightHelper(
371 $this->getSettings(
true),
372 $this->getCopyrightRepository([13, 77, 932, 5], [77], 13)
374 $reader = $this->getReader(
'valid_5');
376 $this->assertSame(
'5', $helper->readPresetCopyright($reader)->exposed_id);
381 $helper = $this->getCopyrightHelper(
382 $this->getSettings(
false),
383 $this->getCopyrightRepository([13, 77, 932, 5], [77], 13)
385 $reader = $this->getReader(
'valid_5');
387 $this->assertSame(
'null', $helper->readPresetCopyright($reader)->exposed_id);
392 $helper = $this->getCopyrightHelper(
393 $this->getSettings(
true),
394 $this->getCopyrightRepository([13, 77, 932, 5], [77], 13)
396 $reader = $this->getReader(
'something else');
398 $this->assertSame(
'null', $helper->readPresetCopyright($reader)->exposed_id);
403 $helper = $this->getCopyrightHelper(
404 $this->getSettings(
true),
405 $this->getCopyrightRepository([13, 77, 932, 5], [77], 13)
407 $reader = $this->getReader(
'');
409 $this->assertSame(
'13', $helper->readPresetCopyright($reader)->exposed_id);
414 $helper = $this->getCopyrightHelper(
415 $this->getSettings(
true),
416 $this->getCopyrightRepository([13, 77, 932, 5], [77], 13)
418 $reader = $this->getReader(
'custom info about the copyright');
421 'custom info about the copyright',
422 $helper->readCustomCopyright($reader)
428 $helper = $this->getCopyrightHelper(
429 $this->getSettings(
true),
430 $this->getCopyrightRepository([13, 77, 932, 5], [77], 13)
432 $reader = $this->getReader(
'valid_5');
436 $helper->readCustomCopyright($reader)
442 $helper = $this->getCopyrightHelper(
443 $this->getSettings(
false),
444 $this->getCopyrightRepository([13, 77, 932, 5], [77], 13)
446 $reader = $this->getReader(
'valid_5');
450 $helper->readCustomCopyright($reader)
456 $helper = $this->getCopyrightHelper(
457 $this->getSettings(
false),
458 $this->getCopyrightRepository([13, 77, 932, 5], [77], 13)
460 $manipulator = $this->getManipulator();
462 $manipulator = $helper->prepareCreateOrUpdateOfCopyrightFromPreset(
468 [[
'path' =>
'>rights>description>string',
'values' => [
'valid_5']]],
469 $manipulator->prepared_creates_or_updates
475 $helper = $this->getCopyrightHelper(
476 $this->getSettings(
false),
477 $this->getCopyrightRepository([13, 77, 932, 5], [77], 13)
479 $manipulator = $this->getManipulator();
481 $manipulator = $helper->prepareCreateOrUpdateOfCustomCopyright(
483 'custom info about the copyright'
487 [[
'path' =>
'>rights>description>string',
'values' => [
'custom info about the copyright']]],
488 $manipulator->prepared_creates_or_updates
494 $helper = $this->getCopyrightHelper(
495 $this->getSettings(
true),
496 $this->getCopyrightRepository([13, 77, 932, 5], [77], 13)
499 $presets = $helper->getAllCopyrightPresets();
501 $this->assertSame(
'13', $presets->current()->exposed_id);
503 $this->assertSame(
'77', $presets->current()->exposed_id);
505 $this->assertSame(
'932', $presets->current()->exposed_id);
507 $this->assertSame(
'5', $presets->current()->exposed_id);
509 $this->assertNull($presets->current());
514 $helper = $this->getCopyrightHelper(
515 $this->getSettings(
false),
516 $this->getCopyrightRepository([13, 77, 932, 5], [77], 13)
519 $presets = $helper->getAllCopyrightPresets();
521 $this->assertNull($presets->current());
526 $helper = $this->getCopyrightHelper(
527 $this->getSettings(
true),
528 $this->getCopyrightRepository([13, 77, 932, 5], [77], 13)
531 $presets = $helper->getNonOutdatedCopyrightPresets();
533 $this->assertSame(
'13', $presets->current()->exposed_id);
535 $this->assertSame(
'932', $presets->current()->exposed_id);
537 $this->assertSame(
'5', $presets->current()->exposed_id);
539 $this->assertNull($presets->current());
544 $helper = $this->getCopyrightHelper(
545 $this->getSettings(
false),
546 $this->getCopyrightRepository([13, 77, 932, 5], [77], 13)
549 $presets = $helper->getNonOutdatedCopyrightPresets();
551 $this->assertNull($presets->current());
556 $helper = $this->getCopyrightHelper(
557 $this->getSettings(
true),
558 $this->getCopyrightRepository([13, 77, 932, 5], [77], 13)
561 $clause = $helper->getCopyrightSearchClause(
'valid_5');
564 '">rights>description>string" equals "valid_5"',
565 $clause->exposed_search_data
571 $helper = $this->getCopyrightHelper(
572 $this->getSettings(
true),
573 $this->getCopyrightRepository([13, 77, 932, 5], [77], 13)
576 $clause = $helper->getCopyrightSearchClause(
583 '">rights>description>string" equals "valid_5" or ' .
584 '">rights>description>string" equals "valid_77" or ' .
585 '">rights>description>string" equals "something else"',
586 $clause->exposed_search_data
592 $helper = $this->getCopyrightHelper(
593 $this->getSettings(
true),
594 $this->getCopyrightRepository([13, 77, 932, 5], [77], 13)
597 $clause = $helper->getCopyrightSearchClause(
'valid_13');
600 '">rights>description>string" equals "valid_13" or ' .
601 '">rights>description>string" equals ""',
602 $clause->exposed_search_data
608 $helper = $this->getCopyrightHelper(
609 $this->getSettings(
false),
610 $this->getCopyrightRepository([13, 77, 932, 5], [77], 13)
613 $clause = $helper->getCopyrightSearchClause(
'valid_13');
616 '">rights>description>string" equals "valid_13"',
617 $clause->exposed_search_data
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...