Skip to content

Commit f7cff2e

Browse files
Merge pull request #700 from owen-it/test_for_custom_event
add test for custom events (pr #699)
2 parents 1e34af5 + 2c3ea6e commit f7cff2e

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

tests/Functional/AuditingTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Illuminate\Support\Facades\App;
99
use Illuminate\Support\Facades\Event;
1010
use InvalidArgumentException;
11+
use OwenIt\Auditing\Events\AuditCustom;
1112
use OwenIt\Auditing\Events\Auditing;
1213
use OwenIt\Auditing\Exceptions\AuditingException;
1314
use OwenIt\Auditing\Models\Audit;
@@ -574,4 +575,30 @@ public function itWillAuditCustomEventData()
574575
$article->audits->last()->getModified()['categories']['new'][1]['name']
575576
);
576577
}
578+
579+
/**
580+
* @test
581+
* @return void
582+
*/
583+
public function canAuditAnyCustomEvent()
584+
{
585+
$article = factory(Article::class)->create();
586+
$article->auditEvent = 'whateverYouWant';
587+
$article->isCustomEvent = true;
588+
$article->auditCustomOld = [
589+
'customExample' => 'Anakin Skywalker'
590+
];
591+
$article->auditCustomNew = [
592+
'customExample' => 'Darth Vader'
593+
];
594+
Event::dispatch(AuditCustom::class, [$article]);
595+
596+
$this->assertDatabaseHas('audits', [
597+
'auditable_id' => $article->id,
598+
'auditable_type' => Article::class,
599+
'event' => 'whateverYouWant',
600+
'new_values' => '{"customExample":"Darth Vader"}',
601+
'old_values' => '{"customExample":"Anakin Skywalker"}'
602+
]);
603+
}
577604
}

0 commit comments

Comments
 (0)