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

Possible bug in auditSync #930

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions tests/Functional/AuditingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -620,13 +620,46 @@ public function itWillAuditSync()

$article->auditSync('categories', [$secondCategory->getKey()]);

$audit = $article->audits()->where('event', 'sync')->latest()->first();
$no_of_audits_after = Audit::where('auditable_type', Article::class)->count();
$categoryAfter = $article->categories()->first()->getKey();

$this->assertSame($firstCategory->getKey(), $categoryBefore);
$this->assertSame($secondCategory->getKey(), $categoryAfter);
$this->assertNotSame($categoryBefore, $categoryAfter);
$this->assertGreaterThan($no_of_audits_before, $no_of_audits_after);
$this->assertCount(1, $audit->old_values['categories']);
$this->assertCount(1, $audit->new_values['categories']);
}

/**
* @test
* @return void
*/
public function itWillAuditSyncAddAndRemove()
{
$firstCategory = factory(Category::class)->create();
$secondCategory = factory(Category::class)->create();
$thirdCategory = factory(Category::class)->create();
$article = factory(Article::class)->create();

$article->categories()->attach([$firstCategory->getKey(), $secondCategory->getKey()]);

$no_of_audits_before = Audit::where('auditable_type', Article::class)->count();

$article->auditSync('categories', [$secondCategory->getKey(), $thirdCategory->getKey()]);
willpower232 marked this conversation as resolved.
Show resolved Hide resolved

$audit = $article->audits()->where('event', 'sync')->latest()->first();
$no_of_audits_after = Audit::where('auditable_type', Article::class)->count();

$attachedCategories = $article->categories()->pluck('id')->toArray();

$this->assertNotContains($firstCategory->getKey(), $attachedCategories);
$this->assertContains($secondCategory->getKey(), $attachedCategories);
$this->assertContains($thirdCategory->getKey(), $attachedCategories);
$this->assertGreaterThan($no_of_audits_before, $no_of_audits_after);
$this->assertCount(1, $audit->old_values['categories']);
$this->assertCount(2, $audit->new_values['categories']);
erikn69 marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down
Loading