/**
  * Generates a pagination URL based on a cursor.
  *
  * @param string $direction The direction of the page: next|previous
  *
  * @return string|null
  *
  * @throws FacebookSDKException
  */
 public function getPaginationUrl($direction)
 {
     $this->validateForPagination();
     // Do we have a paging URL?
     if (isset($this->metaData['paging'][$direction])) {
         // Graph returns the full URL with all the original params.
         // We just want the endpoint though.
         $pageUrl = $this->metaData['paging'][$direction];
         return FacebookUrlManipulator::baseGraphUrlEndpoint($pageUrl);
     }
     // Do we have a cursor to work with?
     $cursorDirection = $direction === 'next' ? 'after' : 'before';
     $cursor = $this->getCursor($cursorDirection);
     if (!$cursor) {
         return null;
     }
     // If we don't know the ID of the parent node, this ain't gonna work.
     if (!$this->parentEdgeEndpoint) {
         return null;
     }
     // We have the parent node ID, paging cursor & original request.
     // These were the ingredients chosen to create the perfect little URL.
     $pageUrl = $this->parentEdgeEndpoint . '?' . $cursorDirection . '=' . urlencode($cursor);
     // Pull in the original params
     $originalUrl = $this->request->getUrl();
     $pageUrl = FacebookUrlManipulator::mergeUrlParams($originalUrl, $pageUrl);
     return FacebookUrlManipulator::forceSlashPrefix($pageUrl);
 }
 /**
  * @dataProvider provideMergableEndpoints
  */
 public function testParamsCanBeMergedOntoUrlProperly($urlOne, $urlTwo, $expected)
 {
     $result = FacebookUrlManipulator::mergeUrlParams($urlOne, $urlTwo);
     $this->assertEquals($result, $expected);
 }