Skip to content

Commit 8b04225

Browse files
committed
First file dialog unit tests
1 parent d051fd0 commit 8b04225

File tree

5 files changed

+287
-1
lines changed

5 files changed

+287
-1
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
3+
namespace Kirby\Panel\Ui\Dialogs;
4+
5+
use Kirby\Panel\Ui\Dialog;
6+
7+
/**
8+
* @coversDefaultClass \Kirby\Panel\Ui\Dialogs\FileChangeNameDialog
9+
* @covers ::__construct
10+
*/
11+
class FileChangeNameDialogTest extends TestCase
12+
{
13+
public const TMP = KIRBY_TMP_DIR . '/Panel.Ui.Dialogs.FileChangeNameDialog';
14+
15+
public function setUp(): void
16+
{
17+
parent::setUp();
18+
19+
$this->setUpSingleLanguage(
20+
site: [
21+
'children' => [
22+
[
23+
'slug' => 'test',
24+
'files' => [
25+
['filename' => 'test.jpg']
26+
]
27+
]
28+
]
29+
]
30+
);
31+
32+
$this->app->impersonate('kirby');
33+
}
34+
35+
/**
36+
* @covers ::for
37+
*/
38+
public function testFor()
39+
{
40+
$dialog = FileChangeNameDialog::for('pages/test', 'test.jpg');
41+
$this->assertInstanceOf(Dialog::class, $dialog);
42+
}
43+
44+
/**
45+
* @covers ::render
46+
*/
47+
public function testRender()
48+
{
49+
$dialog = FileChangeNameDialog::for('pages/test', 'test.jpg');
50+
$result = $dialog->render();
51+
$this->assertSame('k-form-dialog', $result['component']);
52+
$this->assertArrayHasKey('name', $result['props']['fields']);
53+
$this->assertSame('test', $result['props']['value']['name']);
54+
}
55+
56+
/**
57+
* @covers ::submit
58+
*/
59+
public function testSubmit()
60+
{
61+
$_GET['name'] = 'foo';
62+
$_GET['_referrer'] = '/pages/test/files/test.jpg';
63+
64+
$page = $this->app->page('test');
65+
$dialog = FileChangeNameDialog::for('pages/test', 'test.jpg');
66+
$this->assertSame('test', $page->file()->name());
67+
68+
$result = $dialog->submit();
69+
// TODO: why is the following not working?
70+
// Something actually wrong in $file::changeName()?
71+
// $this->assertSame('foo', $page->file()->name());
72+
$this->assertSame('file.changeName', $result['event']);
73+
$this->assertSame('/pages/test/files/foo.jpg', $result['redirect']);
74+
}
75+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
3+
namespace Kirby\Panel\Ui\Dialogs;
4+
5+
use Kirby\Panel\Ui\Dialog;
6+
7+
/**
8+
* @coversDefaultClass \Kirby\Panel\Ui\Dialogs\FileChangeSortDialog
9+
* @covers ::__construct
10+
*/
11+
class FileChangeSortDialogTest extends TestCase
12+
{
13+
public const TMP = KIRBY_TMP_DIR . '/Panel.Ui.Dialogs.FileChangeSortDialog';
14+
15+
public function setUp(): void
16+
{
17+
parent::setUp();
18+
19+
$this->setUpSingleLanguage(
20+
site: [
21+
'children' => [
22+
[
23+
'slug' => 'test',
24+
'files' => [
25+
[
26+
'filename' => 'a.jpg',
27+
'content' => [
28+
'sort' => 1
29+
]
30+
],
31+
[
32+
'filename' => 'b.jpg',
33+
'content' => [
34+
'sort' => 2
35+
]
36+
],
37+
[
38+
'filename' => 'c.jpg',
39+
'content' => [
40+
'sort' => 3
41+
]
42+
]
43+
]
44+
]
45+
]
46+
]
47+
);
48+
49+
$this->app->impersonate('kirby');
50+
}
51+
52+
/**
53+
* @covers ::for
54+
*/
55+
public function testFor()
56+
{
57+
$dialog = FileChangeSortDialog::for('pages/test', 'a.jpg');
58+
$this->assertInstanceOf(Dialog::class, $dialog);
59+
}
60+
61+
/**
62+
* @covers ::render
63+
*/
64+
public function testRender()
65+
{
66+
$dialog = FileChangeSortDialog::for('pages/test', 'a.jpg');
67+
$result = $dialog->render();
68+
$this->assertSame('k-form-dialog', $result['component']);
69+
$this->assertArrayHasKey('position', $result['props']['fields']);
70+
$this->assertSame(1, $result['props']['value']['position']);
71+
}
72+
73+
/**
74+
* @covers ::submit
75+
*/
76+
public function testSubmit()
77+
{
78+
$_GET['position'] = 3;
79+
80+
$page = $this->app->page('test');
81+
$dialog = FileChangeSortDialog::for('pages/test', 'a.jpg');
82+
$this->assertSame(1, $page->file()->sort()->value());
83+
84+
$result = $dialog->submit();
85+
$this->assertSame(3, $page->file()->sort()->value());
86+
$this->assertSame('file.sort', $result['event']);
87+
}
88+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?php
2+
3+
namespace Kirby\Panel\Ui\Dialogs;
4+
5+
use Kirby\Cms\App;
6+
use Kirby\Panel\Ui\Dialog;
7+
8+
/**
9+
* @coversDefaultClass \Kirby\Panel\Ui\Dialogs\FileChangeTemplateDialog
10+
* @covers ::__construct
11+
*/
12+
class FileChangeTemplateDialogTest extends TestCase
13+
{
14+
public const TMP = KIRBY_TMP_DIR . '/Panel.Ui.Dialogs.FileChangeTemplateDialog';
15+
16+
public function setUp(): void
17+
{
18+
parent::setUp();
19+
20+
$this->app = new App([
21+
'blueprints' => [
22+
'pages/test' => [
23+
'sections' => [
24+
[
25+
'type' => 'files',
26+
'template' => 'cover'
27+
],
28+
[
29+
'type' => 'files',
30+
'template' => 'hero'
31+
]
32+
]
33+
],
34+
'files/cover' => [
35+
'title' => 'Cover'
36+
],
37+
'files/hero' => [
38+
'title' => 'hero'
39+
],
40+
],
41+
'roots' => [
42+
'index' => static::TMP
43+
],
44+
'site' => [
45+
'children' => [
46+
[
47+
'slug' => 'test',
48+
'template' => 'test',
49+
'files' => [
50+
[
51+
'filename' => 'test.jpg',
52+
'content' => [
53+
'template' => 'cover'
54+
]
55+
]
56+
]
57+
]
58+
]
59+
]
60+
]);
61+
62+
$this->app->impersonate('kirby');
63+
}
64+
65+
/**
66+
* @covers ::for
67+
*/
68+
public function testFor()
69+
{
70+
$dialog = FileChangeTemplateDialog::for('pages/test', 'test.jpg');
71+
$this->assertInstanceOf(Dialog::class, $dialog);
72+
}
73+
74+
/**
75+
* @covers ::render
76+
*/
77+
public function testRender()
78+
{
79+
$dialog = FileChangeTemplateDialog::for('pages/test', 'test.jpg');
80+
$result = $dialog->render();
81+
$this->assertSame('k-form-dialog', $result['component']);
82+
$this->assertArrayHasKey('template', $result['props']['fields']);
83+
$this->assertSame('cover', $result['props']['value']['template']);
84+
}
85+
86+
/**
87+
* @covers ::submit
88+
*/
89+
public function testSubmit()
90+
{
91+
$_GET['template'] = 'hero';
92+
93+
$page = $this->app->page('test');
94+
$dialog = FileChangeTemplateDialog::for('pages/test', 'test.jpg');
95+
$this->assertSame('cover', $page->file()->template());
96+
97+
$result = $dialog->submit();
98+
$this->assertSame('hero', $page->file()->template());
99+
$this->assertSame('file.changeTemplate', $result['event']);
100+
}
101+
}

tests/Panel/Ui/Dialogs/TestCase.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Kirby\Panel\Ui\Dialogs;
4+
5+
use Kirby\TestCase as BaseTestCase;
6+
7+
class TestCase extends BaseTestCase
8+
{
9+
public const TMP = KIRBY_TMP_DIR . '/Panel.Ui.Dialogs';
10+
11+
public function setUp(): void
12+
{
13+
$this->setUpTmp();
14+
}
15+
16+
public function tearDown(): void
17+
{
18+
$this->tearDownTmp();
19+
20+
// clear fake json requests
21+
$_GET = [];
22+
}
23+
}

tests/Panel/Ui/Dialogs/UserTotpEnableDialogTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ public function testQr(): void
7070

7171
/**
7272
* @covers ::render
73-
* @covers ::secret
7473
* @covers ::totp
7574
*/
7675
public function testRender(): void

0 commit comments

Comments
 (0)