ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
AbstractFactoryTest Class Reference

Defines tests every SHOULD pass UI-factory. More...

+ Inheritance diagram for AbstractFactoryTest:
+ Collaboration diagram for AbstractFactoryTest:

Public Member Functions

 buildFactoryReflection ()
 
 methods_provider ()
 
 setUp ()
 
 test_proper_namespace ()
 
 test_proper_name ()
 
 test_check_yaml_extraction ($method_reflection, $name)
 Tests whether the YAML Kitchen Sink info can be parsed. More...
 
 test_return_type ($method_reflection, $name)
 Tests whether the method either returns a factory or a component. More...
 
 test_factory_method_name_compatible_docstring ($method_reflection, $name)
 Tests whether the method name matches the. More...
 
 test_method_params ($method_reflection, $name)
 Tests whether methods returning factories have no parameters. More...
 
 test_kitchensink_info_description ($method_reflection, $name)
 @dataProvider methods_provider More...
 
 test_kitchensink_info_background ($method_reflection, $name)
 @dataProvider methods_provider More...
 
 test_kitchensink_info_featurewiki ($method_reflection, $name)
 @dataProvider methods_provider More...
 
 test_kitchensink_info_javascript ($method_reflection, $name)
 @dataProvider methods_provider More...
 
 test_kitchensink_info_rules ($method_reflection, $name)
 @dataProvider methods_provider More...
 
 test_kitchensink_info_context ($method_reflection, $name)
 @dataProvider methods_provider More...
 
 kitchensink_info_settings_merged_with_defaults ($name)
 

Data Fields

const COMPONENT = 1
 
const FACTORY = 2
 

Protected Member Functions

 returnsFactory ($docstring_data)
 
 returnsComponent ($docstring_data)
 
 isFactoryName ($name)
 
 get_regex_factory_namespace ()
 

Private Attributes

 $kitchensink_info_settings_default
 
 $description_categories
 
 $rules_categories
 

Detailed Description

Defines tests every SHOULD pass UI-factory.

Checks as much rules as possible from the 'Interfaces to Factories' part of the UI framework rules.

TODO: This test heavily relies on data providers and dependencies. PHPUnit does not support dependencies per provided data set via @depends, therefore the test express the dependencies explicitly by calling subsequent testing methods. These leads to test methods being executed to often.

Definition at line 17 of file AbstractFactoryTest.php.

Member Function Documentation

◆ buildFactoryReflection()

AbstractFactoryTest::buildFactoryReflection ( )
final

Definition at line 71 of file AbstractFactoryTest.php.

72 {
73 return new ReflectionClass($this->factory_title);
74 }

Referenced by methods_provider(), and setUp().

+ Here is the caller graph for this function:

◆ get_regex_factory_namespace()

AbstractFactoryTest::get_regex_factory_namespace ( )
protected

Reimplemented in MainFactoryTest.

Definition at line 189 of file AbstractFactoryTest.php.

190 {
191 return str_replace("\\", "\\\\", $this->reflection->getNamespaceName());
192 }

Referenced by test_factory_method_name_compatible_docstring().

+ Here is the caller graph for this function:

◆ isFactoryName()

AbstractFactoryTest::isFactoryName (   $name)
finalprotected

Definition at line 66 of file AbstractFactoryTest.php.

67 {
68 return preg_match("#^(\\\\)?ILIAS\\\\UI\\\\Component\\\\([a-zA-Z]+\\\\)*Factory$#", $name) === 1;
69 }
if($format !==null) $name
Definition: metadata.php:146

References $name.

Referenced by returnsFactory(), and test_proper_name().

+ Here is the caller graph for this function:

◆ kitchensink_info_settings_merged_with_defaults()

AbstractFactoryTest::kitchensink_info_settings_merged_with_defaults (   $name)
final

Definition at line 321 of file AbstractFactoryTest.php.

322 {
323 if (array_key_exists($name, $this->kitchensink_info_settings)) {
324 return array_merge(
325 $this->kitchensink_info_settings_default,
326 $this->kitchensink_info_settings[$name]
327 );
328 } else {
330 }
331 }

References $kitchensink_info_settings_default, and $name.

Referenced by test_kitchensink_info_background(), test_kitchensink_info_context(), test_kitchensink_info_description(), test_kitchensink_info_featurewiki(), test_kitchensink_info_javascript(), and test_kitchensink_info_rules().

+ Here is the caller graph for this function:

◆ methods_provider()

AbstractFactoryTest::methods_provider ( )
final

Definition at line 76 of file AbstractFactoryTest.php.

77 {
78 $reflection = $this->buildFactoryReflection();
79 return array_map(function ($element) {
80 return array($element, $element->getName());
81 }, $reflection->getMethods());
82 }

References buildFactoryReflection().

+ Here is the call graph for this function:

◆ returnsComponent()

AbstractFactoryTest::returnsComponent (   $docstring_data)
finalprotected

Definition at line 60 of file AbstractFactoryTest.php.

61 {
62 $reflection = new ReflectionClass($docstring_data["namespace"]);
63 return in_array("ILIAS\\UI\\Component\\Component", $reflection->getInterfaceNames());
64 }

Referenced by test_return_type().

+ Here is the caller graph for this function:

◆ returnsFactory()

AbstractFactoryTest::returnsFactory (   $docstring_data)
finalprotected

Definition at line 55 of file AbstractFactoryTest.php.

56 {
57 return $this->isFactoryName($docstring_data["namespace"]);
58 }

References isFactoryName().

Referenced by test_factory_method_name_compatible_docstring(), test_kitchensink_info_context(), test_method_params(), and test_return_type().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setUp()

AbstractFactoryTest::setUp ( )

Definition at line 86 of file AbstractFactoryTest.php.

87 {
88 $this->yaml_parser = new Crawler\EntriesYamlParser();
89 $this->reflection = $this->buildFactoryReflection();
90 }

References buildFactoryReflection().

+ Here is the call graph for this function:

◆ test_check_yaml_extraction()

AbstractFactoryTest::test_check_yaml_extraction (   $method_reflection,
  $name 
)
final

Tests whether the YAML Kitchen Sink info can be parsed.

@dataProvider methods_provider

Definition at line 117 of file AbstractFactoryTest.php.

118 {
119 try {
120 //Todo (TA) this is not pretty. We should think about using only reflection in the parser as well.
121 $function_name_string = "\n public function " . $method_reflection->getName() . "()";
122 $docstring_data = $this->yaml_parser->parseArrayFromString(
123 $method_reflection->getDocComment() . $function_name_string
124 );
125 $this->assertTrue(true);
127 $message = "TODO ($name): fix parse error in kitchen sink yaml: " . $e->getMessage();
128 $this->assertTrue(false, $message);
129 }
130 $this->assertCount(1, $docstring_data);
131 return $docstring_data[0];
132 }
catch(Exception $e) $message

References $message.

Referenced by test_factory_method_name_compatible_docstring(), test_kitchensink_info_background(), test_kitchensink_info_context(), test_kitchensink_info_description(), test_kitchensink_info_featurewiki(), test_kitchensink_info_javascript(), test_kitchensink_info_rules(), test_method_params(), and test_return_type().

+ Here is the caller graph for this function:

◆ test_factory_method_name_compatible_docstring()

AbstractFactoryTest::test_factory_method_name_compatible_docstring (   $method_reflection,
  $name 
)
final

Tests whether the method name matches the.

Returns
doctring?

@dataProvider methods_provider

Definition at line 157 of file AbstractFactoryTest.php.

158 {
159 $docstring_data = $this->test_check_yaml_extraction($method_reflection, $name);
160 $this->test_return_type($method_reflection, $name);
161
162 $return_doc = $docstring_data["namespace"];
163 $name_uppercase = ucwords($name);
164 $regex_factory_namespace = $this->get_regex_factory_namespace();
165 $regex_head = "#^(\\\\?)$regex_factory_namespace";
166
167 $message = "TODO ($name): fix @return, it does not match the method name.";
168 if ($this->returnsFactory($docstring_data)) {
169 $this->assertRegExp(
170 "$regex_head\\\\$name_uppercase\\\\Factory$#",
171 $return_doc,
173 );
174 } else { // returnsComponent
175 // Every component MUST be described by a single interface, where the name of
176 // the interface corresponds to the name of the component.
177 $standard_pattern = "$regex_head\\\\$name_uppercase#";
178 $standard_case = preg_match($standard_pattern, $return_doc);
179
180 // unless they only differ in a type and share a common prefix to their pathes.
181 $namespace_parts = explode("\\", $this->reflection->getNamespaceName());
182 $typediff_only_pattern = "$regex_head\\\\" . array_pop($namespace_parts) . "#";
183 $typediff_only_case = preg_match($typediff_only_pattern, $return_doc);
184
185 $this->assertTrue($standard_case || $typediff_only_case, $message);
186 }
187 }
test_return_type($method_reflection, $name)
Tests whether the method either returns a factory or a component.
returnsFactory($docstring_data)
test_check_yaml_extraction($method_reflection, $name)
Tests whether the YAML Kitchen Sink info can be parsed.

References $message, $name, get_regex_factory_namespace(), returnsFactory(), test_check_yaml_extraction(), and test_return_type().

+ Here is the call graph for this function:

◆ test_kitchensink_info_background()

AbstractFactoryTest::test_kitchensink_info_background (   $method_reflection,
  $name 
)
final

@dataProvider methods_provider

Definition at line 238 of file AbstractFactoryTest.php.

239 {
240 $docstring_data = $this->test_check_yaml_extraction($method_reflection, $name);
241 $kitchensink_info_settings = $this->kitchensink_info_settings_merged_with_defaults($name);
242
243 if ($kitchensink_info_settings['background']) {
244 $message = "TODO ($name): add a background field.";
245 $this->assertArrayHasKey('background', $docstring_data, $message);
246 }
247 }
kitchensink_info_settings_merged_with_defaults($name)

References $message, $name, kitchensink_info_settings_merged_with_defaults(), and test_check_yaml_extraction().

+ Here is the call graph for this function:

◆ test_kitchensink_info_context()

AbstractFactoryTest::test_kitchensink_info_context (   $method_reflection,
  $name 
)
final

@dataProvider methods_provider

Definition at line 304 of file AbstractFactoryTest.php.

305 {
306 $docstring_data = $this->test_check_yaml_extraction($method_reflection, $name);
307 $kitchensink_info_settings = $this->kitchensink_info_settings_merged_with_defaults($name);
308
309 // Special rules for factory methods:
310 if ($this->returnsFactory($docstring_data)) {
311 $message = "TODO ($name): remove 'context' field, method returns a factory.";
312 $this->assertArrayNotHasKey("context", $docstring_data, $message);
313 } else { // returnsComponent
314 if ($kitchensink_info_settings["context"]) {
315 $message = "TODO ($name): factory method returning component should have context field. Add it.";
316 $this->assertArrayHasKey("context", $docstring_data, $message);
317 }
318 }
319 }

References $message, $name, kitchensink_info_settings_merged_with_defaults(), returnsFactory(), and test_check_yaml_extraction().

+ Here is the call graph for this function:

◆ test_kitchensink_info_description()

AbstractFactoryTest::test_kitchensink_info_description (   $method_reflection,
  $name 
)
final

@dataProvider methods_provider

Definition at line 214 of file AbstractFactoryTest.php.

215 {
216 $docstring_data = $this->test_check_yaml_extraction($method_reflection, $name);
217 $kitchensink_info_settings = $this->kitchensink_info_settings_merged_with_defaults($name);
218
219 if ($kitchensink_info_settings['description']) {
220 $message = "TODO ($name): add a description.";
221 $this->assertArrayHasKey('description', $docstring_data, $message);
222
223 $desc_fields = implode(", ", $this->description_categories);
224 $message = "TODO ($name): the description field should at least contain one of these: $desc_fields.";
225 $existing_keys = array_keys($docstring_data["description"]);
226 $existing_expected_keys = array_intersect($this->description_categories, $existing_keys);
227 $this->assertGreaterThanOrEqual(
228 1,
229 $existing_expected_keys,
231 );
232 }
233 }

References $message, $name, kitchensink_info_settings_merged_with_defaults(), and test_check_yaml_extraction().

+ Here is the call graph for this function:

◆ test_kitchensink_info_featurewiki()

AbstractFactoryTest::test_kitchensink_info_featurewiki (   $method_reflection,
  $name 
)
final

@dataProvider methods_provider

Definition at line 252 of file AbstractFactoryTest.php.

253 {
254 $docstring_data = $this->test_check_yaml_extraction($method_reflection, $name);
255 $kitchensink_info_settings = $this->kitchensink_info_settings_merged_with_defaults($name);
256
257 if ($kitchensink_info_settings['featurewiki']) {
258 $message = "TODO ($name): add a featurewiki field.";
259 $this->assertArrayHasKey('featurewiki', $docstring_data, $message);
260 }
261 }

References $message, $name, kitchensink_info_settings_merged_with_defaults(), and test_check_yaml_extraction().

+ Here is the call graph for this function:

◆ test_kitchensink_info_javascript()

AbstractFactoryTest::test_kitchensink_info_javascript (   $method_reflection,
  $name 
)
final

@dataProvider methods_provider

Definition at line 266 of file AbstractFactoryTest.php.

267 {
268 $docstring_data = $this->test_check_yaml_extraction($method_reflection, $name);
269 $kitchensink_info_settings = $this->kitchensink_info_settings_merged_with_defaults($name);
270
271 if ($kitchensink_info_settings['javascript']) {
272 $message = "TODO ($name): add a javascript field.";
273 $this->assertArrayHasKey('javascript', $docstring_data, $message);
274 }
275 }

References $message, $name, kitchensink_info_settings_merged_with_defaults(), and test_check_yaml_extraction().

+ Here is the call graph for this function:

◆ test_kitchensink_info_rules()

AbstractFactoryTest::test_kitchensink_info_rules (   $method_reflection,
  $name 
)
final

@dataProvider methods_provider

Definition at line 280 of file AbstractFactoryTest.php.

281 {
282 $docstring_data = $this->test_check_yaml_extraction($method_reflection, $name);
283 $kitchensink_info_settings = $this->kitchensink_info_settings_merged_with_defaults($name);
284
285 if ($kitchensink_info_settings['rules']) {
286 $message = "TODO ($name): add a rules field.";
287 $this->assertArrayHasKey('rules', $docstring_data, $message);
288
289 $rules_fields = implode(", ", $this->rules_categories);
290 $message = "TODO ($name): the rules field should at least contain one of these: $rules_fields.";
291 $existing_keys = array_keys($docstring_data["rules"]);
292 $existing_expected_keys = array_intersect($this->rules_categories, $existing_keys);
293 $this->assertGreaterThanOrEqual(
294 1,
295 $existing_expected_keys,
297 );
298 }
299 }

References $message, $name, kitchensink_info_settings_merged_with_defaults(), and test_check_yaml_extraction().

+ Here is the call graph for this function:

◆ test_method_params()

AbstractFactoryTest::test_method_params (   $method_reflection,
  $name 
)
final

Tests whether methods returning factories have no parameters.

@dataProvider methods_provider

Definition at line 199 of file AbstractFactoryTest.php.

200 {
201 $docstring_data = $this->test_check_yaml_extraction($method_reflection, $name);
202 if ($this->returnsFactory($docstring_data)) {
203 $message = "TODO ($name): remove params from method that returns Factory.";
204 $this->assertEquals(0, $method_reflection->getNumberOfParameters(), $message);
205 }
206 }

References $message, $name, returnsFactory(), and test_check_yaml_extraction().

+ Here is the call graph for this function:

◆ test_proper_name()

AbstractFactoryTest::test_proper_name ( )

Reimplemented in MainFactoryTest.

Definition at line 102 of file AbstractFactoryTest.php.

103 {
104 $name = $this->reflection->getName();
105 $message = "TODO: Give your factory a proper name.";
106 $this->assertTrue(
107 $this->isFactoryName($name),
109 );
110 }

References $message, $name, and isFactoryName().

+ Here is the call graph for this function:

◆ test_proper_namespace()

AbstractFactoryTest::test_proper_namespace ( )

Reimplemented in MainFactoryTest.

Definition at line 92 of file AbstractFactoryTest.php.

93 {
94 $message = "TODO: Put your factory into the proper namespace.";
95 $this->assertRegExp(
96 "#^ILIAS\\\\UI\\\\Component.#",
97 $this->reflection->getNamespaceName(),
99 );
100 }

References $message.

◆ test_return_type()

AbstractFactoryTest::test_return_type (   $method_reflection,
  $name 
)
final

Tests whether the method either returns a factory or a component.

@dataProvider methods_provider

Definition at line 139 of file AbstractFactoryTest.php.

140 {
141 $message = "TODO ($name): fix return type, it must be a factory or a component.";
142 $docstring_data = $this->test_check_yaml_extraction($method_reflection, $name);
143 if ($this->returnsFactory($docstring_data)) {
144 $this->assertTrue(true);
145 } elseif ($this->returnsComponent($docstring_data)) {
146 $this->assertTrue(true);
147 } else {
148 $this->assertTrue(false, $message);
149 }
150 }
returnsComponent($docstring_data)

References $message, $name, returnsComponent(), returnsFactory(), and test_check_yaml_extraction().

Referenced by test_factory_method_name_compatible_docstring().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $description_categories

AbstractFactoryTest::$description_categories
private
Initial value:
=
array('purpose', 'composition', 'effect', 'rival')

Definition at line 48 of file AbstractFactoryTest.php.

◆ $kitchensink_info_settings_default

AbstractFactoryTest::$kitchensink_info_settings_default
private
Initial value:
= array('description'
=> true
,'background'
=> false
,'context'
=> true
,'featurewiki'
=> false
,'javascript'
=> false
,'rules'
=> true)

Definition at line 27 of file AbstractFactoryTest.php.

Referenced by kitchensink_info_settings_merged_with_defaults().

◆ $rules_categories

AbstractFactoryTest::$rules_categories
private
Initial value:
=
array('usage', 'interaction', 'wording', 'style', 'ordering', 'responsiveness',
'composition','accessibility')

Definition at line 51 of file AbstractFactoryTest.php.

◆ COMPONENT

const AbstractFactoryTest::COMPONENT = 1

Definition at line 19 of file AbstractFactoryTest.php.

◆ FACTORY

const AbstractFactoryTest::FACTORY = 2

Definition at line 20 of file AbstractFactoryTest.php.


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