HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/MdnDirecteur/hours.komma.cloud/tests/Unit/SubProjectTests.php
<?php

namespace Tests;

use App\User;
use App\Komma\Subprojects\Subproject;
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 testCreateSubProject(){
        Session::start();
        $user = User::first();
        $this->be($user);

        $kommaProjectId = 70; // Komma - Algemeen
        $kommaSubProjectTemplateId = 1; // ProjectManagement
        $name = 'Unit Test SubProject';
        $hourlyRate = 70.5;
        $budget = 5;
        $billable = 1;

        $response = $this->post('/subprojecten', [
            '_token' => csrf_token(),
            'project' => $kommaProjectId,
            'subproject' => $kommaSubProjectTemplateId,
            'name' => $name,
            'hourly_rate' => $hourlyRate,
            'budget' => $budget,
            'billable' => $billable,
        ], array('HTTP_X-Requested-With' => 'XMLHttpRequest'));

        $response->assertStatus(200);

        $this->assertDatabaseHas('subprojects', [
            'name' => $name,
            'project_id' => $kommaProjectId,
        ]);

        $subproject = Subproject::where([['name',$name], ['project_id',$kommaProjectId]])->first();

        $this->assertEquals($subproject->hourly_rate, $hourlyRate);

        $response = $this->get('/subprojecten/'.$subproject->id);
        $response->assertStatus(200);
    }

    /*
     * Intentionally tests the "frontend" way of creating an hour
     * since that is where all the magic happens
     */
    public function testEditSubProject()
    {
        Session::start();
        $user = User::first();
        $this->be($user);

        $editSubProject = Subproject::first();

        $name = 'Unit Test SubProject edit';
        $hourlyRate = 75.2;
        $budget = 10;
        $billable = 0;

        $response = $this->followingRedirects()->put('/subprojecten/'.$editSubProject->id, [
            '_token' => csrf_token(),
            'name' => $name,
            'budget' => $budget,
            'billable' => $billable,
            'hourly_rate' => $hourlyRate,
        ]);

        $response->assertStatus(200);

        $editedSubProject = Subproject::first();

        $this->assertEquals($editedSubProject->name, $name);
        $this->assertEquals($editedSubProject->budget, $budget);
        $this->assertEquals($editedSubProject->billable, $billable);
        $this->assertEquals($editedSubProject->hourly_rate, $hourlyRate);


        $response = $this->get('/subprojecten/'.$editedSubProject->id);
        $response->assertStatus(200);

    }



}