Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions OpenGraph.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@ static public function fetch($URI) {
}
}


/**
* Public wrapper for the _parse method
*
* @param $HTML HTML to parse
* @return OpenGraph
*/
static public function parse($HTML) {
return self::_parse($HTML);
}


/**
* Parses HTML and extracts Open Graph data, this assumes
* the document is at least well formed.
Expand Down
39 changes: 38 additions & 1 deletion OpenGraphTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public function testFetch()
'http://www.rottentomatoes.com/m/10011268-oceans/'
);

$this->assertType('OpenGraph', $o);
$this->assertEquals('OpenGraph', get_class($o));

$this->assertAttributeEquals(
array(
Expand All @@ -28,4 +28,41 @@ public function testFetchReturnsFalseForWebsiteWithNoOpenGraphMetadata()
{
$this->assertEquals(FALSE, OpenGraph::fetch('http://www.example.org/'));
}

/**
* Tests that the public method parse method can work for a url with og data present
*/
public function testParsePublicMethodSuccess()
{
$curl = curl_init('http://www.rottentomatoes.com/m/10011268-oceans/');

curl_setopt($curl, CURLOPT_FAILONERROR, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 15);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
//curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);

$response = curl_exec($curl);

curl_close($curl);

$o = OpenGraph::parse($response);
$this->assertAttributeEquals(
array(
'title' => "Oceans (Disneynature's Oceans)",
'type' => 'video.movie',
'image' => 'http://content9.flixster.com/movie/11/04/79/11047971_800.jpg',
'url' => 'http://www.rottentomatoes.com/m/10011268-oceans/',
'image:width' => '800',
'image:height' => '1200',
'description' => 'Oceans adds another visually stunning chapter to the Disney Nature library.'

),
'_values',
$o
);
}

}