File: D:/HostingSpaces/MdnDirecteur/hours.komma.cloud/tests/Unit/ProjectTests.php
<?php
namespace Tests;
use App\User;
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 testCreateProject(){
Session::start();
$user = User::first();
$this->be($user);
$kommaClientId = 53; // Komma
$kommaProjectTemplateId = 5; // Onderhoud
$name = 'Unit Test Project';
$hourlyRate = 70.5;
$internal = 1;
$projectManager = 15; //Stef Bogers
$response = $this->followingRedirects()->post('/projecten', [
'_token' => csrf_token(),
'company' => $kommaClientId,
'project' => $kommaProjectTemplateId,
'name' => $name,
'hourlyRate' => $hourlyRate,
'internal' => $internal,
'projectManager' => $projectManager,
'excluded_users' => [],
'subprojects' => [
[
'name' => 'Projectmanagement',
'budget' => 0,
'hourlyRate' => 85,
'billable' => 1,
]],
]);
$response->assertStatus(200);
$this->assertDatabaseHas('projects', [
'name' => $name,
'company_id' => $kommaClientId,
]);
$project = Project::where([['name',$name], ['company_id',$kommaClientId]])->first();
$this->assertEquals($project->hourly_rate, $hourlyRate);
$response = $this->get('/projecten/'.$project->id);
$response->assertStatus(200);
}
/*
* Intentionally tests the "frontend" way of creating an hour
* since that is where all the magic happens
*/
public function testEditProject()
{
Session::start();
$user = User::first();
$this->be($user);
$editProject = Project::first();
$name = 'Unit Test Project edit';
$hourlyRate = 75.2;
$internal = 0;
$projectManager = 15; //Stef Bogers
$response = $this->followingRedirects()->put('/projecten/'.$editProject->id, [
'_token' => csrf_token(),
'name' => $name,
'hourlyRate' => $hourlyRate,
'internal' => $internal,
'projectManager' => $projectManager,
'projectWorker' => $editProject->ProjectWorkers->first()->id,
]);
$response->assertStatus(200);
$editedProject = Project::first();
$this->assertEquals($editedProject->name, $name);
$this->assertEquals($editedProject->internal, $internal);
$this->assertEquals($editedProject->hourly_rate, $hourlyRate);
$response = $this->get('/projecten/'.$editedProject->id);
$response->assertStatus(200);
}
}