19declare(strict_types=1);
21require_once(dirname(__FILE__) .
'/templates/testrail.case_ids.php');
29 protected const SHOW =
'show';
31 protected const BASE =
'UIBASE';
32 protected const OPEN =
'open';
35 protected SimpleXMLElement
$xml;
47 protected bool $only_new_cases
49 $this->xml =
new SimpleXMLElement(
'<?xml version="1.0"?><sections></sections>');
50 foreach (self::$CASEIDS as $k => $v) {
51 $this->no_expexted_ids += count($v);
52 $this->expected_by_caseids = array_merge($this->expected_by_caseids, array_values($v));
56 public function getXML(): SimpleXMLElement
58 print
"\n found " . $this->no_components .
' components/cases';
59 print
"\n update for " . $this->no_found_ids .
' of ' . $this->no_expexted_ids .
' known IDs';
61 print
"\n known ids unaccounted for: " . implode(
',', $this->expected_by_caseids);
73 ->addChild(
'sections');
77 ->addSection($xml_sections, $section,
'')
81 list($component_name, $entry) = $component;
82 $this->no_components += 2;
91 SimpleXMLElement $xml_parent_node,
93 string $description =
'',
95 $xml_section = $xml_parent_node->addChild(
'section');
96 $xml_section->addChild(
'name', $name);
97 $xml_section->addChild(
'description', $description);
102 SimpleXMLElement $xml_parent_node,
105 string $preconditions,
108 ): SimpleXMLElement {
109 $xml_case = $xml_parent_node->addChild(
'case');
110 $xml_case->addChild(
'id',
$id);
111 $xml_case->addChild(
'title', $title);
112 $xml_case->addChild(
'template',
'Test Case');
113 $xml_case->addChild(
'type',
'Other');
114 $xml_case->addChild(
'priority',
'4 - Must Test');
115 $xml_cust = $xml_case->addChild(
'custom');
116 $xml_cust->addChild(
'preconds',
"\n" . trim($preconditions) .
"\n");
117 $xml_cust->addChild(
'steps',
"\n" . trim($steps) .
"\n");
118 $xml_cust->addChild(
'expected',
"\n" . trim($expected) .
"\n");
119 return $xml_parent_node;
124 $xml_section = $this->addSection(
126 $this->getBlockContents(
'suite_title'),
127 $this->getBlockContents(
'suite_description')
129 $xml_cases = $xml_section->addChild(
'cases');
131 list($build, $case_id) = $this->getCaseId(self::BASE, self::OPEN);
136 $this->getBlockContents(
'suite_case_open_title'),
137 $this->getBlockContents(
'suite_case_open_precond'),
138 $this->getBlockContents(
'suite_case_open_steps'),
139 $this->getBlockContents(
'suite_case_open_expected')
142 list($build, $case_id) = $this->getCaseId(self::BASE, self::PREPARE);
147 $this->getBlockContents(
'suite_case_validate_title'),
148 $this->getBlockContents(
'suite_case_validate_precond'),
149 $this->getBlockContents(
'suite_case_validate_steps'),
150 $this->getBlockContents(
'suite_case_validate_expected')
158 SimpleXMLElement $xml_parent_node,
160 string $component_name,
164 $preconditions = $this->getBlockContents(
'preconditions');
166 list($build, $case_id) = $this->getCaseId($section .
'/' . $component_name, self::SHOW);
168 $steps = $this->getTemplate();
169 $steps->setCurrentBlock(
'steps_show');
170 $steps->setVariable(
'SECTION', $section);
171 $steps->setVariable(
'CLICKPATH', $this->getClickpath($entry));
172 $steps->setVariable(
'TITLE', $entry->
getTitle());
173 $steps->parseCurrentBlock();
174 $steps = $steps->get();
176 $expected = $this->getTemplate();
177 $expected_examples = $this->getExpectedExamples($entry->
getExamples());
178 $expected->setVariable(
'EXAMPLE_COUNTER', (
string) count($entry->
getExamples()));
179 $expected->setVariable(
'EXPECTED', $expected_examples);
180 $expected = $expected->get();
184 $section .
' - ' . $component_name .
': ' . self::SHOW,
191 list($build, $case_id) = $this->getCaseId($section .
'/' . $component_name, self::VALIDATE);
193 $steps = $this->getTemplate();
194 $steps->setCurrentBlock(
'steps_validate');
195 $steps->setVariable(
'SECTION', $section);
196 $steps->setVariable(
'CLICKPATH', $this->getClickpath($entry));
197 $steps->setVariable(
'TITLE', $entry->
getTitle());
198 $steps->parseCurrentBlock();
199 $steps = $steps->get();
201 $expected = $this->getBlockContents(
'expected_validate');
206 $section .
' - ' . $component_name .
': ' . self::VALIDATE,
216 return clone $this->case_tpl;
221 $contents = $this->getTemplate();
222 $contents->touchBlock($block);
223 return "\n" . trim($contents->get()) .
"\n";
228 $clickpath = array_slice(explode(
'/', $entry->
getPath()), 4, -1);
230 return implode(
' -> ', $clickpath);
233 protected function getCaseId(
string $component_path,
string $subkey): array
236 if (array_key_exists($component_path, self::$CASEIDS)
237 && array_key_exists($subkey, self::$CASEIDS[$component_path])
239 $case_id = self::$CASEIDS[$component_path][$subkey];
240 $this->no_found_ids += 1;
241 print
"\n caseId for: $component_path ($subkey)";
243 $this->expected_by_caseids[
244 array_search($case_id, $this->expected_by_caseids)
248 $this->no_new_ids += 1;
249 print
"\n no caseId for: $component_path ($subkey)";
252 $build = ($case_id ===
'' && $this->only_new_cases)
253 || ($case_id !==
'' && !$this->only_new_cases);
255 return [$build, $case_id];
261 foreach (array_keys($examples) as $idx => $example) {
262 $expected_show = $expected_show .
"\n**" . $idx + 1 .
'. ' . ucfirst(str_replace(
'_',
' ', $example)) .
'**';
263 $docs = $this->parser->parseYamlStringArrayFromFile($examples[$example]);
264 if (array_key_exists(
'expected output', $docs)) {
265 $expected_show .=
"\n" . $docs[
'expected output'] .
"\n";
268 return $expected_show;
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Stores Information of UI Components parsed from YAML, examples and less files.
addSection(SimpleXMLElement $xml_parent_node, string $name, string $description='',)
getClickpath(ComponentEntry $entry)
getCaseId(string $component_path, string $subkey)
addComponentCases(SimpleXMLElement $xml_parent_node, string $section, string $component_name, ComponentEntry $entry,)
addCase(SimpleXMLElement $xml_parent_node, string $id, string $title, string $preconditions, string $steps, string $expected,)
getBlockContents(string $block)
getExpectedExamples(array $examples)
__construct(protected \ilTemplate $case_tpl, protected ExamplesYamlParser $parser, protected bool $only_new_cases)
array $expected_by_caseids
special template class to simplify handling of ITX/PEAR
trait TestrailCaseIds
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...