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)
 methods_provider More...
 
 test_kitchensink_info_background ($method_reflection, $name)
 methods_provider More...
 
 test_kitchensink_info_featurewiki ($method_reflection, $name)
 methods_provider More...
 
 test_kitchensink_info_javascript ($method_reflection, $name)
 methods_provider More...
 
 test_kitchensink_info_rules ($method_reflection, $name)
 methods_provider More...
 
 test_kitchensink_info_context ($method_reflection, $name)
 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 , 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.

Referenced by methods_provider(), and setUp().

72  {
73  return new ReflectionClass($this->factory_title);
74  }
+ Here is the caller graph for this function:

◆ get_regex_factory_namespace()

AbstractFactoryTest::get_regex_factory_namespace ( )
protected

Definition at line 189 of file AbstractFactoryTest.php.

Referenced by test_factory_method_name_compatible_docstring().

190  {
191  return str_replace("\\", "\\\\", $this->reflection->getNamespaceName());
192  }
+ Here is the caller graph for this function:

◆ isFactoryName()

AbstractFactoryTest::isFactoryName (   $name)
finalprotected

Definition at line 66 of file AbstractFactoryTest.php.

References $name.

Referenced by returnsFactory(), and test_proper_name().

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

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

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  }
if($format !==null) $name
Definition: metadata.php:146
+ Here is the caller graph for this function:

◆ methods_provider()

AbstractFactoryTest::methods_provider ( )
final

Definition at line 76 of file AbstractFactoryTest.php.

References array, and buildFactoryReflection().

77  {
78  $reflection = $this->buildFactoryReflection();
79  return array_map(function ($element) {
80  return array($element, $element->getName());
81  }, $reflection->getMethods());
82  }
Create styles array
The data for the language used.
+ Here is the call graph for this function:

◆ returnsComponent()

AbstractFactoryTest::returnsComponent (   $docstring_data)
finalprotected

Definition at line 60 of file AbstractFactoryTest.php.

Referenced by test_return_type().

61  {
62  $reflection = new ReflectionClass($docstring_data["namespace"]);
63  return in_array("ILIAS\\UI\\Component\\Component", $reflection->getInterfaceNames());
64  }
+ Here is the caller graph for this function:

◆ returnsFactory()

AbstractFactoryTest::returnsFactory (   $docstring_data)
finalprotected

Definition at line 55 of file AbstractFactoryTest.php.

References isFactoryName().

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

56  {
57  return $this->isFactoryName($docstring_data["namespace"]);
58  }
+ 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.

References buildFactoryReflection().

87  {
88  $this->yaml_parser = new Crawler\EntriesYamlParser();
89  $this->reflection = $this->buildFactoryReflection();
90  }
+ 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.

methods_provider

Definition at line 117 of file AbstractFactoryTest.php.

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

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);
126  } catch (CrawlerException\CrawlerException $e) {
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
+ 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?

methods_provider

Definition at line 157 of file AbstractFactoryTest.php.

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

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,
172  $message
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.
test_check_yaml_extraction($method_reflection, $name)
Tests whether the YAML Kitchen Sink info can be parsed.
returnsFactory($docstring_data)
if($format !==null) $name
Definition: metadata.php:146
catch(Exception $e) $message
+ Here is the call graph for this function:

◆ test_kitchensink_info_background()

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

methods_provider

Definition at line 238 of file AbstractFactoryTest.php.

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

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  }
test_check_yaml_extraction($method_reflection, $name)
Tests whether the YAML Kitchen Sink info can be parsed.
if($format !==null) $name
Definition: metadata.php:146
catch(Exception $e) $message
kitchensink_info_settings_merged_with_defaults($name)
+ Here is the call graph for this function:

◆ test_kitchensink_info_context()

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

methods_provider

Definition at line 304 of file AbstractFactoryTest.php.

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

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  }
test_check_yaml_extraction($method_reflection, $name)
Tests whether the YAML Kitchen Sink info can be parsed.
returnsFactory($docstring_data)
if($format !==null) $name
Definition: metadata.php:146
catch(Exception $e) $message
kitchensink_info_settings_merged_with_defaults($name)
+ Here is the call graph for this function:

◆ test_kitchensink_info_description()

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

methods_provider

Definition at line 214 of file AbstractFactoryTest.php.

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

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,
230  $message
231  );
232  }
233  }
test_check_yaml_extraction($method_reflection, $name)
Tests whether the YAML Kitchen Sink info can be parsed.
if($format !==null) $name
Definition: metadata.php:146
catch(Exception $e) $message
kitchensink_info_settings_merged_with_defaults($name)
+ Here is the call graph for this function:

◆ test_kitchensink_info_featurewiki()

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

methods_provider

Definition at line 252 of file AbstractFactoryTest.php.

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

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  }
test_check_yaml_extraction($method_reflection, $name)
Tests whether the YAML Kitchen Sink info can be parsed.
if($format !==null) $name
Definition: metadata.php:146
catch(Exception $e) $message
kitchensink_info_settings_merged_with_defaults($name)
+ Here is the call graph for this function:

◆ test_kitchensink_info_javascript()

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

methods_provider

Definition at line 266 of file AbstractFactoryTest.php.

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

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  }
test_check_yaml_extraction($method_reflection, $name)
Tests whether the YAML Kitchen Sink info can be parsed.
if($format !==null) $name
Definition: metadata.php:146
catch(Exception $e) $message
kitchensink_info_settings_merged_with_defaults($name)
+ Here is the call graph for this function:

◆ test_kitchensink_info_rules()

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

methods_provider

Definition at line 280 of file AbstractFactoryTest.php.

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

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,
296  $message
297  );
298  }
299  }
test_check_yaml_extraction($method_reflection, $name)
Tests whether the YAML Kitchen Sink info can be parsed.
if($format !==null) $name
Definition: metadata.php:146
catch(Exception $e) $message
kitchensink_info_settings_merged_with_defaults($name)
+ 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.

methods_provider

Definition at line 199 of file AbstractFactoryTest.php.

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

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  }
test_check_yaml_extraction($method_reflection, $name)
Tests whether the YAML Kitchen Sink info can be parsed.
returnsFactory($docstring_data)
if($format !==null) $name
Definition: metadata.php:146
catch(Exception $e) $message
+ Here is the call graph for this function:

◆ test_proper_name()

AbstractFactoryTest::test_proper_name ( )

Definition at line 102 of file AbstractFactoryTest.php.

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

103  {
104  $name = $this->reflection->getName();
105  $message = "TODO: Give your factory a proper name.";
106  $this->assertTrue(
107  $this->isFactoryName($name),
108  $message
109  );
110  }
if($format !==null) $name
Definition: metadata.php:146
catch(Exception $e) $message
+ Here is the call graph for this function:

◆ test_proper_namespace()

AbstractFactoryTest::test_proper_namespace ( )

Definition at line 92 of file AbstractFactoryTest.php.

References $message.

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

◆ test_return_type()

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

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

methods_provider

Definition at line 139 of file AbstractFactoryTest.php.

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

Referenced by test_factory_method_name_compatible_docstring().

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  }
test_check_yaml_extraction($method_reflection, $name)
Tests whether the YAML Kitchen Sink info can be parsed.
returnsFactory($docstring_data)
if($format !==null) $name
Definition: metadata.php:146
catch(Exception $e) $message
returnsComponent($docstring_data)
+ 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 28 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: