Skip to content

Commit

Permalink
Add test case for custom types
Browse files Browse the repository at this point in the history
  • Loading branch information
bezin committed Mar 22, 2024
1 parent e41ec9d commit 2dbabd0
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
41 changes: 39 additions & 2 deletions tests/AutoFileTemplatesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected function tearDown(): void
}

#[DataProvider('files')]
public function testSetsTemplateBasedOnCoreFileTypes(File $file, ?string $expected): void
public function testSetsTemplateForCoreFileTypes(File $file, ?string $expected): void
{
$kirby = new App([
'roots' => [
Expand All @@ -55,7 +55,44 @@ public function testSetsTemplateBasedOnCoreFileTypes(File $file, ?string $expect
$this->assertEquals($expected, $template);
}

public function testFileUpdatedMethodIsCalledOnce(): void
public function testSetsTemplateForCustomFileTypes(): void
{
$kirby = new App([
'roots' => [
'index' => self::$tmpDir,
],
'options' => [
'presprog.auto-file-templates' => [
'autoAssign' => true,
],
],
]);

F::$types['custom-type'] = ['custom'];

$props = ['type' => 'custom-type', 'filename' => 'image.custom', 'parent' => self::page()];

$file = $this->getMockBuilder(File::class)
->disableOriginalConstructor()
->setConstructorArgs($props)
->getMock()
;

$file->expects($this->once())
->method('update')
->with(['template' => 'custom-type'])
;

$file->method('type')
->willReturn($props['type'])
;

$service = new AutoFileTemplates($kirby, PluginOptions::createFromOptions($kirby->options()));
$template = $service->autoAssign($file);
$this->assertEquals('custom-type', $template);
}

public function testFileIsUpdated(): void
{
$kirby = new App([
'roots' => [
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/site/blueprints/files/custom-type.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Title: Custom Type

0 comments on commit 2dbabd0

Please sign in to comment.