ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
SourceSelectorTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use PHPUnit\Framework\TestCase;
28
29class SourceSelectorTest extends TestCase
30{
31 protected function getSourceSelector(): SourceSelector
32 {
33 $repo = new class () extends NullRepository {
34 public function getMD(int $obj_id, int $sub_id, string $type): SetInterface
35 {
36 return new class ($obj_id, $sub_id, $type) extends NullSet {
37 public function __construct(
38 public int $obj_id,
39 public int $sub_id,
40 public string $type,
41 ) {
42 }
43 };
44 }
45 };
46
47 $creator = new class () extends NullCreator {
48 public function createSet(
49 string $title,
50 string $description = '',
51 string $language = ''
52 ): SetInterface {
53 return new class ($title, $description, $language) extends NullSet {
54 public function __construct(
55 public string $title,
56 public string $description,
57 public string $language
58 ) {
59 }
60 };
61 }
62 };
63
64 return new class ($repo, $creator) extends SourceSelector {
65 protected function getDerivator(SetInterface $from_set): DerivatorInterface
66 {
67 return new class ($from_set) extends NullDerivator {
68 public function __construct(public SetInterface $from_set)
69 {
70 }
71 };
72 }
73 };
74 }
75
76 public function testFromObject(): void
77 {
78 $source_selector = $this->getSourceSelector();
79 $derivator = $source_selector->fromObject(7, 33, 'type');
80
81 $this->assertSame(7, $derivator->from_set->obj_id);
82 $this->assertSame(33, $derivator->from_set->sub_id);
83 $this->assertSame('type', $derivator->from_set->type);
84 }
85
86 public function testFromObjectWithSubIDZero(): void
87 {
88 $source_selector = $this->getSourceSelector();
89 $derivator = $source_selector->fromObject(67, 0, 'type');
90
91 $this->assertSame(67, $derivator->from_set->obj_id);
92 $this->assertSame(67, $derivator->from_set->sub_id);
93 $this->assertSame('type', $derivator->from_set->type);
94 }
95
96 public function testFromBasicProperties(): void
97 {
98 $source_selector = $this->getSourceSelector();
99
100 $derivator = $source_selector->fromBasicProperties(
101 'great title',
102 'amazing description',
103 'best language'
104 );
105
106 $this->assertSame('great title', $derivator->from_set->title);
107 $this->assertSame('amazing description', $derivator->from_set->description);
108 $this->assertSame('best language', $derivator->from_set->language);
109 }
110}
__construct()
Constructor setup ILIAS global object @access public.
Definition: class.ilias.php:76