Completed
Push — master ( 5cace7...20fac0 )
by Sam
32:27 queued 20:32
created

EmbedShortcodeProviderTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 44
rs 10
wmc 3
lcom 1
cbo 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testYoutube() 0 12 1
A testSoundcloud() 0 12 1
1
<?php
2
3
4
use Embed\Adapters\Webpage;
5
use Embed\Embed;
6
use SilverStripe\Forms\HtmlEditor\EmbedShortcodeProvider;
7
8
/**
9
 * Class EmbedShortcodeProviderTest
10
 *
11
 * Because Embed/Embed does not have a mockup, the tests have to run against a live environment.
12
 * I've tried to fix it by serializing the data to a file, but to no avail.
13
 * Any improvements on not having to call external resources are welcome.
14
 */
15
class EmbedShortcodeProviderTest extends SapphireTest
16
{
17
18
	/**
19
	 * @var string test youtube. The SilverStripe Platform promotion by UncleCheese
20
	 */
21
	protected static $test_youtube = 'https://www.youtube.com/watch?v=dM15HfUYwF0';
22
23
	/**
24
	 * @var string test Soundcloud. One of my favorite bands, Delain, Suckerpunch.
25
	 */
26
	protected static $test_soundcloud = 'http://soundcloud.com/napalmrecords/delain-suckerpunch';
27
28
	public function setUp()
29
	{
30
		return parent::setUp();
31
	}
32
33
	public function testYoutube()
34
	{
35
		/** @var Webpage $result */
36
		$result = Embed::create(self::$test_youtube, array());
37
		self::assertEquals($result->providerName, 'YouTube');
38
		$embedded = EmbedShortcodeProvider::embedForTemplate($result);
39
		self::assertContains("<div class='media'", $embedded);
40
		self::assertContains('iframe', $embedded);
41
		self::assertContains('youtube.com', $embedded);
42
		self::assertContains('embed', $embedded);
43
		self::assertContains('dM15HfUYwF0', $embedded);
44
	}
45
46
	public function testSoundcloud()
47
	{
48
		/** @var Webpage $result */
49
		$result = Embed::create(self::$test_soundcloud, array());
50
		self::assertEquals($result->providerName, 'SoundCloud');
51
		$embedded = EmbedShortcodeProvider::embedForTemplate($result);
52
		self::assertContains("<div class='media'", $embedded);
53
		self::assertContains('iframe', $embedded);
54
		self::assertContains('soundcloud.com', $embedded);
55
		self::assertContains('player', $embedded);
56
		self::assertContains('tracks%2F242518079', $embedded);
57
	}
58
}
59
60