1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright 2016 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
|
|
|
*/ |
24
|
|
|
namespace Facebook\Tests\GraphNodes; |
25
|
|
|
|
26
|
|
|
use Facebook\FacebookApp; |
27
|
|
|
use Facebook\FacebookRequest; |
28
|
|
|
use Facebook\GraphNodes\GraphEdge; |
29
|
|
|
|
30
|
|
|
class GraphEdgeTest extends \PHPUnit_Framework_TestCase |
31
|
|
|
{ |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var \Facebook\FacebookRequest |
35
|
|
|
*/ |
36
|
|
|
protected $request; |
37
|
|
|
|
38
|
|
|
protected $pagination = [ |
39
|
|
|
'next' => 'https://graph.facebook.com/v7.12/998899/photos?pretty=0&limit=25&after=foo_after_cursor', |
40
|
|
|
'previous' => 'https://graph.facebook.com/v7.12/998899/photos?pretty=0&limit=25&before=foo_before_cursor', |
41
|
|
|
]; |
42
|
|
|
|
43
|
|
View Code Duplication |
protected function setUp() |
|
|
|
|
44
|
|
|
{ |
45
|
|
|
$app = new FacebookApp('123', 'foo_app_secret'); |
46
|
|
|
$this->request = new FacebookRequest( |
47
|
|
|
$app, |
48
|
|
|
'foo_token', |
49
|
|
|
'GET', |
50
|
|
|
'/me/photos?keep=me', |
51
|
|
|
['foo' => 'bar'], |
52
|
|
|
'foo_eTag', |
53
|
|
|
'v1337' |
54
|
|
|
); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @expectedException \Facebook\Exceptions\FacebookSDKException |
59
|
|
|
*/ |
60
|
|
|
public function testNonGetRequestsWillThrow() |
61
|
|
|
{ |
62
|
|
|
$this->request->setMethod('POST'); |
63
|
|
|
$graphEdge = new GraphEdge($this->request); |
64
|
|
|
$graphEdge->validateForPagination(); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function testCanReturnGraphGeneratedPaginationEndpoints() |
68
|
|
|
{ |
69
|
|
|
$graphEdge = new GraphEdge( |
70
|
|
|
$this->request, |
71
|
|
|
[], |
72
|
|
|
['paging' => $this->pagination] |
73
|
|
|
); |
74
|
|
|
$nextPage = $graphEdge->getPaginationUrl('next'); |
75
|
|
|
$prevPage = $graphEdge->getPaginationUrl('previous'); |
76
|
|
|
|
77
|
|
|
$this->assertEquals('/998899/photos?pretty=0&limit=25&after=foo_after_cursor', $nextPage); |
78
|
|
|
$this->assertEquals('/998899/photos?pretty=0&limit=25&before=foo_before_cursor', $prevPage); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function testCanInstantiateNewPaginationRequest() |
82
|
|
|
{ |
83
|
|
|
$graphEdge = new GraphEdge( |
84
|
|
|
$this->request, |
85
|
|
|
[], |
86
|
|
|
['paging' => $this->pagination], |
87
|
|
|
'/1234567890/likes' |
88
|
|
|
); |
89
|
|
|
$nextPage = $graphEdge->getNextPageRequest(); |
90
|
|
|
$prevPage = $graphEdge->getPreviousPageRequest(); |
91
|
|
|
|
92
|
|
|
$this->assertInstanceOf('Facebook\FacebookRequest', $nextPage); |
93
|
|
|
$this->assertInstanceOf('Facebook\FacebookRequest', $prevPage); |
94
|
|
|
$this->assertNotSame($this->request, $nextPage); |
95
|
|
|
$this->assertNotSame($this->request, $prevPage); |
96
|
|
|
$this->assertEquals('/v1337/998899/photos?access_token=foo_token&after=foo_after_cursor&appsecret_proof=857d5f035a894f16b4180f19966e055cdeab92d4d53017b13dccd6d43b6497af&foo=bar&limit=25&pretty=0', $nextPage->getUrl()); |
97
|
|
|
$this->assertEquals('/v1337/998899/photos?access_token=foo_token&appsecret_proof=857d5f035a894f16b4180f19966e055cdeab92d4d53017b13dccd6d43b6497af&before=foo_before_cursor&foo=bar&limit=25&pretty=0', $prevPage->getUrl()); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.