ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 $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 @depends, 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.

101 : ReflectionClass
102 {
103 return new ReflectionClass(static::$factory_title);
104 }

Referenced by getMethodsProvider(), and setUp().

+ 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
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

References $reflection, and buildFactoryReflection().

+ Here is the call graph for this function:

◆ getRegexFactoryNamespace()

AbstractFactoryTestCase::getRegexFactoryNamespace ( )
protected

Reimplemented in MainFactoryTest.

Definition at line 221 of file AbstractFactoryTestCase.php.

221 : string
222 {
223 return str_replace("\\", "\\\\", self::$reflection->getNamespaceName());
224 }

◆ isFactoryName()

AbstractFactoryTestCase::isFactoryName ( string  $name)
finalprotected

Definition at line 96 of file AbstractFactoryTestCase.php.

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

Referenced by returnsFactory(), and testProperName().

+ Here is the caller graph for this function:

◆ kitchensinkInfoSettingsMergedWithDefaults()

AbstractFactoryTestCase::kitchensinkInfoSettingsMergedWithDefaults ( string  $name)
final

Definition at line 344 of file AbstractFactoryTestCase.php.

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 }

◆ returnsComponent()

AbstractFactoryTestCase::returnsComponent ( array  $docstring_data)
finalprotected

Definition at line 90 of file AbstractFactoryTestCase.php.

90 : bool
91 {
92 $reflection = new ReflectionClass($docstring_data["namespace"]);
93 return in_array("ILIAS\\UI\\Component\\Component", $reflection->getInterfaceNames());
94 }

References $reflection.

Referenced by testReturnType().

+ Here is the caller graph for this function:

◆ returnsFactory()

AbstractFactoryTestCase::returnsFactory ( array  $docstring_data)
finalprotected

Definition at line 85 of file AbstractFactoryTestCase.php.

85 : bool
86 {
87 return $this->isFactoryName($docstring_data["namespace"]);
88 }

References isFactoryName().

Referenced by testReturnType().

+ 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.

122 : void
123 {
124 $this->yaml_parser = new Crawler\EntriesYamlParser();
125 self::$reflection = $this->buildFactoryReflection();
126 }

References buildFactoryReflection().

+ 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.

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

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

Referenced by testReturnType().

+ 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.

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,
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)
testCheckYamlExtraction(ReflectionMethod $method_reflection, string $name)
Tests whether the YAML Kitchen Sink info can be parsed.
testReturnType(ReflectionMethod $method_reflection, string $name)
Tests whether the method either returns a factory or a component.

◆ testKitchensinkInfoBackground()

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

Definition at line 276 of file AbstractFactoryTestCase.php.

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 }
kitchensinkInfoSettingsMergedWithDefaults(string $name)

References $message.

◆ testKitchensinkInfoContext()

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

Definition at line 334 of file AbstractFactoryTestCase.php.

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 }

References $message.

◆ testKitchensinkInfoDescription()

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

Definition at line 242 of file AbstractFactoryTestCase.php.

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,
259 );
260 }
261 }

References $message.

◆ testKitchensinkInfoFeatureWiki()

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

Definition at line 288 of file AbstractFactoryTestCase.php.

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 }

References $message.

◆ testKitchensinkInfoJavaScript()

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

Definition at line 300 of file AbstractFactoryTestCase.php.

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 }

References $message.

◆ testKitchensinkInfoRivals()

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

Definition at line 264 of file AbstractFactoryTestCase.php.

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 }

References $message.

◆ testKitchensinkInfoRules()

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

Definition at line 312 of file AbstractFactoryTestCase.php.

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,
329 );
330 }
331 }

References $message.

◆ 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.

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 }

References $message.

◆ testProperName()

AbstractFactoryTestCase::testProperName ( )

Reimplemented in MainFactoryTest.

Definition at line 138 of file AbstractFactoryTestCase.php.

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 }

References $message, and isFactoryName().

+ Here is the call graph for this function:

◆ testProperNamespace()

AbstractFactoryTestCase::testProperNamespace ( )

Reimplemented in MainFactoryTest.

Definition at line 128 of file AbstractFactoryTestCase.php.

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

References $message.

◆ 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.

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)

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

+ Here is the call graph for this function:

Field Documentation

◆ $description_categories

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,
'background' => false,
'context' => true,
'featurewiki' => false,
'javascript' => false,
'rules' => true
]
return 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.

Referenced by getMethodsProvider(), and returnsComponent().

◆ $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: