enhanced plugin support (#634)
- refactored admin controller and templates - plugin support for entity actions - changed column mail to email in customer table - refactored theme events
This commit is contained in:
@@ -23,8 +23,6 @@ use PHPUnit\Framework\TestCase;
|
||||
*/
|
||||
class RateCalculatorTest extends TestCase
|
||||
{
|
||||
public const HOURLY_RATE = 75;
|
||||
|
||||
public function testCalculateWithTimesheetHourlyRate()
|
||||
{
|
||||
$record = new Timesheet();
|
||||
@@ -130,7 +128,7 @@ class RateCalculatorTest extends TestCase
|
||||
$this->assertEquals($exptectedRate, $timesheet->getRate());
|
||||
}
|
||||
|
||||
protected function getTestUser($rate = self::HOURLY_RATE)
|
||||
protected function getTestUser($rate = 75)
|
||||
{
|
||||
$pref = new UserPreference();
|
||||
$pref->setName(UserPreference::HOURLY_RATE);
|
||||
@@ -159,23 +157,23 @@ class RateCalculatorTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses the hourly rate from user_preferences to calculate the rate.
|
||||
*
|
||||
* @dataProvider getRuleDefinitions
|
||||
*/
|
||||
public function testCalculateWithRules($rules, $expectedFactor)
|
||||
public function testCalculateWithRulesByUsersHourlyRate($duration, $rules, $expectedRate)
|
||||
{
|
||||
$seconds = 31837;
|
||||
|
||||
$end = new \DateTime();
|
||||
$end->setTimezone(new \DateTimeZone('UTC'));
|
||||
$end->setTime(12, 0, 0);
|
||||
$start = clone $end;
|
||||
$start->setTimezone(new \DateTimeZone('UTC'));
|
||||
$start->setTimestamp($end->getTimestamp() - $seconds);
|
||||
$start->setTimestamp($end->getTimestamp() - $duration);
|
||||
|
||||
$record = new Timesheet();
|
||||
$record->setUser($this->getTestUser());
|
||||
$record->setBegin($start);
|
||||
$record->setDuration($seconds);
|
||||
$record->setDuration($duration);
|
||||
$record->setActivity(new Activity());
|
||||
|
||||
$this->assertEquals(0, $record->getRate());
|
||||
@@ -185,10 +183,7 @@ class RateCalculatorTest extends TestCase
|
||||
$sut = new RateCalculator($rules);
|
||||
$sut->calculate($record);
|
||||
|
||||
$this->assertEquals(
|
||||
$this->rateForSeconds(self::HOURLY_RATE, $seconds) * $expectedFactor,
|
||||
$record->getRate()
|
||||
);
|
||||
$this->assertEquals($expectedRate, $record->getRate());
|
||||
}
|
||||
|
||||
public function getRuleDefinitions()
|
||||
@@ -200,10 +195,12 @@ class RateCalculatorTest extends TestCase
|
||||
|
||||
return [
|
||||
[
|
||||
31837,
|
||||
[],
|
||||
1
|
||||
663.27
|
||||
],
|
||||
[
|
||||
31837,
|
||||
[
|
||||
'default' => [
|
||||
'days' => [$day],
|
||||
@@ -214,9 +211,10 @@ class RateCalculatorTest extends TestCase
|
||||
'factor' => 1.5
|
||||
],
|
||||
],
|
||||
2.0
|
||||
1326.54
|
||||
],
|
||||
[
|
||||
31837,
|
||||
[
|
||||
'default' => [
|
||||
'days' => [$day],
|
||||
@@ -227,13 +225,8 @@ class RateCalculatorTest extends TestCase
|
||||
'factor' => 1.5
|
||||
],
|
||||
],
|
||||
3.5
|
||||
2321.45
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
protected function rateForSeconds($hourlyRate, $seconds)
|
||||
{
|
||||
return (float) $hourlyRate * ($seconds / 3600);
|
||||
}
|
||||
}
|
||||
|
||||
43
tests/Timesheet/UtilTest.php
Normal file
43
tests/Timesheet/UtilTest.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Timesheet;
|
||||
|
||||
use App\Timesheet\Util;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Timesheet\Util
|
||||
*/
|
||||
class UtilTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider getRateCalculationData
|
||||
*/
|
||||
public function testCalculateRate($hourlyRate, $duration, $expectedRate)
|
||||
{
|
||||
$this->assertEquals($expectedRate, Util::calculateRate($hourlyRate, $duration));
|
||||
}
|
||||
|
||||
public function getRateCalculationData()
|
||||
{
|
||||
yield [0, 0, 0];
|
||||
yield [1, 100, 0.03];
|
||||
yield [1, 900, 0.25];
|
||||
yield [1, 1800, 0.5];
|
||||
yield [10000, 1, 2.78];
|
||||
yield [736, 123.45, 25.15];
|
||||
yield [736, 123, 25.15];
|
||||
yield [7360, 1234.99, 2522.84];
|
||||
yield [7360, 1234, 2522.84];
|
||||
yield [7360.34, 1234, 2522.96];
|
||||
yield [7360.01, 1234, 2522.85];
|
||||
yield [7360.99, 1234, 2523.18];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user