-
-
Notifications
You must be signed in to change notification settings - Fork 190
Expand file tree
/
Copy pathSitePreviewViewControllerTest.php
More file actions
67 lines (57 loc) · 2.02 KB
/
Copy pathSitePreviewViewControllerTest.php
File metadata and controls
67 lines (57 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
namespace Kirby\Panel\Controller\View;
use Kirby\Exception\PermissionException;
use Kirby\Panel\TestCase;
use Kirby\Panel\Ui\View;
use PHPUnit\Framework\Attributes\CoversClass;
#[CoversClass(ModelPreviewViewController::class)]
#[CoversClass(SitePreviewViewController::class)]
class SitePreviewViewControllerTest extends TestCase
{
public const string TMP = KIRBY_TMP_DIR . '/Panel.Controller.View.SitePreviewViewController';
public function testButtons(): void
{
$model = $this->app->site();
$controller = new SitePreviewViewController($model, 'changes');
$buttons = $controller->buttons();
$this->assertCount(2, $buttons->render());
}
public function testFactory(): void
{
$controller = SitePreviewViewController::factory('site', 'changes');
$this->assertInstanceOf(SitePreviewViewController::class, $controller);
$this->assertSame($this->app->site(), $controller->model);
$this->assertSame('changes', $controller->mode);
}
public function testId(): void
{
$model = $this->app->site();
$controller = new SitePreviewViewController($model, 'changes');
$this->assertSame('site.preview', $controller->id());
}
public function testLoad(): void
{
$this->app->impersonate('kirby');
$site = $this->app->site();
$site->createChild([
'slug' => 'home',
'isDraft' => false
]);
$controller = new SitePreviewViewController($site, 'changes');
$view = $controller->load();
$this->assertInstanceOf(View::class, $view);
$this->assertSame('k-preview-view', $view->component);
$this->assertSame('Site | Preview', $view->title);
$props = $view->props();
$token = $site->version('changes')->previewToken();
$this->assertSame('/?_token=' . $token . '&_version=changes', $props['src']['changes']);
}
public function testLoadInvalid(): void
{
$this->expectException(PermissionException::class);
$this->expectExceptionMessage('The preview is not available');
$site = $this->app->site();
$controller = new SitePreviewViewController($site, 'changes');
$controller->load();
}
}