-
-
Notifications
You must be signed in to change notification settings - Fork 897
/
Copy pathLinkedDataPlatformTest.php
68 lines (59 loc) · 2.35 KB
/
LinkedDataPlatformTest.php
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
68
<?php
/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
use ApiPlatform\Laravel\Test\ApiTestAssertionsTrait;
use Illuminate\Contracts\Config\Repository;
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Orchestra\Testbench\Concerns\WithWorkbench;
use Orchestra\Testbench\TestCase;
use Workbench\App\Models\Book;
use Workbench\Database\Factories\BookFactory;
class LinkedDataPlatformTest extends TestCase
{
use ApiTestAssertionsTrait;
use RefreshDatabase;
use WithWorkbench;
/**
* @param Application $app
*/
protected function defineEnvironment($app): void
{
tap($app['config'], function (Repository $config): void {
$config->set('api-platform.formats', ['jsonld' => ['application/ld+json'], 'turtle' => ['text/turtle']]);
$config->set('api-platform.resources', [app_path('Models'), app_path('ApiResource')]);
$config->set('app.debug', true);
});
}
public function testHeadersAcceptPostIsReturnWhenPostAllowed(): void
{
$response = $this->get('/api/books', ['accept' => ['application/ld+json']]);
$response->assertStatus(200);
$response->assertHeader('accept-post', 'application/ld+json, text/turtle, text/html');
}
public function testHeadersAcceptPostIsNotSetWhenPostIsNotAllowed(): void
{
BookFactory::new()->createOne();
$book = Book::first();
$response = $this->get($this->getIriFromResource($book), ['accept' => ['application/ld+json']]);
$response->assertStatus(200);
$response->assertHeaderMissing('accept-post');
}
public function testHeaderAllowReflectsResourceAllowedMethods(): void
{
$response = $this->get('/api/books', ['accept' => ['application/ld+json']]);
$response->assertHeader('allow', 'OPTIONS, HEAD, POST, GET');
BookFactory::new()->createOne();
$book = Book::first();
$response = $this->get($this->getIriFromResource($book), ['accept' => ['application/ld+json']]);
$response->assertStatus(200);
$response->assertHeader('allow', 'OPTIONS, HEAD, PUT, PATCH, GET, DELETE');
}
}