ILIAS  release_7 Revision v7.30-3-g800a261c036
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_rivals ($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 19 of file AbstractFactoryTest.php.

Member Function Documentation

◆ buildFactoryReflection()

AbstractFactoryTest::buildFactoryReflection ( )
final

Definition at line 73 of file AbstractFactoryTest.php.

74 {
75 return new ReflectionClass($this->factory_title);
76 }

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 191 of file AbstractFactoryTest.php.

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

Referenced by test_factory_method_name_compatible_docstring().

+ Here is the caller graph for this function:

◆ isFactoryName()

AbstractFactoryTest::isFactoryName (   $name)
finalprotected

Definition at line 68 of file AbstractFactoryTest.php.

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

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 337 of file AbstractFactoryTest.php.

338 {
339 if (array_key_exists($name, $this->kitchensink_info_settings)) {
340 return array_merge(
341 $this->kitchensink_info_settings_default,
342 $this->kitchensink_info_settings[$name]
343 );
344 } else {
346 }
347 }

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 78 of file AbstractFactoryTest.php.

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

References buildFactoryReflection().

+ Here is the call graph for this function:

◆ returnsComponent()

AbstractFactoryTest::returnsComponent (   $docstring_data)
finalprotected

Definition at line 62 of file AbstractFactoryTest.php.

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

Referenced by test_return_type().

+ Here is the caller graph for this function:

◆ returnsFactory()

AbstractFactoryTest::returnsFactory (   $docstring_data)
finalprotected

Definition at line 57 of file AbstractFactoryTest.php.

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

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 88 of file AbstractFactoryTest.php.

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

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 119 of file AbstractFactoryTest.php.

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

References Vendor\Package\$e, and $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_rivals(), 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 159 of file AbstractFactoryTest.php.

160 {
161 $docstring_data = $this->test_check_yaml_extraction($method_reflection, $name);
162 $this->test_return_type($method_reflection, $name);
163
164 $return_doc = $docstring_data["namespace"];
165 $name_uppercase = ucwords($name);
166 $regex_factory_namespace = $this->get_regex_factory_namespace();
167 $regex_head = "#^(\\\\?)$regex_factory_namespace";
168
169 $message = "TODO ($name): fix @return, it does not match the method name.";
170 if ($this->returnsFactory($docstring_data)) {
171 $this->assertMatchesRegularExpression(
172 "$regex_head\\\\$name_uppercase\\\\Factory$#",
173 $return_doc,
175 );
176 } else { // returnsComponent
177 // Every component MUST be described by a single interface, where the name of
178 // the interface corresponds to the name of the component.
179 $standard_pattern = "$regex_head\\\\$name_uppercase#";
180 $standard_case = preg_match($standard_pattern, $return_doc);
181
182 // unless they only differ in a type and share a common prefix to their pathes.
183 $namespace_parts = explode("\\", $this->reflection->getNamespaceName());
184 $typediff_only_pattern = "$regex_head\\\\" . array_pop($namespace_parts) . "#";
185 $typediff_only_case = preg_match($typediff_only_pattern, $return_doc);
186
187 $this->assertTrue($standard_case || $typediff_only_case, $message);
188 }
189 }
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 254 of file AbstractFactoryTest.php.

255 {
256 $docstring_data = $this->test_check_yaml_extraction($method_reflection, $name);
257 $kitchensink_info_settings = $this->kitchensink_info_settings_merged_with_defaults($name);
258
259 if ($kitchensink_info_settings['background']) {
260 $message = "TODO ($name): add a background field.";
261 $this->assertArrayHasKey('background', $docstring_data, $message);
262 }
263 }
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 320 of file AbstractFactoryTest.php.

321 {
322 $docstring_data = $this->test_check_yaml_extraction($method_reflection, $name);
323 $kitchensink_info_settings = $this->kitchensink_info_settings_merged_with_defaults($name);
324
325 // Special rules for factory methods:
326 if ($this->returnsFactory($docstring_data)) {
327 $message = "TODO ($name): remove 'context' field, method returns a factory.";
328 $this->assertArrayNotHasKey("context", $docstring_data, $message);
329 } else { // returnsComponent
330 if ($kitchensink_info_settings["context"]) {
331 $message = "TODO ($name): factory method returning component should have context field. Add it.";
332 $this->assertArrayHasKey("context", $docstring_data, $message);
333 }
334 }
335 }

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 216 of file AbstractFactoryTest.php.

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

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 268 of file AbstractFactoryTest.php.

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

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 282 of file AbstractFactoryTest.php.

283 {
284 $docstring_data = $this->test_check_yaml_extraction($method_reflection, $name);
285 $kitchensink_info_settings = $this->kitchensink_info_settings_merged_with_defaults($name);
286
287 if ($kitchensink_info_settings['javascript']) {
288 $message = "TODO ($name): add a javascript field.";
289 $this->assertArrayHasKey('javascript', $docstring_data, $message);
290 }
291 }

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_rivals()

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

@dataProvider methods_provider

Definition at line 240 of file AbstractFactoryTest.php.

241 {
242 $docstring_data = $this->test_check_yaml_extraction($method_reflection, $name);
243 if (isset($docstring_data["description"]) && isset($docstring_data["description"]["rivals"])) {
244 $rules = $docstring_data["description"]["rivals"];
245 $message = "TODO ($name): The Rivals field has a non-string index. Format like 'rival_name': 'description'";
246 $this->assertTrue(array_unique(array_map("is_string", array_keys($rules))) === array(true), $message);
247 }
248 $this->assertTrue(true);
249 }

References $message, $name, 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 296 of file AbstractFactoryTest.php.

297 {
298 $docstring_data = $this->test_check_yaml_extraction($method_reflection, $name);
299 $kitchensink_info_settings = $this->kitchensink_info_settings_merged_with_defaults($name);
300
301 if ($kitchensink_info_settings['rules']) {
302 $message = "TODO ($name): add a rules field.";
303 $this->assertArrayHasKey('rules', $docstring_data, $message);
304
305 $rules_fields = implode(", ", $this->rules_categories);
306 $message = "TODO ($name): the rules field should at least contain one of these: $rules_fields.";
307 $existing_keys = array_keys($docstring_data["rules"]);
308 $existing_expected_keys = array_intersect($this->rules_categories, $existing_keys);
309 $this->assertGreaterThanOrEqual(
310 1,
311 $existing_expected_keys,
313 );
314 }
315 }

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 201 of file AbstractFactoryTest.php.

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

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 104 of file AbstractFactoryTest.php.

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

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 94 of file AbstractFactoryTest.php.

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

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 141 of file AbstractFactoryTest.php.

142 {
143 $message = "TODO ($name): fix return type, it must be a factory or a component.";
144 $docstring_data = $this->test_check_yaml_extraction($method_reflection, $name);
145 if ($this->returnsFactory($docstring_data)) {
146 $this->assertTrue(true);
147 } elseif ($this->returnsComponent($docstring_data)) {
148 $this->assertTrue(true);
149 } else {
150 $this->assertTrue(false, $message);
151 }
152 }
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 50 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 29 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 53 of file AbstractFactoryTest.php.

◆ COMPONENT

const AbstractFactoryTest::COMPONENT = 1

Definition at line 21 of file AbstractFactoryTest.php.

◆ FACTORY

const AbstractFactoryTest::FACTORY = 2

Definition at line 22 of file AbstractFactoryTest.php.


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