@@ -429,9 +429,9 @@ public function testGetPageInsightsAudienceDataEmptyResponse()
429429
430430 $ facebook = new Facebook ();
431431 $ responseMock = m::mock ('\Facebook\FacebookResponse ' )
432- ->shouldReceive ('getDecodedBody ' )
433- ->once ()
434- ->andReturn ($ decodedAudienceData )
432+ ->shouldReceive ('getDecodedBody ' )
433+ ->once ()
434+ ->andReturn ($ decodedAudienceData )
435435 ->getMock ();
436436 $ facebookMock = m::mock ('\Facebook\Facebook ' );
437437 $ facebookMock ->shouldReceive ('sendRequest ' )->once ()->andReturn ($ responseMock );
@@ -1806,4 +1806,109 @@ public function testGetInstagramStoryInsightsWithMetricType()
18061806 'views ' => 500
18071807 ]);
18081808 }
1809+
1810+ public function testGetPageInsightsForTotalValueMetrics ()
1811+ {
1812+ $ decodedResponseData = [
1813+ 'data ' => [
1814+ [
1815+ 'name ' => 'page_impressions ' ,
1816+ 'period ' => 'day ' ,
1817+ 'total_value ' => [
1818+ 'value ' => 500
1819+ ]
1820+ ],
1821+ [
1822+ 'name ' => 'page_engaged_users ' ,
1823+ 'period ' => 'day ' ,
1824+ 'total_value ' => [
1825+ 'value ' => 100
1826+ ]
1827+ ]
1828+ ]
1829+ ];
1830+
1831+ $ facebook = new Facebook ();
1832+ $ responseMock = m::mock ('\Facebook\FacebookResponse ' )
1833+ ->shouldReceive ('getDecodedBody ' )
1834+ ->once ()
1835+ ->andReturn ($ decodedResponseData )
1836+ ->getMock ();
1837+ $ facebookMock = m::mock ('\Facebook\Facebook ' );
1838+
1839+ $ metrics = ['page_impressions ' , 'page_engaged_users ' ];
1840+ $ period = 'day ' ;
1841+ $ since = '1493826552 ' ;
1842+ $ until = '1496418552 ' ;
1843+ $ params = [
1844+ 'metric ' => join (', ' , $ metrics ),
1845+ 'metric_type ' => 'total_value ' ,
1846+ 'period ' => $ period ,
1847+ 'since ' => $ since ,
1848+ 'until ' => $ until ,
1849+ ];
1850+
1851+ $ facebookMock ->shouldReceive ('sendRequest ' )
1852+ ->once ()
1853+ ->with ('GET ' , '/ ' . self ::FB_PAGE_ID . '/insights ' , $ params )
1854+ ->andReturn ($ responseMock );
1855+ $ facebook ->setFacebookLibrary ($ facebookMock );
1856+
1857+ $ response = $ facebook ->getPageInsightsForTotalValueMetrics (
1858+ self ::FB_PAGE_ID ,
1859+ $ metrics ,
1860+ $ period ,
1861+ $ since ,
1862+ $ until
1863+ );
1864+
1865+ $ this ->assertEquals (500 , $ response ['page_impressions ' ]);
1866+ $ this ->assertEquals (100 , $ response ['page_engaged_users ' ]);
1867+ }
1868+
1869+ public function testGetPageInsightsForTotalValueMetricsEmptyResponse ()
1870+ {
1871+ $ facebook = new Facebook ();
1872+ $ responseMock = m::mock ('\Facebook\FacebookResponse ' )
1873+ ->shouldReceive ('getDecodedBody ' )
1874+ ->once ()
1875+ ->andReturn (['data ' => []])
1876+ ->getMock ();
1877+ $ facebookMock = m::mock ('\Facebook\Facebook ' );
1878+ $ facebookMock ->shouldReceive ('sendRequest ' )->once ()->andReturn ($ responseMock );
1879+ $ facebook ->setFacebookLibrary ($ facebookMock );
1880+
1881+ $ response = $ facebook ->getPageInsightsForTotalValueMetrics (
1882+ self ::FB_PAGE_ID ,
1883+ ['page_impressions ' ],
1884+ 'day ' ,
1885+ '1493826552 ' ,
1886+ '1496418552 '
1887+ );
1888+
1889+ $ this ->assertEquals ([], $ response );
1890+ }
1891+
1892+ public function testGetPageInsightsForTotalValueMetricsNullResponse ()
1893+ {
1894+ $ facebook = new Facebook ();
1895+ $ responseMock = m::mock ('\Facebook\FacebookResponse ' )
1896+ ->shouldReceive ('getDecodedBody ' )
1897+ ->once ()
1898+ ->andReturn (null )
1899+ ->getMock ();
1900+ $ facebookMock = m::mock ('\Facebook\Facebook ' );
1901+ $ facebookMock ->shouldReceive ('sendRequest ' )->once ()->andReturn ($ responseMock );
1902+ $ facebook ->setFacebookLibrary ($ facebookMock );
1903+
1904+ $ response = $ facebook ->getPageInsightsForTotalValueMetrics (
1905+ self ::FB_PAGE_ID ,
1906+ ['page_impressions ' ],
1907+ 'day ' ,
1908+ '1493826552 ' ,
1909+ '1496418552 '
1910+ );
1911+
1912+ $ this ->assertEquals ([], $ response );
1913+ }
18091914}
0 commit comments