ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
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
 
ilComponentDefinitionReader $reader
 

Detailed Description

Definition at line 29 of file ilComponentDefinitionReaderTest.php.

Member Function Documentation

◆ setUp()

ilComponentDefinitionReaderTest::setUp ( )
protected

Definition at line 40 of file ilComponentDefinitionReaderTest.php.

References $components, and $path.

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

◆ testGetComponents()

ilComponentDefinitionReaderTest::testGetComponents ( )

Definition at line 89 of file ilComponentDefinitionReaderTest.php.

References ILIAS\GlobalScreen\Provider\__construct().

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

◆ testPurge()

ilComponentDefinitionReaderTest::testPurge ( )

Definition at line 75 of file ilComponentDefinitionReaderTest.php.

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

◆ testReadComponentDefinitions()

ilComponentDefinitionReaderTest::testReadComponentDefinitions ( )

Definition at line 108 of file ilComponentDefinitionReaderTest.php.

References $components.

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

Field Documentation

◆ $components

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

Definition at line 35 of file ilComponentDefinitionReaderTest.php.

Referenced by setUp().

◆ $processor1

ilComponentDefinitionProcessor ilComponentDefinitionReaderTest::$processor1
protected

Definition at line 31 of file ilComponentDefinitionReaderTest.php.

◆ $processor2

ilComponentDefinitionProcessor ilComponentDefinitionReaderTest::$processor2
protected

Definition at line 32 of file ilComponentDefinitionReaderTest.php.

◆ $reader

ilComponentDefinitionReader ilComponentDefinitionReaderTest::$reader
protected

Definition at line 33 of file ilComponentDefinitionReaderTest.php.


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