ILIAS  trunk Revision v11.0_alpha-1866-gfa368f7776e
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
TestRailXMLWriter Class Reference
+ Collaboration diagram for TestRailXMLWriter:

Public Member Functions

 __construct (protected \ilTemplate $case_tpl, protected ExamplesYamlParser $parser, protected bool $only_new_cases)
 
 getXML ()
 
 withData (array $data)
 
 addSection (SimpleXMLElement $xml_parent_node, string $name, string $description='',)
 

Protected Member Functions

 addCase (SimpleXMLElement $xml_parent_node, string $id, string $title, string $preconditions, string $steps, string $expected,)
 
 initUISection ()
 
 addComponentCases (SimpleXMLElement $xml_parent_node, string $section, string $component_name, ComponentEntry $entry,)
 
 getTemplate ()
 
 getBlockContents (string $block)
 
 getClickpath (ComponentEntry $entry)
 
 getCaseId (string $component_path, string $subkey)
 
 getExpectedExamples (array $examples)
 

Protected Attributes

const SHOW = 'show'
 
const VALIDATE = 'validate'
 
const BASE = 'UIBASE'
 
const OPEN = 'open'
 
const PREPARE = 'prepare'
 
SimpleXMLElement $xml
 
int $no_found_ids = 0
 
int $no_expexted_ids = 0
 
int $no_new_ids = 0
 
int $no_components = 2
 
array $expected_by_caseids = []
 

Detailed Description

Definition at line 26 of file TestRailXMLWriter.php.

Constructor & Destructor Documentation

◆ __construct()

TestRailXMLWriter::__construct ( protected \ilTemplate  $case_tpl,
protected ExamplesYamlParser  $parser,
protected bool  $only_new_cases 
)

Definition at line 44 of file TestRailXMLWriter.php.

48  {
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));
53  }
54  }

Member Function Documentation

◆ addCase()

TestRailXMLWriter::addCase ( SimpleXMLElement  $xml_parent_node,
string  $id,
string  $title,
string  $preconditions,
string  $steps,
string  $expected 
)
protected

Definition at line 101 of file TestRailXMLWriter.php.

Referenced by addComponentCases(), and initUISection().

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;
120  }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
+ Here is the caller graph for this function:

◆ addComponentCases()

TestRailXMLWriter::addComponentCases ( SimpleXMLElement  $xml_parent_node,
string  $section,
string  $component_name,
ComponentEntry  $entry 
)
protected

Definition at line 157 of file TestRailXMLWriter.php.

References addCase(), getBlockContents(), getCaseId(), getClickpath(), ILIAS\UI\Implementation\Crawler\Entry\ComponentEntry\getExamples(), getExpectedExamples(), getTemplate(), and ILIAS\UI\Implementation\Crawler\Entry\ComponentEntry\getTitle().

Referenced by withData().

162  : void {
163 
164  $preconditions = $this->getBlockContents('preconditions');
165 
166  list($build, $case_id) = $this->getCaseId($section . '/' . $component_name, self::SHOW);
167  if ($build) {
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();
175 
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();
181  $this->addCase(
182  $xml_parent_node,
183  $case_id,
184  $section . ' - ' . $component_name . ': ' . self::SHOW,
185  $preconditions,
186  $steps,
187  $expected
188  );
189  }
190 
191  list($build, $case_id) = $this->getCaseId($section . '/' . $component_name, self::VALIDATE);
192  if ($build) {
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();
200 
201  $expected = $this->getBlockContents('expected_validate');
202 
203  $this->addCase(
204  $xml_parent_node,
205  $case_id,
206  $section . ' - ' . $component_name . ': ' . self::VALIDATE,
207  $preconditions,
208  $steps,
209  $expected
210  );
211  }
212  }
getBlockContents(string $block)
getCaseId(string $component_path, string $subkey)
getExpectedExamples(array $examples)
getClickpath(ComponentEntry $entry)
addCase(SimpleXMLElement $xml_parent_node, string $id, string $title, string $preconditions, string $steps, string $expected,)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addSection()

TestRailXMLWriter::addSection ( SimpleXMLElement  $xml_parent_node,
string  $name,
string  $description = '' 
)

Definition at line 90 of file TestRailXMLWriter.php.

Referenced by initUISection().

95  $xml_section = $xml_parent_node->addChild('section');
96  $xml_section->addChild('name', $name);
97  $xml_section->addChild('description', $description);
98  return $xml_section;
99  }
+ Here is the caller graph for this function:

◆ getBlockContents()

TestRailXMLWriter::getBlockContents ( string  $block)
protected

Definition at line 219 of file TestRailXMLWriter.php.

References getTemplate().

Referenced by addComponentCases(), and initUISection().

219  : string
220  {
221  $contents = $this->getTemplate();
222  $contents->touchBlock($block);
223  return "\n" . trim($contents->get()) . "\n";
224  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getCaseId()

TestRailXMLWriter::getCaseId ( string  $component_path,
string  $subkey 
)
protected

Definition at line 233 of file TestRailXMLWriter.php.

Referenced by addComponentCases(), and initUISection().

233  : array
234  {
235  $case_id = '';
236  if (array_key_exists($component_path, self::$CASEIDS)
237  && array_key_exists($subkey, self::$CASEIDS[$component_path])
238  ) {
239  $case_id = self::$CASEIDS[$component_path][$subkey];
240  $this->no_found_ids += 1;
241  print "\n caseId for: $component_path ($subkey)";
242  unset(
243  $this->expected_by_caseids[
244  array_search($case_id, $this->expected_by_caseids)
245  ]
246  );
247  } else {
248  $this->no_new_ids += 1;
249  print "\n no caseId for: $component_path ($subkey)";
250  }
251 
252  $build = ($case_id === '' && $this->only_new_cases)
253  || ($case_id !== '' && !$this->only_new_cases);
254 
255  return [$build, $case_id];
256  }
+ Here is the caller graph for this function:

◆ getClickpath()

TestRailXMLWriter::getClickpath ( ComponentEntry  $entry)
protected

Definition at line 226 of file TestRailXMLWriter.php.

References ILIAS\UI\Implementation\Crawler\Entry\ComponentEntry\getPath(), and ILIAS\UI\Implementation\Crawler\Entry\ComponentEntry\getTitle().

Referenced by addComponentCases().

226  : string
227  {
228  $clickpath = array_slice(explode('/', $entry->getPath()), 4, -1);
229  $clickpath[] = $entry->getTitle();
230  return implode(' -> ', $clickpath);
231  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getExpectedExamples()

TestRailXMLWriter::getExpectedExamples ( array  $examples)
protected

Definition at line 258 of file TestRailXMLWriter.php.

Referenced by addComponentCases().

258  : string
259  {
260  $expected_show = '';
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";
266  }
267  }
268  return $expected_show;
269  }
+ Here is the caller graph for this function:

◆ getTemplate()

TestRailXMLWriter::getTemplate ( )
protected

Definition at line 214 of file TestRailXMLWriter.php.

Referenced by addComponentCases(), and getBlockContents().

214  : ilTemplate
215  {
216  return clone $this->case_tpl;
217  }
+ Here is the caller graph for this function:

◆ getXML()

TestRailXMLWriter::getXML ( )

Definition at line 56 of file TestRailXMLWriter.php.

References $no_new_ids, and $xml.

57  {
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';
60  print "\n new cases: " . $this->no_new_ids;
61  print "\n known ids unaccounted for: " . implode(',', $this->expected_by_caseids);
62  print "\n";
63  return $this->xml;
64  }
SimpleXMLElement $xml

◆ initUISection()

TestRailXMLWriter::initUISection ( )
protected

Definition at line 122 of file TestRailXMLWriter.php.

References addCase(), addSection(), getBlockContents(), and getCaseId().

123  {
124  $xml_section = $this->addSection(
125  $this->xml,
126  $this->getBlockContents('suite_title'),
127  $this->getBlockContents('suite_description')
128  );
129  $xml_cases = $xml_section->addChild('cases');
130 
131  list($build, $case_id) = $this->getCaseId(self::BASE, self::OPEN);
132  if ($build) {
133  $this->addCase(
134  $xml_cases,
135  $case_id,
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')
140  );
141  }
142  list($build, $case_id) = $this->getCaseId(self::BASE, self::PREPARE);
143  if ($build) {
144  $this->addCase(
145  $xml_cases,
146  $case_id,
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')
151  );
152  }
153 
154  return $xml_section;
155  }
getBlockContents(string $block)
getCaseId(string $component_path, string $subkey)
addSection(SimpleXMLElement $xml_parent_node, string $name, string $description='',)
addCase(SimpleXMLElement $xml_parent_node, string $id, string $title, string $preconditions, string $steps, string $expected,)
+ Here is the call graph for this function:

◆ withData()

TestRailXMLWriter::withData ( array  $data)
Parameters
<string,array>$data

Definition at line 69 of file TestRailXMLWriter.php.

References $components, and addComponentCases().

69  : self
70  {
71  $xml_sections = $this
72  ->initUISection()
73  ->addChild('sections');
74 
75  foreach ($data as $section => $components) {
76  $xml_cases = $this
77  ->addSection($xml_sections, $section, '')
78  ->addChild('cases');
79 
80  foreach ($components as $component) {
81  list($component_name, $entry) = $component;
82  $this->no_components += 2;
83  $this->addComponentCases($xml_cases, $section, $component_name, $entry);
84  }
85  }
86 
87  return $this;
88  }
$components
addComponentCases(SimpleXMLElement $xml_parent_node, string $section, string $component_name, ComponentEntry $entry,)
+ Here is the call graph for this function:

Field Documentation

◆ $expected_by_caseids

array TestRailXMLWriter::$expected_by_caseids = []
protected

Definition at line 42 of file TestRailXMLWriter.php.

◆ $no_components

int TestRailXMLWriter::$no_components = 2
protected

Definition at line 40 of file TestRailXMLWriter.php.

◆ $no_expexted_ids

int TestRailXMLWriter::$no_expexted_ids = 0
protected

Definition at line 38 of file TestRailXMLWriter.php.

◆ $no_found_ids

int TestRailXMLWriter::$no_found_ids = 0
protected

Definition at line 37 of file TestRailXMLWriter.php.

◆ $no_new_ids

int TestRailXMLWriter::$no_new_ids = 0
protected

Definition at line 39 of file TestRailXMLWriter.php.

Referenced by getXML().

◆ $xml

SimpleXMLElement TestRailXMLWriter::$xml
protected

Definition at line 35 of file TestRailXMLWriter.php.

Referenced by getXML().

◆ BASE

const TestRailXMLWriter::BASE = 'UIBASE'
protected

Definition at line 31 of file TestRailXMLWriter.php.

◆ OPEN

const TestRailXMLWriter::OPEN = 'open'
protected

Definition at line 32 of file TestRailXMLWriter.php.

◆ PREPARE

const TestRailXMLWriter::PREPARE = 'prepare'
protected

Definition at line 33 of file TestRailXMLWriter.php.

◆ SHOW

const TestRailXMLWriter::SHOW = 'show'
protected

Definition at line 29 of file TestRailXMLWriter.php.

◆ VALIDATE

const TestRailXMLWriter::VALIDATE = 'validate'
protected

Definition at line 30 of file TestRailXMLWriter.php.


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