|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright 2017 Facebook, Inc. |
|
4
|
|
|
* |
|
5
|
|
|
* You are hereby granted a non-exclusive, worldwide, royalty-free license to |
|
6
|
|
|
* use, copy, modify, and distribute this software in source code or binary |
|
7
|
|
|
* form for use in connection with the web services and APIs provided by |
|
8
|
|
|
* Facebook. |
|
9
|
|
|
* |
|
10
|
|
|
* As with any software that integrates with the Facebook platform, your use |
|
11
|
|
|
* of this software is subject to the Facebook Developer Principles and |
|
12
|
|
|
* Policies [http://developers.facebook.com/policy/]. This copyright notice |
|
13
|
|
|
* shall be included in all copies or substantial portions of the software. |
|
14
|
|
|
* |
|
15
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
16
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
17
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
|
18
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
19
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
20
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
|
21
|
|
|
* DEALINGS IN THE SOFTWARE. |
|
22
|
|
|
*/ |
|
23
|
|
|
namespace Facebook\Tests\GraphNode; |
|
24
|
|
|
|
|
25
|
|
|
use Facebook\GraphNode\GraphApplication; |
|
26
|
|
|
use Facebook\GraphNode\GraphUser; |
|
27
|
|
|
|
|
28
|
|
|
class GraphAchievementTest extends AbstractGraphNode |
|
29
|
|
|
{ |
|
30
|
|
|
public function testIdIsString() |
|
31
|
|
|
{ |
|
32
|
|
|
$dataFromGraph = [ |
|
33
|
|
|
'id' => '1337' |
|
34
|
|
|
]; |
|
35
|
|
|
|
|
36
|
|
|
$factory = $this->makeFactoryWithData($dataFromGraph); |
|
37
|
|
|
$graphNode = $factory->makeGraphAchievement(); |
|
38
|
|
|
|
|
39
|
|
|
$id = $graphNode->getId(); |
|
40
|
|
|
|
|
41
|
|
|
$this->assertEquals($dataFromGraph['id'], $id); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function testTypeIsAlwaysString() |
|
45
|
|
|
{ |
|
46
|
|
|
$dataFromGraph = [ |
|
47
|
|
|
'id' => '1337' |
|
48
|
|
|
]; |
|
49
|
|
|
|
|
50
|
|
|
$factory = $this->makeFactoryWithData($dataFromGraph); |
|
51
|
|
|
$graphNode = $factory->makeGraphAchievement(); |
|
52
|
|
|
|
|
53
|
|
|
$type = $graphNode->getType(); |
|
54
|
|
|
|
|
55
|
|
|
$this->assertEquals('game.achievement', $type); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function testNoFeedStoryIsBoolean() |
|
59
|
|
|
{ |
|
60
|
|
|
$dataFromGraph = [ |
|
61
|
|
|
'no_feed_story' => (rand(0, 1) == 1) |
|
62
|
|
|
]; |
|
63
|
|
|
|
|
64
|
|
|
$factory = $this->makeFactoryWithData($dataFromGraph); |
|
65
|
|
|
$graphNode = $factory->makeGraphAchievement(); |
|
66
|
|
|
|
|
67
|
|
|
$isNoFeedStory = $graphNode->isNoFeedStory(); |
|
68
|
|
|
|
|
69
|
|
|
$this->assertInternalType('bool', $isNoFeedStory); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function testDatesGetCastToDateTime() |
|
73
|
|
|
{ |
|
74
|
|
|
$dataFromGraph = [ |
|
75
|
|
|
'publish_time' => '2014-07-15T03:54:34+0000' |
|
76
|
|
|
]; |
|
77
|
|
|
|
|
78
|
|
|
$factory = $this->makeFactoryWithData($dataFromGraph); |
|
79
|
|
|
$graphNode = $factory->makeGraphAchievement(); |
|
80
|
|
|
|
|
81
|
|
|
$publishTime = $graphNode->getPublishTime(); |
|
82
|
|
|
|
|
83
|
|
|
$this->assertInstanceOf(\DateTime::class, $publishTime); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function testFromGetsCastAsGraphUser() |
|
87
|
|
|
{ |
|
88
|
|
|
$dataFromGraph = [ |
|
89
|
|
|
'from' => [ |
|
90
|
|
|
'id' => '1337', |
|
91
|
|
|
'name' => 'Foo McBar' |
|
92
|
|
|
] |
|
93
|
|
|
]; |
|
94
|
|
|
|
|
95
|
|
|
$factory = $this->makeFactoryWithData($dataFromGraph); |
|
96
|
|
|
$graphNode = $factory->makeGraphAchievement(); |
|
97
|
|
|
|
|
98
|
|
|
$from = $graphNode->getFrom(); |
|
99
|
|
|
|
|
100
|
|
|
$this->assertInstanceOf(GraphUser::class, $from); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
public function testApplicationGetsCastAsGraphApplication() |
|
104
|
|
|
{ |
|
105
|
|
|
$dataFromGraph = [ |
|
106
|
|
|
'application' => [ |
|
107
|
|
|
'id' => '1337' |
|
108
|
|
|
] |
|
109
|
|
|
]; |
|
110
|
|
|
|
|
111
|
|
|
$factory = $this->makeFactoryWithData($dataFromGraph); |
|
112
|
|
|
$graphNode = $factory->makeGraphAchievement(); |
|
113
|
|
|
|
|
114
|
|
|
$app = $graphNode->getApplication(); |
|
115
|
|
|
|
|
116
|
|
|
$this->assertInstanceOf(GraphApplication::class, $app); |
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
|