From 4b8a9a5189a625bf99fedec7fd31f6e146410a14 Mon Sep 17 00:00:00 2001 From: emkael Date: Thu, 26 Apr 2018 01:00:12 +0200 Subject: Update FB API library --- .../tests/GraphNodes/GraphUserTest.php | 70 +++++++++++++++++++++- 1 file changed, 67 insertions(+), 3 deletions(-) (limited to 'lib/facebook-graph-sdk/tests/GraphNodes/GraphUserTest.php') 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 @@ 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() -- cgit v1.2.3