ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 68 of file AbstractFactoryTest.php.

68 {
69 return new ReflectionClass($this->factory_title);
70 }

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

181 {
182 return str_replace("\\", "\\\\", $this->reflection->getNamespaceName());
183 }

Referenced by test_factory_method_name_compatible_docstring().

+ Here is the caller graph for this function:

◆ isFactoryName()

AbstractFactoryTest::isFactoryName (   $name)
finalprotected

Definition at line 64 of file AbstractFactoryTest.php.

64 {
65 return preg_match("#^(\\\\)?ILIAS\\\\UI\\\\Component\\\\([a-zA-Z]+\\\\)*Factory$#", $name) === 1;
66 }

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

306 {
307 if (array_key_exists($name, $this->kitchensink_info_settings)) {
308 return array_merge
309 ( $this->kitchensink_info_settings_default
310 , $this->kitchensink_info_settings[$name]
311 );
312 }
313 else {
315 }
316 }

References $kitchensink_info_settings_default.

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

72 {
73 $reflection = $this->buildFactoryReflection();
74 return array_map(function($element) {
75 return array($element, $element->getName());
76 }, $reflection->getMethods());
77 }

References buildFactoryReflection().

+ Here is the call graph for this function:

◆ returnsComponent()

AbstractFactoryTest::returnsComponent (   $docstring_data)
finalprotected

Definition at line 59 of file AbstractFactoryTest.php.

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

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.

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

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

81 {
82 $this->yaml_parser = new Crawler\EntriesYamlParser();
83 $this->reflection = $this->buildFactoryReflection();
84 }

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

109 {
110 try {
111 //Todo (TA) this is not pretty. We should think about using only reflection in the parser as well.
112 $function_name_string = "\n public function ".$method_reflection->getName()."()";
113 $docstring_data = $this->yaml_parser->parseArrayFromString(
114 $method_reflection->getDocComment().$function_name_string);
115 $this->assertTrue(true);
116 }
118 $message = "TODO ($name): fix parse error in kitchen sink yaml: ".$e->getMessage();
119 $this->assertTrue(false, $message);
120 }
121 $this->assertCount(1, $docstring_data);
122 return $docstring_data[0];
123 }

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

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

227 {
228 $docstring_data = $this->test_check_yaml_extraction($method_reflection, $name);
229 $kitchensink_info_settings = $this->kitchensink_info_settings_merged_with_defaults($name);
230
231 if($kitchensink_info_settings['background']) {
232 $message = "TODO ($name): add a background field.";
233 $this->assertArrayHasKey('background', $docstring_data, $message);
234 }
235 }
kitchensink_info_settings_merged_with_defaults($name)

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

289 {
290 $docstring_data = $this->test_check_yaml_extraction($method_reflection, $name);
291 $kitchensink_info_settings = $this->kitchensink_info_settings_merged_with_defaults($name);
292
293 // Special rules for factory methods:
294 if ($this->returnsFactory($docstring_data)) {
295 $message = "TODO ($name): remove 'context' field, method returns a factory.";
296 $this->assertArrayNotHasKey("context", $docstring_data, $message);
297 }
298 else { // returnsComponent
299 if ($kitchensink_info_settings["context"]) {
300 $message = "TODO ($name): factory method returning component should have context field. Add it.";
301 $this->assertArrayHasKey("context", $docstring_data, $message);
302 }
303 }
304 }

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

204 {
205 $docstring_data = $this->test_check_yaml_extraction($method_reflection, $name);
206 $kitchensink_info_settings = $this->kitchensink_info_settings_merged_with_defaults($name);
207
208 if($kitchensink_info_settings['description']) {
209 $message = "TODO ($name): add a description.";
210 $this->assertArrayHasKey('description', $docstring_data, $message);
211
212 $desc_fields = implode(", ", $this->description_categories);
213 $message = "TODO ($name): the description field should at least contain one of these: $desc_fields.";
214 $existing_keys = array_keys($docstring_data["description"]);
215 $existing_expected_keys = array_intersect($this->description_categories, $existing_keys);
216 $this->assertGreaterThanOrEqual
217 ( 1
218 , $existing_expected_keys
219 , $message
220 );
221 }
222 }

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

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

References 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 253 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['javascript']) {
258 $message = "TODO ($name): add a javascript field.";
259 $this->assertArrayHasKey('javascript' ,$docstring_data, $message);
260 }
261 }

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

266 {
267 $docstring_data = $this->test_check_yaml_extraction($method_reflection, $name);
268 $kitchensink_info_settings = $this->kitchensink_info_settings_merged_with_defaults($name);
269
270 if($kitchensink_info_settings['rules']) {
271 $message = "TODO ($name): add a rules field.";
272 $this->assertArrayHasKey('rules', $docstring_data, $message);
273
274 $rules_fields = implode(", ", $this->rules_categories);
275 $message = "TODO ($name): the rules field should at least contain one of these: $rules_fields.";
276 $existing_keys = array_keys($docstring_data["rules"]);
277 $existing_expected_keys = array_intersect($this->rules_categories, $existing_keys);
278 $this->assertGreaterThanOrEqual
279 ( 1
280 , $existing_expected_keys
281 , $message
282 );
283 }
284 }

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

190 {
191 $docstring_data = $this->test_check_yaml_extraction($method_reflection, $name);
192 if($this->returnsFactory($docstring_data)) {
193 $message = "TODO ($name): remove params from method that returns Factory.";
194 $this->assertEquals(0, $method_reflection->getNumberOfParameters(), $message);
195 }
196 }

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

95 {
96 $name = $this->reflection->getName();
97 $message = "TODO: Give your factory a proper name.";
98 $this->assertTrue
99 ( $this->isFactoryName($name)
100 , $message
101 );
102 }

References isFactoryName().

+ Here is the call graph for this function:

◆ test_proper_namespace()

AbstractFactoryTest::test_proper_namespace ( )

Reimplemented in MainFactoryTest.

Definition at line 86 of file AbstractFactoryTest.php.

86 {
87 $message = "TODO: Put your factory into the proper namespace.";
88 $this->assertRegExp
89 ( "#^ILIAS\\\\UI\\\\Component.#"
90 , $this->reflection->getNamespaceName()
91 , $message
92 );
93 }

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

130 {
131 $message = "TODO ($name): fix return type, it must be a factory or a component.";
132 $docstring_data = $this->test_check_yaml_extraction($method_reflection, $name);
133 if ($this->returnsFactory($docstring_data)) {
134 $this->assertTrue(true);
135 }
136 elseif ($this->returnsComponent($docstring_data)) {
137 $this->assertTrue(true);
138 }
139 else {
140 $this->assertTrue(false, $message);
141 }
142 }
returnsComponent($docstring_data)

References 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: