added hourly and money budgets to activity, project and customer (#843)
This commit is contained in:
2
.github/FUNDING.yml
vendored
2
.github/FUNDING.yml
vendored
@@ -1,2 +1,2 @@
|
||||
github: [kevinpapst]
|
||||
#github: [kevinpapst]
|
||||
custom: https://www.kimai.org/donate/
|
||||
|
||||
@@ -33,6 +33,7 @@ install:
|
||||
- composer require zendframework/zend-ldap
|
||||
|
||||
script:
|
||||
- composer validate --no-check-all --strict
|
||||
- composer kimai:codestyle
|
||||
- composer kimai:phpstan
|
||||
- if [[ $CODECOVERAGE == 1 ]]; then vendor/bin/phpunit tests/ --coverage-clover=coverage.xml; else vendor/bin/phpunit tests/; fi;
|
||||
|
||||
@@ -23,15 +23,18 @@ otherwise you can't use the new features:
|
||||
- `delete_tag` - delete tags
|
||||
- `edit_exported_timesheet` - allows to edit records which were exported
|
||||
- `role_permissions` - view calculated permissions for user roles
|
||||
- `budget_activity` - view and edit budgets for activities
|
||||
- `budget_project` - view and edit budgets for projects
|
||||
- `budget_customer` - view and edit budgets for customers
|
||||
|
||||
Removed permission:
|
||||
- `system_actions` - removed experimental feature to flush app cache from the about screen
|
||||
|
||||
### BC BREAKS
|
||||
|
||||
- API: Format for queries including a datetime object fixed, finally using the HTML5 format (previously `2019-03-02 14:23` - now `2019-03-02T14:23:00`)
|
||||
- API: Format for queries including a datetime object fixed to use HTML5 format (previously `2019-03-02 14:23` - now `2019-03-02T14:23:00`)
|
||||
- **Permission config**: the `permissions` definition in your `local.yaml` needs to be verified/changed, as the internal structure was highly optimized to simplify the definition.
|
||||
Thanks to the new structure, you should be able to remove almost everything from your `local.yaml`: please read [the updated permission docu](https://www.kimai.org/documentation/permissions.html).
|
||||
Thanks to the new structure, you should be able to remove almost everything from your `local.yaml` (tip: start over from scratch!). Please read [the updated permission docu](https://www.kimai.org/documentation/permissions.html).
|
||||
|
||||
## [0.9](https://github.com/kevinpapst/kimai2/releases/tag/0.9)
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
.navbar-nav {
|
||||
li>a.ddt-large {
|
||||
padding: 16px 12px 11px 12px;
|
||||
padding: 15px 12px 11px 10px;
|
||||
font-size: 10px;
|
||||
}
|
||||
li.messages-menu ul.menu li {
|
||||
|
||||
@@ -77,9 +77,9 @@ kimai:
|
||||
permissions:
|
||||
# mapping complex rule sets of single permissions to named "sets" ("set name" = [array of "permissions and sets"])
|
||||
sets:
|
||||
ACTIVITIES: ['view_activity','create_activity','edit_activity','delete_activity']
|
||||
PROJECTS: ['view_project','create_project','edit_project','delete_project']
|
||||
CUSTOMERS: ['view_customer','create_customer','edit_customer','delete_customer']
|
||||
ACTIVITIES: ['view_activity','create_activity','edit_activity','budget_activity','delete_activity']
|
||||
PROJECTS: ['view_project','create_project','edit_project','budget_project','delete_project']
|
||||
CUSTOMERS: ['view_customer','create_customer','edit_customer','budget_customer','delete_customer']
|
||||
INVOICE: ['view_invoice','create_invoice']
|
||||
INVOICE_TEMPLATE: ['view_invoice_template','create_invoice_template','edit_invoice_template','delete_invoice_template']
|
||||
TIMESHEET: ['view_own_timesheet','start_own_timesheet','stop_own_timesheet','create_own_timesheet','edit_own_timesheet','export_own_timesheet','delete_own_timesheet']
|
||||
@@ -173,7 +173,7 @@ kimai:
|
||||
user_rates:
|
||||
title: ~
|
||||
order: 20
|
||||
permission: ROLE_USER
|
||||
permission: view_rate_own_timesheet
|
||||
widgets: [userAmountToday, userAmountWeek, userAmountMonth, userAmountYear]
|
||||
duration:
|
||||
title: dashboard.all
|
||||
@@ -188,7 +188,7 @@ kimai:
|
||||
rates:
|
||||
title: ~
|
||||
order: 50
|
||||
permission: ROLE_ADMIN
|
||||
permission: view_rate_other_timesheet
|
||||
widgets: [amountToday, amountWeek, amountMonth, amountYear]
|
||||
|
||||
widgets:
|
||||
|
||||
@@ -22,29 +22,23 @@ nelmio_api_doc:
|
||||
path_patterns:
|
||||
- ^/api(?!/doc)
|
||||
documentation:
|
||||
# host: '{{hostname}}'
|
||||
schemes: [http, https]
|
||||
#host: '{{hostname}}'
|
||||
host: '%router.request_context.host%'
|
||||
basePath: '%router.request_context.base_url%'
|
||||
schemes: ['%router.request_context.scheme%']
|
||||
info:
|
||||
title: Kimai 2 - API Docs
|
||||
description: |
|
||||
REST API for the Kimai 2 time-tracking software. It is not yet considered stable and BC breaks might happen, even though I try to avoid them as much as possible.
|
||||
- Collections return less data than explicit entity calls
|
||||
- DateTime formats are explained in detail at https://www.kimai.org/documentation/rest-api.html
|
||||
REST API for the Kimai 2 time-tracking software. Read more about its usage in the [API documentation](https://www.kimai.org/documentation/rest-api.html) and then download a [Swagger file](doc.json) for import e.g. in Postman.
|
||||
Be aware: it is not yet considered stable and BC breaks might happen, but we try to avoid them.
|
||||
version: 0.3
|
||||
# parameters:
|
||||
# hostname:
|
||||
# name: hostname
|
||||
# in: url
|
||||
# description: the hostname where your api runs
|
||||
# required: true
|
||||
# type: string
|
||||
securityDefinitions:
|
||||
X-AUTH-USER:
|
||||
apiUser:
|
||||
type: apiKey
|
||||
description: 'Value: {Username}'
|
||||
name: X-AUTH-USER
|
||||
in: header
|
||||
X-AUTH-TOKEN:
|
||||
apiToken:
|
||||
type: apiKey
|
||||
description: 'Value: {API Token}'
|
||||
name: X-AUTH-TOKEN
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
App\Entity\Activity:
|
||||
exclusion_policy: All
|
||||
custom_accessor_order: [id, name, comment, visible, project, fixedRate, hourlyRate, color]
|
||||
custom_accessor_order: [id, name, comment, visible, project, fixedRate, hourlyRate, color, budget, timeBudget]
|
||||
properties:
|
||||
id:
|
||||
include: true
|
||||
@@ -14,6 +14,12 @@ App\Entity\Activity:
|
||||
visible:
|
||||
include: true
|
||||
groups: [Default]
|
||||
budget:
|
||||
include: true
|
||||
groups: [Entity]
|
||||
timeBudget:
|
||||
include: true
|
||||
groups: [Entity]
|
||||
fixedRate:
|
||||
include: true
|
||||
groups: [Activity]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
App\Entity\Customer:
|
||||
exclusion_policy: All
|
||||
custom_accessor_order: [id, name, number, comment, visible, company, contact, address, country, currency, phone, fax, mobile, email, homepage, timezone, fixedRate, hourlyRate, color]
|
||||
custom_accessor_order: [id, name, number, comment, visible, company, contact, address, country, currency, phone, fax, mobile, email, homepage, timezone, fixedRate, hourlyRate, color, budget, timeBudget]
|
||||
properties:
|
||||
id:
|
||||
include: true
|
||||
@@ -14,6 +14,12 @@ App\Entity\Customer:
|
||||
groups: [Entity]
|
||||
visible:
|
||||
include: true
|
||||
budget:
|
||||
include: true
|
||||
groups: [Entity]
|
||||
timeBudget:
|
||||
include: true
|
||||
groups: [Entity]
|
||||
company:
|
||||
include: true
|
||||
groups: [Entity]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
App\Entity\Project:
|
||||
exclusion_policy: All
|
||||
custom_accessor_order: [id, name, comment, visible, budget, orderNumber, customer, fixedRate, hourlyRate, color]
|
||||
custom_accessor_order: [id, name, comment, visible, orderNumber, customer, fixedRate, hourlyRate, color, budget, timeBudget]
|
||||
properties:
|
||||
id:
|
||||
include: true
|
||||
@@ -14,6 +14,9 @@ App\Entity\Project:
|
||||
budget:
|
||||
include: true
|
||||
groups: [Entity]
|
||||
timeBudget:
|
||||
include: true
|
||||
groups: [Entity]
|
||||
orderNumber:
|
||||
include: true
|
||||
groups: [Entity]
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -8,7 +8,7 @@
|
||||
"build/app.26c26669.js"
|
||||
],
|
||||
"css": [
|
||||
"build/app.16fefccc.css"
|
||||
"build/app.7f4a18a1.css"
|
||||
]
|
||||
},
|
||||
"chart": {
|
||||
@@ -36,7 +36,7 @@
|
||||
"build/0.66b5fd0b.js": "sha384-ncT/BKhCsqH6jhxwdsSG95m1ei7ZZjeZtzH1262h+OPUU80TSFFE3dt+abcHHMok",
|
||||
"build/1.93f0cf2b.js": "sha384-pmnwzvj+UJhDD3uDf+ekLARMBRtMDxWGbnJDrJvwIoRZd3MW/tOGzAW5Ybhbvw20",
|
||||
"build/app.26c26669.js": "sha384-SyN1k+3kOWKnJSOyY+atWLSXNubTbsgz1DZ47jH8PrgLFj9WjXB9GRhO6E7tpJWf",
|
||||
"build/app.16fefccc.css": "sha384-eJfoYmxOaglIQAsTI8AEaGdyRU/Moe/ikO3V4ELZFjhd2i7K3aiq6Y5mpDqXQljX",
|
||||
"build/app.7f4a18a1.css": "sha384-p8Dw7CP1RxxJ2K5yuaNpCw8r1lKd64DlVA2IQeEGxBAC2QxOjweafd8w9CSMk0GC",
|
||||
"build/2.c06cd055.js": "sha384-txR0QG+838LKYtPQ99Gx4OU7WmgN9J3joZEyGwIskSz74EN1T4/IBVnmNaKiFN1q",
|
||||
"build/chart.2bb71e2e.js": "sha384-I57c9DtU3AOG2kzKqIZkIu0hi1aGYHRZ5QG4LKC9+9slzJnAMttPGXoL2cQG3m6y",
|
||||
"build/calendar.59417f4c.js": "sha384-16sOZQy1UmOaoLAVFPfHnF8nFqUxhc4URAg+ypJnnab8uqZAGHDfFFrnq0/6PXl1",
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"build/0.66b5fd0b.js": "build/0.66b5fd0b.js",
|
||||
"build/1.93f0cf2b.js": "build/1.93f0cf2b.js",
|
||||
"build/2.c06cd055.js": "build/2.c06cd055.js",
|
||||
"build/app.css": "build/app.16fefccc.css",
|
||||
"build/app.css": "build/app.7f4a18a1.css",
|
||||
"build/app.js": "build/app.26c26669.js",
|
||||
"build/calendar.css": "build/calendar.b0551848.css",
|
||||
"build/calendar.js": "build/calendar.59417f4c.js",
|
||||
|
||||
@@ -645,7 +645,7 @@ class KimaiImporterCommand extends Command
|
||||
* ["visible"]=> string(1) "1"
|
||||
* --- ["filter"]=> string(1) "0"
|
||||
* ["trash"]=> string(1) "1"
|
||||
* --- ["budget"]=> string(4) "0.00"
|
||||
* ["budget"]=> string(4) "0.00"
|
||||
* --- ["effort"]=> NULL
|
||||
* --- ["approved"]=> NULL
|
||||
* --- ["internal"]=> string(1) "0"
|
||||
@@ -677,6 +677,7 @@ class KimaiImporterCommand extends Command
|
||||
->setName($name)
|
||||
->setComment($oldProject['comment'] ?: null)
|
||||
->setVisible($isActive)
|
||||
->setBudget($oldProject['budget'] ?: 0)
|
||||
;
|
||||
|
||||
foreach ($fixedRates as $fixedRow) {
|
||||
@@ -733,7 +734,7 @@ class KimaiImporterCommand extends Command
|
||||
* $activityToProject
|
||||
* ["projectID"]=> string(1) "1"
|
||||
* ["activityID"]=> string(1) "1"
|
||||
* -- ["budget"]=> string(4) "0.00"
|
||||
* ["budget"]=> string(4) "0.00"
|
||||
* -- ["effort"]=> string(4) "0.00"
|
||||
* -- ["approved"]=> string(4) "0.00"
|
||||
*
|
||||
@@ -831,6 +832,7 @@ class KimaiImporterCommand extends Command
|
||||
->setName($name)
|
||||
->setComment($oldActivity['comment'] ?: null)
|
||||
->setVisible($isActive)
|
||||
->setBudget($oldActivity['budget'] ?: 0)
|
||||
;
|
||||
|
||||
if (null !== $projectId) {
|
||||
|
||||
@@ -100,6 +100,21 @@ class ActivityController extends AbstractController
|
||||
return $this->renderActivityForm($activity, $request);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(path="/{id}/budget", name="admin_activity_budget", methods={"GET"})
|
||||
* @Security("is_granted('budget', activity)")
|
||||
*
|
||||
* @param Activity $activity
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function budgetAction(Activity $activity)
|
||||
{
|
||||
return $this->render('activity/budget.html.twig', [
|
||||
'activity' => $activity,
|
||||
'stats' => $this->getRepository()->getActivityStatistics($activity)
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(path="/{id}/edit", name="admin_activity_edit", methods={"GET", "POST"})
|
||||
* @Security("is_granted('edit', activity)")
|
||||
@@ -244,6 +259,7 @@ class ActivityController extends AbstractController
|
||||
'method' => 'POST',
|
||||
'create_more' => true,
|
||||
'customer' => true,
|
||||
'include_budget' => $this->isGranted('budget', $activity)
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,6 +109,21 @@ class CustomerController extends AbstractController
|
||||
return $this->renderCustomerForm($customer, $request);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(path="/{id}/budget", name="admin_customer_budget", methods={"GET"})
|
||||
* @Security("is_granted('budget', customer)")
|
||||
*
|
||||
* @param Customer $customer
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function budgetAction(Customer $customer)
|
||||
{
|
||||
return $this->render('customer/budget.html.twig', [
|
||||
'customer' => $customer,
|
||||
'stats' => $this->getRepository()->getCustomerStatistics($customer)
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(path="/{id}/edit", name="admin_customer_edit", methods={"GET", "POST"})
|
||||
* @Security("is_granted('edit', customer)")
|
||||
@@ -232,7 +247,8 @@ class CustomerController extends AbstractController
|
||||
|
||||
return $this->createForm(CustomerEditForm::class, $customer, [
|
||||
'action' => $url,
|
||||
'method' => 'POST'
|
||||
'method' => 'POST',
|
||||
'include_budget' => $this->isGranted('budget', $customer)
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,6 +101,21 @@ class ProjectController extends AbstractController
|
||||
return $this->renderProjectForm($project, $request);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(path="/{id}/budget", name="admin_project_budget", methods={"GET"})
|
||||
* @Security("is_granted('budget', project)")
|
||||
*
|
||||
* @param Project $project
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function budgetAction(Project $project)
|
||||
{
|
||||
return $this->render('project/budget.html.twig', [
|
||||
'project' => $project,
|
||||
'stats' => $this->getRepository()->getProjectStatistics($project)
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(path="/{id}/edit", name="admin_project_edit", methods={"GET", "POST"})
|
||||
* @Security("is_granted('edit', project)")
|
||||
@@ -238,6 +253,7 @@ class ProjectController extends AbstractController
|
||||
'method' => 'POST',
|
||||
'currency' => $currency,
|
||||
'create_more' => true,
|
||||
'include_budget' => $this->isGranted('budget', $project)
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,8 @@ class CustomerFixtures extends Fixture
|
||||
public const MAX_CUSTOMERS = 15;
|
||||
public const MIN_BUDGET = 0;
|
||||
public const MAX_BUDGET = 100000;
|
||||
public const MIN_TIME_BUDGET = 0;
|
||||
public const MAX_TIME_BUDGET = 10000000;
|
||||
public const MIN_GLOBAL_ACTIVITIES = 5;
|
||||
public const MAX_GLOBAL_ACTIVITIES = 30;
|
||||
public const MIN_PROJECTS_PER_CUSTOMER = 2;
|
||||
@@ -100,6 +102,14 @@ class CustomerFixtures extends Fixture
|
||||
->setVisible($visible)
|
||||
;
|
||||
|
||||
if (rand(0, 3) % 3) {
|
||||
$entry->setBudget(rand(self::MIN_BUDGET, self::MAX_BUDGET));
|
||||
}
|
||||
|
||||
if (rand(0, 3) % 3) {
|
||||
$entry->setTimeBudget(rand(self::MIN_TIME_BUDGET, self::MAX_TIME_BUDGET));
|
||||
}
|
||||
|
||||
return $entry;
|
||||
}
|
||||
|
||||
@@ -115,12 +125,19 @@ class CustomerFixtures extends Fixture
|
||||
|
||||
$entry
|
||||
->setName($faker->catchPhrase . ($visible ? '' : ' (x)'))
|
||||
->setBudget(rand(self::MIN_BUDGET, self::MAX_BUDGET))
|
||||
->setComment($faker->text)
|
||||
->setCustomer($customer)
|
||||
->setVisible($visible)
|
||||
;
|
||||
|
||||
if (rand(0, 3) % 3) {
|
||||
$entry->setBudget(rand(self::MIN_BUDGET, self::MAX_BUDGET));
|
||||
}
|
||||
|
||||
if (rand(0, 3) % 3) {
|
||||
$entry->setTimeBudget(rand(self::MIN_TIME_BUDGET, self::MAX_TIME_BUDGET));
|
||||
}
|
||||
|
||||
return $entry;
|
||||
}
|
||||
|
||||
@@ -140,6 +157,14 @@ class CustomerFixtures extends Fixture
|
||||
->setVisible($visible)
|
||||
;
|
||||
|
||||
if (rand(0, 3) % 3) {
|
||||
$entry->setBudget(rand(self::MIN_BUDGET, self::MAX_BUDGET));
|
||||
}
|
||||
|
||||
if (rand(0, 3) % 3) {
|
||||
$entry->setTimeBudget(rand(self::MIN_TIME_BUDGET, self::MAX_TIME_BUDGET));
|
||||
}
|
||||
|
||||
return $entry;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ class TagFixtures extends Fixture
|
||||
} elseif ($i % 2 == 0) {
|
||||
$tagName = $faker->colorName;
|
||||
} elseif ($i % 1 == 0) {
|
||||
$tagName = $faker->text(rand(10, 20));
|
||||
$tagName = $faker->text(rand(5, 15));
|
||||
}
|
||||
|
||||
if (in_array($tagName, $existing)) {
|
||||
@@ -72,15 +72,12 @@ class TagFixtures extends Fixture
|
||||
|
||||
$manager->persist($tag);
|
||||
|
||||
if ($i % self::BATCH_SIZE == 0) {
|
||||
if ($i % self::BATCH_SIZE === 0) {
|
||||
$manager->flush();
|
||||
$manager->clear(Tag::class);
|
||||
}
|
||||
|
||||
$manager->flush();
|
||||
$manager->clear(Tag::class);
|
||||
}
|
||||
|
||||
$manager->flush();
|
||||
$manager->clear(Tag::class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ class UserFixtures extends Fixture
|
||||
public const MIN_RATE = 30;
|
||||
public const MAX_RATE = 120;
|
||||
|
||||
// lower batch size, as user preferences are added in the same run
|
||||
public const BATCH_SIZE = 50;
|
||||
|
||||
/**
|
||||
@@ -131,15 +132,31 @@ class UserFixtures extends Fixture
|
||||
private function loadTestUsers(ObjectManager $manager)
|
||||
{
|
||||
$passwordEncoder = $this->encoder;
|
||||
|
||||
$faker = Factory::create();
|
||||
$existingName = [];
|
||||
$existingEmail = [];
|
||||
|
||||
for ($i = 1; $i <= self::AMOUNT_EXTRA_USER; $i++) {
|
||||
$username = $faker->userName;
|
||||
$email = $faker->email;
|
||||
|
||||
if (in_array($username, $existingName)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (in_array($email, $existingEmail)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$existingName[] = $username;
|
||||
$existingEmail[] = $email;
|
||||
|
||||
$user = new User();
|
||||
$user
|
||||
->setAlias($faker->name)
|
||||
->setTitle(substr($faker->jobTitle, 0, 49))
|
||||
->setUsername($faker->userName)
|
||||
->setEmail($faker->email)
|
||||
->setUsername($username)
|
||||
->setEmail($email)
|
||||
->setRoles([User::ROLE_USER])
|
||||
->setAvatar(self::DEFAULT_AVATAR)
|
||||
->setEnabled(true)
|
||||
@@ -147,12 +164,12 @@ class UserFixtures extends Fixture
|
||||
->setPreferences($this->getUserPreferences($user))
|
||||
;
|
||||
|
||||
if ($i % self::BATCH_SIZE == 0) {
|
||||
$manager->persist($user);
|
||||
|
||||
if ($i % self::BATCH_SIZE === 0) {
|
||||
$manager->flush();
|
||||
$manager->clear();
|
||||
}
|
||||
|
||||
$manager->persist($user);
|
||||
}
|
||||
|
||||
$manager->flush();
|
||||
|
||||
@@ -71,6 +71,7 @@ class Activity
|
||||
// keep the trait include exactly here, for placing the column at the correct position
|
||||
use RatesTrait;
|
||||
use ColorTrait;
|
||||
use BudgetTrait;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
68
src/Entity/BudgetTrait.php
Normal file
68
src/Entity/BudgetTrait.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?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\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
trait BudgetTrait
|
||||
{
|
||||
/**
|
||||
* @var float
|
||||
*
|
||||
* @ORM\Column(name="budget", type="float", precision=10, scale=2, nullable=false)
|
||||
* @Assert\NotNull()
|
||||
*/
|
||||
private $budget = 0.00;
|
||||
|
||||
/**
|
||||
* Time budget in seconds.
|
||||
*
|
||||
* @var int
|
||||
*
|
||||
* @ORM\Column(name="time_budget", type="integer", precision=10, scale=2, nullable=false)
|
||||
* @Assert\NotNull()
|
||||
*/
|
||||
private $timeBudget = 0;
|
||||
|
||||
/**
|
||||
* @param float $budget
|
||||
* @return self
|
||||
*/
|
||||
public function setBudget(?float $budget)
|
||||
{
|
||||
$this->budget = $budget;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
public function getBudget()
|
||||
{
|
||||
return $this->budget;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $seconds
|
||||
* @return self
|
||||
*/
|
||||
public function setTimeBudget(?int $seconds)
|
||||
{
|
||||
$this->timeBudget = $seconds;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTimeBudget(): int
|
||||
{
|
||||
return $this->timeBudget;
|
||||
}
|
||||
}
|
||||
@@ -152,6 +152,7 @@ class Customer
|
||||
// keep the trait include exactly here, for placing the column at the correct position
|
||||
use RatesTrait;
|
||||
use ColorTrait;
|
||||
use BudgetTrait;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
@@ -70,14 +70,6 @@ class Project
|
||||
*/
|
||||
private $visible = true;
|
||||
|
||||
/**
|
||||
* @var float
|
||||
*
|
||||
* @ORM\Column(name="budget", type="float", precision=10, scale=2, nullable=false)
|
||||
* @Assert\NotNull()
|
||||
*/
|
||||
private $budget = 0.00;
|
||||
|
||||
/**
|
||||
* @var Activity[]|ArrayCollection
|
||||
*
|
||||
@@ -88,6 +80,7 @@ class Project
|
||||
// keep the trait include exactly here, for placing the column at the correct position
|
||||
use RatesTrait;
|
||||
use ColorTrait;
|
||||
use BudgetTrait;
|
||||
|
||||
/**
|
||||
* @var Timesheet[]|ArrayCollection
|
||||
@@ -162,25 +155,6 @@ class Project
|
||||
return $this->visible;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $budget
|
||||
* @return Project
|
||||
*/
|
||||
public function setBudget($budget): Project
|
||||
{
|
||||
$this->budget = $budget;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
public function getBudget()
|
||||
{
|
||||
return $this->budget;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<Timesheet>
|
||||
*/
|
||||
|
||||
@@ -26,11 +26,7 @@ class ServiceExport
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RendererInterface $renderer
|
||||
* @return $this
|
||||
*/
|
||||
public function addRenderer(RendererInterface $renderer)
|
||||
public function addRenderer(RendererInterface $renderer): ServiceExport
|
||||
{
|
||||
$this->renderer[] = $renderer;
|
||||
|
||||
@@ -38,20 +34,14 @@ class ServiceExport
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of export renderer.
|
||||
*
|
||||
* @return RendererInterface[]
|
||||
*/
|
||||
public function getRenderer()
|
||||
public function getRenderer(): array
|
||||
{
|
||||
return $this->renderer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $id
|
||||
* @return RendererInterface|null
|
||||
*/
|
||||
public function getRendererById(string $id)
|
||||
public function getRendererById(string $id): ?RendererInterface
|
||||
{
|
||||
foreach ($this->renderer as $renderer) {
|
||||
if ($renderer->getId() === $id) {
|
||||
|
||||
@@ -10,16 +10,12 @@
|
||||
namespace App\Form;
|
||||
|
||||
use App\Entity\Activity;
|
||||
use App\Form\Type\ColorPickerType;
|
||||
use App\Entity\Customer;
|
||||
use App\Form\Type\CustomerType;
|
||||
use App\Form\Type\FixedRateType;
|
||||
use App\Form\Type\HourlyRateType;
|
||||
use App\Form\Type\ProjectType;
|
||||
use App\Form\Type\YesNoType;
|
||||
use App\Repository\CustomerRepository;
|
||||
use App\Repository\ProjectRepository;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
@@ -27,11 +23,10 @@ use Symfony\Component\Form\FormEvent;
|
||||
use Symfony\Component\Form\FormEvents;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/**
|
||||
* Defines the form used to manipulate Activities.
|
||||
*/
|
||||
class ActivityEditForm extends AbstractType
|
||||
{
|
||||
use EntityFormTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@@ -39,7 +34,6 @@ class ActivityEditForm extends AbstractType
|
||||
{
|
||||
$project = null;
|
||||
$customer = null;
|
||||
$currency = false;
|
||||
$id = null;
|
||||
|
||||
if (isset($options['data'])) {
|
||||
@@ -49,21 +43,19 @@ class ActivityEditForm extends AbstractType
|
||||
if (null !== $entry->getProject()) {
|
||||
$project = $entry->getProject();
|
||||
$customer = $project->getCustomer();
|
||||
$currency = $customer->getCurrency();
|
||||
$options['currency'] = $customer->getCurrency();
|
||||
}
|
||||
|
||||
$id = $entry->getId();
|
||||
}
|
||||
|
||||
$builder
|
||||
// string - length 255
|
||||
->add('name', TextType::class, [
|
||||
'label' => 'label.name',
|
||||
'attr' => [
|
||||
'autofocus' => 'autofocus'
|
||||
],
|
||||
])
|
||||
// text
|
||||
->add('comment', TextareaType::class, [
|
||||
'label' => 'label.comment',
|
||||
'required' => false,
|
||||
@@ -109,26 +101,10 @@ class ActivityEditForm extends AbstractType
|
||||
}
|
||||
);
|
||||
|
||||
$builder
|
||||
->add('color', ColorPickerType::class)
|
||||
->add('fixedRate', FixedRateType::class, [
|
||||
'currency' => $currency,
|
||||
])
|
||||
->add('hourlyRate', HourlyRateType::class, [
|
||||
'currency' => $currency,
|
||||
])
|
||||
// boolean
|
||||
->add('visible', YesNoType::class, [
|
||||
'label' => 'label.visible',
|
||||
])
|
||||
;
|
||||
$this->addCommonFields($builder, $options);
|
||||
|
||||
if (null === $id && $options['create_more']) {
|
||||
$builder->add('create_more', CheckboxType::class, [
|
||||
'label' => 'label.create_more',
|
||||
'required' => false,
|
||||
'mapped' => false,
|
||||
]);
|
||||
$this->addCreateMore($builder);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,6 +120,8 @@ class ActivityEditForm extends AbstractType
|
||||
'csrf_token_id' => 'admin_activity_edit',
|
||||
'create_more' => false,
|
||||
'customer' => false,
|
||||
'currency' => Customer::DEFAULT_CURRENCY,
|
||||
'include_budget' => false,
|
||||
'attr' => [
|
||||
'data-form-event' => 'kimai.activityUpdate'
|
||||
],
|
||||
|
||||
@@ -10,10 +10,6 @@
|
||||
namespace App\Form;
|
||||
|
||||
use App\Entity\Customer;
|
||||
use App\Form\Type\ColorPickerType;
|
||||
use App\Form\Type\FixedRateType;
|
||||
use App\Form\Type\HourlyRateType;
|
||||
use App\Form\Type\YesNoType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CountryType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CurrencyType;
|
||||
@@ -26,22 +22,19 @@ use Symfony\Component\Form\Extension\Core\Type\UrlType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/**
|
||||
* Defines the form used to edit Customer entities.
|
||||
*/
|
||||
class CustomerEditForm extends AbstractType
|
||||
{
|
||||
use EntityFormTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$currency = false;
|
||||
|
||||
if (isset($options['data'])) {
|
||||
/** @var Customer $customer */
|
||||
$customer = $options['data'];
|
||||
$currency = $customer->getCurrency();
|
||||
$options['currency'] = $customer->getCurrency();
|
||||
}
|
||||
|
||||
$builder
|
||||
@@ -101,18 +94,9 @@ class CustomerEditForm extends AbstractType
|
||||
])
|
||||
->add('timezone', TimezoneType::class, [
|
||||
'label' => 'label.timezone',
|
||||
])
|
||||
->add('color', ColorPickerType::class)
|
||||
->add('fixedRate', FixedRateType::class, [
|
||||
'currency' => $currency ?? false,
|
||||
])
|
||||
->add('hourlyRate', HourlyRateType::class, [
|
||||
'currency' => $currency ?? false,
|
||||
])
|
||||
->add('visible', YesNoType::class, [
|
||||
'label' => 'label.visible',
|
||||
])
|
||||
;
|
||||
]);
|
||||
|
||||
$this->addCommonFields($builder, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -125,6 +109,8 @@ class CustomerEditForm extends AbstractType
|
||||
'csrf_protection' => true,
|
||||
'csrf_field_name' => '_token',
|
||||
'csrf_token_id' => 'admin_customer_edit',
|
||||
'currency' => Customer::DEFAULT_CURRENCY,
|
||||
'include_budget' => false,
|
||||
'attr' => [
|
||||
'data-form-event' => 'kimai.customerUpdate'
|
||||
],
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
<?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\Form\DataTransformer;
|
||||
|
||||
use App\Utils\Duration;
|
||||
use App\Validator\Constraints\Duration as DurationConstraint;
|
||||
use Symfony\Component\Form\DataTransformerInterface;
|
||||
use Symfony\Component\Form\Exception\TransformationFailedException;
|
||||
|
||||
class DurationStringToSecondsTransformer implements DataTransformerInterface
|
||||
{
|
||||
/**
|
||||
* @var Duration
|
||||
*/
|
||||
protected $formatter;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $pattern;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->formatter = new Duration();
|
||||
$constraint = new DurationConstraint();
|
||||
$this->pattern = $constraint->pattern;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $intToFormat
|
||||
* @return string|null
|
||||
*/
|
||||
public function transform($intToFormat)
|
||||
{
|
||||
try {
|
||||
return $this->formatter->format($intToFormat);
|
||||
} catch (\Exception $e) {
|
||||
throw new TransformationFailedException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $formatToInt
|
||||
* @return int|null
|
||||
*/
|
||||
public function reverseTransform($formatToInt)
|
||||
{
|
||||
if (null === $formatToInt) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (empty($formatToInt)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// we need this one here, because the data transformer is executed BEFORE the constraint is called
|
||||
if (!preg_match($this->pattern, $formatToInt)) {
|
||||
throw new TransformationFailedException('Invalid duration format given');
|
||||
}
|
||||
|
||||
try {
|
||||
return $this->formatter->parseDurationString($formatToInt);
|
||||
} catch (\Exception $e) {
|
||||
throw new TransformationFailedException($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,7 @@ class TagArrayToStringTransformer implements DataTransformerInterface
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function transform($tags): string
|
||||
public function transform($tags)
|
||||
{
|
||||
if (empty($tags)) {
|
||||
return '';
|
||||
@@ -53,7 +53,7 @@ class TagArrayToStringTransformer implements DataTransformerInterface
|
||||
* @return Tag[]
|
||||
* @throws TransformationFailedException if object (issue) is not found
|
||||
*/
|
||||
public function reverseTransform($stringOfTags): array
|
||||
public function reverseTransform($stringOfTags)
|
||||
{
|
||||
// check for empty tag list
|
||||
if (empty($stringOfTags)) {
|
||||
|
||||
64
src/Form/EntityFormTrait.php
Normal file
64
src/Form/EntityFormTrait.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?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\Form;
|
||||
|
||||
use App\Form\Type\ColorPickerType;
|
||||
use App\Form\Type\DurationType;
|
||||
use App\Form\Type\FixedRateType;
|
||||
use App\Form\Type\HourlyRateType;
|
||||
use App\Form\Type\YesNoType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\MoneyType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
trait EntityFormTrait
|
||||
{
|
||||
public function addCommonFields(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$currency = $options['currency'];
|
||||
$builder
|
||||
->add('color', ColorPickerType::class)
|
||||
->add('fixedRate', FixedRateType::class, [
|
||||
'currency' => $currency,
|
||||
])
|
||||
->add('hourlyRate', HourlyRateType::class, [
|
||||
'currency' => $currency,
|
||||
])
|
||||
;
|
||||
|
||||
if ($options['include_budget']) {
|
||||
$builder
|
||||
->add('budget', MoneyType::class, [
|
||||
'label' => 'label.budget',
|
||||
'required' => false,
|
||||
'currency' => $currency,
|
||||
])
|
||||
->add('timeBudget', DurationType::class, [
|
||||
'label' => 'label.timeBudget',
|
||||
'required' => false,
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
$builder
|
||||
->add('visible', YesNoType::class, [
|
||||
'label' => 'label.visible',
|
||||
]);
|
||||
}
|
||||
|
||||
public function addCreateMore(FormBuilderInterface $builder): void
|
||||
{
|
||||
$builder->add('create_more', CheckboxType::class, [
|
||||
'label' => 'label.create_more',
|
||||
'required' => false,
|
||||
'mapped' => false,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -11,32 +11,24 @@ namespace App\Form;
|
||||
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\Project;
|
||||
use App\Form\Type\ColorPickerType;
|
||||
use App\Form\Type\CustomerType;
|
||||
use App\Form\Type\FixedRateType;
|
||||
use App\Form\Type\HourlyRateType;
|
||||
use App\Form\Type\YesNoType;
|
||||
use App\Repository\CustomerRepository;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\MoneyType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/**
|
||||
* Defines the form used to edit Projects.
|
||||
*/
|
||||
class ProjectEditForm extends AbstractType
|
||||
{
|
||||
use EntityFormTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$customer = null;
|
||||
$currency = false;
|
||||
$id = null;
|
||||
|
||||
if (isset($options['data'])) {
|
||||
@@ -46,7 +38,7 @@ class ProjectEditForm extends AbstractType
|
||||
|
||||
if ($id !== null) {
|
||||
$customer = $entry->getCustomer();
|
||||
$currency = $customer->getCurrency();
|
||||
$options['currency'] = $customer->getCurrency();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,30 +61,12 @@ class ProjectEditForm extends AbstractType
|
||||
'query_builder' => function (CustomerRepository $repo) use ($customer) {
|
||||
return $repo->builderForEntityType($customer);
|
||||
},
|
||||
])
|
||||
->add('color', ColorPickerType::class)
|
||||
->add('fixedRate', FixedRateType::class, [
|
||||
'currency' => $currency,
|
||||
])
|
||||
->add('hourlyRate', HourlyRateType::class, [
|
||||
'currency' => $currency,
|
||||
])
|
||||
->add('budget', MoneyType::class, [
|
||||
'label' => 'label.budget',
|
||||
'required' => false,
|
||||
'currency' => $currency,
|
||||
])
|
||||
->add('visible', YesNoType::class, [
|
||||
'label' => 'label.visible',
|
||||
])
|
||||
;
|
||||
]);
|
||||
|
||||
$this->addCommonFields($builder, $options);
|
||||
|
||||
if (null === $id && $options['create_more']) {
|
||||
$builder->add('create_more', CheckboxType::class, [
|
||||
'label' => 'label.create_more',
|
||||
'required' => false,
|
||||
'mapped' => false,
|
||||
]);
|
||||
$this->addCreateMore($builder);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,6 +81,7 @@ class ProjectEditForm extends AbstractType
|
||||
'csrf_field_name' => '_token',
|
||||
'csrf_token_id' => 'admin_project_edit',
|
||||
'currency' => Customer::DEFAULT_CURRENCY,
|
||||
'include_budget' => false,
|
||||
'create_more' => false,
|
||||
'attr' => [
|
||||
'data-form-event' => 'kimai.projectUpdate'
|
||||
|
||||
@@ -9,42 +9,18 @@
|
||||
|
||||
namespace App\Form\Type;
|
||||
|
||||
use App\Utils\Duration;
|
||||
use App\Form\DataTransformer\DurationStringToSecondsTransformer;
|
||||
use App\Validator\Constraints\Duration as DurationConstraint;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\CallbackTransformer;
|
||||
use Symfony\Component\Form\Exception\TransformationFailedException;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Validator\Constraints\Regex;
|
||||
|
||||
/**
|
||||
* Custom form field type to handle a timesheet duration.
|
||||
* Custom form field type to handle duration strings.
|
||||
*/
|
||||
class DurationType extends AbstractType
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $pattern;
|
||||
|
||||
/**
|
||||
* DurationType constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$patterns = [
|
||||
'[0-9]{1,}',
|
||||
'[0-9]{1,}:[0-9]{1,2}:[0-9]{1,2}',
|
||||
'[0-9]{1,2}:[0-9]{1,2}',
|
||||
'[0-9]{1,}[hmsHMS]{1}',
|
||||
'[0-9]{1,}[hmsHMS]{1}[0-9]{1,}[hmsHMS]{1}',
|
||||
'[0-9]{1,}[hmsHMS]{1}[0-9]{1,}[hmsHMS]{1}[0-9]{1,}[hmsHMS]{1}',
|
||||
];
|
||||
|
||||
$this->pattern = '/^' . implode('$|^', $patterns) . '$/';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@@ -52,7 +28,7 @@ class DurationType extends AbstractType
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'label' => 'label.duration',
|
||||
'constraints' => [new Regex(['pattern' => $this->pattern])],
|
||||
'constraints' => [new DurationConstraint()],
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -61,37 +37,7 @@ class DurationType extends AbstractType
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$formatter = new Duration();
|
||||
$pattern = $this->pattern;
|
||||
|
||||
$builder->addModelTransformer(new CallbackTransformer(
|
||||
function ($intToFormat) use ($formatter) {
|
||||
try {
|
||||
return $formatter->format($intToFormat);
|
||||
} catch (\Exception $e) {
|
||||
throw new TransformationFailedException($e->getMessage());
|
||||
}
|
||||
},
|
||||
function ($formatToInt) use ($formatter, $pattern) {
|
||||
if (null === $formatToInt) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (empty($formatToInt)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!preg_match($pattern, $formatToInt)) {
|
||||
throw new TransformationFailedException('Invalid duration format given');
|
||||
}
|
||||
|
||||
try {
|
||||
return $formatter->parseDurationString($formatToInt);
|
||||
} catch (\Exception $e) {
|
||||
throw new TransformationFailedException($e->getMessage());
|
||||
}
|
||||
}
|
||||
));
|
||||
$builder->addModelTransformer(new DurationStringToSecondsTransformer());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
57
src/Migrations/Version20190605171157.php
Normal file
57
src/Migrations/Version20190605171157.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* 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 DoctrineMigrations;
|
||||
|
||||
use App\Doctrine\AbstractMigration;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
|
||||
/**
|
||||
* Creates the budget columns on: customer, project, activity.
|
||||
*
|
||||
* @version 1.0
|
||||
*/
|
||||
final class Version20190605171157 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Creates the budget columns on: customer, project, activity';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$customers = $schema->getTable('kimai2_customers');
|
||||
$customers->addColumn('time_budget', 'integer', ['notnull' => true, 'default' => 0]);
|
||||
$customers->addColumn('budget', 'float', ['notnull' => true, 'default' => 0]);
|
||||
|
||||
$projects = $schema->getTable('kimai2_projects');
|
||||
$projects->addColumn('time_budget', 'integer', ['notnull' => true, 'default' => 0]);
|
||||
$projects->getColumn('budget')->setDefault(0);
|
||||
|
||||
$activities = $schema->getTable('kimai2_activities');
|
||||
$activities->addColumn('time_budget', 'integer', ['notnull' => true, 'default' => 0]);
|
||||
$activities->addColumn('budget', 'float', ['notnull' => true, 'default' => 0]);
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$customers = $schema->getTable('kimai2_customers');
|
||||
$customers->dropColumn('time_budget');
|
||||
$customers->dropColumn('budget');
|
||||
|
||||
$projects = $schema->getTable('kimai2_projects');
|
||||
$projects->dropColumn('time_budget');
|
||||
|
||||
$activities = $schema->getTable('kimai2_activities');
|
||||
$activities->dropColumn('time_budget');
|
||||
$activities->dropColumn('budget');
|
||||
}
|
||||
}
|
||||
@@ -9,84 +9,6 @@
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
/**
|
||||
* Activity statistics
|
||||
*/
|
||||
class ActivityStatistic
|
||||
class ActivityStatistic extends TimesheetCountedStatistic
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $count = 0;
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $recordAmount = 0;
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $recordDuration = 0;
|
||||
|
||||
/**
|
||||
* Returns the total amount of included timesheet records.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getRecordAmount()
|
||||
{
|
||||
return $this->recordAmount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $recordAmount
|
||||
* @return ActivityStatistic
|
||||
*/
|
||||
public function setRecordAmount($recordAmount)
|
||||
{
|
||||
$this->recordAmount = (int) $recordAmount;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the total duration of all included timesheet records.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getRecordDuration()
|
||||
{
|
||||
return $this->recordDuration;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $recordDuration
|
||||
* @return ActivityStatistic
|
||||
*/
|
||||
public function setRecordDuration($recordDuration)
|
||||
{
|
||||
$this->recordDuration = (int) $recordDuration;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the amount of activities that are included in the statistic result.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getCount()
|
||||
{
|
||||
return $this->count;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $count
|
||||
* @return ActivityStatistic
|
||||
*/
|
||||
public function setCount($count)
|
||||
{
|
||||
$this->count = (int) $count;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,23 +9,8 @@
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
/**
|
||||
* Customer statistics
|
||||
*/
|
||||
class CustomerStatistic
|
||||
class CustomerStatistic extends TimesheetCountedStatistic
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $count = 0;
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $recordAmount = 0;
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $recordDuration = 0;
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
@@ -35,69 +20,6 @@ class CustomerStatistic
|
||||
*/
|
||||
protected $projectAmount = 0;
|
||||
|
||||
/**
|
||||
* Returns the total amount of included timesheet records.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getRecordAmount()
|
||||
{
|
||||
return $this->recordAmount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $recordAmount
|
||||
* @return $this
|
||||
*/
|
||||
public function setRecordAmount($recordAmount)
|
||||
{
|
||||
$this->recordAmount = (int) $recordAmount;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the total duration of all included timesheet records.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getRecordDuration()
|
||||
{
|
||||
return $this->recordDuration;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $recordDuration
|
||||
* @return $this
|
||||
*/
|
||||
public function setRecordDuration($recordDuration)
|
||||
{
|
||||
$this->recordDuration = (int) $recordDuration;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the amount of activities that are included in the statistic result.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getCount()
|
||||
{
|
||||
return $this->count;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $count
|
||||
* @return $this
|
||||
*/
|
||||
public function setCount($count)
|
||||
{
|
||||
$this->count = (int) $count;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
|
||||
@@ -9,91 +9,13 @@
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
/**
|
||||
* Project statistics
|
||||
*/
|
||||
class ProjectStatistic
|
||||
class ProjectStatistic extends TimesheetCountedStatistic
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $count = 0;
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $recordAmount = 0;
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $recordDuration = 0;
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $activityAmount = 0;
|
||||
|
||||
/**
|
||||
* Returns the total amount of included timesheet records.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getRecordAmount()
|
||||
{
|
||||
return $this->recordAmount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $recordAmount
|
||||
* @return ProjectStatistic
|
||||
*/
|
||||
public function setRecordAmount($recordAmount)
|
||||
{
|
||||
$this->recordAmount = (int) $recordAmount;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the total duration of all included timesheet records.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getRecordDuration()
|
||||
{
|
||||
return $this->recordDuration;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $recordDuration
|
||||
* @return ProjectStatistic
|
||||
*/
|
||||
public function setRecordDuration($recordDuration)
|
||||
{
|
||||
$this->recordDuration = (int) $recordDuration;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the amount of activities that are included in the statistic result.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getCount()
|
||||
{
|
||||
return $this->count;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $count
|
||||
* @return ProjectStatistic
|
||||
*/
|
||||
public function setCount($count)
|
||||
{
|
||||
$this->count = (int) $count;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
|
||||
89
src/Model/TimesheetCountedStatistic.php
Normal file
89
src/Model/TimesheetCountedStatistic.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?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\Model;
|
||||
|
||||
class TimesheetCountedStatistic
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $recordAmount = 0;
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $recordDuration = 0;
|
||||
/**
|
||||
* @var float
|
||||
*/
|
||||
protected $recordRate = 0.0;
|
||||
|
||||
/**
|
||||
* Returns the total amount of included timesheet records.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getRecordAmount()
|
||||
{
|
||||
return $this->recordAmount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $recordAmount
|
||||
* @return $this
|
||||
*/
|
||||
public function setRecordAmount($recordAmount)
|
||||
{
|
||||
$this->recordAmount = (int) $recordAmount;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the total duration of all included timesheet records.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getRecordDuration()
|
||||
{
|
||||
return $this->recordDuration;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $recordDuration
|
||||
* @return $this
|
||||
*/
|
||||
public function setRecordDuration($recordDuration)
|
||||
{
|
||||
$this->recordDuration = (int) $recordDuration;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the total rate of all included timesheet records.
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getRecordRate()
|
||||
{
|
||||
return $this->recordRate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $recordRate
|
||||
* @return $this
|
||||
*/
|
||||
public function setRecordRate($recordRate)
|
||||
{
|
||||
$this->recordRate = (float) $recordRate;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -51,23 +51,24 @@ class ActivityRepository extends AbstractRepository
|
||||
*/
|
||||
public function getActivityStatistics(Activity $activity)
|
||||
{
|
||||
$stats = new ActivityStatistic();
|
||||
|
||||
$qb = $this->getEntityManager()->createQueryBuilder();
|
||||
|
||||
$qb->select('COUNT(t.id) as totalRecords', 'SUM(t.duration) as totalDuration')
|
||||
$qb
|
||||
->addSelect('COUNT(t.id) as recordAmount')
|
||||
->addSelect('SUM(t.duration) as recordDuration')
|
||||
->addSelect('SUM(t.rate) as recordRate')
|
||||
->from(Timesheet::class, 't')
|
||||
->where('t.activity = :activity')
|
||||
;
|
||||
|
||||
$result = $qb->getQuery()->execute(['activity' => $activity], Query::HYDRATE_ARRAY);
|
||||
$timesheetResult = $qb->getQuery()->execute(['activity' => $activity], Query::HYDRATE_ARRAY);
|
||||
|
||||
$stats = new ActivityStatistic();
|
||||
|
||||
if (isset($result[0])) {
|
||||
$dbStats = $result[0];
|
||||
|
||||
$stats->setCount(1);
|
||||
$stats->setRecordAmount($dbStats['totalRecords']);
|
||||
$stats->setRecordDuration($dbStats['totalDuration']);
|
||||
if (isset($timesheetResult[0])) {
|
||||
$stats->setRecordAmount($timesheetResult[0]['recordAmount']);
|
||||
$stats->setRecordDuration($timesheetResult[0]['recordDuration']);
|
||||
$stats->setRecordRate($timesheetResult[0]['recordRate']);
|
||||
}
|
||||
|
||||
return $stats;
|
||||
|
||||
@@ -53,12 +53,12 @@ class CustomerRepository extends AbstractRepository
|
||||
public function getCustomerStatistics(Customer $customer)
|
||||
{
|
||||
$stats = new CustomerStatistic();
|
||||
$stats->setCount(1);
|
||||
|
||||
$qb = $this->getEntityManager()->createQueryBuilder();
|
||||
$qb
|
||||
->addSelect('COUNT(t.id) as recordAmount')
|
||||
->addSelect('SUM(t.duration) as recordDuration')
|
||||
->addSelect('SUM(t.rate) as recordRate')
|
||||
->from(Timesheet::class, 't')
|
||||
->join(Project::class, 'p', Query\Expr\Join::WITH, 't.project = p.id')
|
||||
->andWhere('p.customer = :customer')
|
||||
@@ -68,6 +68,7 @@ class CustomerRepository extends AbstractRepository
|
||||
if (isset($timesheetResult[0])) {
|
||||
$stats->setRecordAmount($timesheetResult[0]['recordAmount']);
|
||||
$stats->setRecordDuration($timesheetResult[0]['recordDuration']);
|
||||
$stats->setRecordRate($timesheetResult[0]['recordRate']);
|
||||
}
|
||||
|
||||
$qb = $this->getEntityManager()->createQueryBuilder();
|
||||
|
||||
@@ -49,14 +49,24 @@ class ProjectRepository extends AbstractRepository
|
||||
|
||||
public function getProjectStatistics(Project $project): ProjectStatistic
|
||||
{
|
||||
$stats = new ProjectStatistic();
|
||||
|
||||
$qb = $this->getEntityManager()->createQueryBuilder();
|
||||
|
||||
$qb->select('COUNT(t.id) as recordAmount')
|
||||
$qb
|
||||
->addSelect('COUNT(t.id) as recordAmount')
|
||||
->addSelect('SUM(t.duration) as recordDuration')
|
||||
->addSelect('SUM(t.rate) as recordRate')
|
||||
->from(Timesheet::class, 't')
|
||||
->andWhere('t.project = :project')
|
||||
;
|
||||
$resultTimesheets = $qb->getQuery()->execute(['project' => $project], Query::HYDRATE_ARRAY);
|
||||
$timesheetResult = $qb->getQuery()->execute(['project' => $project], Query::HYDRATE_ARRAY);
|
||||
|
||||
if (isset($timesheetResult[0])) {
|
||||
$stats->setRecordAmount($timesheetResult[0]['recordAmount']);
|
||||
$stats->setRecordDuration($timesheetResult[0]['recordDuration']);
|
||||
$stats->setRecordRate($timesheetResult[0]['recordRate']);
|
||||
}
|
||||
|
||||
$qb = $this->getEntityManager()->createQueryBuilder();
|
||||
$qb->select('COUNT(a.id) as activityAmount')
|
||||
@@ -65,16 +75,6 @@ class ProjectRepository extends AbstractRepository
|
||||
;
|
||||
$resultActivities = $qb->getQuery()->execute(['project' => $project], Query::HYDRATE_ARRAY);
|
||||
|
||||
$stats = new ProjectStatistic();
|
||||
$stats->setCount(1);
|
||||
|
||||
if (isset($resultTimesheets[0])) {
|
||||
$resultTimesheets = $resultTimesheets[0];
|
||||
|
||||
$stats->setRecordAmount($resultTimesheets['recordAmount']);
|
||||
$stats->setRecordDuration($resultTimesheets['recordDuration']);
|
||||
}
|
||||
|
||||
if (isset($resultActivities[0])) {
|
||||
$resultActivities = $resultActivities[0];
|
||||
|
||||
|
||||
@@ -75,6 +75,7 @@ class TagRepository extends AbstractRepository
|
||||
->select('tag.id, tag.name, count(timesheets.id) as amount')
|
||||
->leftJoin('tag.timesheets', 'timesheets')
|
||||
->addGroupBy('tag.id')
|
||||
->addGroupBy('tag.name')
|
||||
->orderBy('tag.name')
|
||||
;
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ class Extensions extends AbstractExtension
|
||||
'activity' => 'fas fa-tasks',
|
||||
'admin' => 'fas fa-wrench',
|
||||
'calendar' => 'far fa-calendar-alt',
|
||||
'customer' => 'fas fa-users',
|
||||
'customer' => 'fas fa-user-tie',
|
||||
'copy' => 'far fa-copy',
|
||||
'create' => 'far fa-plus-square',
|
||||
'dashboard' => 'fas fa-tachometer-alt',
|
||||
@@ -76,7 +76,7 @@ class Extensions extends AbstractExtension
|
||||
'stop-small' => 'far fa-stop-circle',
|
||||
'timesheet' => 'fas fa-clock',
|
||||
'trash' => 'far fa-trash-alt',
|
||||
'user' => 'fas fa-user',
|
||||
'user' => 'fas fa-users',
|
||||
'visibility' => 'far fa-eye',
|
||||
'settings' => 'fas fa-cog',
|
||||
'export' => 'fas fa-file-export',
|
||||
@@ -96,6 +96,8 @@ class Extensions extends AbstractExtension
|
||||
'warning' => 'fas fa-exclamation-triangle',
|
||||
'permissions' => 'fas fa-user-lock',
|
||||
'back' => 'fas fa-long-arrow-alt-left',
|
||||
'tag' => 'fas fa-tags',
|
||||
'avatar' => 'fas fa-user'
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
namespace App\Utils;
|
||||
|
||||
/**
|
||||
* A simple class to help with timesheet record durations.
|
||||
* Convert duration strings into seconds.
|
||||
*/
|
||||
class Duration
|
||||
{
|
||||
@@ -50,6 +50,8 @@ class Duration
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the seconds, which were given as $duration string.
|
||||
*
|
||||
* @param string $duration
|
||||
* @return int
|
||||
*/
|
||||
@@ -67,6 +69,8 @@ class Duration
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the seconds, which were given as $mode formatted $duration string.
|
||||
*
|
||||
* @param string $duration
|
||||
* @param string $mode
|
||||
* @return int
|
||||
@@ -78,31 +82,13 @@ class Duration
|
||||
return 0;
|
||||
}
|
||||
|
||||
$seconds = 0;
|
||||
|
||||
switch ($mode) {
|
||||
case self::FORMAT_COLON:
|
||||
$parts = explode(':', $duration);
|
||||
if (count($parts) < 2) {
|
||||
throw new \InvalidArgumentException('Colon format cannot parse: ' . $duration);
|
||||
}
|
||||
$seconds = 0;
|
||||
if (3 == count($parts)) {
|
||||
$seconds += (int) array_pop($parts);
|
||||
}
|
||||
$seconds += (int) $parts[1] * 60;
|
||||
$seconds += (int) $parts[0] * 3600;
|
||||
$seconds = $this->parseColonFormat($duration);
|
||||
break;
|
||||
|
||||
case self::FORMAT_NATURAL:
|
||||
try {
|
||||
$interval = new \DateInterval('PT' . strtoupper($duration));
|
||||
$reference = new \DateTimeImmutable();
|
||||
$endTime = $reference->add($interval);
|
||||
$seconds = $endTime->getTimestamp() - $reference->getTimestamp();
|
||||
} catch (\Exception $e) {
|
||||
throw new \InvalidArgumentException('Invalid input for natural format: ' . $duration);
|
||||
}
|
||||
$seconds = $this->parseNaturalFormat($duration);
|
||||
break;
|
||||
|
||||
case self::FORMAT_SECONDS:
|
||||
@@ -110,7 +96,7 @@ class Duration
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new \InvalidArgumentException('Invalid duration format: ' . $mode);
|
||||
throw new \InvalidArgumentException(sprintf('Unsupported duration format "%s"', $mode));
|
||||
}
|
||||
|
||||
if ($seconds < 0) {
|
||||
@@ -119,4 +105,51 @@ class Duration
|
||||
|
||||
return $seconds;
|
||||
}
|
||||
|
||||
protected function parseNaturalFormat(string $duration): int
|
||||
{
|
||||
try {
|
||||
$interval = new \DateInterval('PT' . strtoupper($duration));
|
||||
$reference = new \DateTimeImmutable();
|
||||
$endTime = $reference->add($interval);
|
||||
|
||||
return $endTime->getTimestamp() - $reference->getTimestamp();
|
||||
} catch (\Exception $e) {
|
||||
throw new \InvalidArgumentException('Invalid input for natural format: ' . $duration);
|
||||
}
|
||||
}
|
||||
|
||||
protected function parseColonFormat(string $duration): int
|
||||
{
|
||||
$parts = explode(':', $duration);
|
||||
if (count($parts) < 2 || count($parts) > 3) {
|
||||
throw new \InvalidArgumentException(
|
||||
sprintf('Invalid colon format given in "%s"', $duration)
|
||||
);
|
||||
}
|
||||
|
||||
foreach ($parts as $part) {
|
||||
if (strlen($part) === 0) {
|
||||
throw new \InvalidArgumentException(
|
||||
sprintf('Colon format cannot parse "%s"', $duration)
|
||||
);
|
||||
}
|
||||
if (((int) $part) < 0) {
|
||||
throw new \InvalidArgumentException(
|
||||
sprintf('Negative input is not allowed in "%s"', $duration)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$seconds = 0;
|
||||
|
||||
if (3 == count($parts)) {
|
||||
$seconds += (int) array_pop($parts);
|
||||
}
|
||||
|
||||
$seconds += (int) $parts[1] * 60;
|
||||
$seconds += (int) $parts[0] * 3600;
|
||||
|
||||
return $seconds;
|
||||
}
|
||||
}
|
||||
|
||||
34
src/Validator/Constraints/Duration.php
Normal file
34
src/Validator/Constraints/Duration.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?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\Validator\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Constraints\Regex;
|
||||
|
||||
/**
|
||||
* @Annotation
|
||||
* @Target({"PROPERTY", "METHOD", "ANNOTATION"})
|
||||
*/
|
||||
class Duration extends Regex
|
||||
{
|
||||
public function __construct($options = null)
|
||||
{
|
||||
$patterns = [
|
||||
'[0-9]{1,}',
|
||||
'[0-9]{1,}:[0-9]{1,}:[0-9]{1,}',
|
||||
'[0-9]{1,}:[0-9]{1,}',
|
||||
'[0-9]{1,}[hmsHMS]{1}',
|
||||
'[0-9]{1,}[hmsHMS]{1}[0-9]{1,}[hmsHMS]{1}',
|
||||
'[0-9]{1,}[hmsHMS]{1}[0-9]{1,}[hmsHMS]{1}[0-9]{1,}[hmsHMS]{1}',
|
||||
];
|
||||
$options['pattern'] = '/^' . implode('$|^', $patterns) . '$/';
|
||||
|
||||
parent::__construct($options);
|
||||
}
|
||||
}
|
||||
16
src/Validator/Constraints/DurationValidator.php
Normal file
16
src/Validator/Constraints/DurationValidator.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?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\Validator\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Constraints\RegexValidator;
|
||||
|
||||
class DurationValidator extends RegexValidator
|
||||
{
|
||||
}
|
||||
@@ -20,6 +20,7 @@ class ActivityVoter extends AbstractVoter
|
||||
{
|
||||
public const VIEW = 'view';
|
||||
public const EDIT = 'edit';
|
||||
public const BUDGET = 'budget';
|
||||
public const DELETE = 'delete';
|
||||
|
||||
/**
|
||||
@@ -28,7 +29,8 @@ class ActivityVoter extends AbstractVoter
|
||||
public const ALLOWED_ATTRIBUTES = [
|
||||
self::VIEW,
|
||||
self::EDIT,
|
||||
self::DELETE
|
||||
self::BUDGET,
|
||||
self::DELETE,
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@@ -20,6 +20,7 @@ class CustomerVoter extends AbstractVoter
|
||||
{
|
||||
public const VIEW = 'view';
|
||||
public const EDIT = 'edit';
|
||||
public const BUDGET = 'budget';
|
||||
public const DELETE = 'delete';
|
||||
|
||||
/**
|
||||
@@ -28,7 +29,8 @@ class CustomerVoter extends AbstractVoter
|
||||
public const ALLOWED_ATTRIBUTES = [
|
||||
self::VIEW,
|
||||
self::EDIT,
|
||||
self::DELETE
|
||||
self::BUDGET,
|
||||
self::DELETE,
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@@ -20,6 +20,7 @@ class ProjectVoter extends AbstractVoter
|
||||
{
|
||||
public const VIEW = 'view';
|
||||
public const EDIT = 'edit';
|
||||
public const BUDGET = 'budget';
|
||||
public const DELETE = 'delete';
|
||||
|
||||
/**
|
||||
@@ -28,7 +29,8 @@ class ProjectVoter extends AbstractVoter
|
||||
public const ALLOWED_ATTRIBUTES = [
|
||||
self::VIEW,
|
||||
self::EDIT,
|
||||
self::DELETE
|
||||
self::BUDGET,
|
||||
self::DELETE,
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
48
templates/activity/budget.html.twig
Normal file
48
templates/activity/budget.html.twig
Normal file
@@ -0,0 +1,48 @@
|
||||
{% extends 'base.html.twig' %}
|
||||
{% import "macros/actions.html.twig" as actions %}
|
||||
|
||||
{% block page_title %}{{ 'admin_activity.title'|trans }}{% endblock %}
|
||||
{% block page_subtitle %}{{ 'admin_activity.subtitle'|trans }}{% endblock %}
|
||||
{% block page_actions %}{{ actions.activity(activity, 'delete') }}{% endblock %}
|
||||
|
||||
{% block main %}
|
||||
|
||||
{% set params = {
|
||||
'%activity%': '<strong>' ~ activity.name ~ '</strong>',
|
||||
'%project%': '<strong>-</strong>',
|
||||
'%customer%': '<strong>-</strong>',
|
||||
'%records%': '<strong>' ~ stats.recordAmount ~ '</strong>',
|
||||
'%duration%': '<strong>' ~ stats.recordDuration|duration ~ '</strong>'
|
||||
} %}
|
||||
|
||||
{% if activity.project is not null %}
|
||||
{% set params = params|merge({
|
||||
'%project%': '<strong>' ~ activity.project.name ~ '</strong>',
|
||||
'%customer%': '<strong>' ~ activity.project.customer.name ~ '</strong>',
|
||||
}) %}
|
||||
{% endif %}
|
||||
|
||||
{% embed '@AdminLTE/Widgets/box-widget.html.twig' %}
|
||||
{% import "macros/progressbar.html.twig" as progress %}
|
||||
{% block box_title %}{{ activity.name }}{% endblock %}
|
||||
{% block box_body %}
|
||||
<p>
|
||||
{{ 'admin_activity.short_stats'|trans(params)|raw }}
|
||||
</p>
|
||||
|
||||
{% set currency = null %}
|
||||
{% if activity.project is not null %}
|
||||
{% set currency = activity.project.customer.currency %}
|
||||
{% endif %}
|
||||
|
||||
{% if activity.budget > 0 %}
|
||||
{{ progress.progressbar(activity.budget, stats.recordRate, 'label.budget'|trans, stats.recordRate|money(currency) ~ ' / ' ~ activity.budget|money(currency) ) }}
|
||||
{% endif %}
|
||||
|
||||
{% if activity.timeBudget > 0 %}
|
||||
{{ progress.progressbar(activity.timeBudget, stats.recordDuration, 'label.timeBudget'|trans, stats.recordDuration|duration ~ ' / ' ~ activity.timeBudget|duration ) }}
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
{% endembed %}
|
||||
|
||||
{% endblock %}
|
||||
@@ -24,8 +24,10 @@
|
||||
}) %}
|
||||
{% endif %}
|
||||
|
||||
{% set message = '<p>' ~ ("admin_activity.short_stats"|trans(params)|raw) ~ '</p><p>' ~ ("admin_entity.delete_confirm"|trans|raw) ~ '</p>' %}
|
||||
|
||||
{{ include(app.request.xmlHttpRequest ? 'default/_form_delete_modal.html.twig' : 'default/_form_delete.html.twig', {
|
||||
'message': "admin_activity.delete_confirm"|trans(params)|raw,
|
||||
'message': message|raw,
|
||||
'form': form,
|
||||
'used': inUse,
|
||||
'back': path('admin_activity')
|
||||
|
||||
@@ -109,7 +109,7 @@
|
||||
{% import "macros/widgets.html.twig" as widgets %}
|
||||
<li class="dropdown user-menu">
|
||||
<a href="#" class="dropdown-toggle ddt-large" data-toggle="dropdown">
|
||||
<i class="{{ 'user'|icon }} fa-2x"></i>
|
||||
<i class="{{ 'avatar'|icon }} fa-2x"></i>
|
||||
</a>
|
||||
<ul class="dropdown-menu">
|
||||
{% if app.user is not null %}
|
||||
|
||||
37
templates/customer/budget.html.twig
Normal file
37
templates/customer/budget.html.twig
Normal file
@@ -0,0 +1,37 @@
|
||||
{% extends 'base.html.twig' %}
|
||||
{% import "macros/actions.html.twig" as actions %}
|
||||
|
||||
{% block page_title %}{{ 'admin_customer.title'|trans }}{% endblock %}
|
||||
{% block page_subtitle %}{{ 'admin_customer.subtitle'|trans }}{% endblock %}
|
||||
{% block page_actions %}{{ actions.customer(customer, 'delete') }}{% endblock %}
|
||||
|
||||
{% block main %}
|
||||
|
||||
{% set params = {
|
||||
'%activity%': '<strong>' ~ stats.activityAmount ~ '</strong>',
|
||||
'%project%': '<strong>' ~ stats.projectAmount ~ '</strong>',
|
||||
'%customer%': '<strong>' ~ customer.name ~ '</strong>',
|
||||
'%records%': '<strong>' ~ stats.recordAmount ~ '</strong>',
|
||||
'%duration%': '<strong>' ~ stats.recordDuration|duration ~ '</strong>',
|
||||
'%rate%': '<strong>' ~ stats.recordRate|money ~ '</strong>'
|
||||
} %}
|
||||
|
||||
{% embed '@AdminLTE/Widgets/box-widget.html.twig' %}
|
||||
{% import "macros/progressbar.html.twig" as progress %}
|
||||
{% block box_title %}{{ customer.name }}{% endblock %}
|
||||
{% block box_body %}
|
||||
<p>
|
||||
{{ 'admin_customer.short_stats'|trans(params)|raw }}
|
||||
</p>
|
||||
|
||||
{% if customer.budget > 0 %}
|
||||
{{ progress.progressbar(customer.budget, stats.recordRate, 'label.budget'|trans, stats.recordRate|money(customer.currency) ~ ' / ' ~ customer.budget|money(customer.currency) ) }}
|
||||
{% endif %}
|
||||
|
||||
{% if customer.timeBudget > 0 %}
|
||||
{{ progress.progressbar(customer.timeBudget, stats.recordDuration, 'label.timeBudget'|trans, stats.recordDuration|duration ~ ' / ' ~ customer.timeBudget|duration ) }}
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
{% endembed %}
|
||||
|
||||
{% endblock %}
|
||||
@@ -17,8 +17,10 @@
|
||||
'%duration%': '<strong>' ~ stats.recordDuration|duration ~ '</strong>'
|
||||
} %}
|
||||
|
||||
{% set message = '<p>' ~ ("admin_customer.short_stats"|trans(params)|raw) ~ '</p><p>' ~ ("admin_entity.delete_confirm"|trans|raw) ~ '</p>' %}
|
||||
|
||||
{{ include(app.request.xmlHttpRequest ? 'default/_form_delete_modal.html.twig' : 'default/_form_delete.html.twig', {
|
||||
'message': "admin_customer.delete_confirm"|trans(params)|raw,
|
||||
'message': message|raw,
|
||||
'form': form,
|
||||
'used': inUse,
|
||||
'back': path('admin_customer')
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
'comment': 'hidden-xs',
|
||||
'country': 'hidden-xs',
|
||||
'number': 'hidden-xs',
|
||||
'currency': 'hidden-xs',
|
||||
'visible': 'hidden-xs',
|
||||
'actions': 'actions alwaysVisible',
|
||||
} %}
|
||||
@@ -38,7 +37,6 @@
|
||||
<td class="{{ tables.data_table_column_class(tableName, columns, 'comment') }}">{{ entry.comment|comment2html }}</td>
|
||||
<td class="{{ tables.data_table_column_class(tableName, columns, 'country') }}">{{ entry.country|country }}</td>
|
||||
<td class="{{ tables.data_table_column_class(tableName, columns, 'number') }}">{{ entry.number }}</td>
|
||||
<td class="{{ tables.data_table_column_class(tableName, columns, 'currency') }}">{{ entry.currency }} {{ entry.currency|currency }}</td>
|
||||
<td class="{{ tables.data_table_column_class(tableName, columns, 'visible') }}">{{ widgets.label_visible(entry.visible) }}</td>
|
||||
<td class="actions">
|
||||
{{ actions.customer(entry, 'index') }}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<h3 class="box-title">{{ title|default('confirm.delete'|trans) }}</h3>
|
||||
</div>
|
||||
<div class="box-body">
|
||||
{{ message|default('confirm.delete_message'|trans)|raw }}
|
||||
{{ message|raw }}
|
||||
</div>
|
||||
{{ form_start(form) }}
|
||||
<div class="box-body">
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
{{ form_widget(form) }}
|
||||
</div>
|
||||
{% else %}
|
||||
<p>{{ message|default('confirm.delete_message'|trans)|raw }}</p>
|
||||
<p>{{ message|raw }}</p>
|
||||
{{ form_widget(form) }}
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
@@ -23,6 +23,9 @@
|
||||
{% endif %}
|
||||
{% set actions = actions|merge({'edit': {'url': path('admin_activity_edit', {'id': activity.id}), 'class': class}}) %}
|
||||
{% endif %}
|
||||
{% if is_granted('budget', activity) %}
|
||||
{% set actions = actions|merge({'report': {'url': path('admin_activity_budget', {'id': activity.id})}}) %}
|
||||
{% endif %}
|
||||
{% if is_granted('view_other_timesheet') %}
|
||||
{% set actions = actions|merge({'timesheet': path('admin_timesheet', {'customer': activity.project ? activity.project.customer.id : null, 'project': activity.project ? activity.project.id : null, 'activity': activity.id})}) %}
|
||||
{% endif %}
|
||||
@@ -35,7 +38,7 @@
|
||||
{% endif %}
|
||||
|
||||
{% if view != 'index' %}
|
||||
{% set actions = actions|merge({'activity': path('admin_activity')}) %}
|
||||
{% set actions = actions|merge({'back': path('admin_activity')}) %}
|
||||
{% endif %}
|
||||
|
||||
{% set event = trigger('actions.activity', {'actions': actions, 'view': view, 'activity': activity}) %}
|
||||
@@ -139,6 +142,9 @@
|
||||
{% endif %}
|
||||
{% set actions = actions|merge({'edit': {'url': path('admin_project_edit', {'id': project.id}), 'class': class}}) %}
|
||||
{% endif %}
|
||||
{% if is_granted('budget', project) %}
|
||||
{% set actions = actions|merge({'report': {'url': path('admin_project_budget', {'id': project.id})}}) %}
|
||||
{% endif %}
|
||||
{% if is_granted('view_activity') %}
|
||||
{% set actions = actions|merge({'activity': path('admin_activity', {'customer': project.customer.id, 'project': project.id})}) %}
|
||||
{% endif %}
|
||||
@@ -154,7 +160,7 @@
|
||||
{% endif %}
|
||||
|
||||
{% if view != 'index' %}
|
||||
{% set actions = actions|merge({'project': path('admin_project')}) %}
|
||||
{% set actions = actions|merge({'back': path('admin_project')}) %}
|
||||
{% endif %}
|
||||
|
||||
{% set event = trigger('actions.project', {'actions': actions, 'view': view, 'project': project}) %}
|
||||
@@ -189,6 +195,9 @@
|
||||
{% endif %}
|
||||
{% set actions = actions|merge({'edit': {'url': path('admin_customer_edit', {'id': customer.id}), 'class': class}}) %}
|
||||
{% endif %}
|
||||
{% if is_granted('budget', customer) %}
|
||||
{% set actions = actions|merge({'report': {'url': path('admin_customer_budget', {'id': customer.id})}}) %}
|
||||
{% endif %}
|
||||
{% if is_granted('view_project') %}
|
||||
{% set actions = actions|merge({'project': path('admin_project', {'customer': customer.id})}) %}
|
||||
{% endif %}
|
||||
@@ -207,7 +216,7 @@
|
||||
{% endif %}
|
||||
|
||||
{% if view != 'index' %}
|
||||
{% set actions = actions|merge({'customer': path('admin_customer')}) %}
|
||||
{% set actions = actions|merge({'back': path('admin_customer')}) %}
|
||||
{% endif %}
|
||||
|
||||
{% set event = trigger('actions.customer', {'actions': actions, 'view': view, 'customer': customer}) %}
|
||||
@@ -274,7 +283,7 @@
|
||||
{% endif %}
|
||||
|
||||
{% if view != 'index' %}
|
||||
{% set actions = actions|merge({'timesheet': path('timesheet')}) %}
|
||||
{% set actions = actions|merge({'back': path('timesheet')}) %}
|
||||
{% endif %}
|
||||
|
||||
{% set event = trigger('actions.timesheet', {'actions': actions, 'view': view, 'timesheet': timesheet}) %}
|
||||
@@ -329,7 +338,7 @@
|
||||
{% endif %}
|
||||
|
||||
{% if view != 'index' %}
|
||||
{% set actions = actions|merge({'timesheet': path('admin_timesheet')}) %}
|
||||
{% set actions = actions|merge({'back': path('admin_timesheet')}) %}
|
||||
{% endif %}
|
||||
|
||||
{% set event = trigger('actions.timesheet_team', {'actions': actions, 'view': view, 'timesheet': timesheet}) %}
|
||||
|
||||
28
templates/macros/progressbar.html.twig
Normal file
28
templates/macros/progressbar.html.twig
Normal file
@@ -0,0 +1,28 @@
|
||||
{% macro progressbar(max, current, title, subTitle) %}
|
||||
{% set percentReached = (current / (max / 100)) %}
|
||||
{% set class = "progress-bar-info" %}
|
||||
{% set width = percentReached|number_format(1, '.', '') %}
|
||||
|
||||
{% if percentReached > 90 %}
|
||||
{% set class = "progress-bar-danger" %}
|
||||
{% elseif percentReached > 70 %}
|
||||
{% set class = "progress-bar-warning" %}
|
||||
{% elseif percentReached > 50 %}
|
||||
{% set class = "progress-bar-success" %}
|
||||
{% elseif percentReached > 30 %}
|
||||
{% set class = "progress-bar-primary" %}
|
||||
{% endif %}
|
||||
|
||||
{% if width > 100 %}
|
||||
{% set width = 100 %}
|
||||
{% endif %}
|
||||
|
||||
<div class="progress-group">
|
||||
<span class="progress-text">{{ title }} – {{ percentReached|number_format(2) }}%</span>
|
||||
<span class="progress-number">{{ subTitle }}</span>
|
||||
|
||||
<div class="progress">
|
||||
<div class="progress-bar {{ class }}" role="progressbar" aria-valuenow="{{ width }}" aria-valuemin="0" aria-valuemax="100" style="width: {{ width }}%"></div>
|
||||
</div>
|
||||
</div>
|
||||
{% endmacro %}
|
||||
36
templates/project/budget.html.twig
Normal file
36
templates/project/budget.html.twig
Normal file
@@ -0,0 +1,36 @@
|
||||
{% extends 'base.html.twig' %}
|
||||
{% import "macros/actions.html.twig" as actions %}
|
||||
|
||||
{% block page_title %}{{ 'admin_project.title'|trans }}{% endblock %}
|
||||
{% block page_subtitle %}{{ 'admin_project.subtitle'|trans }}{% endblock %}
|
||||
{% block page_actions %}{{ actions.project(project, 'delete') }}{% endblock %}
|
||||
|
||||
{% block main %}
|
||||
|
||||
{% set params = {
|
||||
'%project%': '<strong>' ~ project.name ~ '</strong>',
|
||||
'%customer%': '<strong>' ~ project.customer.name ~ '</strong>',
|
||||
'%records%': '<strong>' ~ stats.recordAmount ~ '</strong>',
|
||||
'%activities%': '<strong>' ~ stats.activityAmount ~ '</strong>',
|
||||
'%duration%': '<strong>' ~ stats.recordDuration|duration ~ '</strong>'
|
||||
} %}
|
||||
|
||||
{% embed '@AdminLTE/Widgets/box-widget.html.twig' %}
|
||||
{% import "macros/progressbar.html.twig" as progress %}
|
||||
{% block box_title %}{{ project.name }}{% endblock %}
|
||||
{% block box_body %}
|
||||
<p>
|
||||
{{ 'admin_project.short_stats'|trans(params)|raw }}
|
||||
</p>
|
||||
|
||||
{% if project.budget > 0 %}
|
||||
{{ progress.progressbar(project.budget, stats.recordRate, 'label.budget'|trans, stats.recordRate|money(project.customer.currency) ~ ' / ' ~ project.budget|money(project.customer.currency) ) }}
|
||||
{% endif %}
|
||||
|
||||
{% if project.timeBudget > 0 %}
|
||||
{{ progress.progressbar(project.timeBudget, stats.recordDuration, 'label.timeBudget'|trans, stats.recordDuration|duration ~ ' / ' ~ project.timeBudget|duration ) }}
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
{% endembed %}
|
||||
|
||||
{% endblock %}
|
||||
@@ -17,8 +17,10 @@
|
||||
'%duration%': '<strong>' ~ stats.recordDuration|duration ~ '</strong>'
|
||||
} %}
|
||||
|
||||
{% set message = '<p>' ~ ("admin_project.short_stats"|trans(params)|raw) ~ '</p><p>' ~ ("admin_entity.delete_confirm"|trans|raw) ~ '</p>' %}
|
||||
|
||||
{{ include(app.request.xmlHttpRequest ? 'default/_form_delete_modal.html.twig' : 'default/_form_delete.html.twig', {
|
||||
'message': "admin_project.delete_confirm"|trans(params)|raw,
|
||||
'message': message|raw,
|
||||
'form': form,
|
||||
'used': inUse,
|
||||
'back': path('admin_project')
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
'name': 'alwaysVisible',
|
||||
'customer': 'hidden-xs',
|
||||
'comment': 'hidden-xs hidden-sm',
|
||||
'budget': 'hidden-xs',
|
||||
'visible': '',
|
||||
'actions': 'actions alwaysVisible',
|
||||
} %}
|
||||
@@ -38,7 +37,6 @@
|
||||
{{ widgets.label_customer(entry.customer, path('admin_customer_edit', {'id' : entry.customer.id})) }}
|
||||
</td>
|
||||
<td class="{{ tables.data_table_column_class(tableName, columns, 'comment') }}">{{ entry.comment|comment2html }}</td>
|
||||
<td class="{{ tables.data_table_column_class(tableName, columns, 'budget') }}">{{ entry.budget|money(entry.customer.currency) }}</td>
|
||||
<td class="{{ tables.data_table_column_class(tableName, columns, 'visible') }}">{{ widgets.label_visible(entry.visible) }}</td>
|
||||
<td class="actions">
|
||||
{{ actions.project(entry, 'index') }}
|
||||
|
||||
@@ -15,8 +15,10 @@
|
||||
'%duration%': '<strong>' ~ stats.durationTotal|duration ~ '</strong>'
|
||||
} %}
|
||||
|
||||
{% set message = '<p>' ~ ("admin_user.short_stats"|trans(params)|raw) ~ '</p>' %}
|
||||
|
||||
{{ include(app.request.xmlHttpRequest ? 'default/_form_delete_modal.html.twig' : 'default/_form_delete.html.twig', {
|
||||
'message': "admin_user.delete_confirm"|trans(params)|raw,
|
||||
'message': message|raw,
|
||||
'form': form,
|
||||
'used': inUse,
|
||||
'back': path('admin_user')
|
||||
|
||||
@@ -40,7 +40,9 @@
|
||||
<td class="{{ tables.data_table_column_class(tableName, columns, 'title') }}">{{ entry.title }}</td>
|
||||
<td class="{{ tables.data_table_column_class(tableName, columns, 'roles') }}">
|
||||
{% for role in entry.roles %}
|
||||
{{ widgets.label_role(role) }}
|
||||
{% if role != 'ROLE_USER' %}
|
||||
{{ widgets.label_role(role) }}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</td>
|
||||
<td class="{{ tables.data_table_column_class(tableName, columns, 'active') }}">{{ widgets.label_visible(entry.enabled) }}</td>
|
||||
|
||||
@@ -223,7 +223,7 @@ class ActivityControllerTest extends APIControllerBaseTest
|
||||
$expectedKeys = ['id', 'name', 'visible', 'project', 'hourlyRate', 'fixedRate', 'color'];
|
||||
|
||||
if ($full) {
|
||||
$expectedKeys = array_merge($expectedKeys, ['comment']);
|
||||
$expectedKeys = array_merge($expectedKeys, ['comment', 'budget', 'timeBudget']);
|
||||
}
|
||||
|
||||
$actual = array_keys($result);
|
||||
|
||||
@@ -167,7 +167,8 @@ class CustomerControllerTest extends APIControllerBaseTest
|
||||
|
||||
if ($full) {
|
||||
$expectedKeys = array_merge($expectedKeys, [
|
||||
'homepage', 'number', 'comment', 'company', 'contact', 'address', 'country', 'currency', 'phone', 'fax', 'mobile', 'email', 'timezone'
|
||||
'homepage', 'number', 'comment', 'company', 'contact', 'address', 'country', 'currency',
|
||||
'phone', 'fax', 'mobile', 'email', 'timezone', 'budget', 'timeBudget'
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -127,7 +127,6 @@ class ProjectControllerTest extends APIControllerBaseTest
|
||||
'name' => 'foo',
|
||||
'customer' => 1,
|
||||
'visible' => true,
|
||||
'budget' => 0,
|
||||
];
|
||||
$this->request($client, '/api/projects', 'POST', [], json_encode($data));
|
||||
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||
@@ -219,7 +218,7 @@ class ProjectControllerTest extends APIControllerBaseTest
|
||||
if ($full) {
|
||||
$expectedKeys = array_merge(
|
||||
$expectedKeys,
|
||||
['comment', 'budget', 'orderNumber']
|
||||
['comment', 'budget', 'timeBudget', 'orderNumber']
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,11 +9,13 @@
|
||||
|
||||
namespace App\Tests\Controller;
|
||||
|
||||
use App\Entity\Activity;
|
||||
use App\Entity\Timesheet;
|
||||
use App\Entity\User;
|
||||
use App\Tests\DataFixtures\ActivityFixtures;
|
||||
use App\Tests\DataFixtures\ProjectFixtures;
|
||||
use App\Tests\DataFixtures\TimesheetFixtures;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
|
||||
/**
|
||||
* @group integration
|
||||
@@ -33,6 +35,23 @@ class ActivityControllerTest extends ControllerBaseTest
|
||||
$this->assertHasDataTable($client);
|
||||
}
|
||||
|
||||
public function testBudgetAction()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
|
||||
/** @var EntityManager $em */
|
||||
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
|
||||
|
||||
$fixture = new TimesheetFixtures();
|
||||
$fixture->setAmount(10);
|
||||
$fixture->setActivities($em->getRepository(Activity::class)->findAll());
|
||||
$fixture->setUser($this->getUserByRole($em, User::ROLE_ADMIN));
|
||||
$this->importFixture($em, $fixture);
|
||||
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
|
||||
$this->assertAccessIsGranted($client, '/admin/activity/1/budget');
|
||||
self::assertHasProgressbar($client);
|
||||
}
|
||||
|
||||
public function testCreateAction()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
|
||||
@@ -62,6 +81,7 @@ class ActivityControllerTest extends ControllerBaseTest
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
|
||||
|
||||
/** @var EntityManager $em */
|
||||
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
|
||||
$fixture = new ProjectFixtures();
|
||||
$fixture->setAmount(10);
|
||||
@@ -158,6 +178,7 @@ class ActivityControllerTest extends ControllerBaseTest
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
|
||||
|
||||
/** @var EntityManager $em */
|
||||
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
|
||||
$fixture = new TimesheetFixtures();
|
||||
$fixture->setUser($this->getUserByRole($em, User::ROLE_USER));
|
||||
@@ -197,6 +218,7 @@ class ActivityControllerTest extends ControllerBaseTest
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
|
||||
|
||||
/** @var EntityManager $em */
|
||||
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
|
||||
$fixture = new TimesheetFixtures();
|
||||
$fixture->setUser($this->getUserByRole($em, User::ROLE_USER));
|
||||
|
||||
@@ -103,12 +103,12 @@ abstract class ControllerBaseTest extends WebTestCase
|
||||
$response = $client->getResponse();
|
||||
self::assertInstanceOf(RedirectResponse::class, $response);
|
||||
|
||||
$this->assertTrue(
|
||||
self::assertTrue(
|
||||
$response->isRedirect(),
|
||||
sprintf('The secure URL %s is not protected.', $url)
|
||||
);
|
||||
|
||||
$this->assertStringEndsWith(
|
||||
self::assertStringEndsWith(
|
||||
'/login',
|
||||
$response->getTargetUrl(),
|
||||
sprintf('The secure URL %s does not redirect to the login form.', $url)
|
||||
@@ -134,7 +134,7 @@ abstract class ControllerBaseTest extends WebTestCase
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser($role);
|
||||
$client->request($method, $this->createUrl($url));
|
||||
$this->assertFalse(
|
||||
self::assertFalse(
|
||||
$client->getResponse()->isSuccessful(),
|
||||
sprintf('The secure URL %s is not protected for role %s', $url, $role)
|
||||
);
|
||||
@@ -143,11 +143,11 @@ abstract class ControllerBaseTest extends WebTestCase
|
||||
|
||||
protected function assertAccessDenied(Client $client)
|
||||
{
|
||||
$this->assertFalse(
|
||||
self::assertFalse(
|
||||
$client->getResponse()->isSuccessful(),
|
||||
'Access is not denied for URL: ' . $client->getRequest()->getUri()
|
||||
);
|
||||
$this->assertContains(
|
||||
self::assertContains(
|
||||
'Symfony\Component\Security\Core\Exception\AccessDeniedException',
|
||||
$client->getResponse()->getContent(),
|
||||
'Could not find AccessDeniedException in response'
|
||||
@@ -157,18 +157,18 @@ abstract class ControllerBaseTest extends WebTestCase
|
||||
protected function assertAccessIsGranted(Client $client, string $url, string $method = 'GET', array $parameters = [])
|
||||
{
|
||||
$this->request($client, $url, $method, $parameters);
|
||||
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||
self::assertTrue($client->getResponse()->isSuccessful());
|
||||
}
|
||||
|
||||
protected function assertRouteNotFound(Client $client)
|
||||
{
|
||||
$this->assertFalse($client->getResponse()->isSuccessful());
|
||||
$this->assertEquals(404, $client->getResponse()->getStatusCode());
|
||||
self::assertFalse($client->getResponse()->isSuccessful());
|
||||
self::assertEquals(404, $client->getResponse()->getStatusCode());
|
||||
}
|
||||
|
||||
protected function assertMainContentClass(Client $client, string $classname)
|
||||
{
|
||||
$this->assertContains('<section class="content ' . $classname . '">', $client->getResponse()->getContent());
|
||||
self::assertContains('<section class="content ' . $classname . '">', $client->getResponse()->getContent());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -176,7 +176,18 @@ abstract class ControllerBaseTest extends WebTestCase
|
||||
*/
|
||||
protected function assertHasDataTable(Client $client)
|
||||
{
|
||||
$this->assertContains('<table class="table table-striped table-hover dataTable" role="grid" data-reload-event="', $client->getResponse()->getContent());
|
||||
self::assertContains('<table class="table table-striped table-hover dataTable" role="grid" data-reload-event="', $client->getResponse()->getContent());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Client $client
|
||||
*/
|
||||
protected static function assertHasProgressbar(Client $client)
|
||||
{
|
||||
$content = $client->getResponse()->getContent();
|
||||
self::assertContains('<div class="progress-bar progress-bar-', $content);
|
||||
self::assertContains('" role="progressbar" aria-valuenow="', $content);
|
||||
self::assertContains('" aria-valuemin="0" aria-valuemax="100" style="width: ', $content);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -187,7 +198,7 @@ abstract class ControllerBaseTest extends WebTestCase
|
||||
protected function assertDataTableRowCount(Client $client, string $id, int $count)
|
||||
{
|
||||
$node = $client->getCrawler()->filter('section.content div#' . $id . ' table.table-striped tbody tr');
|
||||
$this->assertEquals($count, $node->count());
|
||||
self::assertEquals($count, $node->count());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -197,13 +208,13 @@ abstract class ControllerBaseTest extends WebTestCase
|
||||
protected function assertPageActions(Client $client, array $buttons)
|
||||
{
|
||||
$node = $client->getCrawler()->filter('section.content-header div.breadcrumb div.box-tools div.btn-group a.btn');
|
||||
$this->assertEquals(count($buttons), $node->count());
|
||||
self::assertEquals(count($buttons), $node->count());
|
||||
|
||||
foreach ($node->getIterator() as $element) {
|
||||
$expectedClass = str_replace('btn btn-default btn-', '', $element->getAttribute('class'));
|
||||
$this->assertArrayHasKey($expectedClass, $buttons);
|
||||
self::assertArrayHasKey($expectedClass, $buttons);
|
||||
$expectedUrl = $buttons[$expectedClass];
|
||||
$this->assertEquals($expectedUrl, $element->getAttribute('href'));
|
||||
self::assertEquals($expectedUrl, $element->getAttribute('href'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -228,7 +239,7 @@ abstract class ControllerBaseTest extends WebTestCase
|
||||
$submittedForm = $result->filter($formSelector);
|
||||
$validationErrors = $submittedForm->filter('li.text-danger');
|
||||
|
||||
$this->assertEquals(
|
||||
self::assertEquals(
|
||||
count($fieldNames),
|
||||
count($validationErrors),
|
||||
sprintf('Expected %s validation errors, found %s', count($fieldNames), count($validationErrors))
|
||||
@@ -236,15 +247,15 @@ abstract class ControllerBaseTest extends WebTestCase
|
||||
|
||||
foreach ($fieldNames as $name) {
|
||||
$field = $submittedForm->filter($name);
|
||||
$this->assertNotNull($field, 'Could not find form field: ' . $name);
|
||||
self::assertNotNull($field, 'Could not find form field: ' . $name);
|
||||
$list = $field->nextAll();
|
||||
$this->assertNotNull($list, 'Form field has no validation message: ' . $name);
|
||||
self::assertNotNull($list, 'Form field has no validation message: ' . $name);
|
||||
|
||||
$validation = $list->filter('li.text-danger');
|
||||
if (count($validation) < 1) {
|
||||
// decorated form fields with icon have a different html structure, see kimai-theme.html.twig
|
||||
$classes = $field->parents()->getNode(1)->getAttribute('class');
|
||||
$this->assertContains('has-error', $classes, 'Form field has no validation message: ' . $name);
|
||||
self::assertContains('has-error', $classes, 'Form field has no validation message: ' . $name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -264,7 +275,7 @@ abstract class ControllerBaseTest extends WebTestCase
|
||||
protected function assertCalloutWidgetWithMessage(Client $client, string $message)
|
||||
{
|
||||
$node = $client->getCrawler()->filter('div.callout.callout-warning.lead');
|
||||
$this->assertContains($message, $node->text());
|
||||
self::assertContains($message, $node->text());
|
||||
}
|
||||
|
||||
protected function assertHasFlashDeleteSuccess(Client $client)
|
||||
@@ -284,9 +295,9 @@ abstract class ControllerBaseTest extends WebTestCase
|
||||
protected function assertHasFlashSuccess(Client $client, string $message = null)
|
||||
{
|
||||
$node = $client->getCrawler()->filter('div.alert.alert-success.alert-dismissible');
|
||||
$this->assertNotEmpty($node->text());
|
||||
self::assertNotEmpty($node->text());
|
||||
if (null !== $message) {
|
||||
$this->assertContains($message, $node->text());
|
||||
self::assertContains($message, $node->text());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -297,9 +308,9 @@ abstract class ControllerBaseTest extends WebTestCase
|
||||
protected function assertHasFlashError(Client $client, string $message = null)
|
||||
{
|
||||
$node = $client->getCrawler()->filter('div.alert.alert-error.alert-dismissible');
|
||||
$this->assertNotEmpty($node->text());
|
||||
self::assertNotEmpty($node->text());
|
||||
if (null !== $message) {
|
||||
$this->assertContains($message, $node->text());
|
||||
self::assertContains($message, $node->text());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -309,12 +320,12 @@ abstract class ControllerBaseTest extends WebTestCase
|
||||
*/
|
||||
protected function assertIsRedirect(Client $client, $url = null)
|
||||
{
|
||||
$this->assertTrue($client->getResponse()->isRedirect());
|
||||
self::assertTrue($client->getResponse()->isRedirect());
|
||||
if (null === $url) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->assertTrue($client->getResponse()->headers->has('Location'));
|
||||
$this->assertStringEndsWith($url, $client->getResponse()->headers->get('Location'));
|
||||
self::assertTrue($client->getResponse()->headers->has('Location'));
|
||||
self::assertStringEndsWith($url, $client->getResponse()->headers->get('Location'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,10 +9,12 @@
|
||||
|
||||
namespace App\Tests\Controller;
|
||||
|
||||
use App\Entity\Project;
|
||||
use App\Entity\Timesheet;
|
||||
use App\Entity\User;
|
||||
use App\Tests\DataFixtures\CustomerFixtures;
|
||||
use App\Tests\DataFixtures\TimesheetFixtures;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
|
||||
/**
|
||||
* @group integration
|
||||
@@ -32,6 +34,23 @@ class CustomerControllerTest extends ControllerBaseTest
|
||||
$this->assertHasDataTable($client);
|
||||
}
|
||||
|
||||
public function testBudgetAction()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
|
||||
/** @var EntityManager $em */
|
||||
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
|
||||
|
||||
$fixture = new TimesheetFixtures();
|
||||
$fixture->setAmount(10);
|
||||
$fixture->setProjects($em->getRepository(Project::class)->findAll());
|
||||
$fixture->setUser($this->getUserByRole($em, User::ROLE_ADMIN));
|
||||
$this->importFixture($em, $fixture);
|
||||
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
|
||||
$this->assertAccessIsGranted($client, '/admin/customer/1/budget');
|
||||
self::assertHasProgressbar($client);
|
||||
}
|
||||
|
||||
public function testCreateAction()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
|
||||
|
||||
@@ -9,11 +9,13 @@
|
||||
|
||||
namespace App\Tests\Controller;
|
||||
|
||||
use App\Entity\Project;
|
||||
use App\Entity\Timesheet;
|
||||
use App\Entity\User;
|
||||
use App\Tests\DataFixtures\CustomerFixtures;
|
||||
use App\Tests\DataFixtures\ProjectFixtures;
|
||||
use App\Tests\DataFixtures\TimesheetFixtures;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
|
||||
/**
|
||||
* @group integration
|
||||
@@ -33,6 +35,23 @@ class ProjectControllerTest extends ControllerBaseTest
|
||||
$this->assertHasDataTable($client);
|
||||
}
|
||||
|
||||
public function testBudgetAction()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
|
||||
/** @var EntityManager $em */
|
||||
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
|
||||
|
||||
$fixture = new TimesheetFixtures();
|
||||
$fixture->setAmount(10);
|
||||
$fixture->setProjects($em->getRepository(Project::class)->findAll());
|
||||
$fixture->setUser($this->getUserByRole($em, User::ROLE_ADMIN));
|
||||
$this->importFixture($em, $fixture);
|
||||
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
|
||||
$this->assertAccessIsGranted($client, '/admin/project/1/budget');
|
||||
self::assertHasProgressbar($client);
|
||||
}
|
||||
|
||||
public function testCreateAction()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
|
||||
|
||||
@@ -210,6 +210,6 @@ class UserControllerTest extends ControllerBaseTest
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_SUPER_ADMIN);
|
||||
$this->assertAccessIsGranted($client, '/admin/user/permissions');
|
||||
$this->assertHasDataTable($client);
|
||||
$this->assertDataTableRowCount($client, 'datatable_user_admin_permissions', 66);
|
||||
$this->assertDataTableRowCount($client, 'datatable_user_admin_permissions', 69);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,10 @@ class TimesheetFixtures extends Fixture
|
||||
* @var Activity[]
|
||||
*/
|
||||
protected $activities = [];
|
||||
/**
|
||||
* @var Project[]
|
||||
*/
|
||||
protected $projects = [];
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
@@ -172,6 +176,17 @@ class TimesheetFixtures extends Fixture
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Project[] $projects
|
||||
* @return $this
|
||||
*/
|
||||
public function setProjects(array $projects)
|
||||
{
|
||||
$this->projects = $projects;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $useTags
|
||||
* @return TimesheetFixtures
|
||||
@@ -204,7 +219,10 @@ class TimesheetFixtures extends Fixture
|
||||
$activities = $this->getAllActivities($manager);
|
||||
}
|
||||
|
||||
$projects = $this->getAllProjects($manager);
|
||||
$projects = $this->projects;
|
||||
if (empty($projects)) {
|
||||
$projects = $this->getAllProjects($manager);
|
||||
}
|
||||
|
||||
$faker = Factory::create();
|
||||
$user = $this->user;
|
||||
|
||||
@@ -14,12 +14,12 @@ use Doctrine\DBAL\Platforms\AbstractPlatform;
|
||||
use Doctrine\DBAL\Platforms\MySqlPlatform;
|
||||
use Doctrine\DBAL\Platforms\SqlitePlatform;
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Doctrine\UTCDateTimeType
|
||||
*/
|
||||
class UTCDateTimeTypeTest extends KernelTestCase
|
||||
class UTCDateTimeTypeTest extends TestCase
|
||||
{
|
||||
public function testGetUtc()
|
||||
{
|
||||
|
||||
@@ -10,11 +10,12 @@
|
||||
namespace App\Tests\Entity;
|
||||
|
||||
use App\Entity\Activity;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Entity\Activity
|
||||
*/
|
||||
class ActivityTest extends AbstractEntityTest
|
||||
class ActivityTest extends TestCase
|
||||
{
|
||||
public function testDefaultValues()
|
||||
{
|
||||
@@ -28,6 +29,8 @@ class ActivityTest extends AbstractEntityTest
|
||||
$this->assertNull($sut->getFixedRate());
|
||||
$this->assertNull($sut->getHourlyRate());
|
||||
$this->assertNull($sut->getColor());
|
||||
$this->assertEquals(0.0, $sut->getBudget());
|
||||
$this->assertEquals(0, $sut->getTimeBudget());
|
||||
}
|
||||
|
||||
public function testSetterAndGetter()
|
||||
@@ -48,7 +51,14 @@ class ActivityTest extends AbstractEntityTest
|
||||
|
||||
$this->assertInstanceOf(Activity::class, $sut->setFixedRate(13.47));
|
||||
$this->assertEquals(13.47, $sut->getFixedRate());
|
||||
|
||||
$this->assertInstanceOf(Activity::class, $sut->setHourlyRate(99));
|
||||
$this->assertEquals(99, $sut->getHourlyRate());
|
||||
|
||||
$this->assertInstanceOf(Activity::class, $sut->setBudget(12345.67));
|
||||
$this->assertEquals(12345.67, $sut->getBudget());
|
||||
|
||||
$this->assertInstanceOf(Activity::class, $sut->setTimeBudget(937321));
|
||||
$this->assertEquals(937321, $sut->getTimeBudget());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,11 +10,12 @@
|
||||
namespace App\Tests\Entity;
|
||||
|
||||
use App\Entity\Configuration;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Entity\Configuration
|
||||
*/
|
||||
class ConfigurationTest extends AbstractEntityTest
|
||||
class ConfigurationTest extends TestCase
|
||||
{
|
||||
public function testDefaultValues()
|
||||
{
|
||||
|
||||
@@ -10,11 +10,12 @@
|
||||
namespace App\Tests\Entity;
|
||||
|
||||
use App\Entity\Customer;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Entity\Customer
|
||||
*/
|
||||
class CustomerTest extends AbstractEntityTest
|
||||
class CustomerTest extends TestCase
|
||||
{
|
||||
public function testDefaultValues()
|
||||
{
|
||||
@@ -43,6 +44,8 @@ class CustomerTest extends AbstractEntityTest
|
||||
$this->assertNull($sut->getFixedRate());
|
||||
$this->assertNull($sut->getHourlyRate());
|
||||
$this->assertNull($sut->getColor());
|
||||
$this->assertEquals(0.0, $sut->getBudget());
|
||||
$this->assertEquals(0, $sut->getTimeBudget());
|
||||
}
|
||||
|
||||
public function testSetterAndGetter()
|
||||
@@ -84,7 +87,14 @@ class CustomerTest extends AbstractEntityTest
|
||||
|
||||
$this->assertInstanceOf(Customer::class, $sut->setFixedRate(13.47));
|
||||
$this->assertEquals(13.47, $sut->getFixedRate());
|
||||
|
||||
$this->assertInstanceOf(Customer::class, $sut->setHourlyRate(99));
|
||||
$this->assertEquals(99, $sut->getHourlyRate());
|
||||
|
||||
$this->assertInstanceOf(Customer::class, $sut->setBudget(12345.67));
|
||||
$this->assertEquals(12345.67, $sut->getBudget());
|
||||
|
||||
$this->assertInstanceOf(Customer::class, $sut->setTimeBudget(937321));
|
||||
$this->assertEquals(937321, $sut->getTimeBudget());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,13 +9,12 @@
|
||||
|
||||
namespace App\Tests\Entity;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Symfony\Component\Validator\ConstraintViolationInterface;
|
||||
|
||||
/**
|
||||
* @covers \App\Entity\Timesheet
|
||||
* Classes using this MUST extend \Symfony\Bundle\FrameworkBundle\Test\KernelTestCase
|
||||
*/
|
||||
abstract class AbstractEntityTest extends KernelTestCase
|
||||
trait EntityValidationTestTrait
|
||||
{
|
||||
/**
|
||||
* @param object $entity
|
||||
@@ -10,11 +10,12 @@
|
||||
namespace App\Tests\Entity;
|
||||
|
||||
use App\Entity\InvoiceTemplate;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Entity\InvoiceTemplate
|
||||
*/
|
||||
class InvoiceTemplateTest extends AbstractEntityTest
|
||||
class InvoiceTemplateTest extends TestCase
|
||||
{
|
||||
protected function assertIsFluent($actual)
|
||||
{
|
||||
|
||||
@@ -11,11 +11,12 @@ namespace App\Tests\Entity;
|
||||
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\Project;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Entity\Project
|
||||
*/
|
||||
class ProjectTest extends AbstractEntityTest
|
||||
class ProjectTest extends TestCase
|
||||
{
|
||||
public function testDefaultValues()
|
||||
{
|
||||
@@ -26,7 +27,6 @@ class ProjectTest extends AbstractEntityTest
|
||||
$this->assertNull($sut->getOrderNumber());
|
||||
$this->assertNull($sut->getComment());
|
||||
$this->assertTrue($sut->getVisible());
|
||||
$this->assertEquals(0.0, $sut->getBudget());
|
||||
$this->assertNull($sut->getFixedRate());
|
||||
$this->assertNull($sut->getHourlyRate());
|
||||
self::assertIsIterable($sut->getTimesheets());
|
||||
@@ -34,6 +34,8 @@ class ProjectTest extends AbstractEntityTest
|
||||
self::assertIsIterable($sut->getActivities());
|
||||
self::assertEmpty($sut->getActivities());
|
||||
$this->assertNull($sut->getColor());
|
||||
$this->assertEquals(0.0, $sut->getBudget());
|
||||
$this->assertEquals(0, $sut->getTimeBudget());
|
||||
}
|
||||
|
||||
public function testSetterAndGetter()
|
||||
@@ -59,12 +61,16 @@ class ProjectTest extends AbstractEntityTest
|
||||
$this->assertInstanceOf(Project::class, $sut->setVisible(false));
|
||||
$this->assertFalse($sut->getVisible());
|
||||
|
||||
$this->assertInstanceOf(Project::class, $sut->setFixedRate(13.47));
|
||||
$this->assertEquals(13.47, $sut->getFixedRate());
|
||||
|
||||
$this->assertInstanceOf(Project::class, $sut->setHourlyRate(99));
|
||||
$this->assertEquals(99, $sut->getHourlyRate());
|
||||
|
||||
$this->assertInstanceOf(Project::class, $sut->setBudget(12345.67));
|
||||
$this->assertEquals(12345.67, $sut->getBudget());
|
||||
|
||||
$this->assertInstanceOf(Project::class, $sut->setFixedRate(13.47));
|
||||
$this->assertEquals(13.47, $sut->getFixedRate());
|
||||
$this->assertInstanceOf(Project::class, $sut->setHourlyRate(99));
|
||||
$this->assertEquals(99, $sut->getHourlyRate());
|
||||
$this->assertInstanceOf(Project::class, $sut->setTimeBudget(937321));
|
||||
$this->assertEquals(937321, $sut->getTimeBudget());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,11 +11,12 @@ namespace App\Tests\Entity;
|
||||
|
||||
use App\Entity\Tag;
|
||||
use App\Entity\Timesheet;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Entity\Tag
|
||||
*/
|
||||
class TagTest extends AbstractEntityTest
|
||||
class TagTest extends TestCase
|
||||
{
|
||||
public function testDefaultValues()
|
||||
{
|
||||
|
||||
@@ -16,11 +16,12 @@ use App\Entity\Tag;
|
||||
use App\Entity\Timesheet;
|
||||
use App\Entity\User;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Entity\Timesheet
|
||||
*/
|
||||
class TimesheetTest extends AbstractEntityTest
|
||||
class TimesheetTest extends TestCase
|
||||
{
|
||||
public function testDefaultValues()
|
||||
{
|
||||
@@ -66,196 +67,6 @@ class TimesheetTest extends AbstractEntityTest
|
||||
return $entity;
|
||||
}
|
||||
|
||||
public function testValidationNeedsActivity()
|
||||
{
|
||||
$entity = new Timesheet();
|
||||
$entity
|
||||
->setUser(new User())
|
||||
->setProject(new Project())
|
||||
->setBegin(new \DateTime())
|
||||
;
|
||||
|
||||
$this->assertHasViolationForField($entity, 'activity');
|
||||
}
|
||||
|
||||
public function testValidationNeedsProject()
|
||||
{
|
||||
$entity = new Timesheet();
|
||||
$entity
|
||||
->setUser(new User())
|
||||
->setActivity(new Activity())
|
||||
->setBegin(new \DateTime())
|
||||
;
|
||||
|
||||
$this->assertHasViolationForField($entity, 'project');
|
||||
}
|
||||
|
||||
public function testValidationProjectMismatch()
|
||||
{
|
||||
$customer = new Customer();
|
||||
$project = (new Project())->setName('foo')->setCustomer($customer);
|
||||
$project2 = (new Project())->setName('bar')->setCustomer($customer);
|
||||
$activity = (new Activity())->setName('hello-world')->setProject($project);
|
||||
|
||||
$entity = new Timesheet();
|
||||
$entity
|
||||
->setUser(new User())
|
||||
->setActivity($activity)
|
||||
->setProject($project2)
|
||||
->setBegin(new \DateTime())
|
||||
;
|
||||
|
||||
$this->assertHasViolationForField($entity, 'project');
|
||||
}
|
||||
|
||||
public function testValidationCustomerInvisible()
|
||||
{
|
||||
$customer = (new Customer())->setVisible(false);
|
||||
$project = (new Project())->setName('foo')->setCustomer($customer);
|
||||
$activity = (new Activity())->setName('hello-world')->setProject($project);
|
||||
|
||||
$entity = new Timesheet();
|
||||
$entity
|
||||
->setUser(new User())
|
||||
->setActivity($activity)
|
||||
->setProject($project)
|
||||
->setBegin(new \DateTime())
|
||||
;
|
||||
|
||||
$this->assertHasViolationForField($entity, 'customer');
|
||||
}
|
||||
|
||||
public function testValidationCustomerInvisibleDoesNotTriggerOnStoppedEntites()
|
||||
{
|
||||
$customer = (new Customer())->setVisible(false);
|
||||
$project = (new Project())->setName('foo')->setCustomer($customer);
|
||||
$activity = (new Activity())->setName('hello-world')->setProject($project);
|
||||
|
||||
$entity = new Timesheet();
|
||||
$entity
|
||||
->setUser(new User())
|
||||
->setActivity($activity)
|
||||
->setProject($project)
|
||||
->setBegin(new \DateTime())
|
||||
->setEnd(new \DateTime())
|
||||
;
|
||||
|
||||
$this->assertHasNoViolations($entity);
|
||||
}
|
||||
|
||||
public function testValidationProjectInvisible()
|
||||
{
|
||||
$customer = new Customer();
|
||||
$project = (new Project())->setName('foo')->setCustomer($customer)->setVisible(false);
|
||||
$activity = (new Activity())->setName('hello-world')->setProject($project);
|
||||
|
||||
$entity = new Timesheet();
|
||||
$entity
|
||||
->setUser(new User())
|
||||
->setActivity($activity)
|
||||
->setProject($project)
|
||||
->setBegin(new \DateTime())
|
||||
;
|
||||
|
||||
$this->assertHasViolationForField($entity, 'project');
|
||||
}
|
||||
|
||||
public function testValidationProjectInvisibleDoesNotTriggerOnStoppedEntites()
|
||||
{
|
||||
$customer = new Customer();
|
||||
$project = (new Project())->setName('foo')->setCustomer($customer)->setVisible(false);
|
||||
$activity = (new Activity())->setName('hello-world')->setProject($project);
|
||||
|
||||
$entity = new Timesheet();
|
||||
$entity
|
||||
->setUser(new User())
|
||||
->setActivity($activity)
|
||||
->setProject($project)
|
||||
->setBegin(new \DateTime())
|
||||
->setEnd(new \DateTime())
|
||||
;
|
||||
|
||||
$this->assertHasNoViolations($entity);
|
||||
}
|
||||
|
||||
public function testValidationActivityInvisible()
|
||||
{
|
||||
$customer = new Customer();
|
||||
$project = (new Project())->setName('foo')->setCustomer($customer);
|
||||
$activity = (new Activity())->setName('hello-world')->setProject($project)->setVisible(false);
|
||||
|
||||
$entity = new Timesheet();
|
||||
$entity
|
||||
->setUser(new User())
|
||||
->setActivity($activity)
|
||||
->setProject($project)
|
||||
->setBegin(new \DateTime())
|
||||
;
|
||||
|
||||
$this->assertHasViolationForField($entity, 'activity');
|
||||
}
|
||||
|
||||
public function testValidationActivityInvisibleDoesNotTriggerOnStoppedEntites()
|
||||
{
|
||||
$customer = new Customer();
|
||||
$project = (new Project())->setName('foo')->setCustomer($customer);
|
||||
$activity = (new Activity())->setName('hello-world')->setProject($project)->setVisible(false);
|
||||
|
||||
$entity = new Timesheet();
|
||||
$entity
|
||||
->setUser(new User())
|
||||
->setActivity($activity)
|
||||
->setProject($project)
|
||||
->setBegin(new \DateTime())
|
||||
->setEnd(new \DateTime())
|
||||
;
|
||||
|
||||
$this->assertHasNoViolations($entity);
|
||||
}
|
||||
|
||||
public function testValidationEndNotEarlierThanBegin()
|
||||
{
|
||||
$entity = $this->getEntity();
|
||||
$begin = new \DateTime();
|
||||
$end = clone $begin;
|
||||
$end = $end->modify('-1 second');
|
||||
$entity->setBegin($begin);
|
||||
$entity->setEnd($end);
|
||||
|
||||
$this->assertHasViolationForField($entity, 'end');
|
||||
|
||||
// allow same begin and end
|
||||
$entity = $this->getEntity();
|
||||
$begin = new \DateTime();
|
||||
$end = clone $begin;
|
||||
$entity->setBegin($begin);
|
||||
$entity->setEnd($end);
|
||||
|
||||
$this->assertHasViolationForField($entity, []);
|
||||
}
|
||||
|
||||
public function testDurationMustBeGreatorOrEqualThanZero()
|
||||
{
|
||||
$entity = $this->getEntity();
|
||||
$begin = new \DateTime();
|
||||
$end = clone $begin;
|
||||
$entity->setBegin($begin);
|
||||
$entity->setEnd($end);
|
||||
$entity->setDuration(-1);
|
||||
|
||||
$this->assertHasViolationForField($entity, 'duration');
|
||||
|
||||
// allow zero duration
|
||||
$entity = $this->getEntity();
|
||||
$begin = new \DateTime();
|
||||
$end = clone $begin;
|
||||
$entity->setBegin($begin);
|
||||
$entity->setEnd($end);
|
||||
$entity->setDuration(0);
|
||||
|
||||
$this->assertHasViolationForField($entity, []);
|
||||
}
|
||||
|
||||
public function testTags()
|
||||
{
|
||||
$sut = new Timesheet();
|
||||
|
||||
237
tests/Entity/TimesheetValidationTest.php
Normal file
237
tests/Entity/TimesheetValidationTest.php
Normal file
@@ -0,0 +1,237 @@
|
||||
<?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\Entity;
|
||||
|
||||
use App\Entity\Activity;
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\Project;
|
||||
use App\Entity\Timesheet;
|
||||
use App\Entity\User;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Entity\Timesheet
|
||||
* @group integration
|
||||
*/
|
||||
class TimesheetValidationTest extends KernelTestCase
|
||||
{
|
||||
use EntityValidationTestTrait;
|
||||
|
||||
protected function getEntity()
|
||||
{
|
||||
$customer = new Customer();
|
||||
$customer->setName('Test Customer');
|
||||
|
||||
$project = new Project();
|
||||
$project->setName('Test Project');
|
||||
$project->setCustomer($customer);
|
||||
|
||||
$activity = new Activity();
|
||||
$activity->setName('Test');
|
||||
$activity->setProject($project);
|
||||
|
||||
$entity = new Timesheet();
|
||||
$entity->setUser(new User());
|
||||
$entity->setActivity($activity);
|
||||
$entity->setProject($project);
|
||||
|
||||
return $entity;
|
||||
}
|
||||
|
||||
public function testValidationNeedsActivity()
|
||||
{
|
||||
$entity = new Timesheet();
|
||||
$entity
|
||||
->setUser(new User())
|
||||
->setProject(new Project())
|
||||
->setBegin(new \DateTime())
|
||||
;
|
||||
|
||||
$this->assertHasViolationForField($entity, 'activity');
|
||||
}
|
||||
|
||||
public function testValidationNeedsProject()
|
||||
{
|
||||
$entity = new Timesheet();
|
||||
$entity
|
||||
->setUser(new User())
|
||||
->setActivity(new Activity())
|
||||
->setBegin(new \DateTime())
|
||||
;
|
||||
|
||||
$this->assertHasViolationForField($entity, 'project');
|
||||
}
|
||||
|
||||
public function testValidationProjectMismatch()
|
||||
{
|
||||
$customer = new Customer();
|
||||
$project = (new Project())->setName('foo')->setCustomer($customer);
|
||||
$project2 = (new Project())->setName('bar')->setCustomer($customer);
|
||||
$activity = (new Activity())->setName('hello-world')->setProject($project);
|
||||
|
||||
$entity = new Timesheet();
|
||||
$entity
|
||||
->setUser(new User())
|
||||
->setActivity($activity)
|
||||
->setProject($project2)
|
||||
->setBegin(new \DateTime())
|
||||
;
|
||||
|
||||
$this->assertHasViolationForField($entity, 'project');
|
||||
}
|
||||
|
||||
public function testValidationCustomerInvisible()
|
||||
{
|
||||
$customer = (new Customer())->setVisible(false);
|
||||
$project = (new Project())->setName('foo')->setCustomer($customer);
|
||||
$activity = (new Activity())->setName('hello-world')->setProject($project);
|
||||
|
||||
$entity = new Timesheet();
|
||||
$entity
|
||||
->setUser(new User())
|
||||
->setActivity($activity)
|
||||
->setProject($project)
|
||||
->setBegin(new \DateTime())
|
||||
;
|
||||
|
||||
$this->assertHasViolationForField($entity, 'customer');
|
||||
}
|
||||
|
||||
public function testValidationCustomerInvisibleDoesNotTriggerOnStoppedEntites()
|
||||
{
|
||||
$customer = (new Customer())->setVisible(false);
|
||||
$project = (new Project())->setName('foo')->setCustomer($customer);
|
||||
$activity = (new Activity())->setName('hello-world')->setProject($project);
|
||||
|
||||
$entity = new Timesheet();
|
||||
$entity
|
||||
->setUser(new User())
|
||||
->setActivity($activity)
|
||||
->setProject($project)
|
||||
->setBegin(new \DateTime())
|
||||
->setEnd(new \DateTime())
|
||||
;
|
||||
|
||||
$this->assertHasNoViolations($entity);
|
||||
}
|
||||
|
||||
public function testValidationProjectInvisible()
|
||||
{
|
||||
$customer = new Customer();
|
||||
$project = (new Project())->setName('foo')->setCustomer($customer)->setVisible(false);
|
||||
$activity = (new Activity())->setName('hello-world')->setProject($project);
|
||||
|
||||
$entity = new Timesheet();
|
||||
$entity
|
||||
->setUser(new User())
|
||||
->setActivity($activity)
|
||||
->setProject($project)
|
||||
->setBegin(new \DateTime())
|
||||
;
|
||||
|
||||
$this->assertHasViolationForField($entity, 'project');
|
||||
}
|
||||
|
||||
public function testValidationProjectInvisibleDoesNotTriggerOnStoppedEntites()
|
||||
{
|
||||
$customer = new Customer();
|
||||
$project = (new Project())->setName('foo')->setCustomer($customer)->setVisible(false);
|
||||
$activity = (new Activity())->setName('hello-world')->setProject($project);
|
||||
|
||||
$entity = new Timesheet();
|
||||
$entity
|
||||
->setUser(new User())
|
||||
->setActivity($activity)
|
||||
->setProject($project)
|
||||
->setBegin(new \DateTime())
|
||||
->setEnd(new \DateTime())
|
||||
;
|
||||
|
||||
$this->assertHasNoViolations($entity);
|
||||
}
|
||||
|
||||
public function testValidationActivityInvisible()
|
||||
{
|
||||
$customer = new Customer();
|
||||
$project = (new Project())->setName('foo')->setCustomer($customer);
|
||||
$activity = (new Activity())->setName('hello-world')->setProject($project)->setVisible(false);
|
||||
|
||||
$entity = new Timesheet();
|
||||
$entity
|
||||
->setUser(new User())
|
||||
->setActivity($activity)
|
||||
->setProject($project)
|
||||
->setBegin(new \DateTime())
|
||||
;
|
||||
|
||||
$this->assertHasViolationForField($entity, 'activity');
|
||||
}
|
||||
|
||||
public function testValidationActivityInvisibleDoesNotTriggerOnStoppedEntites()
|
||||
{
|
||||
$customer = new Customer();
|
||||
$project = (new Project())->setName('foo')->setCustomer($customer);
|
||||
$activity = (new Activity())->setName('hello-world')->setProject($project)->setVisible(false);
|
||||
|
||||
$entity = new Timesheet();
|
||||
$entity
|
||||
->setUser(new User())
|
||||
->setActivity($activity)
|
||||
->setProject($project)
|
||||
->setBegin(new \DateTime())
|
||||
->setEnd(new \DateTime())
|
||||
;
|
||||
|
||||
$this->assertHasNoViolations($entity);
|
||||
}
|
||||
|
||||
public function testValidationEndNotEarlierThanBegin()
|
||||
{
|
||||
$entity = $this->getEntity();
|
||||
$begin = new \DateTime();
|
||||
$end = clone $begin;
|
||||
$end = $end->modify('-1 second');
|
||||
$entity->setBegin($begin);
|
||||
$entity->setEnd($end);
|
||||
|
||||
$this->assertHasViolationForField($entity, 'end');
|
||||
|
||||
// allow same begin and end
|
||||
$entity = $this->getEntity();
|
||||
$begin = new \DateTime();
|
||||
$end = clone $begin;
|
||||
$entity->setBegin($begin);
|
||||
$entity->setEnd($end);
|
||||
|
||||
$this->assertHasViolationForField($entity, []);
|
||||
}
|
||||
|
||||
public function testDurationMustBeGreatorOrEqualThanZero()
|
||||
{
|
||||
$entity = $this->getEntity();
|
||||
$begin = new \DateTime();
|
||||
$end = clone $begin;
|
||||
$entity->setBegin($begin);
|
||||
$entity->setEnd($end);
|
||||
$entity->setDuration(-1);
|
||||
|
||||
$this->assertHasViolationForField($entity, 'duration');
|
||||
|
||||
// allow zero duration
|
||||
$entity = $this->getEntity();
|
||||
$begin = new \DateTime();
|
||||
$end = clone $begin;
|
||||
$entity->setBegin($begin);
|
||||
$entity->setEnd($end);
|
||||
$entity->setDuration(0);
|
||||
|
||||
$this->assertHasViolationForField($entity, []);
|
||||
}
|
||||
}
|
||||
@@ -12,11 +12,12 @@ namespace App\Tests\Entity;
|
||||
use App\Entity\User;
|
||||
use App\Entity\UserPreference;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Entity\User
|
||||
*/
|
||||
class UserTest extends AbstractEntityTest
|
||||
class UserTest extends TestCase
|
||||
{
|
||||
public function testDefaultValues()
|
||||
{
|
||||
@@ -40,60 +41,6 @@ class UserTest extends AbstractEntityTest
|
||||
$this->assertEquals('Mr. Code Blaster', $user->getTitle());
|
||||
}
|
||||
|
||||
public function getInvalidTestData()
|
||||
{
|
||||
return [
|
||||
['', ''],
|
||||
[null, null],
|
||||
['xx', 'test@'], // too short username
|
||||
[str_pad('#', 61, '-'), 'test@x.'], // too long username
|
||||
[str_pad('#', 61, '-'), 'test@x.', ['xxxxx']], // too short password and invalid role
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getInvalidTestData
|
||||
*/
|
||||
public function testInvalidValues($username, $email, $roles = [])
|
||||
{
|
||||
$defaultFields = [
|
||||
'username', 'email'
|
||||
];
|
||||
|
||||
$user = new User();
|
||||
$user->setUsername($username);
|
||||
$user->setEmail($email);
|
||||
if (!empty($roles)) {
|
||||
$user->setRoles($roles);
|
||||
$defaultFields[] = 'roles';
|
||||
}
|
||||
|
||||
$this->assertHasViolationForField($user, $defaultFields);
|
||||
}
|
||||
|
||||
public function getValidTestData()
|
||||
{
|
||||
return [
|
||||
[str_pad('#', 3, '-'), 'test@x.x'], // shortest possible username
|
||||
[str_pad('#', 60, '-'), 'test@x.x', ['ROLE_TEAMLEAD']], // longest possible password and valid role
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getValidTestData
|
||||
*/
|
||||
public function testValidValues($username, $email, $roles = [])
|
||||
{
|
||||
$user = new User();
|
||||
$user->setUsername($username);
|
||||
$user->setEmail($email);
|
||||
if (!empty($roles)) {
|
||||
$user->setRoles($roles);
|
||||
}
|
||||
|
||||
$this->assertHasNoViolations($user);
|
||||
}
|
||||
|
||||
public function testDatetime()
|
||||
{
|
||||
$date = new \DateTime('+1 day');
|
||||
|
||||
76
tests/Entity/UserValidationTest.php
Normal file
76
tests/Entity/UserValidationTest.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?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\Entity;
|
||||
|
||||
use App\Entity\User;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Entity\User
|
||||
* @group integration
|
||||
*/
|
||||
class UserValidationTest extends KernelTestCase
|
||||
{
|
||||
use EntityValidationTestTrait;
|
||||
|
||||
public function getInvalidTestData()
|
||||
{
|
||||
return [
|
||||
['', ''],
|
||||
[null, null],
|
||||
['xx', 'test@'], // too short username
|
||||
[str_pad('#', 61, '-'), 'test@x.'], // too long username
|
||||
[str_pad('#', 61, '-'), 'test@x.', ['xxxxx']], // too short password and invalid role
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getInvalidTestData
|
||||
*/
|
||||
public function testInvalidValues($username, $email, $roles = [])
|
||||
{
|
||||
$defaultFields = [
|
||||
'username', 'email'
|
||||
];
|
||||
|
||||
$user = new User();
|
||||
$user->setUsername($username);
|
||||
$user->setEmail($email);
|
||||
if (!empty($roles)) {
|
||||
$user->setRoles($roles);
|
||||
$defaultFields[] = 'roles';
|
||||
}
|
||||
|
||||
$this->assertHasViolationForField($user, $defaultFields);
|
||||
}
|
||||
|
||||
public function getValidTestData()
|
||||
{
|
||||
return [
|
||||
[str_pad('#', 3, '-'), 'test@x.x'], // shortest possible username
|
||||
[str_pad('#', 60, '-'), 'test@x.x', ['ROLE_TEAMLEAD']], // longest possible password and valid role
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getValidTestData
|
||||
*/
|
||||
public function testValidValues($username, $email, $roles = [])
|
||||
{
|
||||
$user = new User();
|
||||
$user->setUsername($username);
|
||||
$user->setEmail($email);
|
||||
if (!empty($roles)) {
|
||||
$user->setRoles($roles);
|
||||
}
|
||||
|
||||
$this->assertHasNoViolations($user);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
<?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\Form\DataTransformer;
|
||||
|
||||
use App\Form\DataTransformer\DurationStringToSecondsTransformer;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Form\DataTransformer\DurationStringToSecondsTransformer
|
||||
*/
|
||||
class DurationStringToSecondsTransformerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var DurationStringToSecondsTransformer
|
||||
*/
|
||||
private $sut;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->sut = new DurationStringToSecondsTransformer();
|
||||
}
|
||||
|
||||
public function getValidTestDataTransform()
|
||||
{
|
||||
return [
|
||||
['00:00', '0'],
|
||||
['00:00', 0],
|
||||
['02:00', 7213], // by default no seconds are returned
|
||||
[null, null],
|
||||
];
|
||||
}
|
||||
|
||||
public function getInvalidTestDataTransform()
|
||||
{
|
||||
return [
|
||||
[''],
|
||||
['xxx'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getValidTestDataTransform
|
||||
*/
|
||||
public function testTransform($expected, $transform)
|
||||
{
|
||||
$this->assertEquals($expected, $this->sut->transform($transform));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getInvalidTestDataTransform
|
||||
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
|
||||
*/
|
||||
public function testInvalidTransformThrowsException($transform)
|
||||
{
|
||||
$this->sut->transform($transform);
|
||||
}
|
||||
|
||||
public function getValidTestDataReverseTransform()
|
||||
{
|
||||
return [
|
||||
['2h3s', 7203],
|
||||
['00:00', 0],
|
||||
['0', null],
|
||||
[null, null],
|
||||
];
|
||||
}
|
||||
|
||||
public function getInvalidTestDataReverseTransform()
|
||||
{
|
||||
return [
|
||||
['xxx'],
|
||||
[':::'],
|
||||
['0::0'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getValidTestDataReverseTransform
|
||||
*/
|
||||
public function testReverseTransform($transform, $expected)
|
||||
{
|
||||
$this->assertEquals($expected, $this->sut->reverseTransform($transform));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getInvalidTestDataReverseTransform
|
||||
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
|
||||
*/
|
||||
public function testInvalidReverseTransformThrowsException($transform)
|
||||
{
|
||||
$this->sut->reverseTransform($transform);
|
||||
}
|
||||
}
|
||||
@@ -11,15 +11,19 @@ namespace App\Tests\Invoice\Renderer;
|
||||
|
||||
use App\Invoice\Renderer\CsvRenderer;
|
||||
use App\Model\InvoiceModel;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
|
||||
/**
|
||||
* @covers \App\Invoice\Renderer\CsvRenderer
|
||||
* @covers \App\Invoice\Renderer\AbstractRenderer
|
||||
* @covers \App\Invoice\Renderer\AbstractSpreadsheetRenderer
|
||||
* @group integration
|
||||
*/
|
||||
class CsvRendererTest extends AbstractRendererTest
|
||||
class CsvRendererTest extends TestCase
|
||||
{
|
||||
use RendererTestTrait;
|
||||
|
||||
public function testSupports()
|
||||
{
|
||||
$sut = $this->getAbstractRenderer(CsvRenderer::class);
|
||||
|
||||
@@ -11,10 +11,13 @@ namespace App\Tests\Invoice\Renderer;
|
||||
|
||||
use App\Entity\InvoiceDocument;
|
||||
use App\Model\InvoiceModel;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class DebugRendererTest extends AbstractRendererTest
|
||||
class DebugRendererTest extends TestCase
|
||||
{
|
||||
use RendererTestTrait;
|
||||
|
||||
public function getTestModel()
|
||||
{
|
||||
yield [$this->getInvoiceModel(), '1,947.99', 5, 5, 1, 2, 2, true];
|
||||
|
||||
@@ -10,14 +10,18 @@
|
||||
namespace App\Tests\Invoice\Renderer;
|
||||
|
||||
use App\Invoice\Renderer\DocxRenderer;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
|
||||
/**
|
||||
* @covers \App\Invoice\Renderer\DocxRenderer
|
||||
* @covers \App\Invoice\Renderer\AbstractRenderer
|
||||
* @group integration
|
||||
*/
|
||||
class DocxRendererTest extends AbstractRendererTest
|
||||
class DocxRendererTest extends TestCase
|
||||
{
|
||||
use RendererTestTrait;
|
||||
|
||||
public function testSupports()
|
||||
{
|
||||
$sut = $this->getAbstractRenderer(DocxRenderer::class);
|
||||
|
||||
@@ -11,15 +11,19 @@ namespace App\Tests\Invoice\Renderer;
|
||||
|
||||
use App\Invoice\Renderer\OdsRenderer;
|
||||
use App\Model\InvoiceModel;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
|
||||
/**
|
||||
* @covers \App\Invoice\Renderer\OdsRenderer
|
||||
* @covers \App\Invoice\Renderer\AbstractRenderer
|
||||
* @covers \App\Invoice\Renderer\AbstractSpreadsheetRenderer
|
||||
* @group integration
|
||||
*/
|
||||
class OdsRendererTest extends AbstractRendererTest
|
||||
class OdsRendererTest extends TestCase
|
||||
{
|
||||
use RendererTestTrait;
|
||||
|
||||
public function testSupports()
|
||||
{
|
||||
$sut = $this->getAbstractRenderer(OdsRenderer::class);
|
||||
|
||||
@@ -25,12 +25,11 @@ use App\Repository\Query\InvoiceQuery;
|
||||
use App\Twig\DateExtensions;
|
||||
use App\Twig\Extensions;
|
||||
use App\Utils\LocaleSettings;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
abstract class AbstractRendererTest extends KernelTestCase
|
||||
trait RendererTestTrait
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
@@ -10,15 +10,19 @@
|
||||
namespace App\Tests\Invoice\Renderer;
|
||||
|
||||
use App\Invoice\Renderer\TwigRenderer;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Twig\Environment;
|
||||
use Twig\Loader\FilesystemLoader;
|
||||
|
||||
/**
|
||||
* @covers \App\Invoice\Renderer\TwigRenderer
|
||||
* @group integration
|
||||
*/
|
||||
class TwigRendererTest extends AbstractRendererTest
|
||||
class TwigRendererTest extends KernelTestCase
|
||||
{
|
||||
use RendererTestTrait;
|
||||
|
||||
public function testSupports()
|
||||
{
|
||||
$loader = new FilesystemLoader();
|
||||
|
||||
@@ -11,15 +11,19 @@ namespace App\Tests\Invoice\Renderer;
|
||||
|
||||
use App\Invoice\Renderer\XlsxRenderer;
|
||||
use App\Model\InvoiceModel;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
|
||||
/**
|
||||
* @covers \App\Invoice\Renderer\XlsxRenderer
|
||||
* @covers \App\Invoice\Renderer\AbstractRenderer
|
||||
* @covers \App\Invoice\Renderer\AbstractSpreadsheetRenderer
|
||||
* @group integration
|
||||
*/
|
||||
class XlsxRendererTest extends AbstractRendererTest
|
||||
class XlsxRendererTest extends TestCase
|
||||
{
|
||||
use RendererTestTrait;
|
||||
|
||||
public function testSupports()
|
||||
{
|
||||
$sut = $this->getAbstractRenderer(XlsxRenderer::class);
|
||||
|
||||
@@ -20,7 +20,6 @@ class ActivityStatisticTest extends TestCase
|
||||
public function testDefaultValues()
|
||||
{
|
||||
$sut = new ActivityStatistic();
|
||||
$this->assertEquals(0, $sut->getCount());
|
||||
$this->assertEquals(0, $sut->getRecordAmount());
|
||||
$this->assertEquals(0, $sut->getRecordDuration());
|
||||
}
|
||||
@@ -28,11 +27,9 @@ class ActivityStatisticTest extends TestCase
|
||||
public function testSetter()
|
||||
{
|
||||
$sut = new ActivityStatistic();
|
||||
$sut->setCount(123);
|
||||
$sut->setRecordAmount(7654.298);
|
||||
$sut->setRecordDuration(826.10);
|
||||
|
||||
$this->assertEquals(123, $sut->getCount());
|
||||
$this->assertEquals(7654, $sut->getRecordAmount());
|
||||
$this->assertEquals(826, $sut->getRecordDuration());
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ class CustomerStatisticTest extends TestCase
|
||||
$sut = new CustomerStatistic();
|
||||
$this->assertEquals(0, $sut->getActivityAmount());
|
||||
$this->assertEquals(0, $sut->getProjectAmount());
|
||||
$this->assertEquals(0, $sut->getCount());
|
||||
$this->assertEquals(0, $sut->getRecordAmount());
|
||||
$this->assertEquals(0, $sut->getRecordDuration());
|
||||
}
|
||||
@@ -30,7 +29,6 @@ class CustomerStatisticTest extends TestCase
|
||||
public function testSetter()
|
||||
{
|
||||
$sut = new CustomerStatistic();
|
||||
$sut->setCount(123);
|
||||
$sut->setRecordAmount(7654.298);
|
||||
$sut->setRecordDuration(826.10);
|
||||
$sut->setActivityAmount(13);
|
||||
@@ -38,7 +36,6 @@ class CustomerStatisticTest extends TestCase
|
||||
|
||||
$this->assertEquals(13, $sut->getActivityAmount());
|
||||
$this->assertEquals(2, $sut->getProjectAmount());
|
||||
$this->assertEquals(123, $sut->getCount());
|
||||
$this->assertEquals(7654, $sut->getRecordAmount());
|
||||
$this->assertEquals(826, $sut->getRecordDuration());
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ class ProjectStatisticTest extends TestCase
|
||||
{
|
||||
$sut = new ProjectStatistic();
|
||||
$this->assertEquals(0, $sut->getActivityAmount());
|
||||
$this->assertEquals(0, $sut->getCount());
|
||||
$this->assertEquals(0, $sut->getRecordAmount());
|
||||
$this->assertEquals(0, $sut->getRecordDuration());
|
||||
}
|
||||
@@ -29,13 +28,11 @@ class ProjectStatisticTest extends TestCase
|
||||
public function testSetter()
|
||||
{
|
||||
$sut = new ProjectStatistic();
|
||||
$sut->setCount(123);
|
||||
$sut->setRecordAmount(7654.298);
|
||||
$sut->setRecordDuration(826.10);
|
||||
$sut->setActivityAmount(13);
|
||||
|
||||
$this->assertEquals(13, $sut->getActivityAmount());
|
||||
$this->assertEquals(123, $sut->getCount());
|
||||
$this->assertEquals(7654, $sut->getRecordAmount());
|
||||
$this->assertEquals(826, $sut->getRecordDuration());
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ use App\Tests\DataFixtures\TagFixtures;
|
||||
|
||||
/**
|
||||
* @covers \App\Repository\TagRepository
|
||||
* @group integration
|
||||
*/
|
||||
class TagRepositoryTest extends AbstractRepositoryTest
|
||||
{
|
||||
|
||||
@@ -26,6 +26,7 @@ use Pagerfanta\Pagerfanta;
|
||||
|
||||
/**
|
||||
* @covers \App\Repository\TimesheetRepository
|
||||
* @group integration
|
||||
*/
|
||||
class TimesheetRepositoryTest extends AbstractRepositoryTest
|
||||
{
|
||||
|
||||
@@ -54,6 +54,7 @@ class DurationTest extends TestCase
|
||||
|
||||
[0, '', Duration::FORMAT_NATURAL],
|
||||
[0, 0, Duration::FORMAT_NATURAL],
|
||||
[99, '99s', Duration::FORMAT_NATURAL],
|
||||
[7200, '2h', Duration::FORMAT_NATURAL],
|
||||
[2280, '38m', Duration::FORMAT_NATURAL],
|
||||
[9480, '2h38m', Duration::FORMAT_NATURAL],
|
||||
@@ -65,6 +66,8 @@ class DurationTest extends TestCase
|
||||
[48420, '13:27', Duration::FORMAT_COLON],
|
||||
[48474, '13:27:54', Duration::FORMAT_COLON],
|
||||
[48474, '12:87:54', Duration::FORMAT_COLON],
|
||||
[11257200, '3127:00:00', Duration::FORMAT_COLON],
|
||||
[11257200, '3127:00', Duration::FORMAT_COLON],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -80,6 +83,14 @@ class DurationTest extends TestCase
|
||||
// invalid modes
|
||||
[17, 'foo'],
|
||||
[12, ''],
|
||||
|
||||
['3127::00', Duration::FORMAT_COLON],
|
||||
['00::', Duration::FORMAT_COLON],
|
||||
['3127:00:', Duration::FORMAT_COLON],
|
||||
[':3127:00', Duration::FORMAT_COLON],
|
||||
['::3127', Duration::FORMAT_COLON],
|
||||
['3127:-01', Duration::FORMAT_COLON],
|
||||
['-3127:01:17', Duration::FORMAT_COLON],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Utils\MPdfConverter
|
||||
* @group integration
|
||||
*/
|
||||
class MPdfConverterTest extends KernelTestCase
|
||||
{
|
||||
|
||||
@@ -10,12 +10,12 @@
|
||||
namespace App\Tests\Utils;
|
||||
|
||||
use App\Utils\MomentFormatConverter;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Utils\MomentFormatConverter
|
||||
*/
|
||||
class MomentFormatConverterTest extends KernelTestCase
|
||||
class MomentFormatConverterTest extends TestCase
|
||||
{
|
||||
public function test()
|
||||
{
|
||||
|
||||
102
tests/Validator/Constraints/DurationValidatorTest.php
Normal file
102
tests/Validator/Constraints/DurationValidatorTest.php
Normal file
@@ -0,0 +1,102 @@
|
||||
<?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\Validator\Constraints;
|
||||
|
||||
use App\Validator\Constraints\Duration;
|
||||
use App\Validator\Constraints\DurationValidator;
|
||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||
use Symfony\Component\Validator\Constraints\Regex;
|
||||
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Validator\Constraints\DurationValidator
|
||||
*/
|
||||
class DurationValidatorTest extends ConstraintValidatorTestCase
|
||||
{
|
||||
protected function createValidator()
|
||||
{
|
||||
return new DurationValidator();
|
||||
}
|
||||
|
||||
public function getValidData()
|
||||
{
|
||||
return [
|
||||
['99s'],
|
||||
['2h'],
|
||||
['38m'],
|
||||
['2h38m'],
|
||||
['2h38m17s'],
|
||||
['1h96m137s'],
|
||||
[''],
|
||||
['0'],
|
||||
[null],
|
||||
[0],
|
||||
[11257200],
|
||||
['13:27'],
|
||||
['13:27:54'],
|
||||
['12:87:54'],
|
||||
['3127:00:00'],
|
||||
['3127:00'],
|
||||
[48474],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException
|
||||
*/
|
||||
public function testConstraintIsInvalid()
|
||||
{
|
||||
$this->validator->validate('foo', new NotBlank());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getValidData
|
||||
* @param string $input
|
||||
*/
|
||||
public function testConstraintWithValidData($input)
|
||||
{
|
||||
$constraint = new Duration();
|
||||
$this->validator->validate($input, $constraint);
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function getInvalidData()
|
||||
{
|
||||
return [
|
||||
['13-13'],
|
||||
['13.13'],
|
||||
['3127::00'],
|
||||
['3127:00:'],
|
||||
[':3127:00'],
|
||||
['::3127'],
|
||||
['foo'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getInvalidData
|
||||
* @param mixed $input
|
||||
*/
|
||||
public function testValidationError($input)
|
||||
{
|
||||
$constraint = new Duration([
|
||||
'message' => 'myMessage',
|
||||
]);
|
||||
|
||||
$this->validator->validate($input, $constraint);
|
||||
|
||||
$expectedFormat = is_string($input) ? '"' . $input . '"' : $input;
|
||||
|
||||
$this->buildViolation('myMessage')
|
||||
->setParameter('{{ value }}', $expectedFormat)
|
||||
->setCode(Regex::REGEX_FAILED_ERROR)
|
||||
->assertRaised();
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user