ILIAS  trunk Revision v11.0_alpha-1749-g1a06bdef097
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
WriterTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
30 
31 class WriterTest extends TestCase
32 {
33  protected function getLOMRepository(): RepositoryInterface
34  {
35  return new class () extends NullRepository {
36  public function getMD(int $obj_id, int $sub_id, string $type): SetInterface
37  {
38  $xml_elements = '<obj_id>' . $obj_id . '</obj_id>' .
39  '<sub_id>' . $sub_id . '</sub_id>' .
40  '<type>' . $type . '</type>';
41  return new class ($xml_elements) extends NullSet {
42  public function __construct(public string $xml_elements)
43  {
44  }
45  };
46  }
47  };
48  }
49 
50  protected function getSimpleDCWriter(): SimpleDCInterface
51  {
52  return new class () extends NullSimpleDC {
53  public function write(SetInterface $set, int $object_ref_id): \SimpleXMLElement
54  {
55  return new \SimpleXMLElement(
56  '<xml>' . $set->xml_elements . '<ref_id>' . $object_ref_id . '</ref_id>' . '</xml>'
57  );
58  }
59  };
60  }
61 
62  public function testWriteSimpleDCMetaData(): void
63  {
64  $writer = new Writer(
65  $this->getLOMRepository(),
66  $this->getSimpleDCWriter()
67  );
68 
69  $expected_xml = '<xml><obj_id>' . 21 . '</obj_id>' .
70  '<sub_id>' . 21 . '</sub_id>' .
71  '<type>' . 'some type' . '</type>' .
72  '<ref_id>' . 67 . '</ref_id></xml>';
73 
74  $xml = $writer->writeSimpleDCMetaData(21, 67, 'some type');
75 
76  $this->assertXmlStringEqualsXmlString(
77  $expected_xml,
78  $xml->saveXML()
79  );
80  }
81 }
__construct()
Constructor setup ILIAS global object public.
Definition: class.ilias.php:76