|
8 | 8 | use Illuminate\Support\Facades\App; |
9 | 9 | use Illuminate\Support\Facades\Event; |
10 | 10 | use InvalidArgumentException; |
| 11 | +use OwenIt\Auditing\Events\AuditCustom; |
11 | 12 | use OwenIt\Auditing\Events\Auditing; |
12 | 13 | use OwenIt\Auditing\Exceptions\AuditingException; |
13 | 14 | use OwenIt\Auditing\Models\Audit; |
@@ -574,4 +575,30 @@ public function itWillAuditCustomEventData() |
574 | 575 | $article->audits->last()->getModified()['categories']['new'][1]['name'] |
575 | 576 | ); |
576 | 577 | } |
| 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 | + } |
577 | 604 | } |
0 commit comments