ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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
8
10{
11
12
16 protected $crawler;
17
18
19 protected function setUp()
20 {
21 $this->crawler = new Crawler\FactoriesCrawler();
22 }
23
27 public function testAccessInvalidEntry()
28 {
29 try {
30 $entries = $this->crawler->crawlFactory("tests/UI/Crawler/Fixture/ComponentsTreeFixture/RootFactory.php");
31 $entries->getEntryById("NonExistent")->getChildren();
32 $entries->getParentsOfEntry("NonExistent");
33 $this->assertFalse("This should not happen");
34 } catch (Crawler\Exception\CrawlerException $e) {
35 $this->assertEquals($e->getCode(), Crawler\Exception\CrawlerException::INVALID_ID);
36 }
37 }
38
42 public function testParseValidFile()
43 {
44 $entries = $this->crawler->crawlFactory("tests/UI/Crawler/Fixture/ComponentsTreeFixture/RootFactory.php");
45 $this->assertEquals(6, count($entries));
46
47 $this->assertEquals(2, count($entries->getEntryById("testsUICrawlerFixtureComponentsTreeFixtureComponent1FactoryComponent1")->getChildren()));
48 $this->assertEquals(3, count($entries->getDescendantsOfEntry("testsUICrawlerFixtureComponentsTreeFixtureComponent1FactoryComponent1")));
49 $this->assertEquals(1, count($entries->getEntryById("testsUICrawlerFixtureComponentsTreeFixtureComponent2FactoryComponent2")->getChildren()));
50 $this->assertEquals(0, count($entries->getParentsOfEntry("testsUICrawlerFixtureComponentsTreeFixtureComponent1FactoryComponent1")));
51 $this->assertEquals(2, count($entries->getParentsOfEntry("testsUICrawlerFixtureComponentsTreeFixtureComponent1component12component121Component121")));
52 }
53
57 public function testLoopFactory()
58 {
59 try {
60 $this->crawler->crawlFactory("tests/UI/Crawler/Fixture/LoopFactory.php");
61
62 $this->assertFalse("This should not happen");
63 } catch (Crawler\Exception\CrawlerException $e) {
64 $this->assertEquals($e->getCode(), Crawler\Exception\CrawlerException::CRAWL_MAX_NESTING_REACHED);
65 }
66 }
67
72 public function testIdenticalNamesFactory()
73 {
74 $this->crawler->crawlFactory("tests/UI/Crawler/Fixture/IdenticalNamesFactory.php");
75 $this->assertTrue(true);
76 }
77
82 {
83 try {
84 $this->crawler->crawlFactory("tests/UI/Crawler/Fixture/IdenticalEntriesFactory.php");
85 $this->assertFalse("This should not happen");
86 } catch (Crawler\Exception\CrawlerException $e) {
87 $this->assertEquals($e->getCode(), Crawler\Exception\CrawlerException::DUPLICATE_ENTRY);
88 }
89 }
90
94 public function testNoNamespaceFactory()
95 {
96 try {
97 $this->crawler->crawlFactory("tests/UI/Crawler/Fixture/NoNamespaceFactory.php");
98 $this->assertFalse("This should not happen");
99 } catch (Crawler\Exception\CrawlerException $e) {
100 $this->assertEquals($e->getCode(), Crawler\Exception\CrawlerException::ENTRY_WITH_NO_VALID_RETURN_STATEMENT);
101 }
102 }
103
108 {
109 try {
110 $this->crawler->crawlFactory("tests/UI/Crawler/Fixture/NoClosingDescriptionFactory.php");
111
112 $this->assertFalse("This should not happen");
113 } catch (Crawler\Exception\CrawlerException $e) {
114 $this->assertEquals($e->getCode(), Crawler\Exception\CrawlerException::ENTRY_WITH_NO_YAML_DESCRIPTION);
115 }
116 }
117}
An exception for terminatinating execution or to throw for unit testing.