ILIAS  trunk Revision v11.0_alpha-1713-gd8962da2f67
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilUITestRailExampleTestCasesObjective.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 use ILIAS\Setup;
22 use ILIAS\DI;
24 
25 class ilUITestRailExampleTestCasesObjective extends Setup\Artifact\BuildArtifactObjective
26 {
27  private const TESTCASEWRITER = 'ui.testrail.xmlwriter';
28  private const FILENAME_UPDATE = 'testcases_update.xml';
29  private const FILENAME_NEW = 'testcases_new.xml';
30 
31  public function __construct(
32  protected bool $only_new_cases
33  ) {
34  }
35 
36  public function getArtifactName(): string
37  {
38  return ($this->only_new_cases) ? self::FILENAME_NEW : self::FILENAME_UPDATE;
39  }
40 
41  public function getPreconditions(Setup\Environment $environment): array
42  {
43  return [
44  new \ilComponentFactoryExistsObjective()
45  ];
46  }
47 
48  protected function getPath(): string
49  {
50  return Setup\Artifact\BuildArtifactObjective::ARTIFACTS . "/" . $this->getArtifactName();
51  }
52 
53  public function achieve(Setup\Environment $environment): Setup\Environment
54  {
55  $component_factory = $environment->getResource(Setup\Environment::RESOURCE_COMPONENT_FACTORY);
56  $plugin_admin = $environment->getResource(Setup\Environment::RESOURCE_PLUGIN_ADMIN);
57 
58  $ORIG_DIC = $GLOBALS["DIC"];
59  $GLOBALS["DIC"] = new DI\Container();
60  $GLOBALS["DIC"]["component.factory"] = $component_factory;
61  $GLOBALS["DIC"]["ilPluginAdmin"] = $plugin_admin;
62 
63  $path = 'components/ILIAS/Style/classes/Setup/templates/testrail.case.xml';
64  $tpl = new ilTemplate($path, true, true);
65  $parser = new Crawler\ExamplesYamlParser();
66  $testcases = new TestRailXMLWriter($tpl, $parser, $this->only_new_cases);
67 
68  $environment = $environment->withResource(self::TESTCASEWRITER, $testcases);
69 
70  parent::achieve($environment);
71  $GLOBALS["DIC"] = $ORIG_DIC;
72  return $environment;
73  }
74 
75  public function build(): Setup\Artifact
76  {
77  }
78 
79  public function buildIn(Setup\Environment $env): Setup\Artifact
80  {
81  $crawler = new Crawler\FactoriesCrawler();
83 
84  $sorted = [];
85  foreach ($data as $entry) {
86  $path = explode('/', $entry->getPath());
87  if (end($path) === 'Factory') {
88  continue;
89  }
90  $path = array_slice($path, 3);
91  $section = array_shift($path);
92  $section = array_shift($path);
93  $section = array_shift($path);
94  if (! array_key_exists($section, $sorted)) {
95  $sorted[$section] = [];
96  }
97  $path = array_slice($path, 0, -1);
98  $path[] = $entry->getTitle();
99  $sorted[$section][] = [implode('/', $path), $entry];
100  }
101  ksort($sorted);
102 
103  $writer = $env->getResource(self::TESTCASEWRITER)
104  ->withData($sorted);
105  return new Setup\Artifact\XMLArtifact($writer->getXML());
106  }
107 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Container.php:19
$path
Definition: ltiservices.php:29
$GLOBALS["DIC"]
Definition: wac.php:53
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
An environment holds resources to be used in the setup process.
Definition: Environment.php:27
An artifact is some file that is build on demand per installation and is not shipped with the ILIAS s...
Definition: Artifact.php:27