ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
EntriesYamlParserTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21require_once("vendor/composer/vendor/autoload.php");
22include_once("components/ILIAS/UI/tests/Crawler/Fixture/Fixture.php");
23
25use PHPUnit\Framework\TestCase;
26
27class EntriesYamlParserTest extends TestCase
28{
31
32 protected function setUp(): void
33 {
34 $this->parser = new Crawler\EntriesYamlParser();
35 $this->proper_entry = new ProperEntryFixture();
36 }
37
41 public function testParseInvalidFile(): void
42 {
43 try {
44 $this->parser->parseYamlStringArrayFromFile("Invalid Path");
45 $this->assertFalse("This should not happen");
46 } catch (Crawler\Exception\CrawlerException $e) {
47 $this->assertEquals(Crawler\Exception\CrawlerException::INVALID_FILE_PATH, $e->getCode());
48 }
49 }
50
54 public function testParseProperEntryToYamlEntries(): void
55 {
56 $yaml_entries = $this->parser->parseYamlStringArrayFromFile("components/ILIAS/UI/tests/Crawler/Fixture/ProperEntry.php");
57
58 $this->assertEquals($this->proper_entry->properEntryYamlString, $yaml_entries[0]);
59 $this->assertEquals($this->proper_entry->properEntryYamlString, $yaml_entries[0]);
60 }
61
62 public function testParseProperEntryToArray(): void
63 {
64 $entries = $this->parser->parseArrayFromFile("components/ILIAS/UI/tests/Crawler/Fixture/ProperEntry.php");
65 $this->assertEquals($this->proper_entry->properEntryYamlArray, $entries);
66 }
67
71 public function testNoDescriptionEntry(): void
72 {
73 try {
74 $this->parser->parseYamlStringArrayFromFile("components/ILIAS/UI/tests/Crawler/Fixture/NoDescriptionEntry.php");
75 $this->assertFalse("This should not happen");
76 } catch (Crawler\Exception\CrawlerException $e) {
77 $this->assertEquals(Crawler\Exception\CrawlerException::ENTRY_WITH_NO_YAML_DESCRIPTION, $e->getCode());
78 }
79 }
83 public function testNoReturnValueEntry(): void
84 {
85 try {
86 $this->parser->parseYamlStringArrayFromFile("components/ILIAS/UI/tests/Crawler/Fixture/NoReturnValueEntry.php");
87 $this->assertFalse("This should not happen");
88 } catch (Crawler\Exception\CrawlerException $e) {
89 $this->assertEquals(Crawler\Exception\CrawlerException::ENTRY_WITH_NO_VALID_RETURN_STATEMENT, $e->getCode());
90 }
91 }
92
96 public function testInvalidYamlEntry(): void
97 {
98 try {
99 $this->parser->parseArrayFromFile("components/ILIAS/UI/tests/Crawler/Fixture/InvalidYamlEntry.php");
100 $this->assertFalse("This should not happen");
101 } catch (Crawler\Exception\CrawlerException $e) {
102 $this->assertEquals(Crawler\Exception\CrawlerException::PARSING_YAML_ENTRY_FAILED, $e->getCode());
103 }
104 }
105
106 public function testCamelCase(): void
107 {
108 $test_string = "Hello Camel Case";
109
110 $this->assertEquals("helloCamelCase", Crawler\EntriesYamlParser::toLowerCamelCase($test_string, ' '));
111 $this->assertEquals("HelloCamelCase", Crawler\EntriesYamlParser::toUpperCamelCase($test_string, ' '));
112 }
113
117 public function testGenerateEntry(): void
118 {
119 $entries = $this->parser->parseEntriesFromFile("components/ILIAS/UI/tests/Crawler/Fixture/ProperEntry.php");
120
121 $this->assertCount(1, $entries);
122 $this->assertEquals(
123 "CrawlerFixtureProperEntryProperEntry",
124 $entries->getEntryById("CrawlerFixtureProperEntryProperEntry")->getId()
125 );
126 $this->assertEquals(
127 "components/ILIAS/UI/src/Crawler/Fixture/ProperEntry",
128 $entries->getEntryById("CrawlerFixtureProperEntryProperEntry")->getPath()
129 );
130 }
131}
ProperEntryFixture $proper_entry
Crawler EntriesYamlParser $parser
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Fixture.php:20