ILIAS  release_7 Revision v7.30-3-g800a261c036
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
4require_once("libs/composer/vendor/autoload.php");
5include_once("tests/UI/Crawler/Fixture/Fixture.php");
6
8use PHPUnit\Framework\TestCase;
9
10class CrawlerTest extends TestCase
11{
12
13
17 protected $parser;
18
22 protected $proper_entry;
23
24 protected function setUp() : void
25 {
26 $this->parser = new Crawler\EntriesYamlParser();
27 $this->proper_entry = new ProperEntryFixture();
28 }
29
33 public function testParseInvalidFile()
34 {
35 try {
36 $this->parser->parseYamlStringArrayFromFile("Invalid Path");
37 $this->assertFalse("This should not happen");
38 } catch (Crawler\Exception\CrawlerException $e) {
39 $this->assertEquals($e->getCode(), Crawler\Exception\CrawlerException::INVALID_FILE_PATH);
40 }
41 }
42
47 {
48 $yaml_entries = $this->parser->parseYamlStringArrayFromFile("tests/UI/Crawler/Fixture/ProperEntry.php");
49
50 $this->assertEquals($this->proper_entry->properEntryYamlString, $yaml_entries[0]);
51 $this->assertEquals($this->proper_entry->properEntryYamlString, $yaml_entries[0]);
52 }
53
55 {
56 $entries = $this->parser->parseArrayFromFile("tests/UI/Crawler/Fixture/ProperEntry.php");
57 $this->assertEquals($this->proper_entry->properEntryYamlArray, $entries);
58 }
59
63 public function testNoDescriptionEntry()
64 {
65 try {
66 $this->parser->parseYamlStringArrayFromFile("tests/UI/Crawler/Fixture/NoDescriptionEntry.php");
67 $this->assertFalse("This should not happen");
68 } catch (Crawler\Exception\CrawlerException $e) {
69 $this->assertEquals($e->getCode(), Crawler\Exception\CrawlerException::ENTRY_WITH_NO_YAML_DESCRIPTION);
70 }
71 }
75 public function testNoReturnValueEntry()
76 {
77 try {
78 $this->parser->parseYamlStringArrayFromFile("tests/UI/Crawler/Fixture/NoReturnValueEntry.php");
79 $this->assertFalse("This should not happen");
80 } catch (Crawler\Exception\CrawlerException $e) {
81 $this->assertEquals($e->getCode(), Crawler\Exception\CrawlerException::ENTRY_WITH_NO_VALID_RETURN_STATEMENT);
82 }
83 }
84
88 public function testInvalidYamlEntry()
89 {
90 try {
91 $this->parser->parseArrayFromFile("tests/UI/Crawler/Fixture/InvalidYamlEntry.php");
92 $this->assertFalse("This should not happen");
93 } catch (Crawler\Exception\CrawlerException $e) {
94 $this->assertEquals($e->getCode(), Crawler\Exception\CrawlerException::PARSING_YAML_ENTRY_FAILED);
95 }
96 }
97
98 public function testCamelCase()
99 {
100 $test_string = "Hello Camel Case";
101
102 $this->assertEquals("helloCamelCase", Crawler\EntriesYamlParser::toLowerCamelCase($test_string, ' '));
103 $this->assertEquals("HelloCamelCase", Crawler\EntriesYamlParser::toUpperCamelCase($test_string, ' '));
104 }
105
109 public function testGenerateEntry()
110 {
111 $entries = $this->parser->parseEntriesFromFile("tests/UI/Crawler/Fixture/ProperEntry.php");
112
113 $this->assertEquals(1, count($entries));
114 $this->assertEquals("CrawlerFixtureProperEntryProperEntry", $entries->getEntryById("CrawlerFixtureProperEntryProperEntry")->getId());
115 $this->assertEquals("src/UI/Crawler/Fixture/ProperEntry", $entries->getEntryById("CrawlerFixtureProperEntryProperEntry")->getPath());
116 }
117}
An exception for terminatinating execution or to throw for unit testing.