19declare(strict_types=1);
23use PHPUnit\Framework\TestCase;
52 public array $element_as_array;
54 public function getSubElements(): \Generator
56 foreach ($this->element_as_array[
'subs'] as $sub_array) {
58 $sub->element_as_array = $sub_array;
65 return new class ($this->element_as_array) extends
NullDefinition {
66 public function __construct(
protected array $element_as_array)
70 public function name():
string
72 return $this->element_as_array[
'name'];
79 return new class ($this->element_as_array) extends
NullData {
80 public function __construct(
protected array $element_as_array)
84 public function type():
Type
86 return $this->element_as_array[
'type'];
89 public function value():
string
91 return $this->element_as_array[
'value'];
96 $root->element_as_array = $set_as_array;
98 return new class ($root) extends
NullSet {
116 public function tagForElement(
120 if (!isset($element->element_as_array[
'specials'])) {
124 return new class ($element->element_as_array[
'specials']) extends
NullTag {
126 protected array $specials
130 public function isExportedAsLangString():
bool
132 return in_array(SpecialCase::LANGSTRING, $this->specials);
135 public function isTranslatedAsCopyright():
bool
140 public function isOmitted():
bool
142 return in_array(SpecialCase::OMITTED, $this->specials);
145 public function isExportedAsAttribute():
bool
154 public function __construct(
protected bool $cp_selection_active)
158 public function copyrightForExport(
string $copyright):
string
160 return '~parsed:' . $copyright .
'~';
163 public function isCopyrightSelectionActive():
bool
165 return $this->cp_selection_active;
169 $path_factory =
new class () extends NullPathFactory {
173 protected array
$path = [];
175 public function withNextStep(
string $name,
bool $add_as_first =
false):
BuilderInterface
177 $clone = clone $this;
178 $clone->path[] = $name;
184 $string = implode(
'>', $this->path);
185 return new class ($string) extends
NullPath {
186 public function __construct(
protected string $string)
192 return $this->string;
201 public function prepareCreateOrUpdate(
207 $path->toString() !==
'rights>description>string' ||
210 throw new \ilMDXMLException(
211 'Unexpected preparation, path: "' .
$path->toString() .
212 '", value count: "' . count($values) .
'"'
221 'name' =>
'copyright',
226 'type' => Type::STRING,
233 $set->
getRoot()->element_as_array[
'subs'][] = $insert_array;
238 return new Standard($dictionary, $copyright_handler, $path_factory, $manipulator);
250 'type' => Type::STRING,
261 'type' => Type::NON_NEG_INT,
262 'value' =>
'val1.2.1',
268 'value' =>
'val1.2.2',
276 $expected_xml = <<<XML
279 <el1.1>val1.1</el1.1>
281 <el1.2.1>val1.2.1</el1.2.1>
282 <el1.2.2>val1.2.2</el1.2.2>
288 $set = $this->
getSet($set_array);
289 $xml = $writer->write($set);
291 $this->assertXmlStringEqualsXmlString($expected_xml, $xml->asXML());
303 'type' => Type::STRING,
309 'type' => Type::STRING,
316 $expected_xml = <<<XML
325 $set = $this->
getSet($set_array);
326 $xml = $writer->write($set);
328 $this->assertXmlStringEqualsXmlString($expected_xml, $xml->asXML());
340 'type' => Type::LANG,
347 $expected_xml = <<<XML
355 $set = $this->
getSet($set_array);
356 $xml = $writer->write($set);
358 $this->assertXmlStringEqualsXmlString($expected_xml, $xml->asXML());
372 'specials' => [SpecialCase::LANGSTRING],
376 'type' => Type::STRING,
377 'value' =>
'some text',
381 'name' =>
'language',
382 'type' => Type::LANG,
391 $expected_xml = <<<XML
395 <
string language=
"br">some text</
string>
401 $set = $this->
getSet($set_array);
402 $xml = $writer->write($set);
404 $this->assertXmlStringEqualsXmlString($expected_xml, $xml->asXML());
418 'specials' => [SpecialCase::LANGSTRING],
422 'type' => Type::STRING,
423 'value' =>
'some text',
431 $expected_xml = <<<XML
435 <
string>some text</
string>
441 $set = $this->
getSet($set_array);
442 $xml = $writer->write($set);
444 $this->assertXmlStringEqualsXmlString($expected_xml, $xml->asXML());
458 'specials' => [SpecialCase::LANGSTRING],
462 'type' => Type::STRING,
463 'value' =>
'some text',
467 'name' =>
'language',
468 'type' => Type::LANG,
477 $expected_xml = <<<XML
481 <
string language=
"none">some text</
string>
487 $set = $this->
getSet($set_array);
488 $xml = $writer->write($set);
490 $this->assertXmlStringEqualsXmlString($expected_xml, $xml->asXML());
504 'specials' => [SpecialCase::LANGSTRING],
507 'name' =>
'language',
508 'type' => Type::LANG,
517 $expected_xml = <<<XML
527 $set = $this->
getSet($set_array);
528 $xml = $writer->write($set);
530 $this->assertXmlStringEqualsXmlString($expected_xml, $xml->asXML());
542 'type' => Type::STRING,
543 'value' =>
'some license',
550 $expected_xml = <<<XML
553 <cp>~parsed:some license~</cp>
558 $set = $this->
getSet($set_array);
559 $xml = $writer->write($set);
561 $this->assertXmlStringEqualsXmlString($expected_xml, $xml->asXML());
573 'type' => Type::STRING,
574 'value' =>
'some value',
580 $expected_xml = <<<XML
583 <el2>some value</el2>
584 <copyright><
string>~parsed:~</
string></copyright>
589 $set = $this->
getSet($set_array);
590 $xml = $writer->write($set);
592 $this->assertXmlStringEqualsXmlString($expected_xml, $xml->asXML());
604 'type' => Type::STRING,
606 'specials' => [SpecialCase::OMITTED],
612 $expected_xml = <<<XML
618 $set = $this->
getSet($set_array);
619 $xml = $writer->write($set);
621 $this->assertXmlStringEqualsXmlString($expected_xml, $xml->asXML());
635 'specials' => [SpecialCase::OMITTED],
639 'type' => Type::STRING,
640 'value' =>
'val1.1.1',
645 'type' => Type::STRING,
646 'value' =>
'val1.1.2',
654 $expected_xml = <<<XML
660 $set = $this->
getSet($set_array);
661 $xml = $writer->write($set);
663 $this->assertXmlStringEqualsXmlString($expected_xml, $xml->asXML());
680 'type' => Type::STRING,
681 'value' =>
'val1.1.1',
687 'type' => Type::STRING,
688 'value' =>
'val1.1.2',
696 $expected_xml = <<<XML
699 <el1.1 el1.1.1=
"val1.1.1">
700 <el1.1.2>val1.1.2</el1.1.2>
706 $set = $this->
getSet($set_array);
707 $xml = $writer->write($set);
709 $this->assertXmlStringEqualsXmlString($expected_xml, $xml->asXML());
734 $expected_xml = <<<XML
743 $set = $this->
getSet($set_array);
744 $xml = $writer->write($set);
746 $this->assertXmlStringEqualsXmlString($expected_xml, $xml->asXML());
758 'type' => Type::VOCAB_VALUE,
759 'value' =>
'This contains !@#$%^&*(){}[]<>?=+\/|"\' a bunch of special characters.',
765 $expected_xml = <<<XML
768 <el1.1>This contains !@#$%^&*(){}[]<>?=+\/|
"' a bunch of special characters.</el1.1>
772 $writer = $this->getStandardWriter();
773 $set = $this->getSet($set_array);
774 $xml = $writer->write($set);
776 $this->assertXmlStringEqualsXmlString($expected_xml, $xml->asXML());
779 public function testWriteWithLangStringContainingSpecialCharacters(): void
783 'type' => Type::NULL,
788 'type' => Type::NULL,
790 'specials' => [SpecialCase::LANGSTRING],
794 'type' => Type::STRING,
795 'value' => 'This contains !@#$%^&*(){}[]<>?=+\/|"\
' a bunch of special characters.',
799 'name' =>
'language',
800 'type' => Type::LANG,
809 $expected_xml = <<<XML
813 <
string language=
"br">This contains !@#$%^&*(){}[]<>?=+\/|
"' a bunch of special characters.</string>
818 $writer = $this->getStandardWriter();
819 $set = $this->getSet($set_array);
820 $xml = $writer->write($set);
822 $this->assertXmlStringEqualsXmlString($expected_xml, $xml->asXML());
__construct()
Constructor setup ILIAS global object @access public.