コード例 #1
0
ファイル: LinksTest.php プロジェクト: Joal01/fof
 /**
  * @covers FOF30\Hal\Links::addLinks
  */
 function testAddLinks()
 {
     // Create a sample link
     $link = new Link('http://www.example.com/nada.json');
     $linkset = new Links();
     // ==== Try to add an empty array ====
     $result = $linkset->addLinks('boz', array());
     $this->assertFalse($result);
     // ==== Add a link to a link set ====
     $result = $linkset->addLink('custom', $link);
     // ==== Replace the link in the link set ====
     $newlinks = array(new Link('http://www.example.com/yeah.json', false, 'Something'), new Link('http://www.example.com/another.json', false, 'Something else'));
     $result = $linkset->addLinks('custom', $newlinks, true);
     $links = $this->readAttribute($linkset, '_links');
     $this->assertArrayHasKey('custom', $links, 'The link set must have an array key for our replaced rel');
     $this->assertInternalType('array', $links['custom']);
     $this->assertEquals($newlinks[0], $links['custom'][0]);
     $this->assertEquals($newlinks[1], $links['custom'][1]);
     // ==== Append to an existing set ====
     $result = $linkset->addLink('custom', $link, true);
     $result = $linkset->addLinks('custom', $newlinks, false);
     $links = $this->readAttribute($linkset, '_links');
     $this->assertArrayHasKey('custom', $links, 'The link set must have an array key for our replaced rel');
     $this->assertInternalType('array', $links['custom']);
     $this->assertEquals($link, $links['custom'][0]);
     $this->assertEquals($newlinks[0], $links['custom'][1]);
     $this->assertEquals($newlinks[1], $links['custom'][2]);
 }
コード例 #2
0
ファイル: Document.php プロジェクト: akeeba/fof
 /**
  * Add a link to the document
  *
  * @param   string   $rel        The relation of the link to the document.
  *                               See RFC 5988 http://tools.ietf.org/html/rfc5988#section-6.2.2 A document MUST always have
  *                               a "self" link.
  * @param   Link     $link       The actual link object
  * @param   boolean  $overwrite  When false and a link of $rel relation exists, an array of links is created. Otherwise the
  *                              existing link is overwriten with the new one
  *
  * @see Links::addLink
  *
  * @return  boolean  True if the link was added to the collection
  */
 public function addLink($rel, Link $link, $overwrite = true)
 {
     return $this->_links->addLink($rel, $link, $overwrite);
 }