ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
PCPluggedTest.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 ilPCPlugged($page);
30 $this->assertEquals(
31 ilPCPlugged::class,
32 get_class($pc)
33 );
34 }
35
37 {
38 $page = $this->getEmptyPageWithDom();
39
40 $first_plugin_info = $this->createConfiguredStub(
41 ilPluginInfo::class,
42 [
43 "isActive" => true,
44 "getId" => "first_plugin",
45 ]
46 );
47 $second_plugin_info = $this->createConfiguredStub(
48 ilPluginInfo::class,
49 [
50 "isActive" => true,
51 "getId" => "second_plugin",
52 ]
53 );
54
55 $first_plugin_gui = $this->createStub(ilPageComponentPluginGUI::class);
56 $first_plugin_gui->method("getElementHTML")
57 ->willReturn("");
58 $first_plugin = $this->createStub(ilPageComponentPlugin::class);
59 $first_plugin->method("getUIClassInstance")
60 ->willReturn($first_plugin_gui);
61
62 $second_plugin_gui = $this->createStub(ilPageComponentPluginGUI::class);
63 $second_plugin_gui->method("getElementHTML")
64 ->willReturn("second plugin html");
65 $second_plugin = $this->createStub(ilPageComponentPlugin::class);
66 $second_plugin->method("getUIClassInstance")
67 ->willReturn($second_plugin_gui);
68
69 $component_repository = $this->createStub(ilComponentRepository::class);
70 $component_repository->method("getPluginByName")
71 ->willReturnMap([
72 ["First", $first_plugin_info],
73 ["Second", $second_plugin_info],
74 ]);
75 $this->setGlobalVariable("component.repository", $component_repository);
76
77 $component_factory = $this->createStub(ilComponentFactory::class);
78 $component_factory->method("getPlugin")
79 ->willReturnMap([
80 ["first_plugin", $first_plugin],
81 ["second_plugin", $second_plugin],
82 ]);
83 $this->setGlobalVariable("component.factory", $component_factory);
84
85 $pc = new ilPCPlugged($page);
86 $first_marker = "{{{{{Plugged<pl/>First<pl/>1.0}}}}}";
87 $second_marker = "{{{{{Plugged<pl/>Second<pl/>1.0}}}}}";
88
89 $this->assertEquals(
90 "second plugin html",
91 $pc->modifyPageContentPostXsl($first_marker . $second_marker, "presentation")
92 );
93 }
94
95 public function testCreate(): void
96 {
97 $page = $this->getEmptyPageWithDom();
98 $pc = new ilPCPlugged($page);
99 $pc->create($page, "pg", "", "MyPlugin", "1.0");
100 $this->assertXmlEquals(
101 '<PageObject HierId="pg"><PageContent><Plugged PluginName="MyPlugin" PluginVersion="1.0"></Plugged></PageContent></PageObject>',
102 $page->getXMLFromDom()
103 );
104 }
105
106 public function testProperties(): void
107 {
108 $page = $this->getEmptyPageWithDom();
109 $pc = new ilPCPlugged($page);
110 $pc->create($page, "pg", "", "MyPlugin", "1.0");
111 $pc->setProperties([
112 "prop1" => "val1",
113 "prop2" => "val2",
114 ]);
115
116 $this->assertEquals(
117 [
118 "prop1" => "val1",
119 "prop2" => "val2",
120 ],
121 $pc->getProperties()
122 );
123
124 $page->stripHierIDs();
125
126 $expected = <<<EOT
127<PageObject><PageContent><Plugged PluginName="MyPlugin" PluginVersion="1.0"><PluggedProperty Name="prop1">val1</PluggedProperty><PluggedProperty Name="prop2">val2</PluggedProperty></Plugged></PageContent></PageObject>
128EOT;
129 $this->assertXmlEquals(
130 $expected,
131 $page->getXMLFromDom()
132 );
133 }
134
135 public function testVersion(): void
136 {
137 $page = $this->getEmptyPageWithDom();
138 $pc = new ilPCPlugged($page);
139 $pc->create($page, "pg", "", "MyPlugin", "1.0");
140 $pc->setPluginVersion("2.0");
141
142 $this->assertEquals(
143 "2.0",
144 $pc->getPluginVersion()
145 );
146
147 $page->stripHierIDs();
148
149 $expected = <<<EOT
150<PageObject><PageContent><Plugged PluginName="MyPlugin" PluginVersion="2.0"></Plugged></PageContent></PageObject>
151EOT;
152 $this->assertXmlEquals(
153 $expected,
154 $page->getXMLFromDom()
155 );
156 }
157
158 public function testName(): void
159 {
160 $page = $this->getEmptyPageWithDom();
161 $pc = new ilPCPlugged($page);
162 $pc->create($page, "pg", "", "MyPlugin", "1.0");
163 $pc->setPluginName("YourPlugin");
164
165 $this->assertEquals(
166 "YourPlugin",
167 $pc->getPluginName()
168 );
169
170 $page->stripHierIDs();
171
172 $expected = <<<EOT
173<PageObject><PageContent><Plugged PluginName="YourPlugin" PluginVersion="1.0"></Plugged></PageContent></PageObject>
174EOT;
175 $this->assertXmlEquals(
176 $expected,
177 $page->getXMLFromDom()
178 );
179 }
180}
setGlobalVariable(string $name, $value)
assertXmlEquals(string $expected_xml_as_string, string $html_xml_string)
testModifyPageContentPostXslRendersPluginAfterEmptyPlugin()
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...