File: D:/HostingSpaces/MdnDirecteur/hours.komma.cloud/tests/Unit/ClientTests.php
<?php
namespace Tests;
use App\User;
use App\Komma\Companies\Company;
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 testCreateClient(){
Session::start();
$user = User::first();
$this->be($user);
$name = 'Unit Test Project';
$email = 'test@kommaklant.com';
$country = 1; //Nederland
$contactPerson = 'Unit Test Contact Person';
$response = $this->followingRedirects()->post('/klanten', [
'_token' => csrf_token(),
'name' => $name,
'email' => $email,
'country' => $country,
'person' => $contactPerson,
]);
$response->assertStatus(200);
$this->assertDatabaseHas('companies', [
'name' => $name,
'country_id' => $country,
]);
$client = Company::where([['name',$name], ['country_id',$country]])->first();
$this->assertEquals($client->name, $name);
$response = $this->get('/klanten/'.$client->id);
$response->assertStatus(200);
}
/*
* Intentionally tests the "frontend" way of creating an hour
* since that is where all the magic happens
*/
public function testEditClient()
{
$editClient = Company::first();
$editClientContact = $editClient->Contacts->first();
Session::start();
$user = User::first();
$this->be($user);
$response = $this->followingRedirects()->put('/klanten/'.$editClient->id, [
'_token' => csrf_token(),
'country' => $editClient->country_id+1,
'name' => $editClient->name,
'email' => $editClientContact->email,
]);
$response->assertStatus(200);
$this->assertDatabaseHas('companies', [
'name' => $editClient->name,
'country_id' => $editClient->country_id+1,
]);
$response = $this->get('/klanten/'.$editClient->id);
$response->assertStatus(200);
}
/*
* Intentionally tests the "frontend" way of creating an hour
* since that is where all the magic happens
*/
public function testSearchClient()
{
Session::start();
$user = User::first();
$this->be($user);
$searchClient = Company::first();
$searchEmail = $searchClient->Contacts->first()->email;
$response = $this->followingRedirects()->get('/klanten?action=0&search='.$searchClient->name);
$this->assertContains($searchEmail, $response->getContent());
}
}