File: D:/HostingSpaces/zipwire/zipwire.nl/tests/Unit/ActionLoggerTest.php
<?php
namespace Tests\Unit;
use App\KommaApp\Kms\ActionLog\ActionLog;
use App\KommaApp\Kms\ActionLog\ActionLogger;
use App\KommaApp\Users\Models\User;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\TestCase;
class ActionLoggerTest extends TestCase
{
use DatabaseTransactions; //Automatically rolls back database actions after tests
/**
* @group ActionLogger
* @test
*/
public function instanceCreationTest()
{
$actionLogger = new Actionlogger();
$this->assertInstanceOf(ActionLogger::class, $actionLogger);
}
/**
* @group ActionLogger
* @test
*/
public function logTestAuhtenticatedUser()
{
$authUser = User::first();
$this->be($authUser);
$action = ActionLogger::Log('Phpunit testing');
$this->assertTrue($action->exists());
$this->assertInstanceOf(ActionLog::class, $action);
$this->assertEquals('Phpunit testing', $action->action);
$this->assertEquals($authUser->id, $action->User()->first()->id);
}
/**
* @group ActionLogger
* @test
*/
public function logTestSpecificUser()
{
$user = User::first();
$action = ActionLogger::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->User()->first()->id);
}
/**
* @group ActionLogger
* @test
*/
public function logTestAnonymous()
{
$action = ActionLogger::Log('Phpunit testing');
$this->assertTrue($action->exists());
$this->assertInstanceOf(ActionLog::class, $action);
$this->assertEquals('Phpunit testing', $action->action);
$this->assertNull($action->User()->first());
}
/**
* @group ActionLogger
* @test
*/
public function logTestPayload()
{
$payload = ['metadata' => ['info' => 'just testing']];
$action = ActionLogger::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->assertNull($action->User()->first());
}
}