Skip to content

Commit

Permalink
Add the first batch of unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bastianallgeier committed Jul 22, 2024
1 parent 85c8bfb commit ad72b44
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 1 deletion.
1 change: 0 additions & 1 deletion tests/Content/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Kirby\Cms\App;
use Kirby\Data\Data;
use Kirby\Filesystem\Dir;
use Kirby\TestCase as BaseTestCase;

class TestCase extends BaseTestCase

Check failure on line 9 in tests/Content/TestCase.php

View workflow job for this annotation

GitHub Actions / Unit tests - PHP 8.2

Type of Kirby\Content\TestCase::$model must be Kirby\Cms\ModelWithContent (as in class Kirby\TestCase)

Check failure on line 9 in tests/Content/TestCase.php

View workflow job for this annotation

GitHub Actions / Unit tests - PHP 8.3

Type of Kirby\Content\TestCase::$model must be Kirby\Cms\ModelWithContent (as in class Kirby\TestCase)
Expand Down
81 changes: 81 additions & 0 deletions tests/Panel/Controller/ChangesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

namespace Kirby\Panel\Controller;

use Kirby\Cms\Page;
use Kirby\Data\Data;
use Kirby\TestCase;

class ChangesTest extends TestCase
{
public const TMP = KIRBY_TMP_DIR . '/Panel.Controller.Changes';
public Page $page;

public function setUp(): void
{
$this->setUpTmp();
$this->setUpSingleLanguage();
}

public function tearDown(): void
{
$this->tearDownTmp();
}

public function testDiscard()
{
Data::write($file = $this->model->root() . '/_changes/article.txt', []);

$response = Changes::discard($this->model);

$this->assertSame(['status' => 'ok'], $response);

$this->assertFileDoesNotExist($file);
}

public function testPublish()
{
Data::write($this->model->root() . '/article.txt', []);
Data::write($file = $this->model->root() . '/_changes/article.txt', []);

$response = Changes::publish($this->model, [
'title' => 'Test'
]);

$this->assertSame(['status' => 'ok'], $response);

// the changes should be gone now
$this->assertFileDoesNotExist($file);

// and the content file should be updated with the input
$published = Data::read($this->model->root() . '/article.txt');

$this->assertSame(['title' => 'Test'], $published);
}

public function testSave()
{
Data::write($this->model->root() . '/article.txt', []);
Data::write($this->model->root() . '/_changes/article.txt', []);

$response = Changes::save($this->model, [
'title' => 'Test'
]);

$this->assertSame(['status' => 'ok'], $response);

// the content file should be untouched
$published = Data::read($this->model->root() . '/article.txt');

$this->assertSame([], $published);

// the changes file should have the changes
$changes = Data::read($this->model->root() . '/_changes/article.txt');

$this->assertSame(['title' => 'Test'], $changes);
}

public function testUnlock()
{
}
}
2 changes: 2 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Kirby\Cms\App;
use Kirby\Cms\File;
use Kirby\Cms\ModelWithContent;
use Kirby\Cms\Page;
use Kirby\Cms\Site;
use Kirby\Cms\User;
Expand All @@ -13,6 +14,7 @@
class TestCase extends BaseTestCase
{
protected App $app;
protected ModelWithContent $model;

/**
* Whether $actual is a File object
Expand Down

0 comments on commit ad72b44

Please sign in to comment.