From 770d47ed8ab0ead00947d5f147fd8113b088c573 Mon Sep 17 00:00:00 2001 From: Daniel Mican Date: Thu, 15 Aug 2013 13:47:52 -0400 Subject: [PATCH] Created public parse method --- OpenGraph.php | 12 ++++++++++++ OpenGraphTest.php | 39 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/OpenGraph.php b/OpenGraph.php index af2e7b6..fcbad96 100644 --- a/OpenGraph.php +++ b/OpenGraph.php @@ -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. diff --git a/OpenGraphTest.php b/OpenGraphTest.php index 130ca5f..3f24a97 100644 --- a/OpenGraphTest.php +++ b/OpenGraphTest.php @@ -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( @@ -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 + ); + } + }