Skip to content

Commit

Permalink
Add test.
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanmcclean committed Dec 4, 2024
1 parent 6f73bcf commit 6577cbf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tests/Actions/DuplicateModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,29 @@ public function it_duplicates_models()

$duplicate = Post::query()->whereNot('id', $post->id)->first();

$this->assertEquals('Hello World (Duplicate)', $duplicate->title);
$this->assertNotNull($duplicate->start_date);
$this->assertFalse($duplicate->published());
}

#[Test]
public function only_duplicates_fields_where_duplication_is_enabled()
{
$blueprint = Blueprint::find('runway::post');
$blueprint->ensureFieldHasConfig('start_date', ['duplicate' => false]);

Blueprint::shouldReceive('find')
->with('runway::post')
->andReturn($blueprint);

$post = Post::factory()->create(['title' => 'Hello World', 'start_date' => now()]);

(new DuplicateModel)->run(collect([$post]), []);

$duplicate = Post::query()->whereNot('id', $post->id)->first();

$this->assertEquals('Hello World (Duplicate)', $duplicate->title);
$this->assertNull($duplicate->start_date);
$this->assertFalse($duplicate->published());
}
}
1 change: 1 addition & 0 deletions tests/__fixtures__/database/factories/PostFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function definition()
'slug' => Str::slug($title),
'body' => implode(' ', $this->faker->paragraphs(10)),
'author_id' => Author::factory()->create()->id,
'start_date' => now(),
'published' => true,
'mutated_value' => 'Foo',
];
Expand Down

0 comments on commit 6577cbf

Please sign in to comment.