19 declare(strict_types=1);
21 require_once(
"libs/composer/vendor/autoload.php");
53 'description' =>
true,
54 'background' =>
false,
56 'featurewiki' =>
false,
57 'javascript' =>
false,
92 return in_array(
"ILIAS\\UI\\Component\\Component", $reflection->getInterfaceNames());
97 return preg_match(
"#^(\\\\)?ILIAS\\\\UI\\\\Component\\\\([a-zA-Z]+\\\\)*Factory$#", $name) === 1;
109 array_map(
function ($element) {
111 return array($element, $element->getName());
114 }, $reflection->getMethods())
128 $message =
"TODO: Put your factory into the proper namespace.";
129 $this->assertMatchesRegularExpression(
130 "#^ILIAS\\\\UI\\\\Component.#",
131 $this->reflection->getNamespaceName(),
138 $name = $this->reflection->getName();
139 $message =
"TODO: Give your factory a proper name.";
152 $function_name_string =
"\n public function " . $method_reflection->getName() .
"()";
153 $docstring_data = $this->yaml_parser->parseArrayFromString(
154 $method_reflection->getDocComment() . $function_name_string
156 $this->assertTrue(
true);
158 $message =
"TODO ($name): fix parse error in kitchen sink yaml: " . $e->getMessage();
161 $this->assertCount(1, $docstring_data);
162 return $docstring_data[0];
172 $message =
"TODO ($name): fix return type, it must be a factory or a component.";
175 $this->assertTrue(
true);
177 $this->assertTrue(
true);
195 $return_doc = $docstring_data[
"namespace"];
196 $name_uppercase = ucwords($name);
198 $regex_head =
"#^(\\\\?)$regex_factory_namespace";
200 $message =
"TODO ($name): fix @return, it does not match the method name.";
202 $this->assertMatchesRegularExpression(
203 "$regex_head\\\\$name_uppercase\\\\Factory$#",
210 $standard_pattern =
"$regex_head\\\\$name_uppercase#";
211 $standard_case = preg_match($standard_pattern, $return_doc);
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);
218 $this->assertTrue($standard_case || $typediff_only_case,
$message);
224 return str_replace(
"\\",
"\\\\", $this->reflection->getNamespaceName());
236 $message =
"TODO ($name): remove params from method that returns Factory.";
237 $this->assertEquals(0, $method_reflection->getNumberOfParameters(),
$message);
252 if ($kitchensink_info_settings[
'description']) {
253 $message =
"TODO ($name): add a description.";
254 $this->assertArrayHasKey(
'description', $docstring_data,
$message);
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(
262 $existing_expected_keys,
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);
279 $this->assertTrue(
true);
290 if ($kitchensink_info_settings[
'background']) {
291 $message =
"TODO ($name): add a background field.";
292 $this->assertArrayHasKey(
'background', $docstring_data,
$message);
304 if ($kitchensink_info_settings[
'featurewiki']) {
305 $message =
"TODO ($name): add a featurewiki field.";
306 $this->assertArrayHasKey(
'featurewiki', $docstring_data,
$message);
318 if ($kitchensink_info_settings[
'javascript']) {
319 $message =
"TODO ($name): add a javascript field.";
320 $this->assertArrayHasKey(
'javascript', $docstring_data,
$message);
332 if ($kitchensink_info_settings[
'rules']) {
333 $message =
"TODO ($name): add a rules field.";
334 $this->assertArrayHasKey(
'rules', $docstring_data,
$message);
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(
342 $existing_expected_keys,
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);
363 if (array_key_exists($name, $this->kitchensink_info_settings)) {
365 $this->kitchensink_info_settings_default,
366 $this->kitchensink_info_settings[$name]
testReturnType(ReflectionMethod $method_reflection, string $name)
Tests whether the method either returns a factory or a component.
kitchensinkInfoSettingsMergedWithDefaults(string $name)
testKitchensinkInfoFeatureWiki(ReflectionMethod $method_reflection, string $name)
getMethodsProvider
testKitchensinkInfoDescription(ReflectionMethod $method_reflection, string $name)
getMethodsProvider
testKitchensinkInfoBackground(ReflectionMethod $method_reflection, string $name)
getMethodsProvider
testFactoryMethodNameCompatibleDocstring(ReflectionMethod $method_reflection, string $name)
Tests whether the method name matches the return doctring?
array $kitchensink_info_settings_default
array $omit_factory_methods
Crawler EntriesYamlParser $yaml_parser
returnsComponent(array $docstring_data)
testKitchensinkInfoRivals(ReflectionMethod $method_reflection, string $name)
getMethodsProvider
Defines tests every SHOULD pass UI-factory.
returnsFactory(array $docstring_data)
testKitchensinkInfoRules(ReflectionMethod $method_reflection, string $name)
getMethodsProvider
testKitchensinkInfoContext(ReflectionMethod $method_reflection, string $name)
getMethodsProvider
testKitchensinkInfoJavaScript(ReflectionMethod $method_reflection, string $name)
getMethodsProvider
array array $description_categories
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
testMethodParams(ReflectionMethod $method_reflection, string $name)
Tests whether methods returning factories have no parameters.
ReflectionClass $reflection
getRegexFactoryNamespace()
isFactoryName(string $name)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
testCheckYamlExtraction(ReflectionMethod $method_reflection, string $name)
Tests whether the YAML Kitchen Sink info can be parsed.