mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-06-01 12:19:28 +00:00
added Unit-Tests; changed IDs of organisationseinheit in VertragsGUI
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
if ( !defined("PHPUNIT_TEST") ) {
|
||||
show_404();
|
||||
}
|
||||
|
||||
class Test extends CI_Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
// Yep... This is all we need.
|
||||
ini_set('error_reporting', E_ALL); // or error_reporting(E_ALL);
|
||||
ini_set('display_errors', '1');
|
||||
ini_set('display_startup_errors', '1');
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace vertragsbestandteil;
|
||||
|
||||
use vertragsbestandteil\Vertragsbestandteil;
|
||||
use vertragsbestandteil\VertragsbestandteilFactory;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Description of VertragsbestandteilStunden
|
||||
*
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . "/AbstractBestandteil.php";
|
||||
require_once __DIR__ . "/GUIGueltigkeit.php";
|
||||
|
||||
class FormData extends AbstractBestandteil {
|
||||
|
||||
@@ -61,7 +62,10 @@ class FormData extends AbstractBestandteil {
|
||||
$this->getJSONDataInt($this->data['dienstverhaeltnisid'], $decodedData, 'dienstverhaeltnisid');
|
||||
$this->getJSONData($this->data['unternehmen'], $decodedData, 'unternehmen');
|
||||
$this->getJSONData($this->data['vertragsart_kurzbz'], $decodedData, 'vertragsart_kurzbz');
|
||||
$this->getJSONData($this->data['gueltigkeit'], $decodedData, 'gueltigkeit');
|
||||
$gueltigkeit = new GUIGueltigkeit();
|
||||
$gueltigkeit->mapJSON($decodedData['gueltigkeit']);
|
||||
$this->data['gueltigkeit'] = $gueltigkeit;
|
||||
//$this->getJSONData($this->data['gueltigkeit'], $decodedData, 'gueltigkeit');
|
||||
}
|
||||
|
||||
private function generateDvJSON()
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
<?php
|
||||
|
||||
use phpDocumentor\Reflection\Types\Integer;
|
||||
use PhpParser\Node\Expr;
|
||||
|
||||
require_once __DIR__ . '/FormData.php';
|
||||
require_once __DIR__ . '/GUIHandlerFactory.php';
|
||||
require_once __DIR__ . '/../../../models/vertragsbestandteil/Dienstverhaeltnis_model.php';
|
||||
require_once __DIR__ . '/../VertragsbestandteilLib.php';
|
||||
require_once __DIR__ . '/util.php';
|
||||
|
||||
/**
|
||||
* GUIHandler takes JSON from GUI and manages the process of
|
||||
@@ -23,7 +25,9 @@ class GUIHandler
|
||||
$this->userUID = $userUID;
|
||||
$this->CI = get_instance();
|
||||
$this->CI->load->model('vertragsbestandteil/Dienstverhaeltnis_model',
|
||||
'Dienstverhaeltnis_model');
|
||||
'Dienstverhaeltnis_model');
|
||||
$this->CI->load->library('vertragsbestandteil/VertragsbestandteilLib',
|
||||
null, 'VertragsbestandteilLib');
|
||||
|
||||
|
||||
}
|
||||
@@ -43,13 +47,19 @@ class GUIHandler
|
||||
|
||||
// DV
|
||||
$dvData = $formDataMapper->getData();
|
||||
$this->handleDV($dvData);
|
||||
$res = $this->handleDV($dvData);
|
||||
|
||||
// VBS
|
||||
$vbsList = $formDataMapper->getVbs();
|
||||
if ($res === false)
|
||||
{
|
||||
// TODO write error message
|
||||
} else {
|
||||
|
||||
foreach ($vbsList as $vbsID => $vbs) {
|
||||
$this->handleVBS($dvData['dienstverhaeltnis_id'] ,$vbs);
|
||||
// VBS
|
||||
$vbsList = $formDataMapper->getVbs();
|
||||
|
||||
foreach ($vbsList as $vbsID => $vbs) {
|
||||
$this->handleVBS($dvData['dienstverhaeltnisid'] ,$vbs);
|
||||
}
|
||||
}
|
||||
|
||||
return $formDataMapper->generateJSON();
|
||||
@@ -68,29 +78,50 @@ class GUIHandler
|
||||
if (isset($dienstverhaeltnisid) && intval($dienstverhaeltnisid > 0))
|
||||
{
|
||||
// DV exists
|
||||
$ret = $this->updateDV($dv);
|
||||
$res = $this->updateDV($dv);
|
||||
if (isSuccess($res))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
// DV is new
|
||||
$ret = $this->insertDV($dv);
|
||||
// write back new id
|
||||
$dv['dienstverhaeltnisid'] = $ret['dienstverhaeltnis_id'];
|
||||
$res = $this->insertDV($dv);
|
||||
if (isSuccess($res))
|
||||
{
|
||||
// write back new id
|
||||
$dv['dienstverhaeltnisid'] = $res->retval[0]->dienstverhaeltnis_id;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
private function handleVBS($vbs)
|
||||
private function handleVBS($dienstverhaeltnis_id, $vbs)
|
||||
{
|
||||
/** @var GUIVertragsbestandteilFunktion */
|
||||
$vbsMapper = GUIHandlerFactory::getGUIHandler($vbs['type']);
|
||||
$vbsMapper->mapJSON($vbs);
|
||||
$vbsData = $vbsMapper->getData();
|
||||
|
||||
// merge GUI-Data with DB-Data
|
||||
$vbsInstance = $vbsMapper->generateVertragsbestandteil($vbsData['id']);
|
||||
$vbsInstance = $vbsMapper->generateVertragsbestandteil(isset($vbsData['id'])?$vbsData['id']:null);
|
||||
if ($vbsInstance->getDienstverhaeltnis_id() === null)
|
||||
{
|
||||
$vbsInstance->setDienstverhaeltnis_id($dienstverhaeltnis_id);
|
||||
$vbsInstance->setInsertvon($this->userUID);
|
||||
$vbsInstance->setInsertamum((new DateTime())->format("Y-m-d h:m:s"));
|
||||
} else {
|
||||
$vbsInstance->setUpdatevon($this->userUID);
|
||||
$vbsInstance->setUpdateamum((new DateTime())->format("Y-m-d h:m:s"));
|
||||
}
|
||||
|
||||
// TODO Validate?
|
||||
|
||||
// store
|
||||
$this->VertragsbestandteilLib->store($vbsInstance);
|
||||
$this->CI->VertragsbestandteilLib->storeVertragsbestandteil($vbsInstance);
|
||||
|
||||
// GBS
|
||||
/*
|
||||
@@ -111,13 +142,21 @@ class GUIHandler
|
||||
|
||||
// ------------------------------------
|
||||
// DV does not have a dedicated handler
|
||||
|
||||
private function insertDV($dvJSON)
|
||||
{
|
||||
$dvJSON['mitarbeiter_uid'] = $this->employeeUID;
|
||||
$now = new DateTime();
|
||||
$dvJSON['von'] = string2Date($dvJSON['gueltigkeit']->getData()['gueltig_ab']);
|
||||
$dvJSON['bis'] = string2Date($dvJSON['gueltigkeit']->getData()['gueltig_bis']);
|
||||
$dvJSON['oe_kurzbz'] = $dvJSON['unternehmen'];
|
||||
$dvJSON['insertvon'] = $this->userUID;
|
||||
$dvJSON['insertamum'] = $now->format(DateTime::ATOM);
|
||||
|
||||
unset($dvJSON['dienstverhaeltnisid']);
|
||||
unset($dvJSON['children']);
|
||||
unset($dvJSON['gueltigkeit']);
|
||||
unset($dvJSON['unternehmen']);
|
||||
|
||||
$result = $this->CI->Dienstverhaeltnis_model->insert($dvJSON);
|
||||
|
||||
if (isError($result))
|
||||
@@ -132,15 +171,24 @@ class GUIHandler
|
||||
|
||||
private function updateDV($dvJSON)
|
||||
{
|
||||
$dvJSON['mitarbeiter_uid'] = $this->employeeUID;
|
||||
$dvJSON['von'] = string2Date($dvJSON['gueltigkeit']->getData()['gueltig_ab']);
|
||||
$dvJSON['bis'] = string2Date($dvJSON['gueltigkeit']->getData()['gueltig_bis']);
|
||||
$dvJSON['oe_kurzbz'] = $dvJSON['unternehmen'];
|
||||
$now = new DateTime();
|
||||
$dvJSON['updatevon'] = getAuthUID();
|
||||
$dvJSON['updatevon'] = $this->userUID;
|
||||
$dvJSON['updateamum'] = $now->format(DateTime::ATOM);
|
||||
$dvJSON['dienstverhaeltnis_id'] = $dvJSON['dienstverhaeltnisid'];
|
||||
|
||||
unset($dvJSON['insertamum']);
|
||||
unset($dvJSON['insertvon']);
|
||||
unset($dvJSON['dienstverhaeltnisid']);
|
||||
unset($dvJSON['children']);
|
||||
unset($dvJSON['gueltigkeit']);
|
||||
unset($dvJSON['unternehmen']);
|
||||
|
||||
|
||||
$result = $this->CI->Dienstverhaeltnis_model->update($dvJSON['kontakt_id'], $dvJSON);
|
||||
$result = $this->CI->Dienstverhaeltnis_model->update($dvJSON);
|
||||
//$result = $this->CI->Dienstverhaeltnis_model->update($dvJSON['kontakt_id'], $dvJSON);
|
||||
|
||||
if (isError($result))
|
||||
{
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ .'/GUIVertragsbestandteilStunden.php';
|
||||
require_once __DIR__ .'/GUIVertragsbestandteilFunktion.php';
|
||||
require_once __DIR__ .'/GUIVertragsbestandteilKuendigungsfrist.php';
|
||||
require_once __DIR__ .'/GUIVertragsbestandteilZeitaufzeichnung.php';
|
||||
require_once __DIR__ .'/GUIVertragsbestandteilZusatzvereinbarung.php';
|
||||
|
||||
class GUIHandlerFactory {
|
||||
|
||||
public static function getGUIHandler($type)
|
||||
|
||||
@@ -108,7 +108,20 @@ class GUIVertragsbestandteilFunktion extends AbstractGUIVertragsbestandteil imp
|
||||
|
||||
|
||||
public function generateVertragsbestandteil($id) {
|
||||
// TODO
|
||||
/** @var vertragsbestandteil\VertragsbestandteilFunktion */
|
||||
$vbs = null;
|
||||
if (isset($vbsData['id']) && $vbsData['id'] > 0)
|
||||
{
|
||||
// load VBS
|
||||
$vbs = $this->vbsLib->fetchVertragsbestandteil($vbsData['id']);
|
||||
} else {
|
||||
$vbs = new vertragsbestandteil\VertragsbestandteilFunktion();
|
||||
}
|
||||
// merge
|
||||
$vbs->setBenutzerfunktion_id($this->data['benutzerfunktionid']);
|
||||
$vbs->setVon(string2Date($this->data['gueltigkeit']->getData()['gueltig_ab']));
|
||||
$vbs->setBis(string2Date($this->data['gueltigkeit']->getData()['gueltig_bis']));
|
||||
return $vbs;
|
||||
}
|
||||
|
||||
public function jsonSerialize() {
|
||||
|
||||
@@ -1,10 +1,18 @@
|
||||
<?php
|
||||
|
||||
use vertragsbestandteil\VertragsbestandteilFactory;
|
||||
|
||||
|
||||
require_once __DIR__ . "/AbstractGUIVertragsbestandteil.php";
|
||||
require_once __DIR__ . "/GUIGehaltsbestandteil.php";
|
||||
require_once __DIR__ . "/GUIGueltigkeit.php";
|
||||
require_once __DIR__ . "/../VertragsbestandteilFactory.php";
|
||||
require_once __DIR__ . "/../Vertragsbestandteil.php";
|
||||
require_once __DIR__ .'/../VertragsbestandteilStunden.php';
|
||||
|
||||
|
||||
use vertragsbestandteil\VertragsbestandteilFactory;
|
||||
use vertragsbestandteil\VertragsbestandteilStunden;
|
||||
|
||||
|
||||
class GUIVertragsbestandteilStunden extends AbstractGUIVertragsbestandteil implements JsonSerializable
|
||||
{
|
||||
@@ -115,8 +123,8 @@ class GUIVertragsbestandteilStunden extends AbstractGUIVertragsbestandteil imple
|
||||
}
|
||||
// merge
|
||||
$vbs->setWochenstunden($this->data['stunden']);
|
||||
$vbs->setVon($this->data['gueltigkeit']->getData()['gueltig_ab']);
|
||||
$vbs->setBis($this->data['gueltigkeit']->getData()['gueltig_bis']);
|
||||
$vbs->setVon(string2Date($this->data['gueltigkeit']->getData()['gueltig_ab']));
|
||||
$vbs->setBis(string2Date($this->data['gueltigkeit']->getData()['gueltig_bis']));
|
||||
return $vbs;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
function string2Date($datestring)
|
||||
{
|
||||
$date = DateTimeImmutable::createFromFormat('j.m.Y', $datestring);
|
||||
if ($date === false) return null;
|
||||
return $date->format('Y-m-d');
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<phpunit bootstrap="index.ci.php">
|
||||
<testsuites>
|
||||
<testsuite name="UnitTests">
|
||||
<directory>system/UnitTests/vertragsbestandteil/gui</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<php>
|
||||
<ini name="display_errors" value="1"/>
|
||||
<ini name="display_startup_errors" value="1" />
|
||||
<const name="PHPUNIT_TEST" value="1" />
|
||||
</php>
|
||||
</phpunit>
|
||||
@@ -6,8 +6,8 @@ export default {
|
||||
<div class="col-3">
|
||||
<select v-model="unternehmen" class="form-select form-select-sm" aria-label=".form-select-sm example">
|
||||
<option value="" selected disabled>Unternehmen wählen</option>
|
||||
<option value="fhtw">FH Technikum Wien</option>
|
||||
<option value="twacademy">Technikum Wien GmbH</option>
|
||||
<option value="gst">FH Technikum Wien</option>
|
||||
<option value="gmbh">Technikum Wien GmbH</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-3">
|
||||
|
||||
@@ -22,7 +22,7 @@ class FormDataTest extends TestCase
|
||||
$dataDV = $formDataMapper->getData();
|
||||
$this->assertNotEmpty($dataDV);
|
||||
$this->assertNotEmpty($dataDV['unternehmen']);
|
||||
$this->assertEquals('fhtw', $dataDV['unternehmen']);
|
||||
$this->assertEquals('gst', $dataDV['unternehmen']);
|
||||
$this->assertNull($dataDV['dienstverhaeltnisid']);
|
||||
$this->assertNotEmpty($dataDV['vertragsart_kurzbz']);
|
||||
$this->assertEquals('echterDV', $dataDV['vertragsart_kurzbz']);
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
|
||||
require_once __DIR__ . "/../../../../application/libraries/vertragsbestandteil/gui/GUIHandler.php";
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class GuiHandlerTest extends TestCase
|
||||
{
|
||||
protected $employeeUID = 'masik';
|
||||
protected $userUID = 'user4712';
|
||||
private static $CI;
|
||||
|
||||
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
error_reporting(E_ALL & ~E_STRICT & ~E_DEPRECATED);
|
||||
self::$CI =& get_instance();
|
||||
self::$CI->load->helper('hlp_common');
|
||||
self::$CI->load->helper('hlp_return_object');
|
||||
}
|
||||
|
||||
|
||||
public function testHandleInsert(): void
|
||||
{
|
||||
$jsondata = file_get_contents('./system/UnitTests/vertragsbestandteil/gui/stunden01.json');
|
||||
$this->assertNotEmpty($jsondata);
|
||||
$GH = new GUIHandler($this->employeeUID, $this->userUID);
|
||||
$res = $GH->handle($jsondata);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function test_true()
|
||||
{
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -148,8 +148,8 @@
|
||||
],
|
||||
"data": {
|
||||
"dienstverhaeltnisid": null,
|
||||
"unternehmen": "fhtw",
|
||||
"vertragsart_kurzbz": "echterDV",
|
||||
"unternehmen": "gst",
|
||||
"vertragsart_kurzbz": "echterdv",
|
||||
"gueltigkeit": {
|
||||
"guioptions": {
|
||||
"sharedstatemode": "set"
|
||||
|
||||
@@ -150,8 +150,8 @@
|
||||
],
|
||||
"data": {
|
||||
"dienstverhaeltnisid": null,
|
||||
"unternehmen": "fhtw",
|
||||
"vertragsart_kurzbz": "echterDV",
|
||||
"unternehmen": "gst",
|
||||
"vertragsart_kurzbz": "echterdv",
|
||||
"gueltigkeit": {
|
||||
"guioptions": {
|
||||
"sharedstatemode": "set"
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
|
||||
|
||||
testen:
|
||||
|
||||
./vendor/bin/phpunit system/UnitTests/vertragsbestandteil/gui/FormDataTest.php
|
||||
./vendor/bin/phpunit system/UnitTests/vertragsbestandteil/gui/GuiHandlerTest.php
|
||||
@@ -148,8 +148,8 @@
|
||||
],
|
||||
"data": {
|
||||
"dienstverhaeltnisid": null,
|
||||
"unternehmen": "fhtw",
|
||||
"vertragsart_kurzbz": "echterDV",
|
||||
"unternehmen": "gst",
|
||||
"vertragsart_kurzbz": "echterdv",
|
||||
"gueltigkeit": {
|
||||
"guioptions": {
|
||||
"sharedstatemode": "set"
|
||||
|
||||
@@ -28,7 +28,7 @@ require_once('../version.php');
|
||||
require_once('../include/benutzerberechtigung.class.php');
|
||||
|
||||
// Datenbank Verbindung
|
||||
$db = new basis_db();
|
||||
$db = new basis_db();
|
||||
echo '<html>
|
||||
<head>
|
||||
<title>CheckSystem</title>
|
||||
|
||||
Reference in New Issue
Block a user