ILIAS  trunk Revision v11.0_alpha-1715-g7fc467680fb
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
AbstractFactoryTestCase Class Reference

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

+ Inheritance diagram for AbstractFactoryTestCase:
+ Collaboration diagram for AbstractFactoryTestCase:

Public Member Functions

 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)
 

Static Public Member Functions

static buildFactoryReflection ()
 
static getMethodsProvider ()
 

Data Fields

const COMPONENT = 1
 
const FACTORY = 2
 

Static Public Attributes

static string $factory_title = ''
 

Protected Member Functions

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

Private Attributes

Crawler EntriesYamlParser $yaml_parser
 

Static Private Attributes

static array $omit_factory_methods
 
static array $kitchensink_info_settings_default
 
static array static array $description_categories = ['purpose', 'composition', 'effect', 'rival']
 
static array $rules_categories
 
static 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 AbstractFactoryTestCase.php.

Member Function Documentation

◆ buildFactoryReflection()

static AbstractFactoryTestCase::buildFactoryReflection ( )
staticfinal

Definition at line 101 of file AbstractFactoryTestCase.php.

Referenced by setUp().

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

◆ getMethodsProvider()

static AbstractFactoryTestCase::getMethodsProvider ( )
staticfinal

Definition at line 106 of file AbstractFactoryTestCase.php.

106  : array
107  {
108 
109  $reflection = self::buildFactoryReflection();
110  return array_filter(
111  array_map(function ($element) {
112  if (!in_array($element->getName(), self::$omit_factory_methods)) {
113  return array($element, $element->getName());
114  }
115  return false;
116  }, $reflection->getMethods())
117  );
118  }
static ReflectionClass $reflection

◆ getRegexFactoryNamespace()

AbstractFactoryTestCase::getRegexFactoryNamespace ( )
protected

Definition at line 224 of file AbstractFactoryTestCase.php.

Referenced by testFactoryMethodNameCompatibleDocstring().

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

◆ isFactoryName()

AbstractFactoryTestCase::isFactoryName ( string  $name)
finalprotected

Definition at line 96 of file AbstractFactoryTestCase.php.

Referenced by returnsFactory(), and testProperName().

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

◆ kitchensinkInfoSettingsMergedWithDefaults()

AbstractFactoryTestCase::kitchensinkInfoSettingsMergedWithDefaults ( string  $name)
final

Definition at line 363 of file AbstractFactoryTestCase.php.

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

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

◆ returnsComponent()

AbstractFactoryTestCase::returnsComponent ( array  $docstring_data)
finalprotected

Definition at line 90 of file AbstractFactoryTestCase.php.

Referenced by testReturnType().

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

◆ returnsFactory()

AbstractFactoryTestCase::returnsFactory ( array  $docstring_data)
finalprotected

Definition at line 85 of file AbstractFactoryTestCase.php.

References isFactoryName().

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

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

◆ setUp()

AbstractFactoryTestCase::setUp ( )

Definition at line 122 of file AbstractFactoryTestCase.php.

References buildFactoryReflection().

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

◆ testCheckYamlExtraction()

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

Tests whether the YAML Kitchen Sink info can be parsed.

getMethodsProvider

Definition at line 150 of file AbstractFactoryTestCase.php.

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

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

150  : array
151  {
152  try {
153  //Todo (TA) this is not pretty. We should think about using only reflection in the parser as well.
154  $function_name_string = "\n public function " . $method_reflection->getName() . "()";
155  $docstring_data = $this->yaml_parser->parseArrayFromString(
156  $method_reflection->getDocComment() . $function_name_string
157  );
158  $this->assertTrue(true);
160  $message = "TODO ($name): fix parse error in kitchen sink yaml: " . $e->getMessage();
161  $this->assertTrue(false, $message);
162  }
163  $this->assertCount(1, $docstring_data);
164  return $docstring_data[0];
165  }
$message
Definition: xapiexit.php:31
+ Here is the caller graph for this function:

◆ testFactoryMethodNameCompatibleDocstring()

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

Tests whether the method name matches the return doctring?

getMethodsProvider

Definition at line 190 of file AbstractFactoryTestCase.php.

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

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

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

getMethodsProvider

Definition at line 287 of file AbstractFactoryTestCase.php.

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

287  : void
288  {
289  $docstring_data = $this->testCheckYamlExtraction($method_reflection, $name);
290  $kitchensink_info_settings = $this->kitchensinkInfoSettingsMergedWithDefaults($name);
291 
292  if ($kitchensink_info_settings['background']) {
293  $message = "TODO ($name): add a background field.";
294  $this->assertArrayHasKey('background', $docstring_data, $message);
295  }
296  }
$message
Definition: xapiexit.php:31
kitchensinkInfoSettingsMergedWithDefaults(string $name)
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()

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

getMethodsProvider

Definition at line 353 of file AbstractFactoryTestCase.php.

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

353  : void
354  {
355  $docstring_data = $this->testCheckYamlExtraction($method_reflection, $name);
356  $kitchensink_info_settings = $this->kitchensinkInfoSettingsMergedWithDefaults($name);
357  if (!$this->returnsFactory($docstring_data) && $kitchensink_info_settings["context"]) {
358  $message = "TODO ($name): factory method returning component should have context field. Add it.";
359  $this->assertArrayHasKey("context", $docstring_data, $message);
360  }
361  }
returnsFactory(array $docstring_data)
$message
Definition: xapiexit.php:31
kitchensinkInfoSettingsMergedWithDefaults(string $name)
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()

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

getMethodsProvider

Definition at line 249 of file AbstractFactoryTestCase.php.

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

249  : void
250  {
251  $docstring_data = $this->testCheckYamlExtraction($method_reflection, $name);
252  $kitchensink_info_settings = $this->kitchensinkInfoSettingsMergedWithDefaults($name);
253 
254  if ($kitchensink_info_settings['description']) {
255  $message = "TODO ($name): add a description.";
256  $this->assertArrayHasKey('description', $docstring_data, $message);
257 
258  $desc_fields = implode(", ", static::$description_categories);
259  $message = "TODO ($name): the description field should at least contain one of these: $desc_fields.";
260  $existing_keys = array_keys($docstring_data["description"]);
261  $existing_expected_keys = array_intersect(static::$description_categories, $existing_keys);
262  $this->assertGreaterThanOrEqual(
263  1,
264  $existing_expected_keys,
265  $message
266  );
267  }
268  }
$message
Definition: xapiexit.php:31
kitchensinkInfoSettingsMergedWithDefaults(string $name)
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()

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

getMethodsProvider

Definition at line 301 of file AbstractFactoryTestCase.php.

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

301  : void
302  {
303  $docstring_data = $this->testCheckYamlExtraction($method_reflection, $name);
304  $kitchensink_info_settings = $this->kitchensinkInfoSettingsMergedWithDefaults($name);
305 
306  if ($kitchensink_info_settings['featurewiki']) {
307  $message = "TODO ($name): add a featurewiki field.";
308  $this->assertArrayHasKey('featurewiki', $docstring_data, $message);
309  }
310  }
$message
Definition: xapiexit.php:31
kitchensinkInfoSettingsMergedWithDefaults(string $name)
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()

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

getMethodsProvider

Definition at line 315 of file AbstractFactoryTestCase.php.

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

315  : void
316  {
317  $docstring_data = $this->testCheckYamlExtraction($method_reflection, $name);
318  $kitchensink_info_settings = $this->kitchensinkInfoSettingsMergedWithDefaults($name);
319 
320  if ($kitchensink_info_settings['javascript']) {
321  $message = "TODO ($name): add a javascript field.";
322  $this->assertArrayHasKey('javascript', $docstring_data, $message);
323  }
324  }
$message
Definition: xapiexit.php:31
kitchensinkInfoSettingsMergedWithDefaults(string $name)
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()

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

getMethodsProvider

Definition at line 273 of file AbstractFactoryTestCase.php.

References $message, and testCheckYamlExtraction().

273  : void
274  {
275  $docstring_data = $this->testCheckYamlExtraction($method_reflection, $name);
276  if (isset($docstring_data["description"]) && isset($docstring_data["description"]["rivals"])) {
277  $rules = $docstring_data["description"]["rivals"];
278  $message = "TODO ($name): The Rivals field has a non-string index. Format like 'rival_name': 'description'";
279  $this->assertTrue(array_unique(array_map("is_string", array_keys($rules))) === array(true), $message);
280  }
281  $this->assertTrue(true);
282  }
$message
Definition: xapiexit.php:31
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()

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

getMethodsProvider

Definition at line 329 of file AbstractFactoryTestCase.php.

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

329  : void
330  {
331  $docstring_data = $this->testCheckYamlExtraction($method_reflection, $name);
332  $kitchensink_info_settings = $this->kitchensinkInfoSettingsMergedWithDefaults($name);
333 
334  if ($kitchensink_info_settings['rules']) {
335  $message = "TODO ($name): add a rules field.";
336  $this->assertArrayHasKey('rules', $docstring_data, $message);
337 
338  $rules_fields = implode(", ", static::$rules_categories);
339  $message = "TODO ($name): the rules field should at least contain one of these: $rules_fields.";
340  $existing_keys = array_keys($docstring_data["rules"]);
341  $existing_expected_keys = array_intersect(static::$rules_categories, $existing_keys);
342  $this->assertGreaterThanOrEqual(
343  1,
344  $existing_expected_keys,
345  $message
346  );
347  }
348  }
$message
Definition: xapiexit.php:31
kitchensinkInfoSettingsMergedWithDefaults(string $name)
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()

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

Tests whether methods returning factories have no parameters.

getMethodsProvider

Definition at line 234 of file AbstractFactoryTestCase.php.

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

234  : void
235  {
236  $docstring_data = $this->testCheckYamlExtraction($method_reflection, $name);
237  if ($this->returnsFactory($docstring_data)) {
238  $message = "TODO ($name): remove params from method that returns Factory.";
239  $this->assertEquals(0, $method_reflection->getNumberOfParameters(), $message);
240  }
241  }
returnsFactory(array $docstring_data)
$message
Definition: xapiexit.php:31
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()

AbstractFactoryTestCase::testProperName ( )

Definition at line 138 of file AbstractFactoryTestCase.php.

References $message, and isFactoryName().

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

◆ testProperNamespace()

AbstractFactoryTestCase::testProperNamespace ( )

Definition at line 128 of file AbstractFactoryTestCase.php.

References $message.

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

◆ testReturnType()

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

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

getMethodsProvider

Definition at line 172 of file AbstractFactoryTestCase.php.

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

Referenced by testFactoryMethodNameCompatibleDocstring().

172  : void
173  {
174  $message = "TODO ($name): fix return type, it must be a factory or a component.";
175  $docstring_data = $this->testCheckYamlExtraction($method_reflection, $name);
176  if ($this->returnsFactory($docstring_data)) {
177  $this->assertTrue(true);
178  } elseif ($this->returnsComponent($docstring_data)) {
179  $this->assertTrue(true);
180  } else {
181  $this->assertTrue(false, $message);
182  }
183  }
returnsFactory(array $docstring_data)
returnsComponent(array $docstring_data)
$message
Definition: xapiexit.php:31
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 static array AbstractFactoryTestCase::$description_categories = ['purpose', 'composition', 'effect', 'rival']
staticprivate

Definition at line 68 of file AbstractFactoryTestCase.php.

◆ $factory_title

string AbstractFactoryTestCase::$factory_title = ''
static

Definition at line 83 of file AbstractFactoryTestCase.php.

◆ $kitchensink_info_settings_default

array AbstractFactoryTestCase::$kitchensink_info_settings_default
staticprivate
Initial value:
= [
'description' => true

Definition at line 52 of file AbstractFactoryTestCase.php.

◆ $omit_factory_methods

array AbstractFactoryTestCase::$omit_factory_methods
staticprivate
Initial value:
= [
"helpTopics"
]

Definition at line 43 of file AbstractFactoryTestCase.php.

◆ $reflection

ReflectionClass AbstractFactoryTestCase::$reflection
staticprivate

Definition at line 82 of file AbstractFactoryTestCase.php.

◆ $rules_categories

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

Definition at line 70 of file AbstractFactoryTestCase.php.

◆ $yaml_parser

Crawler EntriesYamlParser AbstractFactoryTestCase::$yaml_parser
private

Definition at line 81 of file AbstractFactoryTestCase.php.

◆ COMPONENT

const AbstractFactoryTestCase::COMPONENT = 1

Definition at line 38 of file AbstractFactoryTestCase.php.

◆ FACTORY

const AbstractFactoryTestCase::FACTORY = 2

Definition at line 39 of file AbstractFactoryTestCase.php.


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