ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
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)
 
 testKitchensinkInfoRivals (ReflectionMethod $method_reflection, string $name)
 
 testKitchensinkInfoBackground (ReflectionMethod $method_reflection, string $name)
 
 testKitchensinkInfoFeatureWiki (ReflectionMethod $method_reflection, string $name)
 
 testKitchensinkInfoJavaScript (ReflectionMethod $method_reflection, string $name)
 
 testKitchensinkInfoRules (ReflectionMethod $method_reflection, string $name)
 
 testKitchensinkInfoContext (ReflectionMethod $method_reflection, string $name)
 
 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 221 of file AbstractFactoryTestCase.php.

Referenced by testFactoryMethodNameCompatibleDocstring().

221  : string
222  {
223  return str_replace("\\", "\\\\", self::$reflection->getNamespaceName());
224  }
+ 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 344 of file AbstractFactoryTestCase.php.

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

344  : array
345  {
346  if (array_key_exists($name, static::$kitchensink_info_settings)) {
347  return array_merge(
348  static::$kitchensink_info_settings_default,
349  static::$kitchensink_info_settings[$name]
350  );
351  } else {
352  return static::$kitchensink_info_settings_default;
353  }
354  }
+ 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.

Definition at line 149 of file AbstractFactoryTestCase.php.

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

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

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

Definition at line 187 of file AbstractFactoryTestCase.php.

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

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

Definition at line 276 of file AbstractFactoryTestCase.php.

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

276  : void
277  {
278  $docstring_data = $this->testCheckYamlExtraction($method_reflection, $name);
279  $kitchensink_info_settings = $this->kitchensinkInfoSettingsMergedWithDefaults($name);
280 
281  if ($kitchensink_info_settings['background']) {
282  $message = "TODO ($name): add a background field.";
283  $this->assertArrayHasKey('background', $docstring_data, $message);
284  }
285  }
$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

Definition at line 334 of file AbstractFactoryTestCase.php.

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

334  : void
335  {
336  $docstring_data = $this->testCheckYamlExtraction($method_reflection, $name);
337  $kitchensink_info_settings = $this->kitchensinkInfoSettingsMergedWithDefaults($name);
338  if (!$this->returnsFactory($docstring_data) && $kitchensink_info_settings["context"]) {
339  $message = "TODO ($name): factory method returning component should have context field. Add it.";
340  $this->assertArrayHasKey("context", $docstring_data, $message);
341  }
342  }
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

Definition at line 242 of file AbstractFactoryTestCase.php.

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

242  : void
243  {
244  $docstring_data = $this->testCheckYamlExtraction($method_reflection, $name);
245  $kitchensink_info_settings = $this->kitchensinkInfoSettingsMergedWithDefaults($name);
246 
247  if ($kitchensink_info_settings['description']) {
248  $message = "TODO ($name): add a description.";
249  $this->assertArrayHasKey('description', $docstring_data, $message);
250 
251  $desc_fields = implode(", ", static::$description_categories);
252  $message = "TODO ($name): the description field should at least contain one of these: $desc_fields.";
253  $existing_keys = array_keys($docstring_data["description"]);
254  $existing_expected_keys = array_intersect(static::$description_categories, $existing_keys);
255  $this->assertGreaterThanOrEqual(
256  1,
257  $existing_expected_keys,
258  $message
259  );
260  }
261  }
$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

Definition at line 288 of file AbstractFactoryTestCase.php.

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

288  : void
289  {
290  $docstring_data = $this->testCheckYamlExtraction($method_reflection, $name);
291  $kitchensink_info_settings = $this->kitchensinkInfoSettingsMergedWithDefaults($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  }
$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

Definition at line 300 of file AbstractFactoryTestCase.php.

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

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

Definition at line 264 of file AbstractFactoryTestCase.php.

References $message, and testCheckYamlExtraction().

264  : void
265  {
266  $docstring_data = $this->testCheckYamlExtraction($method_reflection, $name);
267  if (isset($docstring_data["description"]) && isset($docstring_data["description"]["rivals"])) {
268  $rules = $docstring_data["description"]["rivals"];
269  $message = "TODO ($name): The Rivals field has a non-string index. Format like 'rival_name': 'description'";
270  $this->assertTrue(array_unique(array_map("is_string", array_keys($rules))) === array(true), $message);
271  }
272  $this->assertTrue(true);
273  }
$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

Definition at line 312 of file AbstractFactoryTestCase.php.

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

312  : void
313  {
314  $docstring_data = $this->testCheckYamlExtraction($method_reflection, $name);
315  $kitchensink_info_settings = $this->kitchensinkInfoSettingsMergedWithDefaults($name);
316 
317  if ($kitchensink_info_settings['rules']) {
318  $message = "TODO ($name): add a rules field.";
319  $this->assertArrayHasKey('rules', $docstring_data, $message);
320 
321  $rules_fields = implode(", ", static::$rules_categories);
322  $message = "TODO ($name): the rules field should at least contain one of these: $rules_fields.";
323  $existing_keys = array_keys($docstring_data["rules"]);
324  $existing_expected_keys = array_intersect(static::$rules_categories, $existing_keys);
325  $this->assertGreaterThanOrEqual(
326  1,
327  $existing_expected_keys,
328  $message
329  );
330  }
331  }
$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.

Definition at line 230 of file AbstractFactoryTestCase.php.

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

230  : void
231  {
232  $docstring_data = $this->testCheckYamlExtraction($method_reflection, $name);
233  if ($this->returnsFactory($docstring_data)) {
234  $message = "TODO ($name): remove params from method that returns Factory.";
235  $this->assertEquals(0, $method_reflection->getNumberOfParameters(), $message);
236  }
237  }
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.

Definition at line 170 of file AbstractFactoryTestCase.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  }
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: