Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/anonymous causer #605

Merged
merged 11 commits into from
Oct 6, 2019
Merged
13 changes: 13 additions & 0 deletions src/ActivityLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,19 @@ public function by($modelOrId)
return $this->causedBy($modelOrId);
}

public function causedByAnonymous()
Gummibeer marked this conversation as resolved.
Show resolved Hide resolved
{
$this->activity->causer_id = null;
$this->activity->causer_type = null;

return $this;
}

public function byAnonymous()
{
return $this->causedByAnonymous();
}

public function withProperties($properties)
{
$this->getActivity()->properties = collect($properties);
Expand Down
26 changes: 26 additions & 0 deletions tests/ActivityLoggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,32 @@ public function it_will_use_the_logged_in_user_as_the_causer_by_default()
$this->assertEquals($userId, $this->getLastActivity()->causer->id);
}

/** @test */
public function it_can_log_activity_using_an_anonymous_causer()
{
activity()
->causedByAnonymous()
->log('hello poetsvrouwman');

$this->assertNull($this->getLastActivity()->causer_id);
$this->assertNull($this->getLastActivity()->causer_type);
}

/** @test */
public function it_will_override_the_logged_in_user_as_the_causer_when_an_anonymous_causer_is_specified()
Jhnbrn90 marked this conversation as resolved.
Show resolved Hide resolved
{
$userId = 1;

Auth::login(User::find($userId));

activity()
->byAnonymous()
->log('hello poetsvrouwman');

$this->assertNull($this->getLastActivity()->causer_id);
$this->assertNull($this->getLastActivity()->causer_type);
}

/** @test */
public function it_can_replace_the_placeholders()
{
Expand Down