Latest updates from IceHrmPro
This commit is contained in:
24
test/unit/CalenderToolsUnit.php
Normal file
24
test/unit/CalenderToolsUnit.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
namespace Test\Unit;
|
||||
|
||||
use Utils\CalendarTools;
|
||||
|
||||
class CalenderToolsUnit extends \TestTemplate
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
public function testGetYearFromDate()
|
||||
{
|
||||
$date = '2019-08-12';
|
||||
self::assertEquals('2019', CalendarTools::getYearFromDate($date));
|
||||
}
|
||||
|
||||
public function testAssignYearToDate()
|
||||
{
|
||||
$date = '2019-08-12';
|
||||
self::assertEquals('2017-08-12', CalendarTools::assignYearToDate($date, 2017));
|
||||
}
|
||||
}
|
||||
21
test/unit/EmployeeUtilUnit.php
Normal file
21
test/unit/EmployeeUtilUnit.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Test\Unit;
|
||||
|
||||
use Employees\Admin\Api\EmployeeUtil;
|
||||
|
||||
class EmployeeUtilUnit extends \TestTemplate
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
public function testMapping()
|
||||
{
|
||||
$emplyeeUtils = new EmployeeUtil();
|
||||
$data = json_decode($emplyeeUtils->getMapping(), true);
|
||||
|
||||
$this->assertEquals($data['nationality'][0], 'Nationality');
|
||||
}
|
||||
}
|
||||
31
test/unit/EvalMathUnit.php
Normal file
31
test/unit/EvalMathUnit.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
namespace Test\Unit;
|
||||
|
||||
use Utils\Math\EvalMath;
|
||||
|
||||
class EvalMathUnit extends \TestTemplate
|
||||
{
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
public function testTran()
|
||||
{
|
||||
$m = new EvalMath();
|
||||
// basic evaluation:
|
||||
$result = $m->evaluate('2+2');
|
||||
self::assertEquals(4, $result);
|
||||
// supports: order of operation; parentheses; negation; built-in functions
|
||||
$result = $m->evaluate('-8(5/2)^2*(1-sqrt(4))-8');
|
||||
self::assertEquals(42, $result);
|
||||
// create your own variables
|
||||
$m->evaluate('a = e^(ln(pi))');
|
||||
// or functions
|
||||
$m->evaluate('f(x,y) = x^2 + y^2 - 2x*y + 1');
|
||||
// and then use them
|
||||
$result = $m->evaluate('3*f(42,a)');
|
||||
self::assertEquals(4533, round($result));
|
||||
}
|
||||
}
|
||||
45
test/unit/PasswordManagerUnit.php
Normal file
45
test/unit/PasswordManagerUnit.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Test\Unit;
|
||||
|
||||
use Classes\PasswordManager;
|
||||
|
||||
class PasswordManagerUnit extends \TestTemplate
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
public function testVerifyCorrectPasswordBCrypt()
|
||||
{
|
||||
$password = 'tester-password327Red';
|
||||
$hash = PasswordManager::createPasswordHash($password);
|
||||
$this->assertTrue(PasswordManager::verifyPassword($password, $hash));
|
||||
}
|
||||
|
||||
public function testVerifyWrongPasswordBCrypt()
|
||||
{
|
||||
$password = 'tester-password327Red';
|
||||
$hash = PasswordManager::createPasswordHash($password);
|
||||
$this->assertFalse(PasswordManager::verifyPassword($password.'W', $hash));
|
||||
}
|
||||
|
||||
public function testVerifyCorrectPasswordMD5()
|
||||
{
|
||||
$hash = '21232f297a57a5a743894a0e4a801fc3';
|
||||
$this->assertTrue(PasswordManager::verifyPassword('admin', $hash));
|
||||
|
||||
$hash = '4048bb914a704a0728549a26b92d8550';
|
||||
$this->assertTrue(PasswordManager::verifyPassword('demouserpwd', $hash));
|
||||
}
|
||||
|
||||
public function testVerifyWrongPasswordMD5()
|
||||
{
|
||||
$hash = '21232f297a57a5a743894a0e4a801fc4';
|
||||
$this->assertFalse(PasswordManager::verifyPassword('admin', $hash));
|
||||
|
||||
$hash = '4048bb914a704a0728549a26b92d8550';
|
||||
$this->assertFalse(PasswordManager::verifyPassword('demouserpwd1', $hash));
|
||||
}
|
||||
}
|
||||
146
test/unit/ScriptRunnerUnit.php
Normal file
146
test/unit/ScriptRunnerUnit.php
Normal file
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
namespace Test\Unit;
|
||||
|
||||
use Utils\ScriptRunner;
|
||||
|
||||
class ScriptRunnerUnit extends \TestTemplate
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
}
|
||||
public function testBasicSafeScript()
|
||||
{
|
||||
$script = <<<JS
|
||||
function main(k) {
|
||||
return k + Math.max(a, b);
|
||||
}
|
||||
const c = a * 8 + b;
|
||||
main(c);
|
||||
JS;
|
||||
$this->assertEquals(264, ScriptRunner::executeJs(['a' => 8, 'b' => 100], $script));
|
||||
}
|
||||
/*
|
||||
public function testScriptWithLongExecutionTime()
|
||||
{
|
||||
$script = <<<JS
|
||||
let c = a * 8 + b;
|
||||
let n = 0;
|
||||
while(n < 10000) {
|
||||
console.log(new Date().getTime());
|
||||
n++;
|
||||
}
|
||||
(c + Math.max(a, b));
|
||||
JS;
|
||||
$this->assertEquals(264, ScriptRunner::executeJs(['a' => 8, 'b' => 100], $script));
|
||||
}
|
||||
|
||||
public function testNeverEndingScript()
|
||||
{
|
||||
$script = <<<JS
|
||||
let c = a * 8 + b;
|
||||
while(1) {
|
||||
console.log(new Date().getTime());
|
||||
}
|
||||
(c + Math.max(a, b));
|
||||
JS;
|
||||
$this->assertEquals('', ScriptRunner::executeJs(['a' => 8, 'b' => 100], $script));
|
||||
}
|
||||
|
||||
public function testScriptWithRequire()
|
||||
{
|
||||
$script = <<<JS
|
||||
const fs = require('fs');
|
||||
let c = a * 8 + b;
|
||||
let n = 0;
|
||||
while(n < 10000) {
|
||||
console.log(new Date().getTime());
|
||||
n++;
|
||||
}
|
||||
(c + Math.max(a, b));
|
||||
JS;
|
||||
$this->assertEquals('', ScriptRunner::executeJs(['a' => 8, 'b' => 100], $script));
|
||||
}
|
||||
|
||||
public function testAccessFileSystem1()
|
||||
{
|
||||
$script = <<<JS
|
||||
__dirname
|
||||
JS;
|
||||
$this->assertEquals('', ScriptRunner::executeJs([], $script));
|
||||
}
|
||||
|
||||
public function testAccessFileSystem2()
|
||||
{
|
||||
$script = <<<JS
|
||||
const fs = module.constructor._load('fs');
|
||||
console.log(fs.readFileSync('./test.txt'));
|
||||
JS;
|
||||
$this->assertEquals('', ScriptRunner::executeJs([], $script));
|
||||
}
|
||||
|
||||
public function testAccessProcess()
|
||||
{
|
||||
$script = <<<JS
|
||||
process.exit(22);
|
||||
JS;
|
||||
$this->assertEquals('', ScriptRunner::executeJs([], $script));
|
||||
}
|
||||
|
||||
public function testScriptWithImport()
|
||||
{
|
||||
$script = <<<JS
|
||||
import { readFileSync } from 'fs'
|
||||
let c = a * 8 + b;
|
||||
(c + Math.max(a, b));
|
||||
JS;
|
||||
$this->assertEquals('', ScriptRunner::executeJs(['a' => 8, 'b' => 100], $script));
|
||||
}
|
||||
|
||||
public function testDoNotWaitForPromisesToResolve()
|
||||
{
|
||||
$script = <<<JS
|
||||
function test(){
|
||||
let k = new Promise((resolve, reject) => { resolve(val) });
|
||||
let n = 0;
|
||||
while (n < 2) {
|
||||
k = k.then((val) => new Promise((resolve, reject) => { resolve(val + 1); }));
|
||||
n ++;
|
||||
}
|
||||
return k;
|
||||
}
|
||||
|
||||
async function main() {
|
||||
await test();
|
||||
}
|
||||
main();
|
||||
val;
|
||||
JS;
|
||||
$res = ScriptRunner::executeJs(['val' => 100], $script);
|
||||
|
||||
$this->assertEquals(100, $res);
|
||||
}
|
||||
|
||||
public function testNeverEndingPromiseChain()
|
||||
{
|
||||
$script = <<<JS
|
||||
function test(){
|
||||
let k = new Promise((resolve, reject) => { resolve(val) });
|
||||
while (1) {
|
||||
k = k.then((val) => new Promise((resolve, reject) => { resolve(val + 1); }));
|
||||
}
|
||||
return k;
|
||||
}
|
||||
|
||||
async function main() {
|
||||
await test();
|
||||
}
|
||||
main();
|
||||
val;
|
||||
JS;
|
||||
$res = ScriptRunner::executeJs(['val' => 100], $script);
|
||||
|
||||
$this->assertEquals('', $res);
|
||||
}
|
||||
*/
|
||||
}
|
||||
Reference in New Issue
Block a user