From 337c4601de73f077cee212840a78617104a4393c Mon Sep 17 00:00:00 2001 From: yungts97 Date: Tue, 15 Mar 2022 14:18:32 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=AA=20Test=20for=20hidden=20attribute?= =?UTF-8?q?=20feature?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Feature/UserActivityLogTest.php | 26 ++++++++++++++++++++++++-- tests/Models/PostWithHidden.php | 19 +++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 tests/Models/PostWithHidden.php diff --git a/tests/Feature/UserActivityLogTest.php b/tests/Feature/UserActivityLogTest.php index 284bff9..8a01a71 100644 --- a/tests/Feature/UserActivityLogTest.php +++ b/tests/Feature/UserActivityLogTest.php @@ -2,11 +2,12 @@ namespace Yungts97\LaravelUserActivityLog\Tests\Feature; +use Illuminate\Support\Facades\Auth; use Yungts97\LaravelUserActivityLog\Tests\TestCase; -use Yungts97\LaravelUserActivityLog\Tests\Models\User; use Yungts97\LaravelUserActivityLog\Tests\Models\Post; +use Yungts97\LaravelUserActivityLog\Tests\Models\User; +use Yungts97\LaravelUserActivityLog\Tests\Models\PostWithHidden; use Yungts97\LaravelUserActivityLog\Tests\Models\PostWithoutLog; -use Illuminate\Support\Facades\Auth; class UserActivityLogTest extends TestCase { @@ -92,4 +93,25 @@ function it_can_skip_logging() 'table_name' => 'posts', ]); } + + /** @test */ + function it_can_hide_attribute_on_logging() + { + //user login + $user = User::first(); + Auth::login($user); + + //create a post + $newPost = new PostWithHidden(['name' => 'Post 1']); + $user->posts()->save($newPost); + $data = json_encode($newPost->makeHidden(['name'])->toArray()); + + //checking database doesn't have the activity log record + $this->assertDatabaseHas('logs', [ + 'log_type' => 'create', + 'user_id' => $user->id, + 'table_name' => 'posts', + 'data' => $data + ]); + } } \ No newline at end of file diff --git a/tests/Models/PostWithHidden.php b/tests/Models/PostWithHidden.php new file mode 100644 index 0000000..5879a66 --- /dev/null +++ b/tests/Models/PostWithHidden.php @@ -0,0 +1,19 @@ +belongsTo(User::class); + } +} \ No newline at end of file