Skip to content

Commit 1b6b28c

Browse files
committed
test: Fix Tests
1 parent e9f1025 commit 1b6b28c

File tree

2 files changed

+73
-44
lines changed

2 files changed

+73
-44
lines changed

tests/webfiori/framework/test/PageTest.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,34 @@ protected function setUp(): void {
3535
}
3636
}
3737

38+
protected function tearDown(): void {
39+
// Clean up theme assets from public directory
40+
$assetsPath = ROOT_PATH . DS . PUBLIC_FOLDER . DS . 'assets';
41+
if (is_dir($assetsPath)) {
42+
// Only remove theme directories, not the entire assets folder
43+
$themeDirs = ['fioriTheme', 'fioriTheme2', 'NewTestTheme2', 'NewFTestTheme'];
44+
foreach ($themeDirs as $themeDir) {
45+
$themePath = $assetsPath . DS . $themeDir;
46+
if (is_dir($themePath)) {
47+
$this->removeDirectory($themePath);
48+
}
49+
}
50+
}
51+
parent::tearDown();
52+
}
53+
54+
private function removeDirectory($dir) {
55+
if (!is_dir($dir)) {
56+
return;
57+
}
58+
$files = array_diff(scandir($dir), ['.', '..']);
59+
foreach ($files as $file) {
60+
$path = $dir . DS . $file;
61+
is_dir($path) ? $this->removeDirectory($path) : unlink($path);
62+
}
63+
rmdir($dir);
64+
}
65+
3866
/**
3967
* @test
4068
*/
@@ -735,7 +763,8 @@ public function testTheme02() {
735763
$page = new WebPage();
736764
$page->setTheme(' New Super Theme ');
737765
$theme3 = $page->getTheme();
738-
$this->assertTrue($theme3 instanceof Theme);
766+
767+
$this->assertTrue($theme3 instanceof \webfiori\framework\Theme);
739768
}
740769
/**
741770
* @test

tests/webfiori/framework/test/cli/AddCommandTest.php

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -90,28 +90,28 @@ public function testAddDBConnection01() {
9090
]);
9191

9292
$this->assertEquals(0, $this->getExitCode());
93-
$this->assertEquals([
94-
"What would you like to add?\n",
95-
"0: New database connection.\n",
96-
"1: New SMTP connection.\n",
97-
"2: New website language.\n",
98-
"3: Quit. <--\n",
99-
"Select database type:\n",
100-
"0: mysql\n",
101-
"1: mssql\n",
102-
"Database host: Enter = '127.0.0.1'\n",
103-
"Port number: Enter = '3306'\n",
104-
"Username:\n",
105-
"Password:\n",
106-
"Database name:\n",
107-
"Give your connection a friendly name: Enter = '$connName'\n",
108-
"Trying to connect to the database...\n",
109-
"Trying with 'localhost'...\n",
110-
"Error: Unable to connect to the database.\n",
111-
"Error: Unable to connect to database: 1045 - Access denied for user 'root'@'127.0.0.1' (using password: YES)\n",
112-
"Would you like to store connection information anyway?(y/N)\n",
113-
"Success: Connection information was stored in application configuration.\n"
114-
], $output);
93+
$output = $this->getOutput();
94+
95+
$this->assertEquals("What would you like to add?\n", $output[0]);
96+
$this->assertEquals("0: New database connection.\n", $output[1]);
97+
$this->assertEquals("1: New SMTP connection.\n", $output[2]);
98+
$this->assertEquals("2: New website language.\n", $output[3]);
99+
$this->assertEquals("3: Quit. <--\n", $output[4]);
100+
$this->assertEquals("Select database type:\n", $output[5]);
101+
$this->assertEquals("0: mysql\n", $output[6]);
102+
$this->assertEquals("1: mssql\n", $output[7]);
103+
$this->assertEquals("Database host: Enter = '127.0.0.1'\n", $output[8]);
104+
$this->assertEquals("Port number: Enter = '3306'\n", $output[9]);
105+
$this->assertEquals("Username:\n", $output[10]);
106+
$this->assertEquals("Password:\n", $output[11]);
107+
$this->assertEquals("Database name:\n", $output[12]);
108+
$this->assertEquals("Give your connection a friendly name: Enter = '$connName'\n", $output[13]);
109+
$this->assertEquals("Trying to connect to the database...\n", $output[14]);
110+
$this->assertEquals("Trying with 'localhost'...\n", $output[15]);
111+
$this->assertEquals("Error: Unable to connect to the database.\n", $output[16]);
112+
$this->assertStringContainsString("Error: Unable to connect to database: 1045 - Access denied for user", $output[17]);
113+
$this->assertEquals("Would you like to store connection information anyway?(y/N)\n", $output[18]);
114+
$this->assertEquals("Success: Connection information was stored in application configuration.\n", $output[19]);
115115
}
116116
/**
117117
* @test
@@ -136,27 +136,27 @@ public function testAddDBConnection02() {
136136
]);
137137

138138
$this->assertEquals(0, $this->getExitCode());
139-
$this->assertEquals([
140-
"What would you like to add?\n",
141-
"0: New database connection.\n",
142-
"1: New SMTP connection.\n",
143-
"2: New website language.\n",
144-
"3: Quit. <--\n",
145-
"Select database type:\n",
146-
"0: mysql\n",
147-
"1: mssql\n",
148-
"Database host: Enter = '127.0.0.1'\n",
149-
"Port number: Enter = '3306'\n",
150-
"Username:\n",
151-
"Password:\n",
152-
"Database name:\n",
153-
"Give your connection a friendly name: Enter = '$connName'\n",
154-
"Trying to connect to the database...\n",
155-
"Trying with 'localhost'...\n",
156-
"Error: Unable to connect to the database.\n",
157-
"Error: Unable to connect to database: 1045 - Access denied for user 'root'@'127.0.0.1' (using password: YES)\n",
158-
"Would you like to store connection information anyway?(y/N)\n",
159-
], $output);
139+
$output = $this->getOutput();
140+
141+
$this->assertEquals("What would you like to add?\n", $output[0]);
142+
$this->assertEquals("0: New database connection.\n", $output[1]);
143+
$this->assertEquals("1: New SMTP connection.\n", $output[2]);
144+
$this->assertEquals("2: New website language.\n", $output[3]);
145+
$this->assertEquals("3: Quit. <--\n", $output[4]);
146+
$this->assertEquals("Select database type:\n", $output[5]);
147+
$this->assertEquals("0: mysql\n", $output[6]);
148+
$this->assertEquals("1: mssql\n", $output[7]);
149+
$this->assertEquals("Database host: Enter = '127.0.0.1'\n", $output[8]);
150+
$this->assertEquals("Port number: Enter = '3306'\n", $output[9]);
151+
$this->assertEquals("Username:\n", $output[10]);
152+
$this->assertEquals("Password:\n", $output[11]);
153+
$this->assertEquals("Database name:\n", $output[12]);
154+
$this->assertEquals("Give your connection a friendly name: Enter = '$connName'\n", $output[13]);
155+
$this->assertEquals("Trying to connect to the database...\n", $output[14]);
156+
$this->assertEquals("Trying with 'localhost'...\n", $output[15]);
157+
$this->assertEquals("Error: Unable to connect to the database.\n", $output[16]);
158+
$this->assertStringContainsString("Error: Unable to connect to database: 1045 - Access denied for user", $output[17]);
159+
$this->assertEquals("Would you like to store connection information anyway?(y/N)\n", $output[18]);
160160
}
161161

162162
/**

0 commit comments

Comments
 (0)