1
|
|
|
<?php |
2
|
|
|
namespace VGirol\JsonApiAssert\Laravel\Tests\Asserts\Response; |
3
|
|
|
|
4
|
|
|
use Illuminate\Database\Eloquent\Collection; |
5
|
|
|
use Illuminate\Foundation\Testing\TestResponse; |
6
|
|
|
use Illuminate\Http\Response; |
7
|
|
|
use VGirol\JsonApiAssert\Laravel\Assert; |
8
|
|
|
use VGirol\JsonApiAssert\Laravel\Tests\TestCase; |
9
|
|
|
use VGirol\JsonApiAssert\Laravel\Tests\Tools\Models\ModelForTest; |
10
|
|
|
use VGirol\JsonApiAssert\Messages; |
11
|
|
|
|
12
|
|
|
class FetchedRelationshipsCollectionTest extends TestCase |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @test |
16
|
|
|
*/ |
17
|
|
|
public function response_relationships_links() |
18
|
|
|
{ |
19
|
|
|
$status = 200; |
20
|
|
|
$headers = [ |
21
|
|
|
'Content-Type' => [self::$mediaType] |
22
|
|
|
]; |
23
|
|
|
|
24
|
|
|
$content = [ |
25
|
|
|
'data' => [ |
26
|
|
|
'relationships' => [ |
27
|
|
|
'test' => [ |
28
|
|
|
'links' => [ |
29
|
|
|
'self' => 'url', |
30
|
|
|
'related' => 'url' |
31
|
|
|
] |
32
|
|
|
] |
33
|
|
|
] |
34
|
|
|
] |
35
|
|
|
]; |
36
|
|
|
$expected = [ |
37
|
|
|
'self' => 'url', |
38
|
|
|
'related' => 'url' |
39
|
|
|
]; |
40
|
|
|
$path = 'data.relationships.test'; |
41
|
|
|
|
42
|
|
|
$response = Response::create(json_encode($content), $status, $headers); |
43
|
|
|
$response = TestResponse::fromBaseResponse($response); |
44
|
|
|
|
45
|
|
|
$response->assertJsonApiRelationshipsLinks($expected, $path); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @test |
50
|
|
|
* @dataProvider relationshipsLinksFailedProvider |
51
|
|
|
*/ |
52
|
|
|
public function response_relationships_links_failed($content, $expected, $path, $failureMsg) |
53
|
|
|
{ |
54
|
|
|
$fn = function ($content, $expected, $path) { |
55
|
|
|
$status = 200; |
56
|
|
|
$headers = [ |
57
|
|
|
'Content-Type' => [self::$mediaType] |
58
|
|
|
]; |
59
|
|
|
|
60
|
|
|
$response = Response::create(json_encode($content), $status, $headers); |
61
|
|
|
$response = TestResponse::fromBaseResponse($response); |
62
|
|
|
|
63
|
|
|
$response->assertJsonApiRelationshipsLinks($expected, $path); |
64
|
|
|
}; |
65
|
|
|
|
66
|
|
|
Assert::assertTestFail($fn, $failureMsg, $content, $expected, $path); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function relationshipsLinksFailedProvider() |
70
|
|
|
{ |
71
|
|
|
return [ |
72
|
|
|
'no links member' => [ |
73
|
|
|
[ |
74
|
|
|
'meta' => [ |
75
|
|
|
'bad' => 'content' |
76
|
|
|
] |
77
|
|
|
], |
78
|
|
|
[ |
79
|
|
|
'first' => 'url', |
80
|
|
|
'last' => 'url' |
81
|
|
|
], |
82
|
|
|
'meta', |
83
|
|
|
sprintf(Messages::HAS_MEMBER, 'links') |
84
|
|
|
], |
85
|
|
|
'bad links member' => [ |
86
|
|
|
[ |
87
|
|
|
'links' => [ |
88
|
|
|
'first' => 'url', |
89
|
|
|
'bad' => 'url' |
90
|
|
|
] |
91
|
|
|
], |
92
|
|
|
[ |
93
|
|
|
'first' => 'url', |
94
|
|
|
'last' => 'url' |
95
|
|
|
], |
96
|
|
|
null, |
97
|
|
|
Messages::ONLY_ALLOWED_MEMBERS |
98
|
|
|
], |
99
|
|
|
'no match' => [ |
100
|
|
|
[ |
101
|
|
|
'links' => [ |
102
|
|
|
'first' => 'url', |
103
|
|
|
'last' => 'url2' |
104
|
|
|
] |
105
|
|
|
], |
106
|
|
|
[ |
107
|
|
|
'first' => 'url', |
108
|
|
|
'last' => 'url' |
109
|
|
|
], |
110
|
|
|
null, |
111
|
|
|
null |
112
|
|
|
] |
113
|
|
|
]; |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|