ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
PCContentIncludeTest.php
Go to the documentation of this file.
1<?php
2
19use PHPUnit\Framework\TestCase;
20
25{
26 public function testConstruction(): void
27 {
28 $page = $this->getEmptyPageWithDom();
29 $pc = new ilPCContentInclude($page);
30 $this->assertEquals(
31 ilPCContentInclude::class,
32 get_class($pc)
33 );
34 }
35
36 public function testCreate(): void
37 {
38 $page = $this->getEmptyPageWithDom();
39 $pc = new ilPCContentInclude($page);
40 $pc->create($page, "pg");
41 $this->assertXmlEquals(
42 '<PageObject HierId="pg"><PageContent><ContentInclude></ContentInclude></PageContent></PageObject>',
43 $page->getXMLFromDom()
44 );
45 }
46
47 public function testCreateSingleUsesSelectedId(): void
48 {
49 $gui = new class () extends ilPCContentIncludeGUI {
50 public ?array $created_ids = null;
51
52 public function __construct()
53 {
54 }
55
56 public function create(?array $ids = null): void
57 {
58 $this->created_ids = $ids;
59 }
60 };
61
62 $gui->createSingle(123);
63
64 $this->assertSame([123], $gui->created_ids);
65 }
66
67 public function testContentId(): void
68 {
69 $page = $this->getEmptyPageWithDom();
70 $pc = new ilPCContentInclude($page);
71 $pc->create($page, "pg");
72 $pc->setContentId("10");
73
74 $this->assertEquals(
75 "10",
76 $pc->getContentId()
77 );
78
79 $expected = <<<EOT
80<PageObject HierId="pg"><PageContent><ContentInclude ContentId="10"></ContentInclude></PageContent></PageObject>
81EOT;
82
83 $this->assertXmlEquals(
84 $expected,
85 $page->getXMLFromDom()
86 );
87 }
88
89 public function testContentType(): void
90 {
91 $page = $this->getEmptyPageWithDom();
92 $pc = new ilPCContentInclude($page);
93 $pc->create($page, "pg");
94 $pc->setContentType("type");
95
96 $this->assertEquals(
97 "type",
98 $pc->getContentType()
99 );
100
101 $expected = <<<EOT
102<PageObject HierId="pg"><PageContent><ContentInclude ContentType="type"></ContentInclude></PageContent></PageObject>
103EOT;
104
105 $this->assertXmlEquals(
106 $expected,
107 $page->getXMLFromDom()
108 );
109 }
110
111 public function testInstId(): void
112 {
113 $page = $this->getEmptyPageWithDom();
114 $pc = new ilPCContentInclude($page);
115 $pc->create($page, "pg");
116 $pc->setInstId("123");
117
118 $this->assertEquals(
119 "123",
120 $pc->getInstId()
121 );
122
123 $expected = <<<EOT
124<PageObject HierId="pg"><PageContent><ContentInclude InstId="123"></ContentInclude></PageContent></PageObject>
125EOT;
126
127 $this->assertXmlEquals(
128 $expected,
129 $page->getXMLFromDom()
130 );
131 }
132
133 public function testCollectContentIncludes(): void
134 {
135 $page = $this->getEmptyPageWithDom();
136 $pc = new ilPCContentInclude($page);
137 $pc->create($page, "pg");
138 $pc->setInstId("123");
139 $pc->setContentType("type");
140 $pc->setContentId(55);
141
142 $includes = ilPCContentInclude::collectContentIncludes($page, $page->getDomDoc());
143
144 $this->assertEquals(
145 ['type:55:123' => [
146 "type" => "type",
147 "id" => "55",
148 "inst_id" => "123"
149 ]],
150 $includes
151 );
152 }
153}
assertXmlEquals(string $expected_xml_as_string, string $html_xml_string)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilPCContentInclude.
static collectContentIncludes(ilPageObject $a_page, DOMDocument $a_domdoc)
get all content includes that are used within the page
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc