ILIAS  release_8 Revision v8.23
ilComponentDefinitionReaderTest Class Reference
+ Inheritance diagram for ilComponentDefinitionReaderTest:
+ Collaboration diagram for ilComponentDefinitionReaderTest:

Public Member Functions

 testPurge ()
 
 testGetComponents ()
 
 testReadComponentDefinitions ()
 

Static Public Attributes

static array $components
 

Protected Member Functions

 setUp ()
 

Protected Attributes

ilComponentDefinitionProcessor $processor1
 
ilComponentDefinitionProcessor $processor2
 

Detailed Description

Definition at line 28 of file ilComponentDefinitionReaderTest.php.

Member Function Documentation

◆ setUp()

ilComponentDefinitionReaderTest::setUp ( )
protected

Definition at line 38 of file ilComponentDefinitionReaderTest.php.

References $components, and $path.

38  : void
39  {
40  $this->processor1 = $this->createMock(ilComponentDefinitionProcessorMock1::class);
41  $this->processor2 = $this->createMock(ilComponentDefinitionProcessorMock2::class);
42 
43  $this->reader = new class ($this->processor1, $this->processor2) extends ilComponentDefinitionReader {
44  protected function getComponents(): Iterator
45  {
47  }
48  public $read_files = [];
49  protected function readFile(string $path): string
50  {
51  $this->read_files[] = $path;
52  if ($path === "/path/to/module.xml") {
53  return
54 '<?xml version = "1.0" encoding = "UTF-8"?>
55 <module a1="a1" a2="a2">
56  <tag1>
57  <tag11></tag11>
58  </tag1>
59  <tag2></tag2>
60 </module>';
61  }
62  if ($path === "/other/path/to/service.xml") {
63  return
64 '<?xml version = "1.0" encoding = "UTF-8"?>
65 <service>
66 </service>';
67  }
68  return "";
69  }
70  };
71  }
ilComponentDefinitionProcessor $processor1
ilComponentDefinitionProcessor $processor2
$path
Definition: ltiservices.php:32

◆ testGetComponents()

ilComponentDefinitionReaderTest::testGetComponents ( )

Definition at line 87 of file ilComponentDefinitionReaderTest.php.

References ILIAS\GlobalScreen\Provider\__construct().

87  : void
88  {
89  $reader = new class () extends ilComponentDefinitionReader {
90  public function __construct()
91  {
92  }
93  public function _getComponents(): array
94  {
95  return iterator_to_array($this->getComponents());
96  }
97  };
98 
99  $components = $reader->_getComponents();
100 
101  $this->assertIsArray($components);
102  $this->assertContains(["Modules", "Course", realpath(__DIR__ . "/../../../Modules/Course/module.xml")], $components);
103  $this->assertContains(["Services", "Component", realpath(__DIR__ . "/../../../Services/Component/service.xml")], $components);
104  }
__construct(Container $dic, ilPlugin $plugin)
+ Here is the call graph for this function:

◆ testPurge()

ilComponentDefinitionReaderTest::testPurge ( )

Definition at line 73 of file ilComponentDefinitionReaderTest.php.

73  : void
74  {
75  $this->processor1
76  ->expects($this->once())
77  ->method("purge")
78  ->with();
79  $this->processor2
80  ->expects($this->once())
81  ->method("purge")
82  ->with();
83 
84  $this->reader->purge();
85  }

◆ testReadComponentDefinitions()

ilComponentDefinitionReaderTest::testReadComponentDefinitions ( )

Definition at line 106 of file ilComponentDefinitionReaderTest.php.

106  : void
107  {
108  $processor1_stack = [];
109  $this->processor1
110  ->method("beginComponent")
111  ->willReturnCallback(function ($s1, $s2) use (&$processor1_stack) {
112  $processor1_stack[] = "beginComponent";
113  $processor1_stack[] = $s1;
114  $processor1_stack[] = $s2;
115  });
116  $this->processor1
117  ->method("endComponent")
118  ->willReturnCallback(function ($s1, $s2) use (&$processor1_stack) {
119  $processor1_stack[] = "endComponent";
120  $processor1_stack[] = $s1;
121  $processor1_stack[] = $s2;
122  });
123  $this->processor1
124  ->method("beginTag")
125  ->willReturnCallback(function ($s1, $s2) use (&$processor1_stack) {
126  $processor1_stack[] = "beginTag";
127  $processor1_stack[] = $s1;
128  $processor1_stack[] = $s2;
129  });
130  $this->processor1
131  ->method("endTag")
132  ->willReturnCallback(function ($s1) use (&$processor1_stack) {
133  $processor1_stack[] = "endTag";
134  $processor1_stack[] = $s1;
135  });
136 
137  $processor2_stack = [];
138  $this->processor2
139  ->method("beginComponent")
140  ->willReturnCallback(function ($s1, $s2) use (&$processor2_stack) {
141  $processor2_stack[] = "beginComponent";
142  $processor2_stack[] = $s1;
143  $processor2_stack[] = $s2;
144  });
145  $this->processor2
146  ->method("endComponent")
147  ->willReturnCallback(function ($s1, $s2) use (&$processor2_stack) {
148  $processor2_stack[] = "endComponent";
149  $processor2_stack[] = $s1;
150  $processor2_stack[] = $s2;
151  });
152  $this->processor2
153  ->method("beginTag")
154  ->willReturnCallback(function ($s1, $s2) use (&$processor2_stack) {
155  $processor2_stack[] = "beginTag";
156  $processor2_stack[] = $s1;
157  $processor2_stack[] = $s2;
158  });
159  $this->processor2
160  ->method("endTag")
161  ->willReturnCallback(function ($s1) use (&$processor2_stack) {
162  $processor2_stack[] = "endTag";
163  $processor2_stack[] = $s1;
164  });
165 
166 
167  $this->reader->readComponentDefinitions();
168 
169 
170  $this->assertEquals([self::$components[0][2], self::$components[1][2]], $this->reader->read_files);
171 
172  $expected_processor_stack = [
173  "beginComponent",
174  self::$components[0][1], // A_Module
175  self::$components[0][0], // Modules
176  "beginTag",
177  "module", ["a1" => "a1", "a2" => "a2"],
178  "beginTag",
179  "tag1", [],
180  "beginTag",
181  "tag11", [],
182  "endTag",
183  "tag11",
184  "endTag",
185  "tag1",
186  "beginTag",
187  "tag2", [],
188  "endTag",
189  "tag2",
190  "endTag",
191  "module",
192  "endComponent",
193  self::$components[0][1], // A_Module
194  self::$components[0][0], // Modules
195  "beginComponent",
196  self::$components[1][1], // A_Service
197  self::$components[1][0], // Services
198  "beginTag",
199  "service", [],
200  "endTag",
201  "service",
202  "endComponent",
203  self::$components[1][1], // A_Service
204  self::$components[1][0], // Services
205  ];
206  $this->assertEquals($expected_processor_stack, $processor1_stack);
207  $this->assertEquals($expected_processor_stack, $processor2_stack);
208  }

Field Documentation

◆ $components

array ilComponentDefinitionReaderTest::$components
static
Initial value:
= [
["Modules", "A_Module", "/path/to/module.xml"],
["Services", "A_Service", "/other/path/to/service.xml"]
]

Definition at line 33 of file ilComponentDefinitionReaderTest.php.

Referenced by setUp().

◆ $processor1

ilComponentDefinitionProcessor ilComponentDefinitionReaderTest::$processor1
protected

Definition at line 30 of file ilComponentDefinitionReaderTest.php.

◆ $processor2

ilComponentDefinitionProcessor ilComponentDefinitionReaderTest::$processor2
protected

Definition at line 31 of file ilComponentDefinitionReaderTest.php.


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