Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bastianallgeier committed Jun 5, 2024
1 parent 8c4449d commit 524947f
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions tests/Content/MemoryContentStorageHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,18 @@
/**
* @coversDefaultClass Kirby\Content\MemoryContentStorageHandler
* @covers ::__construct
* @covers ::cacheId
*/
class MemoryContentStorageHandlerTest extends TestCase
{
protected $storage;

/**
* @covers ::create
* @covers ::delete
* @covers ::exists
* @covers ::write
*/
public function assertCreateAndDelete(VersionId $versionId, Language $language): void
{
$this->storage->create($versionId, $language, []);
Expand All @@ -23,6 +30,12 @@ public function assertCreateAndDelete(VersionId $versionId, Language $language):
$this->assertFalse($this->storage->exists($versionId, $language));
}

/**
* @covers ::create
* @covers ::exists
* @covers ::read
* @covers ::write
*/
public function assertCreateAndRead(VersionId $versionId, Language $language): void
{
$fields = [
Expand All @@ -36,6 +49,30 @@ public function assertCreateAndRead(VersionId $versionId, Language $language): v
$this->assertSame($fields, $this->storage->read($versionId, $language));
}

/**
* @covers ::create
* @covers ::exists
* @covers ::read
* @covers ::update
* @covers ::write
*/
public function assertCreateAndUpdate(VersionId $versionId, Language $language): void
{
$fields = [
'title' => 'Foo',
'text' => 'Bar'
];

$this->storage->create($versionId, $language, []);

$this->assertSame([], $this->storage->read($versionId, $language));

$this->storage->update($versionId, $language, $fields);

$this->assertTrue($this->storage->exists($versionId, $language));
$this->assertSame($fields, $this->storage->read($versionId, $language));
}

public function setUpMultiLanguage(): void
{
parent::setUpMultiLanguage();
Expand Down Expand Up @@ -108,6 +145,7 @@ public function testCreateAndReadPublishedSingleLang()

/**
* @covers ::delete
* @covers ::exists
*/
public function testDeleteNonExisting()
{
Expand Down Expand Up @@ -286,4 +324,30 @@ public function testTouchSingleLang()

$this->assertGreaterThanOrEqual($time, $this->storage->modified($versionId, $language));
}

/**
* @covers ::update
*/
public function testUpdateMultiLang()
{
$this->setUpMultiLanguage();

$versionId = VersionId::changes();
$language = $this->app->language('en');

$this->assertCreateAndUpdate($versionId, $language);
}

/**
* @covers ::update
*/
public function testUpdateSingleLang()
{
$this->setUpSingleLanguage();

$versionId = VersionId::changes();
$language = Language::single();

$this->assertCreateAndUpdate($versionId, $language);
}
}

0 comments on commit 524947f

Please sign in to comment.