Skip to content

Commit

Permalink
Merge pull request #230 from WebFiori/dev
Browse files Browse the repository at this point in the history
Code Quality Improvments
  • Loading branch information
usernane authored Aug 21, 2024
2 parents 3f107ce + 5749763 commit e5bd109
Show file tree
Hide file tree
Showing 22 changed files with 306 additions and 101 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"webfiori/ui":"v2.6.3",
"webfiori/collections":"v1.1.4",
"webfiori/database":"v0.8.10",
"webfiori/cli":"v1.2.2",
"webfiori/cli":"v1.3.0",
"webfiori/mailer":"v1.2.0",
"webfiori/err":"v1.1.0"
},
Expand Down
5 changes: 4 additions & 1 deletion tests/webfiori/framework/test/PageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,10 @@ public function testTheme03() {

$page->setTheme($secondThemeName);
$fTheme = $page->getTheme();


$this->assertEquals($firstThemeName, $theme3->getName());
$this->assertEquals($secondThemeName, $fTheme->getName());

$this->assertFalse($theme3 === $fTheme);
$this->assertNotEquals($firstThemeName,$fTheme->getName());
$page->setTheme($secondThemeName);
Expand Down
2 changes: 2 additions & 0 deletions tests/webfiori/framework/test/PrivilegesGroupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public function testRemoveParentGroup00($gArr) {
public function testRemoveParentGroup01() {
$child = new PrivilegesGroup('CH_GROUP_1', 'Child Group #1');
$this->assertFalse($child->setParentGroup());

}
/**
* @test
Expand Down Expand Up @@ -141,6 +142,7 @@ public function testSetID01() {
public function testSetParentGroup00() {
$child = new PrivilegesGroup('CH_GROUP_1', 'Child Group #1');
$parentGroup = new PrivilegesGroup('PARENT_1', 'Parent Group #1');
$this->assertFalse($parentGroup->setParentGroup(null));
$this->assertFalse($child->setParentGroup($child));
$this->assertTrue($child->setParentGroup($parentGroup));
$this->assertSame($parentGroup,$child->getParentGroup());
Expand Down
4 changes: 4 additions & 0 deletions tests/webfiori/framework/test/cli/CreateMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ public function testCreateMiddleware01() {
$runner->setInputs([
'NewCool',
'app\middleware',
' ',
'Check is cool',

'22',
'y',
'global',
Expand All @@ -77,6 +79,8 @@ public function testCreateMiddleware01() {
"Enter a name for the new class:\n",
"Enter an optional namespace for the class: Enter = 'app\middleware'\n",
"Enter a name for the middleware:\n",
"Error: Invalid input is given. Try again.\n",
"Enter a name for the middleware:\n",
"Enter middleware priority: Enter = '0'\n",
"Would you like to add the middleware to a group?(y/N)\n",
"Enter group name:\n",
Expand Down
5 changes: 4 additions & 1 deletion tests/webfiori/framework/test/cli/CreateTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ public function test02() {
'',
'Invalid#',
'Create Round task',
'The task will do nothing.',
' ',
' The task will do nothing. ',
'N',
'',
]);
Expand All @@ -149,6 +150,8 @@ public function test02() {
"Error: Provided name is invalid!\n",
"Enter a name for the task:\n",
"Provide short description of what does the task will do:\n",
"Error: Invalid input is given. Try again.\n",
"Provide short description of what does the task will do:\n",
"Would you like to add arguments to the task?(y/N)\n",
"Info: New class was created at \"".ROOT_PATH.DS.'app'.DS."tasks\".\n",
], $runner->getOutput());
Expand Down
10 changes: 5 additions & 5 deletions tests/webfiori/framework/test/cli/SchedulerCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,16 +173,16 @@ public function test05() {
"Line: 44\n",
"Stack Trace:\n",
"#0 At class app\\tasks\Fail2TestTask line 44\n",
"#1 At class webfiori\\framework\scheduler\AbstractTask line 1101\n",
"#2 At class webfiori\\framework\scheduler\AbstractTask line 422\n",
"#1 At class webfiori\\framework\scheduler\AbstractTask line 1128\n",
"#2 At class webfiori\\framework\scheduler\AbstractTask line 449\n",
"#3 At class webfiori\\framework\scheduler\AbstractTask line 951\n",
"#4 At class webfiori\\framework\scheduler\TasksManager line 673\n",
"#5 At class webfiori\\framework\scheduler\TasksManager line 139\n",
"#6 At class webfiori\\framework\cli\commands\SchedulerCommand line 86\n",
"#7 At class webfiori\\framework\cli\commands\SchedulerCommand line 328\n",
"#7 At class webfiori\\framework\cli\commands\SchedulerCommand line 331\n",
"#8 At class webfiori\\cli\CLICommand line 409\n",
"#9 At class webfiori\\cli\Runner line 684\n",
"#10 At class webfiori\\cli\Runner line 615\n",
"#9 At class webfiori\\cli\Runner line 725\n",
"#10 At class webfiori\\cli\Runner line 656\n",
"#11 At class webfiori\cli\Runner line 156\n",
"Skip"];
$actual = $runner->getOutput();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use PHPUnit\Framework\TestCase;
use webfiori\framework\App;
use webfiori\framework\config\Controller;
use webfiori\framework\config\JsonDriver;
use webfiori\framework\router\Router;

/**
Expand All @@ -16,6 +17,7 @@ class UpdateSettingsCommandTest extends TestCase {
* @test
*/
public function test00() {
JsonDriver::setConfigFileName('app-config.json');
$runner = App::getRunner();
$runner->setArgsVector([
'webfiori',
Expand Down
2 changes: 1 addition & 1 deletion tests/webfiori/framework/test/config/JsonDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,6 @@ public function testDatabaseConnections02() {
}
/**
* @test
* @depends testSetConfigFileName00
*/
public function testAppWithError00() {
$this->expectExceptionMessage('The property "username" of the connection "New_Connection" is missing.');
Expand All @@ -475,4 +474,5 @@ public function testAppWithError00() {
$driver->initialize();
$driver->getDBConnections();
}

}
131 changes: 130 additions & 1 deletion tests/webfiori/framework/test/scheduler/SchedulerTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
use Exception;
use InvalidArgumentException;
use PHPUnit\Framework\TestCase;
use webfiori\framework\exceptions\InvalidCRONExprException;
use webfiori\framework\Privilege;
use webfiori\framework\scheduler\BaseTask;
use webfiori\framework\scheduler\TaskArgument;
use webfiori\framework\scheduler\TasksManager;
Expand Down Expand Up @@ -79,7 +81,7 @@ public function testAttributes06() {
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage("Invalid argument type. Expected 'string' or 'webfiori\\framework\\scheduler\\TaskArgument'");
$job = new BaseTask();
$job->addExecutionArg(new \webfiori\framework\Privilege());
$job->addExecutionArg(new Privilege());
}
/**
* @test
Expand Down Expand Up @@ -376,6 +378,30 @@ public function testConstructor28() {
$this->expectExceptionMessage('Invalid cron expression: \'5-a * * * *\'.');
$task = new BaseTask('5-a * * * *');
}
/**
* @test
*/
public function testConstructor29() {
$this->expectException(Exception::class);
$this->expectExceptionMessage('Invalid cron expression: \'5-7,8- * * * *\'.');
$task = new BaseTask('5-7,8- * * * *');
}
/**
* @test
*/
public function testConstructor30() {
$this->expectException(Exception::class);
$this->expectExceptionMessage('Invalid cron expression: \'5/,8- * * * *\'.');
$task = new BaseTask('5/,8- * * * *');
}
/**
* @test
*/
public function testConstructor31() {
$this->expectException(Exception::class);
$this->expectExceptionMessage('Invalid cron expression: \'5/b,8- * * * *\'.');
$task = new BaseTask('5/b,8- * * * *');
}
/**
* @test
*/
Expand Down Expand Up @@ -708,6 +734,37 @@ public function testIsDayOfWeek02() {
TasksManager::setDayOfWeek(5);
$this->assertFalse($job->isDayOfWeek());
}
/**
* @test
*/
public function testIsDayOfWeek03() {
$job = new BaseTask();
$job->everyWeek();

TasksManager::setDayOfWeek(0);
TasksManager::setHour(0);
$this->assertTrue($job->isDayOfWeek());
$this->assertTrue($job->isHour());

}
/**
* @test
*/
public function testIsDayOfWeek04() {
$this->expectException(InvalidCRONExprException::class);
$this->expectExceptionMessage("Invalid cron expression: '5 4 * * 0-a,5-6'");
$job = new BaseTask('5 4 * * 0-a,5-6');

}
/**
* @test
*/
public function testIsDayOfWeek05() {
$this->expectException(InvalidCRONExprException::class);
$this->expectExceptionMessage("Invalid cron expression: '5 4 * * 0-,5-6'");
$job = new BaseTask('5 4 * * 0-,5-6');

}
/**
* @test
*/
Expand Down Expand Up @@ -774,7 +831,40 @@ public function testIsHour02() {
$this->assertFalse($job->isHour());
}

/**
* @test
*/
public function testIsHour03() {
$job = new BaseTask();
$job->everyXHour(2);

for ($x = 0 ; $x < 24 ; $x++) {
TasksManager::setHour($x);

if ($x % 2 == 0) {
$this->assertTrue($job->isHour());
} else {
$this->assertFalse($job->isHour());
}
}
}
/**
* @test
*/
public function testIsHour04() {
$job = new BaseTask();
$job->everyXHour(3);

for ($x = 0 ; $x < 24 ; $x++) {
TasksManager::setHour($x);

if ($x % 3 == 0) {
$this->assertTrue($job->isHour());
} else {
$this->assertFalse($job->isHour());
}
}
}
/**
* @test
*/
Expand Down Expand Up @@ -914,6 +1004,24 @@ public function testIsMonth02() {
TasksManager::setMinute(1);
$this->assertFalse($job->isMinute());
}
/**
* @test
*/
public function testIsMonth03() {
$this->expectException(InvalidCRONExprException::class);
$this->expectExceptionMessage("Invalid cron expression: '* 4 * 1-3,9-b *");
$job = new BaseTask('* 4 * 1-3,9-b *');

}
/**
* @test
*/
public function testIsMonth04() {
$this->expectException(InvalidCRONExprException::class);
$this->expectExceptionMessage("Invalid cron expression: '* 4 * 1-3,9- *");
$job = new BaseTask('* 4 * 1-3,9- *');

}
/**
* @test
*/
Expand Down Expand Up @@ -1255,4 +1363,25 @@ public function testEveryXMinute00() {
$this->assertTrue($task->isDayOfMonth());

}
/**
* @test
*/
public function testEveryXMinute01() {
$task = new BaseTask();
$task->everyXMinuts(17);
TasksManager::setDayOfMonth(15);
TasksManager::setHour(23);
TasksManager::setMonth(5);
TasksManager::setMinute(33);

for ($x = 1 ; $x < 60 ; $x++) {
TasksManager::setMinute($x);
if ($x % 17 == 0) {
$this->assertTrue($task->isMinute());
} else {
$this->assertFalse($task->isMinute());
}
}

}
}
9 changes: 6 additions & 3 deletions tests/webfiori/framework/test/session/SessionsManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ public function test00() {
$this->assertFalse(SessionsManager::remove('xyz'));
$this->assertFalse(SessionsManager::set('xyz','hello'));
$this->assertNull(SessionsManager::pull('xyz'));


$this->assertFalse(SessionsManager::hasCookie());
SessionsManager::start('hello');
$this->assertFalse(SessionsManager::hasCookie());
$this->assertEquals(1, count(SessionsManager::getSessions()));
$activeSesstion = SessionsManager::getActiveSession();
$this->assertFalse($activeSesstion->isRefresh());
Expand All @@ -39,7 +41,7 @@ public function test00() {
$this->assertEquals(7200, $activeSesstion->getDuration());
$this->assertEquals(SessionStatus::NEW, $activeSesstion->getStatus());

$activeSesstion->set('var-1', 'Good');
SessionsManager::set('var-1', 'Good');
$activeSesstion->set('var-2', 'Bad');
$activeSesstion->set('var-3', 'Average');
$activeSesstion->set('var-4', 'Almost Good');
Expand Down Expand Up @@ -107,6 +109,7 @@ public function test00() {
SessionsManager::destroy();
$this->assertNull(SessionsManager::getActiveSession());
$this->assertEquals(SessionStatus::KILLED, $active2->getStatus());
SessionsManager::validateStorage();
$active2->start();
$this->assertEquals(SessionStatus::NEW, $active2->getStatus());
$this->assertNotNull(SessionsManager::getActiveSession());
Expand Down Expand Up @@ -162,8 +165,8 @@ public function testDatabaseSession01() {
$conn = new ConnectionInfo('mysql', 'root', '123456', 'testing_db', '127.0.0.1');
$conn->setName('sessions-connection');
App::getConfig()->addOrUpdateDBConnection($conn);
SessionsManager::reset();
SessionsManager::setStorage(new DatabaseSessionStorage());
SessionsManager::getStorage()->getController()->removeTables();
SessionsManager::start('hello');
}
/**
Expand Down
Loading

0 comments on commit e5bd109

Please sign in to comment.