ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
EntriesYamlParserTest.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 
4 require_once("libs/composer/vendor/autoload.php");
5 include_once("tests/UI/Crawler/Fixture/Fixture.php");
6 
8 
9 
11 
12 
16  protected $parser;
17 
21  protected $proper_entry;
22 
23  protected function setUp()
24  {
25  $this->parser = new Crawler\EntriesYamlParser();
26  $this->proper_entry = new ProperEntryFixture();
27  }
28 
32  public function testParseInvalidFile() {
33  try{
34  $this->parser->parseYamlStringArrayFromFile("Invalid Path");
35  $this->assertFalse("This should not happen");
36 
38  $this->assertEquals($e->getCode(),Crawler\Exception\CrawlerException::INVALID_FILE_PATH);
39  }
40  }
41 
46  $yaml_entries = $this->parser->parseYamlStringArrayFromFile("tests/UI/Crawler/Fixture/ProperEntry.php");
47 
48  $this->assertEquals($this->proper_entry->properEntryYamlString,$yaml_entries[0]);
49  $this->assertEquals($this->proper_entry->properEntryYamlString,$yaml_entries[0]);
50  }
51 
52  public function testParseProperEntryToArray() {
53  $entries = $this->parser->parseArrayFromFile("tests/UI/Crawler/Fixture/ProperEntry.php");
54  $this->assertEquals($this->proper_entry->properEntryYamlArray,$entries);
55  }
56 
60  public function testNoDescriptionEntry() {
61  try{
62  $this->parser->parseYamlStringArrayFromFile("tests/UI/Crawler/Fixture/NoDescriptionEntry.php");
63  $this->assertFalse("This should not happen");
64 
66  $this->assertEquals($e->getCode(),Crawler\Exception\CrawlerException::ENTRY_WITH_NO_YAML_DESCRIPTION);
67  }
68  }
72  public function testNoReturnValueEntry() {
73  try{
74  $this->parser->parseYamlStringArrayFromFile("tests/UI/Crawler/Fixture/NoReturnValueEntry.php");
75  $this->assertFalse("This should not happen");
76 
78  $this->assertEquals($e->getCode(),Crawler\Exception\CrawlerException::ENTRY_WITH_NO_VALID_RETURN_STATEMENT);
79  }
80  }
81 
85  public function testInvalidYamlEntry() {
86  try{
87  $this->parser->parseArrayFromFile("tests/UI/Crawler/Fixture/InvalidYamlEntry.php");
88  $this->assertFalse("This should not happen");
89 
91  $this->assertEquals($e->getCode(),Crawler\Exception\CrawlerException::PARSING_YAML_ENTRY_FAILED);
92  }
93  }
94 
95  public function testCamelCase() {
96  $test_string = "Hello Camel Case";
97 
98  $this->assertEquals("helloCamelCase",Crawler\EntriesYamlParser::toLowerCamelCase($test_string, ' '));
99  $this->assertEquals("HelloCamelCase",Crawler\EntriesYamlParser::toUpperCamelCase($test_string, ' '));
100 
101  }
102 
106  public function testGenerateEntry() {
107  $entries = $this->parser->parseEntriesFromFile("tests/UI/Crawler/Fixture/ProperEntry.php");
108 
109  $this->assertEquals(1,count($entries));
110  $this->assertEquals("CrawlerFixtureProperEntryProperEntry",$entries->getEntryById("CrawlerFixtureProperEntryProperEntry")->getId());
111  $this->assertEquals("src/UI/Crawler/Fixture/ProperEntry",$entries->getEntryById("CrawlerFixtureProperEntryProperEntry")->getPath());
112  }
113 }