annotate core/modules/media/tests/src/Unit/IFrameUrlHelperTest.php @ 5:12f9dff5fda9 tip

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents a9cd425dd02b
children
rev   line source
Chris@4 1 <?php
Chris@4 2
Chris@4 3 namespace Drupal\Tests\media\Unit;
Chris@4 4
Chris@4 5 use Drupal\Core\PrivateKey;
Chris@4 6 use Drupal\Core\Routing\RequestContext;
Chris@4 7 use Drupal\media\IFrameUrlHelper;
Chris@4 8 use Drupal\Tests\UnitTestCase;
Chris@4 9
Chris@4 10 /**
Chris@4 11 * @coversDefaultClass \Drupal\media\IFrameUrlHelper
Chris@4 12 *
Chris@4 13 * @group media
Chris@4 14 */
Chris@4 15 class IFrameUrlHelperTest extends UnitTestCase {
Chris@4 16
Chris@4 17 /**
Chris@4 18 * Data provider for testIsSecure().
Chris@4 19 *
Chris@4 20 * @see ::testIsSecure()
Chris@4 21 *
Chris@4 22 * @return array
Chris@4 23 */
Chris@4 24 public function providerIsSecure() {
Chris@4 25 return [
Chris@4 26 'no domain' => [
Chris@4 27 '/path/to/media.php',
Chris@4 28 'http://www.example.com/',
Chris@4 29 FALSE,
Chris@4 30 ],
Chris@4 31 'no base URL domain' => [
Chris@4 32 'http://www.example.com/media.php',
Chris@4 33 '/invalid/base/url',
Chris@4 34 FALSE,
Chris@4 35 ],
Chris@4 36 'same domain' => [
Chris@4 37 'http://www.example.com/media.php',
Chris@4 38 'http://www.example.com/',
Chris@4 39 FALSE,
Chris@4 40 ],
Chris@4 41 'different domain' => [
Chris@4 42 'http://www.example.com/media.php',
Chris@4 43 'http://www.example-assets.com/',
Chris@4 44 TRUE,
Chris@4 45 ],
Chris@4 46 'same subdomain' => [
Chris@4 47 'http://foo.example.com/media.php',
Chris@4 48 'http://foo.example.com/',
Chris@4 49 FALSE,
Chris@4 50 ],
Chris@4 51 'different subdomain' => [
Chris@4 52 'http://assets.example.com/media.php',
Chris@4 53 'http://foo.example.com/',
Chris@4 54 TRUE,
Chris@4 55 ],
Chris@4 56 'subdomain and top-level domain' => [
Chris@4 57 'http://assets.example.com/media.php',
Chris@4 58 'http://example.com/',
Chris@4 59 TRUE,
Chris@4 60 ],
Chris@4 61 ];
Chris@4 62 }
Chris@4 63
Chris@4 64 /**
Chris@4 65 * Tests that isSecure() behaves properly.
Chris@4 66 *
Chris@4 67 * @param string $url
Chris@4 68 * The URL to test for security.
Chris@4 69 * @param string $base_url
Chris@4 70 * The base URL to compare $url against.
Chris@4 71 * @param bool $secure
Chris@4 72 * The expected result of isSecure().
Chris@4 73 *
Chris@4 74 * @covers ::isSecure
Chris@4 75 *
Chris@4 76 * @dataProvider providerIsSecure
Chris@4 77 */
Chris@4 78 public function testIsSecure($url, $base_url, $secure) {
Chris@4 79 $request_context = $this->prophesize(RequestContext::class);
Chris@4 80 $request_context->getCompleteBaseUrl()->willReturn($base_url);
Chris@4 81 $url_helper = new IFrameUrlHelper(
Chris@4 82 $request_context->reveal(),
Chris@4 83 $this->prophesize(PrivateKey::class)->reveal()
Chris@4 84 );
Chris@4 85
Chris@4 86 $this->assertSame($secure, $url_helper->isSecure($url));
Chris@4 87 }
Chris@4 88
Chris@4 89 }