|
4 | 4 |
|
5 | 5 | use Facades\Statamic\API\FilterAuthorizer;
|
6 | 6 | use Facades\Statamic\API\ResourceAuthorizer;
|
| 7 | +use Facades\Statamic\CP\LivePreview; |
7 | 8 | use Facades\Statamic\Fields\BlueprintRepository;
|
8 | 9 | use Facades\Tests\Factories\EntryFactory;
|
9 | 10 | use PHPUnit\Framework\Attributes\DataProvider;
|
@@ -755,4 +756,44 @@ public function it_only_shows_published_entries_by_default()
|
755 | 756 | 'title' => 'That will be so rad!',
|
756 | 757 | ]]]);
|
757 | 758 | }
|
| 759 | + |
| 760 | + #[Test] |
| 761 | + public function it_only_shows_unpublished_entries_with_token() |
| 762 | + { |
| 763 | + FilterAuthorizer::shouldReceive('allowedForSubResources') |
| 764 | + ->andReturn(['published', 'status']); |
| 765 | + |
| 766 | + $entry = EntryFactory::collection('blog') |
| 767 | + ->id('6') |
| 768 | + ->slug('that-was-so-rad') |
| 769 | + ->data(['title' => 'That was so rad!']) |
| 770 | + ->published(false) |
| 771 | + ->create(); |
| 772 | + |
| 773 | + LivePreview::tokenize('test-token', $entry); |
| 774 | + |
| 775 | + $query = <<<'GQL' |
| 776 | +{ |
| 777 | + entry(id: "6") { |
| 778 | + id |
| 779 | + title |
| 780 | + } |
| 781 | +} |
| 782 | +GQL; |
| 783 | + |
| 784 | + $this |
| 785 | + ->withoutExceptionHandling() |
| 786 | + ->post('/graphql', ['query' => $query]) |
| 787 | + ->assertGqlOk() |
| 788 | + ->assertExactJson(['data' => ['entry' => null]]); |
| 789 | + |
| 790 | + $this |
| 791 | + ->withoutExceptionHandling() |
| 792 | + ->post('/graphql?token=test-token', ['query' => $query]) |
| 793 | + ->assertGqlOk() |
| 794 | + ->assertExactJson(['data' => ['entry' => [ |
| 795 | + 'id' => '6', |
| 796 | + 'title' => 'That was so rad!', |
| 797 | + ]]]); |
| 798 | + } |
758 | 799 | }
|
0 commit comments