summaryrefslogtreecommitdiff
path: root/lib/facebook-graph-sdk/tests/GraphNodes
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2018-04-26 01:00:12 +0200
committeremkael <emkael@tlen.pl>2018-04-26 01:00:12 +0200
commit4b8a9a5189a625bf99fedec7fd31f6e146410a14 (patch)
treea29759d5f0f0c29f07c89c59f6b5cf38407d1470 /lib/facebook-graph-sdk/tests/GraphNodes
parentab82beef33f4c196383a81213dcdff4ebe9447ae (diff)
Update FB API library
Diffstat (limited to 'lib/facebook-graph-sdk/tests/GraphNodes')
-rw-r--r--lib/facebook-graph-sdk/tests/GraphNodes/AbstractGraphNode.php4
-rwxr-xr-xlib/facebook-graph-sdk/tests/GraphNodes/CollectionTest.php16
-rw-r--r--lib/facebook-graph-sdk/tests/GraphNodes/GraphAchievementTest.php2
-rw-r--r--lib/facebook-graph-sdk/tests/GraphNodes/GraphAlbumTest.php4
-rw-r--r--lib/facebook-graph-sdk/tests/GraphNodes/GraphEdgeTest.php64
-rw-r--r--lib/facebook-graph-sdk/tests/GraphNodes/GraphEventTest.php4
-rw-r--r--lib/facebook-graph-sdk/tests/GraphNodes/GraphGroupTest.php4
-rw-r--r--lib/facebook-graph-sdk/tests/GraphNodes/GraphNodeFactoryTest.php34
-rw-r--r--lib/facebook-graph-sdk/tests/GraphNodes/GraphNodeTest.php2
-rw-r--r--lib/facebook-graph-sdk/tests/GraphNodes/GraphObjectFactoryTest.php4
-rw-r--r--lib/facebook-graph-sdk/tests/GraphNodes/GraphPageTest.php4
-rw-r--r--lib/facebook-graph-sdk/tests/GraphNodes/GraphSessionInfoTest.php4
-rw-r--r--lib/facebook-graph-sdk/tests/GraphNodes/GraphUserTest.php70
13 files changed, 146 insertions, 70 deletions
diff --git a/lib/facebook-graph-sdk/tests/GraphNodes/AbstractGraphNode.php b/lib/facebook-graph-sdk/tests/GraphNodes/AbstractGraphNode.php
index 1c4ce15..b4f0e90 100644
--- a/lib/facebook-graph-sdk/tests/GraphNodes/AbstractGraphNode.php
+++ b/lib/facebook-graph-sdk/tests/GraphNodes/AbstractGraphNode.php
@@ -1,6 +1,6 @@
<?php
/**
- * Copyright 2014 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
*
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
* use, copy, modify, and distribute this software in source code or binary
@@ -33,7 +33,7 @@ abstract class AbstractGraphNode extends \PHPUnit_Framework_TestCase
*/
protected $responseMock;
- public function setUp()
+ protected function setUp()
{
parent::setUp();
$this->responseMock = m::mock('\Facebook\FacebookResponse');
diff --git a/lib/facebook-graph-sdk/tests/GraphNodes/CollectionTest.php b/lib/facebook-graph-sdk/tests/GraphNodes/CollectionTest.php
index af3eba8..14af476 100755
--- a/lib/facebook-graph-sdk/tests/GraphNodes/CollectionTest.php
+++ b/lib/facebook-graph-sdk/tests/GraphNodes/CollectionTest.php
@@ -1,6 +1,6 @@
<?php
/**
- * Copyright 2014 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
*
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
* use, copy, modify, and distribute this software in source code or binary
@@ -60,6 +60,20 @@ class CollectionTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('faz', $property);
}
+ public function testFalseDefaultsWillReturnSameType()
+ {
+ $graphNode = new Collection(['foo' => 'bar']);
+
+ $field = $graphNode->getField('baz', '');
+ $this->assertSame('', $field);
+
+ $field = $graphNode->getField('baz', 0);
+ $this->assertSame(0, $field);
+
+ $field = $graphNode->getField('baz', false);
+ $this->assertSame(false, $field);
+ }
+
public function testTheKeysFromTheCollectionCanBeReturned()
{
$graphNode = new Collection([
diff --git a/lib/facebook-graph-sdk/tests/GraphNodes/GraphAchievementTest.php b/lib/facebook-graph-sdk/tests/GraphNodes/GraphAchievementTest.php
index d5e276e..5be1140 100644
--- a/lib/facebook-graph-sdk/tests/GraphNodes/GraphAchievementTest.php
+++ b/lib/facebook-graph-sdk/tests/GraphNodes/GraphAchievementTest.php
@@ -1,6 +1,6 @@
<?php
/**
- * Copyright 2014 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
*
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
* use, copy, modify, and distribute this software in source code or binary
diff --git a/lib/facebook-graph-sdk/tests/GraphNodes/GraphAlbumTest.php b/lib/facebook-graph-sdk/tests/GraphNodes/GraphAlbumTest.php
index f7a5521..0c4eab5 100644
--- a/lib/facebook-graph-sdk/tests/GraphNodes/GraphAlbumTest.php
+++ b/lib/facebook-graph-sdk/tests/GraphNodes/GraphAlbumTest.php
@@ -1,6 +1,6 @@
<?php
/**
- * Copyright 2014 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
*
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
* use, copy, modify, and distribute this software in source code or binary
@@ -34,7 +34,7 @@ class GraphAlbumTest extends \PHPUnit_Framework_TestCase
*/
protected $responseMock;
- public function setUp()
+ protected function setUp()
{
$this->responseMock = m::mock('\\Facebook\\FacebookResponse');
}
diff --git a/lib/facebook-graph-sdk/tests/GraphNodes/GraphEdgeTest.php b/lib/facebook-graph-sdk/tests/GraphNodes/GraphEdgeTest.php
index 4e70f52..3afaf9c 100644
--- a/lib/facebook-graph-sdk/tests/GraphNodes/GraphEdgeTest.php
+++ b/lib/facebook-graph-sdk/tests/GraphNodes/GraphEdgeTest.php
@@ -1,6 +1,6 @@
<?php
/**
- * Copyright 2014 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
*
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
* use, copy, modify, and distribute this software in source code or binary
@@ -26,6 +26,7 @@ namespace Facebook\Tests\GraphNodes;
use Facebook\FacebookApp;
use Facebook\FacebookRequest;
use Facebook\GraphNodes\GraphEdge;
+use Facebook\GraphNodes\GraphNode;
class GraphEdgeTest extends \PHPUnit_Framework_TestCase
{
@@ -35,18 +36,12 @@ class GraphEdgeTest extends \PHPUnit_Framework_TestCase
*/
protected $request;
- protected $basePagination = [
+ protected $pagination = [
'next' => 'https://graph.facebook.com/v7.12/998899/photos?pretty=0&limit=25&after=foo_after_cursor',
'previous' => 'https://graph.facebook.com/v7.12/998899/photos?pretty=0&limit=25&before=foo_before_cursor',
];
- protected $cursorPagination = [
- 'cursors' => [
- 'after' => 'bar_after_cursor',
- 'before' => 'bar_before_cursor',
- ],
- ];
- public function setUp()
+ protected function setUp()
{
$app = new FacebookApp('123', 'foo_app_secret');
$this->request = new FacebookRequest(
@@ -75,7 +70,7 @@ class GraphEdgeTest extends \PHPUnit_Framework_TestCase
$graphEdge = new GraphEdge(
$this->request,
[],
- ['paging' => $this->basePagination]
+ ['paging' => $this->pagination]
);
$nextPage = $graphEdge->getPaginationUrl('next');
$prevPage = $graphEdge->getPaginationUrl('previous');
@@ -84,37 +79,52 @@ class GraphEdgeTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('/998899/photos?pretty=0&limit=25&before=foo_before_cursor', $prevPage);
}
- public function testCanGeneratePaginationEndpointsFromACursor()
+ public function testCanInstantiateNewPaginationRequest()
{
$graphEdge = new GraphEdge(
$this->request,
[],
- ['paging' => $this->cursorPagination],
+ ['paging' => $this->pagination],
'/1234567890/likes'
);
- $nextPage = $graphEdge->getPaginationUrl('next');
- $prevPage = $graphEdge->getPaginationUrl('previous');
+ $nextPage = $graphEdge->getNextPageRequest();
+ $prevPage = $graphEdge->getPreviousPageRequest();
- $this->assertEquals('/1234567890/likes?access_token=foo_token&after=bar_after_cursor&appsecret_proof=857d5f035a894f16b4180f19966e055cdeab92d4d53017b13dccd6d43b6497af&foo=bar&keep=me', $nextPage);
- $this->assertEquals('/1234567890/likes?access_token=foo_token&appsecret_proof=857d5f035a894f16b4180f19966e055cdeab92d4d53017b13dccd6d43b6497af&before=bar_before_cursor&foo=bar&keep=me', $prevPage);
+ $this->assertInstanceOf('Facebook\FacebookRequest', $nextPage);
+ $this->assertInstanceOf('Facebook\FacebookRequest', $prevPage);
+ $this->assertNotSame($this->request, $nextPage);
+ $this->assertNotSame($this->request, $prevPage);
+ $this->assertEquals('/v1337/998899/photos?access_token=foo_token&after=foo_after_cursor&appsecret_proof=857d5f035a894f16b4180f19966e055cdeab92d4d53017b13dccd6d43b6497af&foo=bar&limit=25&pretty=0', $nextPage->getUrl());
+ $this->assertEquals('/v1337/998899/photos?access_token=foo_token&appsecret_proof=857d5f035a894f16b4180f19966e055cdeab92d4d53017b13dccd6d43b6497af&before=foo_before_cursor&foo=bar&limit=25&pretty=0', $prevPage->getUrl());
}
- public function testCanInstantiateNewPaginationRequest()
+ public function testCanMapOverNodes()
{
$graphEdge = new GraphEdge(
$this->request,
- [],
- ['paging' => $this->cursorPagination],
+ [
+ new GraphNode(['name' => 'dummy']),
+ new GraphNode(['name' => 'dummy']),
+ ],
+ ['paging' => $this->pagination],
'/1234567890/likes'
);
- $nextPage = $graphEdge->getNextPageRequest();
- $prevPage = $graphEdge->getPreviousPageRequest();
- $this->assertInstanceOf('Facebook\FacebookRequest', $nextPage);
- $this->assertInstanceOf('Facebook\FacebookRequest', $prevPage);
- $this->assertNotSame($this->request, $nextPage);
- $this->assertNotSame($this->request, $prevPage);
- $this->assertEquals('/v1337/1234567890/likes?access_token=foo_token&after=bar_after_cursor&appsecret_proof=857d5f035a894f16b4180f19966e055cdeab92d4d53017b13dccd6d43b6497af&foo=bar&keep=me', $nextPage->getUrl());
- $this->assertEquals('/v1337/1234567890/likes?access_token=foo_token&appsecret_proof=857d5f035a894f16b4180f19966e055cdeab92d4d53017b13dccd6d43b6497af&before=bar_before_cursor&foo=bar&keep=me', $prevPage->getUrl());
+ $graphEdge = $graphEdge->map(function (GraphNode $node) {
+ $node['name'] = str_replace('dummy', 'foo', $node['name']);
+ return $node;
+ });
+
+ $graphEdgeToCompare = new GraphEdge(
+ $this->request,
+ [
+ new GraphNode(['name' => 'foo']),
+ new GraphNode(['name' => 'foo'])
+ ],
+ ['paging' => $this->pagination],
+ '/1234567890/likes'
+ );
+
+ $this->assertEquals($graphEdgeToCompare, $graphEdge);
}
}
diff --git a/lib/facebook-graph-sdk/tests/GraphNodes/GraphEventTest.php b/lib/facebook-graph-sdk/tests/GraphNodes/GraphEventTest.php
index 98ccd85..7c6f127 100644
--- a/lib/facebook-graph-sdk/tests/GraphNodes/GraphEventTest.php
+++ b/lib/facebook-graph-sdk/tests/GraphNodes/GraphEventTest.php
@@ -1,6 +1,6 @@
<?php
/**
- * Copyright 2014 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
*
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
* use, copy, modify, and distribute this software in source code or binary
@@ -34,7 +34,7 @@ class GraphEventTest extends \PHPUnit_Framework_TestCase
*/
protected $responseMock;
- public function setUp()
+ protected function setUp()
{
$this->responseMock = m::mock('\Facebook\FacebookResponse');
}
diff --git a/lib/facebook-graph-sdk/tests/GraphNodes/GraphGroupTest.php b/lib/facebook-graph-sdk/tests/GraphNodes/GraphGroupTest.php
index 21893b5..c62d50f 100644
--- a/lib/facebook-graph-sdk/tests/GraphNodes/GraphGroupTest.php
+++ b/lib/facebook-graph-sdk/tests/GraphNodes/GraphGroupTest.php
@@ -1,6 +1,6 @@
<?php
/**
- * Copyright 2014 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
*
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
* use, copy, modify, and distribute this software in source code or binary
@@ -34,7 +34,7 @@ class GraphGroupTest extends \PHPUnit_Framework_TestCase
*/
protected $responseMock;
- public function setUp()
+ protected function setUp()
{
$this->responseMock = m::mock('\Facebook\FacebookResponse');
}
diff --git a/lib/facebook-graph-sdk/tests/GraphNodes/GraphNodeFactoryTest.php b/lib/facebook-graph-sdk/tests/GraphNodes/GraphNodeFactoryTest.php
index 7d2f023..a4aa5e1 100644
--- a/lib/facebook-graph-sdk/tests/GraphNodes/GraphNodeFactoryTest.php
+++ b/lib/facebook-graph-sdk/tests/GraphNodes/GraphNodeFactoryTest.php
@@ -1,6 +1,6 @@
<?php
/**
- * Copyright 2014 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
*
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
* use, copy, modify, and distribute this software in source code or binary
@@ -27,18 +27,6 @@ use Facebook\FacebookApp;
use Facebook\FacebookRequest;
use Facebook\FacebookResponse;
use Facebook\GraphNodes\GraphNodeFactory;
-use Facebook\GraphNodes\GraphNode;
-
-class MyFooSubClassGraphNode extends GraphNode
-{
-}
-
-class MyFooGraphNode extends GraphNode
-{
- protected static $graphObjectMap = [
- 'foo_object' => '\Facebook\Tests\GraphNodes\MyFooSubClassGraphNode',
- ];
-}
class GraphNodeFactoryTest extends \PHPUnit_Framework_TestCase
{
@@ -47,7 +35,7 @@ class GraphNodeFactoryTest extends \PHPUnit_Framework_TestCase
*/
protected $request;
- public function setUp()
+ protected function setUp()
{
$app = new FacebookApp('123', 'foo_app_secret');
$this->request = new FacebookRequest(
@@ -126,7 +114,7 @@ class GraphNodeFactoryTest extends \PHPUnit_Framework_TestCase
{
GraphNodeFactory::validateSubclass('\Facebook\GraphNodes\GraphNode');
GraphNodeFactory::validateSubclass('\Facebook\GraphNodes\GraphAlbum');
- GraphNodeFactory::validateSubclass('\Facebook\Tests\GraphNodes\MyFooGraphNode');
+ GraphNodeFactory::validateSubclass('\Facebook\Tests\Fixtures\MyFooGraphNode');
}
public function testCastingAsASubClassObjectWillInstantiateTheSubClass()
@@ -135,9 +123,9 @@ class GraphNodeFactoryTest extends \PHPUnit_Framework_TestCase
$res = new FacebookResponse($this->request, $data);
$factory = new GraphNodeFactory($res);
- $mySubClassObject = $factory->makeGraphNode('\Facebook\Tests\GraphNodes\MyFooGraphNode');
+ $mySubClassObject = $factory->makeGraphNode('\Facebook\Tests\Fixtures\MyFooGraphNode');
- $this->assertInstanceOf('\Facebook\Tests\GraphNodes\MyFooGraphNode', $mySubClassObject);
+ $this->assertInstanceOf('\Facebook\Tests\Fixtures\MyFooGraphNode', $mySubClassObject);
}
public function testASubClassMappingWillAutomaticallyInstantiateSubClass()
@@ -146,11 +134,11 @@ class GraphNodeFactoryTest extends \PHPUnit_Framework_TestCase
$res = new FacebookResponse($this->request, $data);
$factory = new GraphNodeFactory($res);
- $mySubClassObject = $factory->makeGraphNode('\Facebook\Tests\GraphNodes\MyFooGraphNode');
+ $mySubClassObject = $factory->makeGraphNode('\Facebook\Tests\Fixtures\MyFooGraphNode');
$fooObject = $mySubClassObject->getField('foo_object');
- $this->assertInstanceOf('\Facebook\Tests\GraphNodes\MyFooGraphNode', $mySubClassObject);
- $this->assertInstanceOf('\Facebook\Tests\GraphNodes\MyFooSubClassGraphNode', $fooObject);
+ $this->assertInstanceOf('\Facebook\Tests\Fixtures\MyFooGraphNode', $mySubClassObject);
+ $this->assertInstanceOf('\Facebook\Tests\Fixtures\MyFooSubClassGraphNode', $fooObject);
}
public function testAnUnknownGraphNodeWillBeCastAsAGenericGraphNode()
@@ -167,12 +155,12 @@ class GraphNodeFactoryTest extends \PHPUnit_Framework_TestCase
$factory = new GraphNodeFactory($res);
- $mySubClassObject = $factory->makeGraphNode('\Facebook\Tests\GraphNodes\MyFooGraphNode');
+ $mySubClassObject = $factory->makeGraphNode('\Facebook\Tests\Fixtures\MyFooGraphNode');
$unknownObject = $mySubClassObject->getField('unknown_object');
- $this->assertInstanceOf('\Facebook\Tests\GraphNodes\MyFooGraphNode', $mySubClassObject);
+ $this->assertInstanceOf('\Facebook\Tests\Fixtures\MyFooGraphNode', $mySubClassObject);
$this->assertInstanceOf('\Facebook\GraphNodes\GraphNode', $unknownObject);
- $this->assertNotInstanceOf('\Facebook\Tests\GraphNodes\MyFooGraphNode', $unknownObject);
+ $this->assertNotInstanceOf('\Facebook\Tests\Fixtures\MyFooGraphNode', $unknownObject);
}
public function testAListFromGraphWillBeCastAsAGraphEdge()
diff --git a/lib/facebook-graph-sdk/tests/GraphNodes/GraphNodeTest.php b/lib/facebook-graph-sdk/tests/GraphNodes/GraphNodeTest.php
index 50f58ae..67444fa 100644
--- a/lib/facebook-graph-sdk/tests/GraphNodes/GraphNodeTest.php
+++ b/lib/facebook-graph-sdk/tests/GraphNodes/GraphNodeTest.php
@@ -1,6 +1,6 @@
<?php
/**
- * Copyright 2014 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
*
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
* use, copy, modify, and distribute this software in source code or binary
diff --git a/lib/facebook-graph-sdk/tests/GraphNodes/GraphObjectFactoryTest.php b/lib/facebook-graph-sdk/tests/GraphNodes/GraphObjectFactoryTest.php
index 764503a..3ef1d0b 100644
--- a/lib/facebook-graph-sdk/tests/GraphNodes/GraphObjectFactoryTest.php
+++ b/lib/facebook-graph-sdk/tests/GraphNodes/GraphObjectFactoryTest.php
@@ -1,6 +1,6 @@
<?php
/**
- * Copyright 2014 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
*
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
* use, copy, modify, and distribute this software in source code or binary
@@ -38,7 +38,7 @@ class GraphObjectFactoryTest extends \PHPUnit_Framework_TestCase
*/
protected $request;
- public function setUp()
+ protected function setUp()
{
$app = new FacebookApp('123', 'foo_app_secret');
$this->request = new FacebookRequest(
diff --git a/lib/facebook-graph-sdk/tests/GraphNodes/GraphPageTest.php b/lib/facebook-graph-sdk/tests/GraphNodes/GraphPageTest.php
index a3a88e9..c7ce163 100644
--- a/lib/facebook-graph-sdk/tests/GraphNodes/GraphPageTest.php
+++ b/lib/facebook-graph-sdk/tests/GraphNodes/GraphPageTest.php
@@ -1,6 +1,6 @@
<?php
/**
- * Copyright 2014 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
*
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
* use, copy, modify, and distribute this software in source code or binary
@@ -33,7 +33,7 @@ class GraphPageTest extends \PHPUnit_Framework_TestCase
*/
protected $responseMock;
- public function setUp()
+ protected function setUp()
{
$this->responseMock = m::mock('\\Facebook\\FacebookResponse');
}
diff --git a/lib/facebook-graph-sdk/tests/GraphNodes/GraphSessionInfoTest.php b/lib/facebook-graph-sdk/tests/GraphNodes/GraphSessionInfoTest.php
index 2960c28..b2e56fa 100644
--- a/lib/facebook-graph-sdk/tests/GraphNodes/GraphSessionInfoTest.php
+++ b/lib/facebook-graph-sdk/tests/GraphNodes/GraphSessionInfoTest.php
@@ -1,6 +1,6 @@
<?php
/**
- * Copyright 2014 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
*
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
* use, copy, modify, and distribute this software in source code or binary
@@ -33,7 +33,7 @@ class GraphSessionInfoTest extends \PHPUnit_Framework_TestCase
*/
protected $responseMock;
- public function setUp()
+ protected function setUp()
{
$this->responseMock = m::mock('\\Facebook\\FacebookResponse');
}
diff --git a/lib/facebook-graph-sdk/tests/GraphNodes/GraphUserTest.php b/lib/facebook-graph-sdk/tests/GraphNodes/GraphUserTest.php
index ca75573..a3230fa 100644
--- a/lib/facebook-graph-sdk/tests/GraphNodes/GraphUserTest.php
+++ b/lib/facebook-graph-sdk/tests/GraphNodes/GraphUserTest.php
@@ -1,6 +1,6 @@
<?php
/**
- * Copyright 2014 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
*
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
* use, copy, modify, and distribute this software in source code or binary
@@ -34,7 +34,7 @@ class GraphUserTest extends \PHPUnit_Framework_TestCase
*/
protected $responseMock;
- public function setUp()
+ protected function setUp()
{
$this->responseMock = m::mock('\\Facebook\\FacebookResponse');
}
@@ -42,7 +42,25 @@ class GraphUserTest extends \PHPUnit_Framework_TestCase
public function testDatesGetCastToDateTime()
{
$dataFromGraph = [
- 'birthday' => '1984-01-01',
+ 'updated_time' => '2016-04-26 13:22:05',
+ ];
+
+ $this->responseMock
+ ->shouldReceive('getDecodedBody')
+ ->once()
+ ->andReturn($dataFromGraph);
+ $factory = new GraphNodeFactory($this->responseMock);
+ $graphNode = $factory->makeGraphUser();
+
+ $updatedTime = $graphNode->getField('updated_time');
+
+ $this->assertInstanceOf('DateTime', $updatedTime);
+ }
+
+ public function testBirthdaysGetCastToBirthday()
+ {
+ $dataFromGraph = [
+ 'birthday' => '1984/01/01',
];
$this->responseMock
@@ -54,7 +72,53 @@ class GraphUserTest extends \PHPUnit_Framework_TestCase
$birthday = $graphNode->getBirthday();
+ // Test to ensure BC
$this->assertInstanceOf('DateTime', $birthday);
+
+ $this->assertInstanceOf('\\Facebook\\GraphNodes\\Birthday', $birthday);
+ $this->assertTrue($birthday->hasDate());
+ $this->assertTrue($birthday->hasYear());
+ $this->assertEquals('1984/01/01', $birthday->format('Y/m/d'));
+ }
+
+ public function testBirthdayCastHandlesDateWithoutYear()
+ {
+ $dataFromGraph = [
+ 'birthday' => '03/21',
+ ];
+
+ $this->responseMock
+ ->shouldReceive('getDecodedBody')
+ ->once()
+ ->andReturn($dataFromGraph);
+ $factory = new GraphNodeFactory($this->responseMock);
+ $graphNode = $factory->makeGraphUser();
+
+ $birthday = $graphNode->getBirthday();
+
+ $this->assertTrue($birthday->hasDate());
+ $this->assertFalse($birthday->hasYear());
+ $this->assertEquals('03/21', $birthday->format('m/d'));
+ }
+
+ public function testBirthdayCastHandlesYearWithoutDate()
+ {
+ $dataFromGraph = [
+ 'birthday' => '1984',
+ ];
+
+ $this->responseMock
+ ->shouldReceive('getDecodedBody')
+ ->once()
+ ->andReturn($dataFromGraph);
+ $factory = new GraphNodeFactory($this->responseMock);
+ $graphNode = $factory->makeGraphUser();
+
+ $birthday = $graphNode->getBirthday();
+
+ $this->assertTrue($birthday->hasYear());
+ $this->assertFalse($birthday->hasDate());
+ $this->assertEquals('1984', $birthday->format('Y'));
}
public function testPagePropertiesWillGetCastAsGraphPageObjects()