File: D:/HostingSpaces/MdnDirecteur/hours.komma.cloud/tests/Unit/HourTests.php
<?php
namespace Tests;
use App\User;
use App\Komma\Hours\Hour;
use App\Komma\Projects\Project;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\Session;
class UserTests extends TestCase
{
use DatabaseTransactions;
/*
* Intentionally tests the "frontend" way of creating an hour
* since that is where all the magic happens
*/
public function testBookHour(){
Session::start();
$user = User::first();
$this->be($user);
$project = Project::find(70);
$subproject = $project->Subprojects->first();
$task = $subproject->Tasks->first();
$description = 'Unit Test Uur';
$date = "13-11-2018";
$response = $this->followingRedirects()->post('/hours', [
'_token' => csrf_token(),
'project' => $project->id,
'subproject' => $subproject->id,
'task' => $task->id,
'hours' => 1.5,
'description' => $description,
'billable' => 1,
'date' => $date,
]);
$response->assertStatus(200);
$this->assertDatabaseHas('hours', [
'description' => $description,
'value' => 1.5,
]);
$hour = Hour::where([['task_id', $task->id], ['value', 1.5], ['description', $description]])->first();
$response = $this->get('/getHourFormData?project='.$project->id.'&subproject='.$subproject->id.'&hour='.$hour->id.'&user='.$user->id.'&date='.$date);
$response->assertStatus(200);
}
public function testEditHour(){
$hour = Hour::first();
Session::start();
$user = User::first();
$this->be($user);
$task = $hour->Task;
$subproject = $task->Subproject;
$project = $subproject->Project;
$newValue = "0.25";
$newTask = $subproject->Tasks()->latest()->first();
$newBillable = 0;
$newDate = "15-11-2018";
$response = $this->get('/getHourFormData?project='.$project->id.'&subproject='.$subproject->id.'&hour='.$hour->id.'&user='.$user->id.'&date='.$hour->date);
$response->assertStatus(200);
$response = $this->followingRedirects()->put('/hours/'.$hour->id, [
'_token' => csrf_token(),
'project' => $project->id,
'subproject' => $subproject->id,
'task' => $newTask->id,
'hours' => $newValue,
'description' => $hour->description,
'billable' => $newBillable,
'date' => $newDate,
]);
$response->assertStatus(200);
$editedHour = Hour::first();
$this->assertEquals($newValue, $editedHour->value);
$this->assertEquals($newTask->id, $editedHour->Task->id);
$this->assertEquals($newBillable, $editedHour->billable);
$response = $this->get('/getHourFormData?project='.$project->id.'&subproject='.$subproject->id.'&hour='.$editedHour->id.'&user='.$user->id.'&date='.$editedHour->date);
$response->assertStatus(200);
// project: 70
//subproject: 266
//hour: 16490
//user: 18
//date: 12-11-2018
}
}