forked from json-api-php/json-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRelationshipTest.php
101 lines (93 loc) · 3.24 KB
/
RelationshipTest.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
/**
*
* * This file is part of JSON:API implementation for PHP.
* *
* * (c) Alexey Karapetov <[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);
namespace JsonApiPhp\JsonApi\Test\Document\Resource\Relationship;
use JsonApiPhp\JsonApi\Document\Resource\Relationship\Linkage;
use JsonApiPhp\JsonApi\Document\Resource\Relationship\Relationship;
use JsonApiPhp\JsonApi\Test\HasAssertEqualsAsJson;
use PHPUnit\Framework\TestCase;
/**
* Relationships
*
* The value of the relationships key MUST be an object (a “relationships object”).
* Members of the relationships object (“relationships”) represent references
* from the resource object in which it’s defined to other resource objects.
*
* Relationships may be to-one or to-many.
*
* A “relationship object” MUST contain at least one of the following:
*
* - links: a links object containing at least one of the following:
* - self: a link for the relationship itself (a “relationship link”).
* This link allows the client to directly manipulate the relationship.
* For example, removing an author through an article’s relationship URL would disconnect the person
* from the article without deleting the people resource itself. When fetched successfully, this link
* returns the linkage for the related resources as its primary data. (See Fetching Relationships.)
* - related: a related resource link
* - data: resource linkage
* - meta: a meta object that contains non-standard meta-information about the relationship.
*
* A relationship object that represents a to-many relationship MAY also contain
* pagination links under the links member, as described below.
*
* @see http://jsonapi.org/format/#document-resource-object-relationships
* @see RelationshipTest::testCanCreateFromSelfLink()
* @see RelationshipTest::testCanCreateFromRelatedLink())
* @see RelationshipTest::testCanCreateFromLinkage())
* @see RelationshipTest::testCanCreateFromMeta())
*/
class RelationshipTest extends TestCase
{
use HasAssertEqualsAsJson;
public function testCanCreateFromSelfLink()
{
$this->assertEqualsAsJson(
[
'links' => [
'self' => 'http://localhost',
]
],
Relationship::fromSelfLink('http://localhost')
);
}
public function testCanCreateFromRelatedLink()
{
$this->assertEqualsAsJson(
[
'links' => [
'related' => 'http://localhost',
]
],
Relationship::fromRelatedLink('http://localhost')
);
}
public function testCanCreateFromLinkage()
{
$this->assertEqualsAsJson(
[
'data' => null,
],
Relationship::fromLinkage(Linkage::nullLinkage())
);
}
public function testCanCreateFromMeta()
{
$this->assertEqualsAsJson(
[
'meta' => [
'a' => 'b',
]
],
Relationship::fromMeta(['a' => 'b'])
);
}
}