Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Http/Responses/DataResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Statamic\Facades\Site;
use Statamic\Routing\ResolveRedirect;
use Statamic\Statamic;
use Statamic\Tokens\Handlers\LivePreview;
use Statamic\View\View;

class DataResponse implements Responsable
Expand Down Expand Up @@ -192,7 +193,7 @@ public function with($data)

protected function isLivePreview()
{
return $this->request->headers->get('X-Statamic-Live-Preview');
return optional($this->request->statamicToken())->handler() === LivePreview::class;
}

protected function versionJavascriptModules($contents)
Expand Down
2 changes: 0 additions & 2 deletions src/Tokens/Handlers/LivePreview.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ public function handle(Token $token, $request, Closure $next)

$item->repository()->substitute($item);

$request->headers->set('X-Statamic-Live-Preview', true);

$response = $next($request);

$response->headers->set('X-Statamic-Live-Preview', true);
Expand Down
19 changes: 13 additions & 6 deletions tests/FrontendTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Tests;

use Facades\Statamic\CP\LivePreview;
use Facades\Tests\Factories\EntryFactory;
use Illuminate\Http\Response;
use Illuminate\Support\Carbon;
Expand Down Expand Up @@ -231,10 +232,12 @@ public function drafts_are_visible_if_using_live_preview()
{
$this->withStandardBlueprints();

$this->createPage('about')->published(false)->set('content', 'Testing 123')->save();
$page = tap($this->createPage('about')->published(false)->set('content', 'Testing 123'))->save();

LivePreview::tokenize('test-token', $page);

$response = $this
->get('/about', ['X-Statamic-Live-Preview' => true])
->get('/about?token=test-token')
->assertStatus(200)
->assertHeader('X-Statamic-Draft', true);

Expand Down Expand Up @@ -279,10 +282,12 @@ public function future_private_entries_viewable_in_live_preview()
$this->viewShouldReturnRendered('default', 'The template contents');

tap($this->makeCollection()->dated(true)->futureDateBehavior('private'))->save();
tap($this->makePage('about')->date('2019-01-02'))->save();
$page = tap($this->makePage('about')->date('2019-01-02'))->save();

LivePreview::tokenize('test-token', $page);

$this
->get('/about', ['X-Statamic-Live-Preview' => true])
->get('/about?token=test-token')
->assertStatus(200)
->assertHeader('X-Statamic-Private', true);
}
Expand Down Expand Up @@ -325,10 +330,12 @@ public function past_private_entries_are_viewable_in_live_preview()
$this->viewShouldReturnRendered('default', 'The template contents');

tap($this->makeCollection()->dated(true)->pastDateBehavior('private'))->save();
tap($this->makePage('about')->date('2018-01-01'))->save();
$page = tap($this->makePage('about')->date('2018-01-01'))->save();

LivePreview::tokenize('test-token', $page);

$this
->get('/about', ['X-Statamic-Live-Preview' => true])
->get('/about?token=test-token')
->assertStatus(200)
->assertHeader('X-Statamic-Private', true);
}
Expand Down
40 changes: 0 additions & 40 deletions tests/Tokens/Handlers/LivePreviewTest.php

This file was deleted.