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/SBogers10/werken-bij-stafa.komma.pro/tests/Unit/ActionLoggerTest.php
<?php

namespace Tests\Unit;

use App\Komma\Kms\ActionLog\ActionLog;
use App\Komma\Kms\ActionLog\ActionLogService;
use App\Komma\Users\Models\KmsUser;
use App\Komma\Users\Models\SiteUser;
use App\Komma\Users\SiteUserPolicy;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\TestCase;

class ActionLoggerTest extends TestCase
{
    use DatabaseTransactions; //Automatically rolls back database actions after tests

    /**
     * @group ActionLogService
     * @test
     */
    public function instanceCreationTest()
    {
        $actionLogger = new ActionLogService();
        $this->assertInstanceOf(ActionLogService::class, $actionLogger);
    }

    /**
     * @group ActionLogService
     * @test
     * @throws \Exception
     */
    public function logTestSpecificKmsUser()
    {
        $user = KmsUser::first();

        $action = ActionLogService::Log('Phpunit testing', null, $user);

        $this->assertTrue($action->exists());
        $this->assertInstanceOf(ActionLog::class, $action);
        $this->assertEquals('Phpunit testing', $action->action);

        $this->assertEquals(true, $action->hasAuthenticatable());
        $this->assertEquals($user->id, $action->authenticatable()->first()->id);
    }

    /**
     * @group ActionLogService
     * @test
     * @throws \Exception
     */
    public function logTestSpecificSiteUser()
    {
        $user = factory(SiteUser::class)->create();


        $action = ActionLogService::Log('Phpunit testing', null, $user);
        $this->assertTrue($action->exists());
        $this->assertInstanceOf(ActionLog::class, $action);
        $this->assertEquals('Phpunit testing', $action->action);
        $this->assertEquals($user->id, $action->authenticatable()->first()->id);
    }

    /**
     * @group ActionLogService
     * @test
     * @throws \Exception
     */
    public function logTestAnonymous()
    {
        $action = ActionLogService::Log('Phpunit testing');

        $this->assertTrue($action->exists());
        $this->assertInstanceOf(ActionLog::class, $action);
        $this->assertEquals('Phpunit testing', $action->action);
        $this->assertFalse($action->hasAuthenticatable());
    }

    /**
     * @group ActionLogService
     * @test
     * @throws \Exception
     */
    public function logTestPayload()
    {
        $payload = ['metadata' => ['info' => 'just testing']];
        $action = ActionLogService::Log('Phpunit testing', $payload);

        $this->assertTrue($action->exists());
        $this->assertInstanceOf(ActionLog::class, $action);
        $this->assertEquals('Phpunit testing', $action->action);
        $this->assertEquals($payload, $action->payload);
        $this->assertFalse($action->hasAuthenticatable());
    }
}