Updated to Drupal 8.6.4, which is PHP 7.3 friendly. Also updated HTMLaw library....
[yaffs-website] / web / core / modules / media / tests / src / Unit / IFrameUrlHelperTest.php
1 <?php
2
3 namespace Drupal\Tests\media\Unit;
4
5 use Drupal\Core\PrivateKey;
6 use Drupal\Core\Routing\RequestContext;
7 use Drupal\media\IFrameUrlHelper;
8 use Drupal\Tests\UnitTestCase;
9
10 /**
11  * @coversDefaultClass \Drupal\media\IFrameUrlHelper
12  *
13  * @group media
14  */
15 class IFrameUrlHelperTest extends UnitTestCase {
16
17   /**
18    * Data provider for testIsSecure().
19    *
20    * @see ::testIsSecure()
21    *
22    * @return array
23    */
24   public function providerIsSecure() {
25     return [
26       'no domain' => [
27         '/path/to/media.php',
28         'http://www.example.com/',
29         FALSE,
30       ],
31       'no base URL domain' => [
32         'http://www.example.com/media.php',
33         '/invalid/base/url',
34         FALSE,
35       ],
36       'same domain' => [
37         'http://www.example.com/media.php',
38         'http://www.example.com/',
39         FALSE,
40       ],
41       'different domain' => [
42         'http://www.example.com/media.php',
43         'http://www.example-assets.com/',
44         TRUE,
45       ],
46       'same subdomain' => [
47         'http://foo.example.com/media.php',
48         'http://foo.example.com/',
49         FALSE,
50       ],
51       'different subdomain' => [
52         'http://assets.example.com/media.php',
53         'http://foo.example.com/',
54         TRUE,
55       ],
56       'subdomain and top-level domain' => [
57         'http://assets.example.com/media.php',
58         'http://example.com/',
59         TRUE,
60       ],
61     ];
62   }
63
64   /**
65    * Tests that isSecure() behaves properly.
66    *
67    * @param string $url
68    *   The URL to test for security.
69    * @param string $base_url
70    *   The base URL to compare $url against.
71    * @param bool $secure
72    *   The expected result of isSecure().
73    *
74    * @covers ::isSecure
75    *
76    * @dataProvider providerIsSecure
77    */
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()
84     );
85
86     $this->assertSame($secure, $url_helper->isSecure($url));
87   }
88
89 }