ILIAS  trunk Revision v11.0_alpha-1715-g7fc467680fb
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
FactoriesCrawlerTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 require_once("vendor/composer/vendor/autoload.php");
22 include_once("components/ILIAS/UI/tests/Crawler/Fixture/Fixture.php");
23 
26 
28 {
29  protected Crawler\FactoriesCrawler $crawler;
30 
31  protected function setUp(): void
32  {
33  $this->crawler = new Crawler\FactoriesCrawler();
34  }
35 
39  public function testAccessInvalidEntry(): void
40  {
41  try {
42  $entries = $this->crawler->crawlFactory(__DIR__ . "/Fixture/ComponentsTreeFixture/RootFactory.php");
43  $entries->getEntryById("NonExistent")->getChildren();
44  $entries->getParentsOfEntry("NonExistent");
45  $this->assertFalse("This should not happen");
47  $this->assertEquals(Crawler\Exception\CrawlerException::INVALID_ID, $e->getCode());
48  }
49  }
50 
54  public function testParseValidFile(): void
55  {
56  $entries = $this->crawler->crawlFactory(__DIR__ . "/../../../../../components/ILIAS/UI/tests/Crawler/Fixture/ComponentsTreeFixture/RootFactory.php");
57  $this->assertCount(6, $entries);
58  $this->assertCount(
59  2,
60  $entries->getEntryById("testsUICrawlerFixtureComponentsTreeFixtureComponent1FactoryComponent1")->getChildren()
61  );
62  $this->assertCount(
63  3,
64  $entries->getDescendantsOfEntry("testsUICrawlerFixtureComponentsTreeFixtureComponent1FactoryComponent1")
65  );
66  $this->assertCount(
67  1,
68  $entries->getEntryById("testsUICrawlerFixtureComponentsTreeFixtureComponent2FactoryComponent2")->getChildren()
69  );
70  $this->assertCount(
71  0,
72  $entries->getParentsOfEntry("testsUICrawlerFixtureComponentsTreeFixtureComponent1FactoryComponent1")
73  );
74  $this->assertCount(
75  2,
76  $entries->getParentsOfEntry("testsUICrawlerFixtureComponentsTreeFixtureComponent1component12component121Component121")
77  );
78  }
79 
83  public function testLoopFactory(): void
84  {
85  try {
86  $this->crawler->crawlFactory("components/ILIAS/UI/tests/Crawler/Fixture/LoopFactory.php");
87 
88  $this->assertFalse("This should not happen");
90  $this->assertEquals(Crawler\Exception\CrawlerException::CRAWL_MAX_NESTING_REACHED, $e->getCode());
91  }
92  }
93 
97  public function testNoNamespaceFactory(): void
98  {
99  try {
100  $this->crawler->crawlFactory("components/ILIAS/UI/tests/Crawler/Fixture/NoNamespaceFactory.php");
101  $this->assertFalse("This should not happen");
103  $this->assertEquals(Crawler\Exception\CrawlerException::ENTRY_WITH_NO_VALID_RETURN_STATEMENT, $e->getCode());
104  }
105  }
106 
110  public function testNoClosingDescriptionFactory(): void
111  {
112  try {
113  $this->crawler->crawlFactory("components/ILIAS/UI/tests/Crawler/Fixture/NoClosingDescriptionFactory.php");
114 
115  $this->assertFalse("This should not happen");
117  $this->assertEquals(Crawler\Exception\CrawlerException::ENTRY_WITH_NO_YAML_DESCRIPTION, $e->getCode());
118  }
119  }
120 }
Crawler FactoriesCrawler $crawler