2012-05-24 06:51:30 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class OembedTest extends SapphireTest {
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testGetOembedFromUrl() {
|
2012-05-24 06:51:30 +02:00
|
|
|
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);
|
2012-09-26 23:34:00 +02:00
|
|
|
$this->assertEquals($result->getOembedURL(),
|
|
|
|
'http://www.silverstripe.com/oembed/?format=json&url='.urlencode('http://www.silverstripe.com/watch12345'),
|
|
|
|
'Triggers on matching URL');
|
2012-05-24 06:51:30 +02:00
|
|
|
|
|
|
|
// Test without www.
|
|
|
|
$result = Oembed::get_oembed_from_url('http://silverstripe.com/watch12345');
|
|
|
|
$this->assertTrue($result!=false);
|
2012-09-26 23:34:00 +02:00
|
|
|
$this->assertEquals($result->getOembedURL(),
|
|
|
|
'http://www.silverstripe.com/oembed/?format=json&url='.urlencode('http://silverstripe.com/watch12345'),
|
|
|
|
'Triggers on matching URL without www');
|
2012-05-24 06:51:30 +02:00
|
|
|
|
|
|
|
// 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);
|
2012-09-26 23:34:00 +02:00
|
|
|
$this->assertEquals($result->getOembedURL(), 'http://www.silverstripe.com/oembed/?format=json&url='
|
|
|
|
. urlencode('http://www.silverstripe.com/watch12345').'&foo=bar',
|
|
|
|
'Includes options');
|
2012-05-24 06:51:30 +02:00
|
|
|
|
|
|
|
// Test magic.
|
2012-09-26 23:34:00 +02:00
|
|
|
$result = Oembed::get_oembed_from_url('http://www.silverstripe.com/watch12345', false,
|
|
|
|
array('height'=>'foo', 'width'=>'bar'));
|
2012-05-24 06:51:30 +02:00
|
|
|
$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');
|
|
|
|
}
|
|
|
|
}
|