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