Skip to content

Commit

Permalink
Refactor unit tests to use the new version method
Browse files Browse the repository at this point in the history
  • Loading branch information
bastianallgeier committed Jun 11, 2024
1 parent fef9990 commit 020451c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
36 changes: 18 additions & 18 deletions tests/Cms/Files/FileActionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,19 @@ public function testChangeName(File $file)
// create an empty dummy file
F::write($file->root(), '');
// ...and an empty content file for it
F::write($file->storage()->contentFile(VersionId::published(), 'default'), '');
F::write($file->version(VersionId::published())->contentFile('default'), '');

$this->assertFileExists($file->root());
$this->assertFileExists($file->storage()->contentFile(VersionId::published(), 'default'));
$this->assertFileExists($file->version(VersionId::published())->contentFile('default'));

$result = $file->changeName('test');

$this->assertNotSame($file->root(), $result->root());
$this->assertSame('test.csv', $result->filename());
$this->assertFileExists($result->root());
$this->assertFileExists($result->storage()->contentFile(VersionId::published(), 'default'));
$this->assertFileExists($result->version(VersionId::published())->contentFile('default'));
$this->assertFileDoesNotExist($file->root());
$this->assertFileDoesNotExist($file->storage()->contentFile(VersionId::published(), 'default'));
$this->assertFileDoesNotExist($file->version(VersionId::published())->contentFile('default'));
}

public static function fileProviderMultiLang(): array
Expand All @@ -142,20 +142,20 @@ public function testChangeNameMultiLang(File $file)
// create an empty dummy file
F::write($file->root(), '');
// ...and empty content files for it
F::write($file->storage()->contentFile(VersionId::published(), 'en'), '');
F::write($file->storage()->contentFile(VersionId::published(), 'de'), '');
F::write($file->version(VersionId::published())->contentFile('en'), '');
F::write($file->version(VersionId::published())->contentFile('de'), '');

$this->assertFileExists($file->root());
$this->assertFileExists($file->storage()->contentFile(VersionId::published(), 'en'));
$this->assertFileExists($file->storage()->contentFile(VersionId::published(), 'de'));
$this->assertFileExists($file->version(VersionId::published())->contentFile('en'));
$this->assertFileExists($file->version(VersionId::published())->contentFile('de'));

$result = $file->changeName('test');

$this->assertNotEquals($file->root(), $result->root());
$this->assertSame('test.csv', $result->filename());
$this->assertFileExists($result->root());
$this->assertFileExists($result->storage()->contentFile(VersionId::published(), 'en'));
$this->assertFileExists($result->storage()->contentFile(VersionId::published(), 'de'));
$this->assertFileExists($result->version(VersionId::published())->contentFile('en'));
$this->assertFileExists($result->version(VersionId::published())->contentFile('de'));
}

public function testChangeTemplate()
Expand Down Expand Up @@ -377,9 +377,9 @@ public function testChangeTemplateMultilang()
$this->assertNull($modified->caption()->value());
$this->assertSame('Das ist der Text', $modified->text()->value());

$this->assertFileExists($modified->storage()->contentFile(VersionId::published(), 'en'));
$this->assertFileExists($modified->storage()->contentFile(VersionId::published(), 'de'));
$this->assertFileDoesNotExist($modified->storage()->contentFile(VersionId::published(), 'fr'));
$this->assertFileExists($modified->version(VersionId::published())->contentFile('en'));
$this->assertFileExists($modified->version(VersionId::published())->contentFile('de'));
$this->assertFileDoesNotExist($modified->version(VersionId::published())->contentFile('fr'));
}

public function testChangeTemplateDefault()
Expand Down Expand Up @@ -755,17 +755,17 @@ public function testDelete(File $file)
// create an empty dummy file
F::write($file->root(), '');
// ...and an empty content file for it
F::write($file->storage()->contentFile(VersionId::published(), 'default'), '');
F::write($file->version(VersionId::published())->contentFile('default'), '');

$this->assertFileExists($file->root());
$this->assertFileExists($file->storage()->contentFile(VersionId::published(), 'default'));
$this->assertFileExists($file->version(VersionId::published())->contentFile('default'));

$result = $file->delete();

$this->assertTrue($result);

$this->assertFileDoesNotExist($file->root());
$this->assertFileDoesNotExist($file->storage()->contentFile(VersionId::published(), 'default'));
$this->assertFileDoesNotExist($file->version(VersionId::published())->contentFile('default'));
}

/**
Expand Down Expand Up @@ -875,11 +875,11 @@ public function testSave($file)
F::write($file->root(), '');

$this->assertFileExists($file->root());
$this->assertFileDoesNotExist($file->storage()->contentFile(VersionId::published(), 'default'));
$this->assertFileDoesNotExist($file->version(VersionId::published())->contentFile('default'));

$file = $file->clone(['content' => ['caption' => 'save']])->save();

$this->assertFileExists($file->storage()->contentFile(VersionId::published(), 'default'));
$this->assertFileExists($file->version(VersionId::published())->contentFile('default'));
}

/**
Expand Down
20 changes: 10 additions & 10 deletions tests/Cms/Pages/PageActionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,9 +424,9 @@ public function testChangeTemplateMultilang()
$this->assertSame('article', $modified->intendedTemplate()->name());
$this->assertSame(2, $calls);

$this->assertFileExists($modified->storage()->contentFile(VersionId::published(), 'en'));
$this->assertFileExists($modified->storage()->contentFile(VersionId::published(), 'de'));
$this->assertFileDoesNotExist($modified->storage()->contentFile(VersionId::published(), 'fr'));
$this->assertFileExists($modified->version(VersionId::published())->contentFile('en'));
$this->assertFileExists($modified->version(VersionId::published())->contentFile('de'));
$this->assertFileDoesNotExist($modified->version(VersionId::published())->contentFile('fr'));
$this->assertNull($modified->caption()->value());
$this->assertSame('Text', $modified->text()->value());
$this->assertNull($modified->content('de')->get('caption')->value());
Expand Down Expand Up @@ -891,15 +891,15 @@ public function testDuplicateMultiLang()
'parent' => $page,
'code' => 'en',
]);
$this->assertFileExists($page->storage()->contentFile(VersionId::changes(), 'en'));
$this->assertFileExists($page->version(VersionId::changes())->contentFile('en'));

$drafts = $app->site()->drafts();
$childrenAndDrafts = $app->site()->childrenAndDrafts();

$copy = $page->duplicate('test-copy');

$this->assertFileExists($copy->storage()->contentFile(VersionId::changes(), 'en'));
$this->assertFileDoesNotExist($copy->storage()->contentFile(VersionId::changes(), 'de'));
$this->assertFileExists($copy->version(VersionId::changes())->contentFile('en'));
$this->assertFileDoesNotExist($copy->version(VersionId::changes())->contentFile('de'));

$this->assertIsPage($page, $drafts->find('test'));
$this->assertIsPage($page, $childrenAndDrafts->find('test'));
Expand Down Expand Up @@ -931,8 +931,8 @@ public function testDuplicateMultiLangSlug()
'slug' => 'test-de'
], 'de');

$this->assertFileExists($page->storage()->contentFile(VersionId::changes(), 'en'));
$this->assertFileExists($page->storage()->contentFile(VersionId::changes(), 'de'));
$this->assertFileExists($page->version(VersionId::changes())->contentFile('en'));
$this->assertFileExists($page->version(VersionId::changes())->contentFile('de'));
$this->assertSame('test', $page->slug());
$this->assertSame('test-de', $page->slug('de'));

Expand Down Expand Up @@ -1046,8 +1046,8 @@ public function testDuplicateChildrenMultiLang()

$copy = $page->duplicate('test-copy', ['children' => true]);

$this->assertFileExists($copy->storage()->contentFile(VersionId::changes(), 'en'));
$this->assertFileDoesNotExist($copy->storage()->contentFile(VersionId::changes(), 'de'));
$this->assertFileExists($copy->version(VersionId::changes())->contentFile('en'));
$this->assertFileDoesNotExist($copy->version(VersionId::changes())->contentFile('de'));


$this->assertNotSame($page->uuid()->id(), $copy->uuid()->id());
Expand Down

0 comments on commit 020451c

Please sign in to comment.