ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ILIAS\MetaData\Presentation\DataTest Class Reference
+ Inheritance diagram for ILIAS\MetaData\Presentation\DataTest:
+ Collaboration diagram for ILIAS\MetaData\Presentation\DataTest:

Public Member Functions

 testVocabularyValue ()
 
 testLanguage ()
 
 testDatetime ()
 
 testDuration ()
 
 testDataValue ()
 

Protected Member Functions

 getElementData (Type $type, string $value, SlotIdentifier $vocab_slot=SlotIdentifier::NULL)
 
 getData ()
 

Detailed Description

Definition at line 35 of file DataTest.php.

Member Function Documentation

◆ getData()

ILIAS\MetaData\Presentation\DataTest::getData ( )
protected

Definition at line 70 of file DataTest.php.

70 : Data
71 {
72 $format = $this->createMock(DateFormat::class);
73 $format->method('applyTo')->willReturnCallback(function (\DateTimeImmutable $arg) {
74 return $arg->format('d:m:Y');
75 });
76
77 $util = new class ($format) extends NullUtilities {
78 protected DateFormat $format;
79
80 public function __construct(DateFormat $format)
81 {
82 $this->format = $format;
83 }
84
85 public function getUserDateFormat(): DateFormat
86 {
87 return $this->format;
88 }
89
90 public function txt(string $key): string
91 {
92 return 'translated ' . $key;
93 }
94 };
95
96 $helper = new class () extends NullDataHelper {
97 public function durationToIterator(string $duration): \Generator
98 {
99 foreach (explode(':', $duration) as $v) {
100 if ($v === '') {
101 yield null;
102 } else {
103 yield $v;
104 }
105 }
106 }
107
108 public function datetimeToObject(string $datetime): \DateTimeImmutable
109 {
110 return new \DateTimeImmutable($datetime);
111 }
112 };
113
114 $vocab_presentation = new class () extends NullVocabulariesPresentation {
115 public function presentableLabels(
116 PresentationUtilities $presentation_utilities,
117 SlotIdentifier $slot,
118 bool $with_unknown_vocab_flag,
119 string ...$values
120 ): \Generator {
121 foreach ($values as $value) {
122 yield new class ($value, $slot, $with_unknown_vocab_flag) extends NullLabelledValue {
123 public function __construct(
124 protected string $value,
125 protected SlotIdentifier $slot,
126 protected bool $with_unknown_vocab_flag
127 ) {
128 }
129
130 public function value(): string
131 {
132 return $this->value;
133 }
134
135 public function label(): string
136 {
137 return 'vocab ' . $this->slot->value . ' ' .
138 $this->value . ($this->with_unknown_vocab_flag ? ' flagged' : '');
139 }
140 };
141 }
142 }
143 };
144
145 return new Data($util, $helper, $vocab_presentation);
146 }
$datetime
$duration
__construct()
Constructor setup ILIAS global object @access public.
Definition: class.ilias.php:76

References $datetime, $duration, and ILIAS\GlobalScreen\Provider\__construct().

+ Here is the call graph for this function:

◆ getElementData()

ILIAS\MetaData\Presentation\DataTest::getElementData ( Type  $type,
string  $value,
SlotIdentifier  $vocab_slot = SlotIdentifier::NULL 
)
protected

Definition at line 37 of file DataTest.php.

41 : ElementData {
42 return new class ($type, $value, $vocab_slot) extends NullData {
43 public function __construct(
44 protected Type $type,
45 protected string $value,
46 protected SlotIdentifier $vocab_slot
47 ) {
48 $this->type = $type;
49 $this->value = $value;
50 $this->vocab_slot = $vocab_slot;
51 }
52
53 public function type(): Type
54 {
55 return $this->type;
56 }
57
58 public function value(): string
59 {
60 return $this->value;
61 }
62
63 public function vocabularySlot(): SlotIdentifier
64 {
65 return $this->vocab_slot;
66 }
67 };
68 }

◆ testDataValue()

ILIAS\MetaData\Presentation\DataTest::testDataValue ( )

Definition at line 184 of file DataTest.php.

184 : void
185 {
186 $data = $this->getData();
187 $this->assertSame(
188 'vocab rights_cost SomeKey',
189 $data->dataValue($this->getElementData(
190 Type::VOCAB_VALUE,
191 'SomeKey',
192 SlotIdentifier::RIGHTS_COST
193 ))
194 );
195 $this->assertSame(
196 'vocab rights_cost SomeKey',
197 $data->dataValue($this->getElementData(
198 Type::STRING,
199 'SomeKey',
200 SlotIdentifier::RIGHTS_COST
201 ))
202 );
203 $this->assertSame(
204 'translated meta_l_key',
205 $data->dataValue($this->getElementData(Type::LANG, 'key'))
206 );
207 $this->assertSame(
208 '31:12:2012',
209 $data->dataValue($this->getElementData(Type::DATETIME, '2012-12-31'))
210 );
211 $this->assertSame(
212 '89 translated years, 5 translated months, 1 translated second',
213 $data->dataValue($this->getElementData(Type::DURATION, '89:5::::1'))
214 );
215 $this->assertSame(
216 'This should just go through.',
217 $data->dataValue($this->getElementData(Type::VOCAB_SOURCE, 'This should just go through.'))
218 );
219 }

References $data, and ILIAS\MetaData\Elements\Data\DURATION.

◆ testDatetime()

ILIAS\MetaData\Presentation\DataTest::testDatetime ( )

Definition at line 166 of file DataTest.php.

166 : void
167 {
168 $data = $this->getData();
169 $this->assertSame(
170 '31:12:2012',
171 $data->datetime('2012-12-31')
172 );
173 }

References $data.

◆ testDuration()

ILIAS\MetaData\Presentation\DataTest::testDuration ( )

Definition at line 175 of file DataTest.php.

175 : void
176 {
177 $data = $this->getData();
178 $this->assertSame(
179 '89 translated years, 0 translated months, 1 translated second',
180 $data->duration('89:0::::1')
181 );
182 }

References $data.

◆ testLanguage()

ILIAS\MetaData\Presentation\DataTest::testLanguage ( )

Definition at line 157 of file DataTest.php.

157 : void
158 {
159 $data = $this->getData();
160 $this->assertSame(
161 'translated meta_l_key',
162 $data->language('key')
163 );
164 }

References $data.

◆ testVocabularyValue()

ILIAS\MetaData\Presentation\DataTest::testVocabularyValue ( )

Definition at line 148 of file DataTest.php.

148 : void
149 {
150 $data = $this->getData();
151 $this->assertSame(
152 'vocab rights_cost SomeKey',
153 $data->vocabularyValue('SomeKey', SlotIdentifier::RIGHTS_COST),
154 );
155 }

References $data.


The documentation for this class was generated from the following file: