Refactor task management and add attachment functionality
- Updated task editing template to handle default status for new tasks and corrected variable names. - Enhanced work time reporting by rounding time to the nearest quarter hour and adjusting amount formatting. - Introduced TasksController to manage task-related operations, including status resolution and email notifications. - Added TaskAttachmentRepository for handling task attachments, including upload, rename, and delete functionalities. - Implemented WorkTimeRepository to fetch clients with unsettled tasks and calculate total work time. - Created unit tests for TasksController and TaskAttachmentRepository to ensure functionality and correctness.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/../../autoload/Controllers/class.TasksController.php';
|
||||
require_once __DIR__ . '/../../autoload/Controllers/TasksController.php';
|
||||
|
||||
use Controllers\TasksController;
|
||||
|
||||
@@ -21,4 +21,19 @@ function run_tasks_controller_tests()
|
||||
|
||||
assert_same( $clients, $view_model['work_time_clients'], 'Expected work_time_clients to be passed through.' );
|
||||
assert_same( $settings, $view_model['settings'], 'Expected settings to be passed through.' );
|
||||
|
||||
assert_same( 5, TasksController::resolveTaskStatusForForm( [ 'id' => null, 'status' => null ] ), 'Expected default form status for new task to be 5 (do zrobienia).' );
|
||||
assert_same( 1, TasksController::resolveTaskStatusForForm( [ 'id' => 10, 'status' => 1 ] ), 'Expected existing task form status to be preserved.' );
|
||||
|
||||
assert_same( 5, TasksController::resolveTaskStatusForSave( [ 'id' => null ] ), 'Expected default save status for new task to be 5 (do zrobienia).' );
|
||||
assert_same( 3, TasksController::resolveTaskStatusForSave( [ 'id' => 22, 'status' => 3 ] ), 'Expected existing task save status to be preserved.' );
|
||||
|
||||
assert_same( true, TasksController::shouldStopTimerOnStatus( 1 ), 'Expected timer stop on status do sprawdzenia.' );
|
||||
assert_same( true, TasksController::shouldStopTimerOnStatus( 2 ), 'Expected timer stop on status zamkniete.' );
|
||||
assert_same( true, TasksController::shouldStopTimerOnStatus( 3 ), 'Expected timer stop on status do rozliczenia.' );
|
||||
assert_same( false, TasksController::shouldStopTimerOnStatus( 0 ), 'Expected no timer stop on status nowe.' );
|
||||
|
||||
assert_same( true, TasksController::shouldSendStatusChangeEmail( 1 ), 'Expected status email for do sprawdzenia.' );
|
||||
assert_same( true, TasksController::shouldSendStatusChangeEmail( 3 ), 'Expected status email for do rozliczenia.' );
|
||||
assert_same( false, TasksController::shouldSendStatusChangeEmail( 2 ), 'Expected no status email for zamkniete.' );
|
||||
}
|
||||
|
||||
28
tests/Domain/Tasks/TaskAttachmentRepositoryTest.php
Normal file
28
tests/Domain/Tasks/TaskAttachmentRepositoryTest.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/../../../autoload/Domain/Tasks/TaskAttachmentRepository.php';
|
||||
|
||||
use Domain\Tasks\TaskAttachmentRepository;
|
||||
|
||||
function run_task_attachment_repository_tests()
|
||||
{
|
||||
assert_true(
|
||||
TaskAttachmentRepository::effectiveTitle( ' Raport ', 'plik.pdf' ) === 'Raport',
|
||||
'Expected effective title to prefer trimmed custom title.'
|
||||
);
|
||||
|
||||
assert_true(
|
||||
TaskAttachmentRepository::effectiveTitle( '', 'plik.pdf' ) === 'plik.pdf',
|
||||
'Expected effective title to fallback to original file name.'
|
||||
);
|
||||
|
||||
$sanitized = TaskAttachmentRepository::sanitizeFileName( 'Załącznik #1 (final).pdf' );
|
||||
assert_true(
|
||||
strpos( $sanitized, '#' ) === false
|
||||
&& strpos( $sanitized, '(' ) === false
|
||||
&& strpos( $sanitized, ')' ) === false
|
||||
&& strpos( $sanitized, ' ' ) === false
|
||||
&& substr( $sanitized, -4 ) === '.pdf',
|
||||
'Expected sanitized file name to remove unsupported characters and keep extension.'
|
||||
);
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/../../../autoload/Domain/Tasks/class.WorkTimeRepository.php';
|
||||
require_once __DIR__ . '/../../../autoload/Domain/Tasks/WorkTimeRepository.php';
|
||||
|
||||
use Domain\Tasks\WorkTimeRepository;
|
||||
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/Domain/Tasks/WorkTimeRepositoryTest.php';
|
||||
require_once __DIR__ . '/Domain/Tasks/TaskAttachmentRepositoryTest.php';
|
||||
require_once __DIR__ . '/Controllers/TasksControllerTest.php';
|
||||
|
||||
$tests = [
|
||||
'run_work_time_repository_tests',
|
||||
'run_task_attachment_repository_tests',
|
||||
'run_tasks_controller_tests'
|
||||
];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user