Permalink
Browse files

ENHANCEMENT: add test to Oembed

  • Loading branch information...
1 parent 32817b4 commit 5b845248edae640a7e8bac877488a9177c2fafa1 @mateusz mateusz committed May 24, 2012
Showing with 37 additions and 0 deletions.
  1. +4 −0 oembed/Oembed.php
  2. +33 −0 tests/oembed/OembedTest.php
View
4 oembed/Oembed.php
@@ -202,6 +202,10 @@ public function __construct($url, $origin = false, $type = false, array $options
parent::__construct();
}
+
+ public function getOembedURL() {
+ return $this->url;
+ }
/**
* Fetches the JSON data from the Oembed URL (cached).
View
33 tests/oembed/OembedTest.php
@@ -0,0 +1,33 @@
+<?php
+
+class OembedTest extends SapphireTest {
+ function testGetOembedFromUrl() {
+ Config::inst()->update('Oembed', 'providers', array(
+ 'http://*.silverstripe.com/watch*'=>'http://www.silverstripe.com/oembed/'
+ ));
+ $escapedEndpointURL = urlencode("http://www.silverstripe.com/oembed/");
+
+ // Test with valid URL
+ $result = Oembed::get_oembed_from_url('http://www.silverstripe.com/watch12345');
+ $this->assertTrue($result!=false);
+ $this->assertEquals($result->getOembedURL(), 'http://www.silverstripe.com/oembed/?format=json&url='.urlencode('http://www.silverstripe.com/watch12345'), 'Triggers on matching URL');
+
+ // Test without www.
+ $result = Oembed::get_oembed_from_url('http://silverstripe.com/watch12345');
+ $this->assertTrue($result!=false);
+ $this->assertEquals($result->getOembedURL(), 'http://www.silverstripe.com/oembed/?format=json&url='.urlencode('http://silverstripe.com/watch12345'), 'Triggers on matching URL without www');
+
+ // Test if options make their way to the URL
+ $result = Oembed::get_oembed_from_url('http://www.silverstripe.com/watch12345', false, array('foo'=>'bar'));
+ $this->assertTrue($result!=false);
+ $this->assertEquals($result->getOembedURL(), 'http://www.silverstripe.com/oembed/?format=json&url='.urlencode('http://www.silverstripe.com/watch12345').'&foo=bar', 'Includes options');
+
+ // Test magic.
+ $result = Oembed::get_oembed_from_url('http://www.silverstripe.com/watch12345', false, array('height'=>'foo', 'width'=>'bar'));
+ $this->assertTrue($result!=false);
+ $urlParts = parse_url($result->getOembedURL());
+ parse_str($urlParts['query'], $query);
+ $this->assertEquals($query['maxheight'], 'foo', 'Magically creates maxheight option');
+ $this->assertEquals($query['maxwidth'], 'bar', 'Magically creates maxwidth option');
+ }
+}

0 comments on commit 5b84524

Please sign in to comment.