ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
FactoriesCrawlerTest.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 2016 Timon Amstutz <timon.amstutz@ilub.unibe.ch> Extended GPL, see docs/LICENSE */
3
4require_once("libs/composer/vendor/autoload.php");
5include_once("tests/UI/Crawler/Fixture/Fixture.php");
6
8use PHPUnit\Framework\TestCase;
9
10class FactoriesCrawlerTest extends TestCase
11{
12
13
17 protected $crawler;
18
19
20 protected function setUp() : void
21 {
22 $this->crawler = new Crawler\FactoriesCrawler();
23 }
24
28 public function testAccessInvalidEntry()
29 {
30 try {
31 $entries = $this->crawler->crawlFactory("tests/UI/Crawler/Fixture/ComponentsTreeFixture/RootFactory.php");
32 $entries->getEntryById("NonExistent")->getChildren();
33 $entries->getParentsOfEntry("NonExistent");
34 $this->assertFalse("This should not happen");
35 } catch (Crawler\Exception\CrawlerException $e) {
36 $this->assertEquals($e->getCode(), Crawler\Exception\CrawlerException::INVALID_ID);
37 }
38 }
39
43 public function testParseValidFile()
44 {
45 $entries = $this->crawler->crawlFactory("tests/UI/Crawler/Fixture/ComponentsTreeFixture/RootFactory.php");
46 $this->assertEquals(6, count($entries));
47
48 $this->assertEquals(2, count($entries->getEntryById("testsUICrawlerFixtureComponentsTreeFixtureComponent1FactoryComponent1")->getChildren()));
49 $this->assertEquals(3, count($entries->getDescendantsOfEntry("testsUICrawlerFixtureComponentsTreeFixtureComponent1FactoryComponent1")));
50 $this->assertEquals(1, count($entries->getEntryById("testsUICrawlerFixtureComponentsTreeFixtureComponent2FactoryComponent2")->getChildren()));
51 $this->assertEquals(0, count($entries->getParentsOfEntry("testsUICrawlerFixtureComponentsTreeFixtureComponent1FactoryComponent1")));
52 $this->assertEquals(2, count($entries->getParentsOfEntry("testsUICrawlerFixtureComponentsTreeFixtureComponent1component12component121Component121")));
53 }
54
58 public function testLoopFactory()
59 {
60 try {
61 $this->crawler->crawlFactory("tests/UI/Crawler/Fixture/LoopFactory.php");
62
63 $this->assertFalse("This should not happen");
64 } catch (Crawler\Exception\CrawlerException $e) {
65 $this->assertEquals($e->getCode(), Crawler\Exception\CrawlerException::CRAWL_MAX_NESTING_REACHED);
66 }
67 }
68
73 public function testIdenticalNamesFactory()
74 {
75 $this->crawler->crawlFactory("tests/UI/Crawler/Fixture/IdenticalNamesFactory.php");
76 $this->assertTrue(true);
77 }
78
83 {
84 try {
85 $this->crawler->crawlFactory("tests/UI/Crawler/Fixture/IdenticalEntriesFactory.php");
86 $this->assertFalse("This should not happen");
87 } catch (Crawler\Exception\CrawlerException $e) {
88 $this->assertEquals($e->getCode(), Crawler\Exception\CrawlerException::DUPLICATE_ENTRY);
89 }
90 }
91
95 public function testNoNamespaceFactory()
96 {
97 try {
98 $this->crawler->crawlFactory("tests/UI/Crawler/Fixture/NoNamespaceFactory.php");
99 $this->assertFalse("This should not happen");
100 } catch (Crawler\Exception\CrawlerException $e) {
101 $this->assertEquals($e->getCode(), Crawler\Exception\CrawlerException::ENTRY_WITH_NO_VALID_RETURN_STATEMENT);
102 }
103 }
104
109 {
110 try {
111 $this->crawler->crawlFactory("tests/UI/Crawler/Fixture/NoClosingDescriptionFactory.php");
112
113 $this->assertFalse("This should not happen");
114 } catch (Crawler\Exception\CrawlerException $e) {
115 $this->assertEquals($e->getCode(), Crawler\Exception\CrawlerException::ENTRY_WITH_NO_YAML_DESCRIPTION);
116 }
117 }
118}
An exception for terminatinating execution or to throw for unit testing.