ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
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 (ReflectionMethod $method_reflection, string $name)
 Tests whether the YAML Kitchen Sink info can be parsed. More...
 
 test_return_type (ReflectionMethod $method_reflection, string $name)
 Tests whether the method either returns a factory or a component. More...
 
 test_factory_method_name_compatible_docstring (ReflectionMethod $method_reflection, string $name)
 Tests whether the method name matches the return doctring? More...
 
 test_method_params (ReflectionMethod $method_reflection, string $name)
 Tests whether methods returning factories have no parameters. More...
 
 test_kitchensink_info_description (ReflectionMethod $method_reflection, string $name)
 methods_provider More...
 
 test_kitchensink_info_rivals (ReflectionMethod $method_reflection, string $name)
 methods_provider More...
 
 test_kitchensink_info_background (ReflectionMethod $method_reflection, string $name)
 methods_provider More...
 
 test_kitchensink_info_featurewiki (ReflectionMethod $method_reflection, string $name)
 methods_provider More...
 
 test_kitchensink_info_javascript (ReflectionMethod $method_reflection, string $name)
 methods_provider More...
 
 test_kitchensink_info_rules (ReflectionMethod $method_reflection, string $name)
 methods_provider More...
 
 test_kitchensink_info_context (ReflectionMethod $method_reflection, string $name)
 methods_provider More...
 
 kitchensink_info_settings_merged_with_defaults (string $name)
 

Data Fields

const COMPONENT = 1
 
const FACTORY = 2
 

Protected Member Functions

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

Private Attributes

array $kitchensink_info_settings_default
 
array array $description_categories = ['purpose', 'composition', 'effect', 'rival']
 
array $rules_categories
 
Crawler EntriesYamlParser $yaml_parser
 
ReflectionClass $reflection
 

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

Member Function Documentation

◆ buildFactoryReflection()

AbstractFactoryTest::buildFactoryReflection ( )
final

Definition at line 94 of file AbstractFactoryTest.php.

Referenced by methods_provider(), and setUp().

95  {
96  return new ReflectionClass($this->factory_title);
97  }
+ Here is the caller graph for this function:

◆ get_regex_factory_namespace()

AbstractFactoryTest::get_regex_factory_namespace ( )
protected

Definition at line 211 of file AbstractFactoryTest.php.

Referenced by test_factory_method_name_compatible_docstring().

211  : string
212  {
213  return str_replace("\\", "\\\\", $this->reflection->getNamespaceName());
214  }
+ Here is the caller graph for this function:

◆ isFactoryName()

AbstractFactoryTest::isFactoryName ( string  $name)
finalprotected

Definition at line 89 of file AbstractFactoryTest.php.

Referenced by returnsFactory(), and test_proper_name().

89  : bool
90  {
91  return preg_match("#^(\\\\)?ILIAS\\\\UI\\\\Component\\\\([a-zA-Z]+\\\\)*Factory$#", $name) === 1;
92  }
if($format !==null) $name
Definition: metadata.php:247
+ Here is the caller graph for this function:

◆ kitchensink_info_settings_merged_with_defaults()

AbstractFactoryTest::kitchensink_info_settings_merged_with_defaults ( string  $name)
final

Definition at line 357 of file AbstractFactoryTest.php.

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

357  : array
358  {
359  if (array_key_exists($name, $this->kitchensink_info_settings)) {
360  return array_merge(
361  $this->kitchensink_info_settings_default,
362  $this->kitchensink_info_settings[$name]
363  );
364  } else {
366  }
367  }
if($format !==null) $name
Definition: metadata.php:247
+ Here is the caller graph for this function:

◆ methods_provider()

AbstractFactoryTest::methods_provider ( )
final

Definition at line 99 of file AbstractFactoryTest.php.

References buildFactoryReflection().

99  : array
100  {
102  return array_map(function ($element) {
103  return array($element, $element->getName());
104  }, $reflection->getMethods());
105  }
ReflectionClass $reflection
+ Here is the call graph for this function:

◆ returnsComponent()

AbstractFactoryTest::returnsComponent ( array  $docstring_data)
finalprotected

Definition at line 83 of file AbstractFactoryTest.php.

Referenced by test_return_type().

83  : bool
84  {
85  $reflection = new ReflectionClass($docstring_data["namespace"]);
86  return in_array("ILIAS\\UI\\Component\\Component", $reflection->getInterfaceNames());
87  }
ReflectionClass $reflection
+ Here is the caller graph for this function:

◆ returnsFactory()

AbstractFactoryTest::returnsFactory ( array  $docstring_data)
finalprotected

Definition at line 78 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().

78  : bool
79  {
80  return $this->isFactoryName($docstring_data["namespace"]);
81  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setUp()

AbstractFactoryTest::setUp ( )

Definition at line 109 of file AbstractFactoryTest.php.

References buildFactoryReflection().

109  : void
110  {
111  $this->yaml_parser = new Crawler\EntriesYamlParser();
112  $this->reflection = $this->buildFactoryReflection();
113  }
+ Here is the call graph for this function:

◆ test_check_yaml_extraction()

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

Tests whether the YAML Kitchen Sink info can be parsed.

methods_provider

Definition at line 137 of file AbstractFactoryTest.php.

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

137  : array
138  {
139  try {
140  //Todo (TA) this is not pretty. We should think about using only reflection in the parser as well.
141  $function_name_string = "\n public function " . $method_reflection->getName() . "()";
142  $docstring_data = $this->yaml_parser->parseArrayFromString(
143  $method_reflection->getDocComment() . $function_name_string
144  );
145  $this->assertTrue(true);
147  $message = "TODO ($name): fix parse error in kitchen sink yaml: " . $e->getMessage();
148  $this->assertTrue(false, $message);
149  }
150  $this->assertCount(1, $docstring_data);
151  return $docstring_data[0];
152  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$message
Definition: xapiexit.php:32
+ Here is the caller graph for this function:

◆ test_factory_method_name_compatible_docstring()

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

Tests whether the method name matches the return doctring?

methods_provider

Definition at line 177 of file AbstractFactoryTest.php.

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

180  : void {
181  $docstring_data = $this->test_check_yaml_extraction($method_reflection, $name);
182  $this->test_return_type($method_reflection, $name);
183 
184  $return_doc = $docstring_data["namespace"];
185  $name_uppercase = ucwords($name);
186  $regex_factory_namespace = $this->get_regex_factory_namespace();
187  $regex_head = "#^(\\\\?)$regex_factory_namespace";
188 
189  $message = "TODO ($name): fix @return, it does not match the method name.";
190  if ($this->returnsFactory($docstring_data)) {
191  $this->assertMatchesRegularExpression(
192  "$regex_head\\\\$name_uppercase\\\\Factory$#",
193  $return_doc,
194  $message
195  );
196  } else { // returnsComponent
197  // Every component MUST be described by a single interface, where the name of
198  // the interface corresponds to the name of the component.
199  $standard_pattern = "$regex_head\\\\$name_uppercase#";
200  $standard_case = preg_match($standard_pattern, $return_doc);
201 
202  // unless they only differ in a type and share a common prefix to their pathes.
203  $namespace_parts = explode("\\", $this->reflection->getNamespaceName());
204  $typediff_only_pattern = "$regex_head\\\\" . array_pop($namespace_parts) . "#";
205  $typediff_only_case = preg_match($typediff_only_pattern, $return_doc);
206 
207  $this->assertTrue($standard_case || $typediff_only_case, $message);
208  }
209  }
test_return_type(ReflectionMethod $method_reflection, string $name)
Tests whether the method either returns a factory or a component.
if($format !==null) $name
Definition: metadata.php:247
returnsFactory(array $docstring_data)
test_check_yaml_extraction(ReflectionMethod $method_reflection, string $name)
Tests whether the YAML Kitchen Sink info can be parsed.
$message
Definition: xapiexit.php:32
+ Here is the call graph for this function:

◆ test_kitchensink_info_background()

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

methods_provider

Definition at line 274 of file AbstractFactoryTest.php.

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

274  : void
275  {
276  $docstring_data = $this->test_check_yaml_extraction($method_reflection, $name);
277  $kitchensink_info_settings = $this->kitchensink_info_settings_merged_with_defaults($name);
278 
279  if ($kitchensink_info_settings['background']) {
280  $message = "TODO ($name): add a background field.";
281  $this->assertArrayHasKey('background', $docstring_data, $message);
282  }
283  }
kitchensink_info_settings_merged_with_defaults(string $name)
if($format !==null) $name
Definition: metadata.php:247
test_check_yaml_extraction(ReflectionMethod $method_reflection, string $name)
Tests whether the YAML Kitchen Sink info can be parsed.
$message
Definition: xapiexit.php:32
+ Here is the call graph for this function:

◆ test_kitchensink_info_context()

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

methods_provider

Definition at line 340 of file AbstractFactoryTest.php.

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

340  : void
341  {
342  $docstring_data = $this->test_check_yaml_extraction($method_reflection, $name);
343  $kitchensink_info_settings = $this->kitchensink_info_settings_merged_with_defaults($name);
344 
345  // Special rules for factory methods:
346  if ($this->returnsFactory($docstring_data)) {
347  $message = "TODO ($name): remove 'context' field, method returns a factory.";
348  $this->assertArrayNotHasKey("context", $docstring_data, $message);
349  } else { // returnsComponent
350  if ($kitchensink_info_settings["context"]) {
351  $message = "TODO ($name): factory method returning component should have context field. Add it.";
352  $this->assertArrayHasKey("context", $docstring_data, $message);
353  }
354  }
355  }
kitchensink_info_settings_merged_with_defaults(string $name)
if($format !==null) $name
Definition: metadata.php:247
returnsFactory(array $docstring_data)
test_check_yaml_extraction(ReflectionMethod $method_reflection, string $name)
Tests whether the YAML Kitchen Sink info can be parsed.
$message
Definition: xapiexit.php:32
+ Here is the call graph for this function:

◆ test_kitchensink_info_description()

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

methods_provider

Definition at line 236 of file AbstractFactoryTest.php.

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

236  : void
237  {
238  $docstring_data = $this->test_check_yaml_extraction($method_reflection, $name);
239  $kitchensink_info_settings = $this->kitchensink_info_settings_merged_with_defaults($name);
240 
241  if ($kitchensink_info_settings['description']) {
242  $message = "TODO ($name): add a description.";
243  $this->assertArrayHasKey('description', $docstring_data, $message);
244 
245  $desc_fields = implode(", ", $this->description_categories);
246  $message = "TODO ($name): the description field should at least contain one of these: $desc_fields.";
247  $existing_keys = array_keys($docstring_data["description"]);
248  $existing_expected_keys = array_intersect($this->description_categories, $existing_keys);
249  $this->assertGreaterThanOrEqual(
250  1,
251  $existing_expected_keys,
252  $message
253  );
254  }
255  }
kitchensink_info_settings_merged_with_defaults(string $name)
if($format !==null) $name
Definition: metadata.php:247
test_check_yaml_extraction(ReflectionMethod $method_reflection, string $name)
Tests whether the YAML Kitchen Sink info can be parsed.
$message
Definition: xapiexit.php:32
+ Here is the call graph for this function:

◆ test_kitchensink_info_featurewiki()

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

methods_provider

Definition at line 288 of file AbstractFactoryTest.php.

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

288  : void
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  if ($kitchensink_info_settings['featurewiki']) {
294  $message = "TODO ($name): add a featurewiki field.";
295  $this->assertArrayHasKey('featurewiki', $docstring_data, $message);
296  }
297  }
kitchensink_info_settings_merged_with_defaults(string $name)
if($format !==null) $name
Definition: metadata.php:247
test_check_yaml_extraction(ReflectionMethod $method_reflection, string $name)
Tests whether the YAML Kitchen Sink info can be parsed.
$message
Definition: xapiexit.php:32
+ Here is the call graph for this function:

◆ test_kitchensink_info_javascript()

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

methods_provider

Definition at line 302 of file AbstractFactoryTest.php.

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

302  : void
303  {
304  $docstring_data = $this->test_check_yaml_extraction($method_reflection, $name);
305  $kitchensink_info_settings = $this->kitchensink_info_settings_merged_with_defaults($name);
306 
307  if ($kitchensink_info_settings['javascript']) {
308  $message = "TODO ($name): add a javascript field.";
309  $this->assertArrayHasKey('javascript', $docstring_data, $message);
310  }
311  }
kitchensink_info_settings_merged_with_defaults(string $name)
if($format !==null) $name
Definition: metadata.php:247
test_check_yaml_extraction(ReflectionMethod $method_reflection, string $name)
Tests whether the YAML Kitchen Sink info can be parsed.
$message
Definition: xapiexit.php:32
+ Here is the call graph for this function:

◆ test_kitchensink_info_rivals()

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

methods_provider

Definition at line 260 of file AbstractFactoryTest.php.

References $message, and test_check_yaml_extraction().

260  : void
261  {
262  $docstring_data = $this->test_check_yaml_extraction($method_reflection, $name);
263  if (isset($docstring_data["description"]) && isset($docstring_data["description"]["rivals"])) {
264  $rules = $docstring_data["description"]["rivals"];
265  $message = "TODO ($name): The Rivals field has a non-string index. Format like 'rival_name': 'description'";
266  $this->assertTrue(array_unique(array_map("is_string", array_keys($rules))) === array(true), $message);
267  }
268  $this->assertTrue(true);
269  }
if($format !==null) $name
Definition: metadata.php:247
test_check_yaml_extraction(ReflectionMethod $method_reflection, string $name)
Tests whether the YAML Kitchen Sink info can be parsed.
$message
Definition: xapiexit.php:32
+ Here is the call graph for this function:

◆ test_kitchensink_info_rules()

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

methods_provider

Definition at line 316 of file AbstractFactoryTest.php.

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

316  : void
317  {
318  $docstring_data = $this->test_check_yaml_extraction($method_reflection, $name);
319  $kitchensink_info_settings = $this->kitchensink_info_settings_merged_with_defaults($name);
320 
321  if ($kitchensink_info_settings['rules']) {
322  $message = "TODO ($name): add a rules field.";
323  $this->assertArrayHasKey('rules', $docstring_data, $message);
324 
325  $rules_fields = implode(", ", $this->rules_categories);
326  $message = "TODO ($name): the rules field should at least contain one of these: $rules_fields.";
327  $existing_keys = array_keys($docstring_data["rules"]);
328  $existing_expected_keys = array_intersect($this->rules_categories, $existing_keys);
329  $this->assertGreaterThanOrEqual(
330  1,
331  $existing_expected_keys,
332  $message
333  );
334  }
335  }
kitchensink_info_settings_merged_with_defaults(string $name)
if($format !==null) $name
Definition: metadata.php:247
test_check_yaml_extraction(ReflectionMethod $method_reflection, string $name)
Tests whether the YAML Kitchen Sink info can be parsed.
$message
Definition: xapiexit.php:32
+ Here is the call graph for this function:

◆ test_method_params()

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

Tests whether methods returning factories have no parameters.

methods_provider

Definition at line 221 of file AbstractFactoryTest.php.

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

221  : void
222  {
223  $docstring_data = $this->test_check_yaml_extraction($method_reflection, $name);
224  if ($this->returnsFactory($docstring_data)) {
225  $message = "TODO ($name): remove params from method that returns Factory.";
226  $this->assertEquals(0, $method_reflection->getNumberOfParameters(), $message);
227  }
228  }
if($format !==null) $name
Definition: metadata.php:247
returnsFactory(array $docstring_data)
test_check_yaml_extraction(ReflectionMethod $method_reflection, string $name)
Tests whether the YAML Kitchen Sink info can be parsed.
$message
Definition: xapiexit.php:32
+ Here is the call graph for this function:

◆ test_proper_name()

AbstractFactoryTest::test_proper_name ( )

Definition at line 125 of file AbstractFactoryTest.php.

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

125  : void
126  {
127  $name = $this->reflection->getName();
128  $message = "TODO: Give your factory a proper name.";
129  $this->assertTrue($this->isFactoryName($name), $message);
130  }
if($format !==null) $name
Definition: metadata.php:247
$message
Definition: xapiexit.php:32
+ Here is the call graph for this function:

◆ test_proper_namespace()

AbstractFactoryTest::test_proper_namespace ( )

Definition at line 115 of file AbstractFactoryTest.php.

References $message.

115  : void
116  {
117  $message = "TODO: Put your factory into the proper namespace.";
118  $this->assertMatchesRegularExpression(
119  "#^ILIAS\\\\UI\\\\Component.#",
120  $this->reflection->getNamespaceName(),
121  $message
122  );
123  }
$message
Definition: xapiexit.php:32

◆ test_return_type()

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

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

methods_provider

Definition at line 159 of file AbstractFactoryTest.php.

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

Referenced by test_factory_method_name_compatible_docstring().

159  : void
160  {
161  $message = "TODO ($name): fix return type, it must be a factory or a component.";
162  $docstring_data = $this->test_check_yaml_extraction($method_reflection, $name);
163  if ($this->returnsFactory($docstring_data)) {
164  $this->assertTrue(true);
165  } elseif ($this->returnsComponent($docstring_data)) {
166  $this->assertTrue(true);
167  } else {
168  $this->assertTrue(false, $message);
169  }
170  }
returnsComponent(array $docstring_data)
if($format !==null) $name
Definition: metadata.php:247
returnsFactory(array $docstring_data)
test_check_yaml_extraction(ReflectionMethod $method_reflection, string $name)
Tests whether the YAML Kitchen Sink info can be parsed.
$message
Definition: xapiexit.php:32
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $description_categories

array array AbstractFactoryTest::$description_categories = ['purpose', 'composition', 'effect', 'rival']
private

Definition at line 62 of file AbstractFactoryTest.php.

◆ $kitchensink_info_settings_default

array AbstractFactoryTest::$kitchensink_info_settings_default
private
Initial value:
= [
'description' => true

Definition at line 46 of file AbstractFactoryTest.php.

Referenced by kitchensink_info_settings_merged_with_defaults().

◆ $reflection

ReflectionClass AbstractFactoryTest::$reflection
private

Definition at line 76 of file AbstractFactoryTest.php.

◆ $rules_categories

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

Definition at line 64 of file AbstractFactoryTest.php.

◆ $yaml_parser

Crawler EntriesYamlParser AbstractFactoryTest::$yaml_parser
private

Definition at line 75 of file AbstractFactoryTest.php.

◆ COMPONENT

const AbstractFactoryTest::COMPONENT = 1

Definition at line 38 of file AbstractFactoryTest.php.

◆ FACTORY

const AbstractFactoryTest::FACTORY = 2

Definition at line 39 of file AbstractFactoryTest.php.


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