public function testUserPropertiesWillGetCastAsGraphUserObjects()
 {
     $dataFromGraph = ['id' => '123', 'name' => 'Foo User', 'significant_other' => ['id' => '1337', 'name' => 'Bar User']];
     $this->responseMock->shouldReceive('getDecodedBody')->once()->andReturn($dataFromGraph);
     $factory = new GraphObjectFactory($this->responseMock);
     $graphObject = $factory->makeGraphUser();
     $significantOther = $graphObject->getSignificantOther();
     $this->assertInstanceOf('\\Facebook\\GraphNodes\\GraphUser', $significantOther);
 }
 public function testLocationPropertyWillGetCastAsGraphLocationObject()
 {
     $dataFromGraph = ['id' => '123', 'name' => 'Foo Page', 'location' => ['city' => 'Washington', 'country' => 'United States', 'latitude' => 38.881634205431, 'longitude' => -77.029121075722, 'state' => 'DC']];
     $this->responseMock->shouldReceive('getDecodedBody')->once()->andReturn($dataFromGraph);
     $factory = new GraphObjectFactory($this->responseMock);
     $graphObject = $factory->makeGraphPage();
     $location = $graphObject->getLocation();
     $this->assertInstanceOf('\\Facebook\\GraphNodes\\GraphLocation', $location);
 }
 public function testPlacePropertyWillGetCastAsGraphPageObject()
 {
     $dataFromGraph = ['id' => '123', 'name' => 'Foo Album', 'place' => ['id' => '1', 'name' => 'For Bar Place']];
     $this->responseMock->shouldReceive('getDecodedBody')->once()->andReturn($dataFromGraph);
     $factory = new GraphObjectFactory($this->responseMock);
     $graphObject = $factory->makeGraphAlbum();
     $place = $graphObject->getPlace();
     $this->assertInstanceOf('\\Facebook\\GraphNodes\\GraphPage', $place);
 }
 public function testDatesGetCastToDateTime()
 {
     $dataFromGraph = ['expires_at' => 123, 'issued_at' => 1337];
     $this->responseMock->shouldReceive('getDecodedBody')->once()->andReturn($dataFromGraph);
     $factory = new GraphObjectFactory($this->responseMock);
     $graphObject = $factory->makeGraphSessionInfo();
     $expires = $graphObject->getExpiresAt();
     $issuedAt = $graphObject->getIssuedAt();
     $this->assertInstanceOf('DateTime', $expires);
     $this->assertInstanceOf('DateTime', $issuedAt);
 }
 public function testAListFromGraphWillBeCastAsAGraphEdge()
 {
     $data = json_encode(['data' => [['id' => '123', 'name' => 'Foo McBar', 'link' => 'http://facebook/foo'], ['id' => '1337', 'name' => 'Bar McBaz', 'link' => 'http://facebook/bar']], 'paging' => ['next' => 'http://facebook/next', 'previous' => 'http://facebook/prev']]);
     $res = new FacebookResponse($this->request, $data);
     $factory = new GraphObjectFactory($res);
     $graphList = $factory->makeGraphList();
     $graphData = $graphList->asArray();
     $this->assertInstanceOf('\\Facebook\\GraphNodes\\GraphList', $graphList);
     $this->assertEquals(['id' => '123', 'name' => 'Foo McBar', 'link' => 'http://facebook/foo'], $graphData[0]);
     $this->assertEquals(['id' => '1337', 'name' => 'Bar McBaz', 'link' => 'http://facebook/bar'], $graphData[1]);
 }
 public function testACollectionWillBeCastRecursively()
 {
     $someUser = ['id' => '123', 'name' => 'Foo McBar'];
     $likesCollection = ['data' => [['id' => '1', 'name' => 'Sammy Kaye Powers', 'is_sexy' => true], ['id' => '2', 'name' => 'Yassine Guedidi', 'is_sexy' => true], ['id' => '3', 'name' => 'Fosco Marotto', 'is_sexy' => true], ['id' => '4', 'name' => 'Foo McUgly', 'is_sexy' => false]], 'paging' => ['next' => 'http://facebook/next_likes', 'previous' => 'http://facebook/prev_likes']];
     $commentsCollection = ['data' => [['id' => '42_1', 'from' => $someUser, 'message' => 'Foo comment.', 'created_time' => '2014-07-15T03:54:34+0000', 'likes' => $likesCollection], ['id' => '42_2', 'from' => $someUser, 'message' => 'Bar comment.', 'created_time' => '2014-07-15T04:11:24+0000', 'likes' => $likesCollection]], 'paging' => ['next' => 'http://facebook/next_comments', 'previous' => 'http://facebook/prev_comments']];
     $dataFromGraph = ['data' => [['id' => '1337_1', 'from' => $someUser, 'story' => 'Some great foo story.', 'likes' => $likesCollection, 'comments' => $commentsCollection], ['id' => '1337_2', 'from' => $someUser, 'to' => ['data' => [$someUser]], 'message' => 'Some great bar message.', 'likes' => $likesCollection, 'comments' => $commentsCollection]], 'paging' => ['next' => 'http://facebook/next', 'previous' => 'http://facebook/prev']];
     $this->responseMock->shouldReceive('getDecodedBody')->once()->andReturn($dataFromGraph);
     $factory = new GraphObjectFactory($this->responseMock);
     $graphObject = $factory->makeGraphList();
     $this->assertInstanceOf('\\Facebook\\GraphNodes\\GraphList', $graphObject);
     // Story
     $storyObject = $graphObject[0];
     $this->assertInstanceOf('\\Facebook\\GraphNodes\\GraphObject', $storyObject['from']);
     $this->assertInstanceOf('\\Facebook\\GraphNodes\\GraphList', $storyObject['likes']);
     $this->assertInstanceOf('\\Facebook\\GraphNodes\\GraphList', $storyObject['comments']);
     // Story Comments
     $storyComments = $storyObject['comments'];
     $firstStoryComment = $storyComments[0];
     $this->assertInstanceOf('\\Facebook\\GraphNodes\\GraphObject', $firstStoryComment['from']);
     // Message
     $messageObject = $graphObject[1];
     $this->assertInstanceOf('\\Facebook\\GraphNodes\\GraphList', $messageObject['to']);
     $toUsers = $messageObject['to'];
     $this->assertInstanceOf('\\Facebook\\GraphNodes\\GraphObject', $toUsers[0]);
 }
 /**
  * Instantiate a new GraphList from response.
  *
  * @param string|null $subclassName The GraphObject sub class to cast list items to.
  * @param boolean     $auto_prefix  Toggle to auto-prefix the subclass name.
  *
  * @return \Facebook\GraphNodes\GraphList
  *
  * @throws FacebookSDKException
  */
 public function getGraphList($subclassName = null, $auto_prefix = true)
 {
     $factory = new GraphObjectFactory($this);
     return $factory->makeGraphList($subclassName, $auto_prefix);
 }
 public function testAGraphListWillGenerateTheProperParentGraphEdges()
 {
     $likesList = ['data' => [['id' => '1', 'name' => 'Sammy Kaye Powers']], 'paging' => ['cursors' => ['after' => 'like_after_cursor', 'before' => 'like_before_cursor']]];
     $photosList = ['data' => [['id' => '777', 'name' => 'Foo Photo', 'likes' => $likesList]], 'paging' => ['cursors' => ['after' => 'photo_after_cursor', 'before' => 'photo_before_cursor']]];
     $data = json_encode(['data' => [['id' => '111', 'name' => 'Foo McBar', 'likes' => $likesList, 'photos' => $photosList], ['id' => '222', 'name' => 'Bar McBaz', 'likes' => $likesList, 'photos' => $photosList]], 'paging' => ['next' => 'http://facebook/next', 'previous' => 'http://facebook/prev']]);
     $res = new FacebookResponse($this->request, $data);
     $factory = new GraphObjectFactory($res);
     $graphList = $factory->makeGraphList();
     $topGraphEdge = $graphList->getParentGraphEdge();
     $childGraphEdgeOne = $graphList[0]['likes']->getParentGraphEdge();
     $childGraphEdgeTwo = $graphList[1]['likes']->getParentGraphEdge();
     $childGraphEdgeThree = $graphList[1]['photos']->getParentGraphEdge();
     $childGraphEdgeFour = $graphList[1]['photos'][0]['likes']->getParentGraphEdge();
     $this->assertNull($topGraphEdge);
     $this->assertEquals('/111/likes', $childGraphEdgeOne);
     $this->assertEquals('/222/likes', $childGraphEdgeTwo);
     $this->assertEquals('/222/photos', $childGraphEdgeThree);
     $this->assertEquals('/777/likes', $childGraphEdgeFour);
 }