Skip to content

Commit

Permalink
EWPP-4267: Add override for webtools iframe URL.
Browse files Browse the repository at this point in the history
  • Loading branch information
sergepavle committed Jun 12, 2024
1 parent 2d7c64d commit 3906eef
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ declare(strict_types=1);

use Drupal\Component\Serialization\Json;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Site\Settings;
use Drupal\Core\Url;
use Drupal\media\IFrameMarkup;
use Drupal\oe_webtools_cookie_consent\Event\ConfigBannerPopupEvent;
use Drupal\oe_webtools_cookie_consent\Event\ConfigVideoPopupEvent;
use Drupal\oe_webtools_cookie_consent\Form\WebtoolsCookieConsentSettingsForm;

const OE_WEBTOOLS_COOKIE_CONSENT_EMBED_COOKIE_URL = '//webtools.europa.eu/crs/iframe/';
define("OE_WEBTOOLS_COOKIE_CONSENT_EMBED_COOKIE_URL", Settings::get('webtools_cookie_consent_embed_cookie_url') ?? '//webtools.europa.eu/crs/iframe/');

/**
* Implements hook_page_attachments().
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class IframeFilterPluginKernelTest extends KernelTestBase {
'system',
'filter',
'language',
'oe_webtools_cookie_consent',
];

/**
Expand All @@ -40,6 +39,9 @@ protected function setUp(): void {
* Tests the iframe with cookie consent kit filter.
*/
public function testIframeFilter() {
// Enable the module inside test method to allow other tests to initialize
// with specific settings.
$this->enableModules(['oe_webtools_cookie_consent']);
$manager = $this->container->get('plugin.manager.filter');
$filters = new FilterPluginCollection($manager, []);
$cck_filter = $filters->get('filter_iframe_cck');
Expand All @@ -56,4 +58,21 @@ public function testIframeFilter() {
$this->assertEquals($expected, $cck_filter->process($input, LanguageInterface::LANGCODE_NOT_SPECIFIED)->getProcessedText());
}

/**
* Tests the iframe URL override through settings.
*/
public function testOverrideCookieConsentExternalUrls(): void {
// Initialize settings for overriding default iframe URL.
$this->setSetting('webtools_cookie_consent_embed_cookie_url', 'https://webtools.europa.eu/crs/iframe/');
$this->enableModules(['oe_webtools_cookie_consent']);
$manager = \Drupal::service('plugin.manager.filter');
$filters = new FilterPluginCollection($manager, []);
$cck_filter = $filters->get('filter_iframe_cck');
$input = '<p><iframe src="https://example.com?q=a+b&p=1" style="width: 400px; height: 200px;"></iframe></p>';

// Assert application of iframe URL through settings.
$expected = '<p><iframe src="https://webtools.europa.eu/crs/iframe/?oriurl=https%3A//example.com%3Fq%3Da%2Bb%26p%3D1&amp;lang=en" style="width: 400px; height: 200px;"></iframe></p>';
$this->assertEquals($expected, $cck_filter->process($input, LanguageInterface::LANGCODE_NOT_SPECIFIED)->getProcessedText());
}

}

0 comments on commit 3906eef

Please sign in to comment.