ILIAS  trunk Revision v5.2.0beta1-34115-g3a2438be29
AbstractFactoryTest Class Reference

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

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

Public Member Functions

 buildFactoryReflection ()
 
 getMethodsProvider ()
 
 setUp ()
 
 testProperNamespace ()
 
 testProperName ()
 
 testCheckYamlExtraction (ReflectionMethod $method_reflection, string $name)
 Tests whether the YAML Kitchen Sink info can be parsed. More...
 
 testReturnType (ReflectionMethod $method_reflection, string $name)
 Tests whether the method either returns a factory or a component. More...
 
 testFactoryMethodNameCompatibleDocstring (ReflectionMethod $method_reflection, string $name)
 Tests whether the method name matches the return doctring? More...
 
 testMethodParams (ReflectionMethod $method_reflection, string $name)
 Tests whether methods returning factories have no parameters. More...
 
 testKitchensinkInfoDescription (ReflectionMethod $method_reflection, string $name)
 getMethodsProvider More...
 
 testKitchensinkInfoRivals (ReflectionMethod $method_reflection, string $name)
 getMethodsProvider More...
 
 testKitchensinkInfoBackground (ReflectionMethod $method_reflection, string $name)
 getMethodsProvider More...
 
 testKitchensinkInfoFeatureWiki (ReflectionMethod $method_reflection, string $name)
 getMethodsProvider More...
 
 testKitchensinkInfoJavaScript (ReflectionMethod $method_reflection, string $name)
 getMethodsProvider More...
 
 testKitchensinkInfoRules (ReflectionMethod $method_reflection, string $name)
 getMethodsProvider More...
 
 testKitchensinkInfoContext (ReflectionMethod $method_reflection, string $name)
 getMethodsProvider More...
 
 kitchensinkInfoSettingsMergedWithDefaults (string $name)
 

Data Fields

const COMPONENT = 1
 
const FACTORY = 2
 

Protected Member Functions

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

Private Attributes

array $omit_factory_methods
 
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 100 of file AbstractFactoryTest.php.

Referenced by getMethodsProvider(), and setUp().

101  {
102  return new ReflectionClass($this->factory_title);
103  }
+ Here is the caller graph for this function:

◆ getMethodsProvider()

AbstractFactoryTest::getMethodsProvider ( )
final

Definition at line 105 of file AbstractFactoryTest.php.

References $omit_factory_methods, and buildFactoryReflection().

105  : array
106  {
108  return array_filter(
109  array_map(function ($element) {
110  if (!in_array($element->getName(), $this->omit_factory_methods)) {
111  return array($element, $element->getName());
112  }
113  return false;
114  }, $reflection->getMethods())
115  );
116  }
ReflectionClass $reflection
+ Here is the call graph for this function:

◆ getRegexFactoryNamespace()

AbstractFactoryTest::getRegexFactoryNamespace ( )
protected

Definition at line 222 of file AbstractFactoryTest.php.

Referenced by testFactoryMethodNameCompatibleDocstring().

222  : string
223  {
224  return str_replace("\\", "\\\\", $this->reflection->getNamespaceName());
225  }
+ Here is the caller graph for this function:

◆ isFactoryName()

AbstractFactoryTest::isFactoryName ( string  $name)
finalprotected

Definition at line 95 of file AbstractFactoryTest.php.

Referenced by returnsFactory(), and testProperName().

95  : bool
96  {
97  return preg_match("#^(\\\\)?ILIAS\\\\UI\\\\Component\\\\([a-zA-Z]+\\\\)*Factory$#", $name) === 1;
98  }
+ Here is the caller graph for this function:

◆ kitchensinkInfoSettingsMergedWithDefaults()

AbstractFactoryTest::kitchensinkInfoSettingsMergedWithDefaults ( string  $name)
final

Definition at line 361 of file AbstractFactoryTest.php.

References $kitchensink_info_settings_default.

Referenced by testKitchensinkInfoBackground(), testKitchensinkInfoContext(), testKitchensinkInfoDescription(), testKitchensinkInfoFeatureWiki(), testKitchensinkInfoJavaScript(), and testKitchensinkInfoRules().

361  : array
362  {
363  if (array_key_exists($name, $this->kitchensink_info_settings)) {
364  return array_merge(
365  $this->kitchensink_info_settings_default,
366  $this->kitchensink_info_settings[$name]
367  );
368  } else {
370  }
371  }
+ Here is the caller graph for this function:

◆ returnsComponent()

AbstractFactoryTest::returnsComponent ( array  $docstring_data)
finalprotected

Definition at line 89 of file AbstractFactoryTest.php.

Referenced by testReturnType().

89  : bool
90  {
91  $reflection = new ReflectionClass($docstring_data["namespace"]);
92  return in_array("ILIAS\\UI\\Component\\Component", $reflection->getInterfaceNames());
93  }
ReflectionClass $reflection
+ Here is the caller graph for this function:

◆ returnsFactory()

AbstractFactoryTest::returnsFactory ( array  $docstring_data)
finalprotected

Definition at line 84 of file AbstractFactoryTest.php.

References isFactoryName().

Referenced by testFactoryMethodNameCompatibleDocstring(), testKitchensinkInfoContext(), testMethodParams(), and testReturnType().

84  : bool
85  {
86  return $this->isFactoryName($docstring_data["namespace"]);
87  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setUp()

AbstractFactoryTest::setUp ( )

Definition at line 120 of file AbstractFactoryTest.php.

References buildFactoryReflection().

120  : void
121  {
122  $this->yaml_parser = new Crawler\EntriesYamlParser();
123  $this->reflection = $this->buildFactoryReflection();
124  }
+ Here is the call graph for this function:

◆ testCheckYamlExtraction()

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

Tests whether the YAML Kitchen Sink info can be parsed.

getMethodsProvider

Definition at line 148 of file AbstractFactoryTest.php.

References Vendor\Package\$e, and $message.

Referenced by testFactoryMethodNameCompatibleDocstring(), testKitchensinkInfoBackground(), testKitchensinkInfoContext(), testKitchensinkInfoDescription(), testKitchensinkInfoFeatureWiki(), testKitchensinkInfoJavaScript(), testKitchensinkInfoRivals(), testKitchensinkInfoRules(), testMethodParams(), and testReturnType().

148  : array
149  {
150  try {
151  //Todo (TA) this is not pretty. We should think about using only reflection in the parser as well.
152  $function_name_string = "\n public function " . $method_reflection->getName() . "()";
153  $docstring_data = $this->yaml_parser->parseArrayFromString(
154  $method_reflection->getDocComment() . $function_name_string
155  );
156  $this->assertTrue(true);
158  $message = "TODO ($name): fix parse error in kitchen sink yaml: " . $e->getMessage();
159  $this->assertTrue(false, $message);
160  }
161  $this->assertCount(1, $docstring_data);
162  return $docstring_data[0];
163  }
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:

◆ testFactoryMethodNameCompatibleDocstring()

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

Tests whether the method name matches the return doctring?

getMethodsProvider

Definition at line 188 of file AbstractFactoryTest.php.

References $message, getRegexFactoryNamespace(), returnsFactory(), testCheckYamlExtraction(), and testReturnType().

191  : void {
192  $docstring_data = $this->testCheckYamlExtraction($method_reflection, $name);
193  $this->testReturnType($method_reflection, $name);
194 
195  $return_doc = $docstring_data["namespace"];
196  $name_uppercase = ucwords($name);
197  $regex_factory_namespace = $this->getRegexFactoryNamespace();
198  $regex_head = "#^(\\\\?)$regex_factory_namespace";
199 
200  $message = "TODO ($name): fix @return, it does not match the method name.";
201  if ($this->returnsFactory($docstring_data)) {
202  $this->assertMatchesRegularExpression(
203  "$regex_head\\\\$name_uppercase\\\\Factory$#",
204  $return_doc,
205  $message
206  );
207  } else { // returnsComponent
208  // Every component MUST be described by a single interface, where the name of
209  // the interface corresponds to the name of the component.
210  $standard_pattern = "$regex_head\\\\$name_uppercase#";
211  $standard_case = preg_match($standard_pattern, $return_doc);
212 
213  // unless they only differ in a type and share a common prefix to their pathes.
214  $namespace_parts = explode("\\", $this->reflection->getNamespaceName());
215  $typediff_only_pattern = "$regex_head\\\\" . array_pop($namespace_parts) . "#";
216  $typediff_only_case = preg_match($typediff_only_pattern, $return_doc);
217 
218  $this->assertTrue($standard_case || $typediff_only_case, $message);
219  }
220  }
testReturnType(ReflectionMethod $method_reflection, string $name)
Tests whether the method either returns a factory or a component.
returnsFactory(array $docstring_data)
$message
Definition: xapiexit.php:32
testCheckYamlExtraction(ReflectionMethod $method_reflection, string $name)
Tests whether the YAML Kitchen Sink info can be parsed.
+ Here is the call graph for this function:

◆ testKitchensinkInfoBackground()

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

getMethodsProvider

Definition at line 285 of file AbstractFactoryTest.php.

References $message, kitchensinkInfoSettingsMergedWithDefaults(), and testCheckYamlExtraction().

285  : void
286  {
287  $docstring_data = $this->testCheckYamlExtraction($method_reflection, $name);
288  $kitchensink_info_settings = $this->kitchensinkInfoSettingsMergedWithDefaults($name);
289 
290  if ($kitchensink_info_settings['background']) {
291  $message = "TODO ($name): add a background field.";
292  $this->assertArrayHasKey('background', $docstring_data, $message);
293  }
294  }
kitchensinkInfoSettingsMergedWithDefaults(string $name)
$message
Definition: xapiexit.php:32
testCheckYamlExtraction(ReflectionMethod $method_reflection, string $name)
Tests whether the YAML Kitchen Sink info can be parsed.
+ Here is the call graph for this function:

◆ testKitchensinkInfoContext()

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

getMethodsProvider

Definition at line 351 of file AbstractFactoryTest.php.

References $message, kitchensinkInfoSettingsMergedWithDefaults(), returnsFactory(), and testCheckYamlExtraction().

351  : void
352  {
353  $docstring_data = $this->testCheckYamlExtraction($method_reflection, $name);
354  $kitchensink_info_settings = $this->kitchensinkInfoSettingsMergedWithDefaults($name);
355  if (!$this->returnsFactory($docstring_data) && $kitchensink_info_settings["context"]) {
356  $message = "TODO ($name): factory method returning component should have context field. Add it.";
357  $this->assertArrayHasKey("context", $docstring_data, $message);
358  }
359  }
kitchensinkInfoSettingsMergedWithDefaults(string $name)
returnsFactory(array $docstring_data)
$message
Definition: xapiexit.php:32
testCheckYamlExtraction(ReflectionMethod $method_reflection, string $name)
Tests whether the YAML Kitchen Sink info can be parsed.
+ Here is the call graph for this function:

◆ testKitchensinkInfoDescription()

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

getMethodsProvider

Definition at line 247 of file AbstractFactoryTest.php.

References $message, kitchensinkInfoSettingsMergedWithDefaults(), and testCheckYamlExtraction().

247  : void
248  {
249  $docstring_data = $this->testCheckYamlExtraction($method_reflection, $name);
250  $kitchensink_info_settings = $this->kitchensinkInfoSettingsMergedWithDefaults($name);
251 
252  if ($kitchensink_info_settings['description']) {
253  $message = "TODO ($name): add a description.";
254  $this->assertArrayHasKey('description', $docstring_data, $message);
255 
256  $desc_fields = implode(", ", $this->description_categories);
257  $message = "TODO ($name): the description field should at least contain one of these: $desc_fields.";
258  $existing_keys = array_keys($docstring_data["description"]);
259  $existing_expected_keys = array_intersect($this->description_categories, $existing_keys);
260  $this->assertGreaterThanOrEqual(
261  1,
262  $existing_expected_keys,
263  $message
264  );
265  }
266  }
kitchensinkInfoSettingsMergedWithDefaults(string $name)
$message
Definition: xapiexit.php:32
testCheckYamlExtraction(ReflectionMethod $method_reflection, string $name)
Tests whether the YAML Kitchen Sink info can be parsed.
+ Here is the call graph for this function:

◆ testKitchensinkInfoFeatureWiki()

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

getMethodsProvider

Definition at line 299 of file AbstractFactoryTest.php.

References $message, kitchensinkInfoSettingsMergedWithDefaults(), and testCheckYamlExtraction().

299  : void
300  {
301  $docstring_data = $this->testCheckYamlExtraction($method_reflection, $name);
302  $kitchensink_info_settings = $this->kitchensinkInfoSettingsMergedWithDefaults($name);
303 
304  if ($kitchensink_info_settings['featurewiki']) {
305  $message = "TODO ($name): add a featurewiki field.";
306  $this->assertArrayHasKey('featurewiki', $docstring_data, $message);
307  }
308  }
kitchensinkInfoSettingsMergedWithDefaults(string $name)
$message
Definition: xapiexit.php:32
testCheckYamlExtraction(ReflectionMethod $method_reflection, string $name)
Tests whether the YAML Kitchen Sink info can be parsed.
+ Here is the call graph for this function:

◆ testKitchensinkInfoJavaScript()

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

getMethodsProvider

Definition at line 313 of file AbstractFactoryTest.php.

References $message, kitchensinkInfoSettingsMergedWithDefaults(), and testCheckYamlExtraction().

313  : void
314  {
315  $docstring_data = $this->testCheckYamlExtraction($method_reflection, $name);
316  $kitchensink_info_settings = $this->kitchensinkInfoSettingsMergedWithDefaults($name);
317 
318  if ($kitchensink_info_settings['javascript']) {
319  $message = "TODO ($name): add a javascript field.";
320  $this->assertArrayHasKey('javascript', $docstring_data, $message);
321  }
322  }
kitchensinkInfoSettingsMergedWithDefaults(string $name)
$message
Definition: xapiexit.php:32
testCheckYamlExtraction(ReflectionMethod $method_reflection, string $name)
Tests whether the YAML Kitchen Sink info can be parsed.
+ Here is the call graph for this function:

◆ testKitchensinkInfoRivals()

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

getMethodsProvider

Definition at line 271 of file AbstractFactoryTest.php.

References $message, and testCheckYamlExtraction().

271  : void
272  {
273  $docstring_data = $this->testCheckYamlExtraction($method_reflection, $name);
274  if (isset($docstring_data["description"]) && isset($docstring_data["description"]["rivals"])) {
275  $rules = $docstring_data["description"]["rivals"];
276  $message = "TODO ($name): The Rivals field has a non-string index. Format like 'rival_name': 'description'";
277  $this->assertTrue(array_unique(array_map("is_string", array_keys($rules))) === array(true), $message);
278  }
279  $this->assertTrue(true);
280  }
$message
Definition: xapiexit.php:32
testCheckYamlExtraction(ReflectionMethod $method_reflection, string $name)
Tests whether the YAML Kitchen Sink info can be parsed.
+ Here is the call graph for this function:

◆ testKitchensinkInfoRules()

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

getMethodsProvider

Definition at line 327 of file AbstractFactoryTest.php.

References $message, kitchensinkInfoSettingsMergedWithDefaults(), and testCheckYamlExtraction().

327  : void
328  {
329  $docstring_data = $this->testCheckYamlExtraction($method_reflection, $name);
330  $kitchensink_info_settings = $this->kitchensinkInfoSettingsMergedWithDefaults($name);
331 
332  if ($kitchensink_info_settings['rules']) {
333  $message = "TODO ($name): add a rules field.";
334  $this->assertArrayHasKey('rules', $docstring_data, $message);
335 
336  $rules_fields = implode(", ", $this->rules_categories);
337  $message = "TODO ($name): the rules field should at least contain one of these: $rules_fields.";
338  $existing_keys = array_keys($docstring_data["rules"]);
339  $existing_expected_keys = array_intersect($this->rules_categories, $existing_keys);
340  $this->assertGreaterThanOrEqual(
341  1,
342  $existing_expected_keys,
343  $message
344  );
345  }
346  }
kitchensinkInfoSettingsMergedWithDefaults(string $name)
$message
Definition: xapiexit.php:32
testCheckYamlExtraction(ReflectionMethod $method_reflection, string $name)
Tests whether the YAML Kitchen Sink info can be parsed.
+ Here is the call graph for this function:

◆ testMethodParams()

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

Tests whether methods returning factories have no parameters.

getMethodsProvider

Definition at line 232 of file AbstractFactoryTest.php.

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

232  : void
233  {
234  $docstring_data = $this->testCheckYamlExtraction($method_reflection, $name);
235  if ($this->returnsFactory($docstring_data)) {
236  $message = "TODO ($name): remove params from method that returns Factory.";
237  $this->assertEquals(0, $method_reflection->getNumberOfParameters(), $message);
238  }
239  }
returnsFactory(array $docstring_data)
$message
Definition: xapiexit.php:32
testCheckYamlExtraction(ReflectionMethod $method_reflection, string $name)
Tests whether the YAML Kitchen Sink info can be parsed.
+ Here is the call graph for this function:

◆ testProperName()

AbstractFactoryTest::testProperName ( )

Definition at line 136 of file AbstractFactoryTest.php.

References $message, and isFactoryName().

136  : void
137  {
138  $name = $this->reflection->getName();
139  $message = "TODO: Give your factory a proper name.";
140  $this->assertTrue($this->isFactoryName($name), $message);
141  }
$message
Definition: xapiexit.php:32
+ Here is the call graph for this function:

◆ testProperNamespace()

AbstractFactoryTest::testProperNamespace ( )

Definition at line 126 of file AbstractFactoryTest.php.

References $message.

126  : void
127  {
128  $message = "TODO: Put your factory into the proper namespace.";
129  $this->assertMatchesRegularExpression(
130  "#^ILIAS\\\\UI\\\\Component.#",
131  $this->reflection->getNamespaceName(),
132  $message
133  );
134  }
$message
Definition: xapiexit.php:32

◆ testReturnType()

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

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

getMethodsProvider

Definition at line 170 of file AbstractFactoryTest.php.

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

Referenced by testFactoryMethodNameCompatibleDocstring().

170  : void
171  {
172  $message = "TODO ($name): fix return type, it must be a factory or a component.";
173  $docstring_data = $this->testCheckYamlExtraction($method_reflection, $name);
174  if ($this->returnsFactory($docstring_data)) {
175  $this->assertTrue(true);
176  } elseif ($this->returnsComponent($docstring_data)) {
177  $this->assertTrue(true);
178  } else {
179  $this->assertTrue(false, $message);
180  }
181  }
returnsComponent(array $docstring_data)
returnsFactory(array $docstring_data)
$message
Definition: xapiexit.php:32
testCheckYamlExtraction(ReflectionMethod $method_reflection, string $name)
Tests whether the YAML Kitchen Sink info can be parsed.
+ 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 68 of file AbstractFactoryTest.php.

◆ $kitchensink_info_settings_default

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

Definition at line 52 of file AbstractFactoryTest.php.

Referenced by kitchensinkInfoSettingsMergedWithDefaults().

◆ $omit_factory_methods

array AbstractFactoryTest::$omit_factory_methods
private
Initial value:
= [
"helpTopics"
]

Definition at line 43 of file AbstractFactoryTest.php.

Referenced by getMethodsProvider().

◆ $reflection

ReflectionClass AbstractFactoryTest::$reflection
private

Definition at line 82 of file AbstractFactoryTest.php.

◆ $rules_categories

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

Definition at line 70 of file AbstractFactoryTest.php.

◆ $yaml_parser

Crawler EntriesYamlParser AbstractFactoryTest::$yaml_parser
private

Definition at line 81 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: