3 namespace Drupal\Tests\media\Unit;
5 use Drupal\Core\PrivateKey;
6 use Drupal\Core\Routing\RequestContext;
7 use Drupal\media\IFrameUrlHelper;
8 use Drupal\Tests\UnitTestCase;
11 * @coversDefaultClass \Drupal\media\IFrameUrlHelper
15 class IFrameUrlHelperTest extends UnitTestCase {
18 * Data provider for testIsSecure().
20 * @see ::testIsSecure()
24 public function providerIsSecure() {
28 'http://www.example.com/',
31 'no base URL domain' => [
32 'http://www.example.com/media.php',
37 'http://www.example.com/media.php',
38 'http://www.example.com/',
41 'different domain' => [
42 'http://www.example.com/media.php',
43 'http://www.example-assets.com/',
47 'http://foo.example.com/media.php',
48 'http://foo.example.com/',
51 'different subdomain' => [
52 'http://assets.example.com/media.php',
53 'http://foo.example.com/',
56 'subdomain and top-level domain' => [
57 'http://assets.example.com/media.php',
58 'http://example.com/',
65 * Tests that isSecure() behaves properly.
68 * The URL to test for security.
69 * @param string $base_url
70 * The base URL to compare $url against.
72 * The expected result of isSecure().
76 * @dataProvider providerIsSecure
78 public function testIsSecure($url, $base_url, $secure) {
79 $request_context = $this->prophesize(RequestContext::class);
80 $request_context->getCompleteBaseUrl()->willReturn($base_url);
81 $url_helper = new IFrameUrlHelper(
82 $request_context->reveal(),
83 $this->prophesize(PrivateKey::class)->reveal()
86 $this->assertSame($secure, $url_helper->isSecure($url));