public static function getLinkHref(\SimpleXMLElement $xml, $rel) { foreach ($xml->link as $link) { $attributes = $link->attributes(); if ($attributes['rel']->__toString() === $rel) { return $attributes['href']->__toString(); } } throw new Exception('No link found with rel "' . $rel . '"'); }
public function testGetLinkHref() { $xml = new SimpleXMLElement(file_get_contents(__DIR__ . '/xml/worksheet.xml')); $expected = 'https://spreadsheets.google.com/feeds/worksheets/tA3TdJ0RIVEem3xQZhG2Ceg/private/full/od8'; $actual = Util::getLinkHref($xml, 'self'); $this->assertEquals($expected, $actual); }