Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EWPP-963: Fix css selector for CCK. #161

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion behat.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ default:
- Drupal\DrupalExtension\Context\MessageContext
- Drupal\Tests\oe_webtools\Behat\WebtoolsAnalyticsMinkContext
- Drupal\Tests\oe_webtools\Behat\WebtoolsConfigContext
- Drupal\Tests\oe_webtools\Behat\WebtoolsCookieConsentContext
- Drupal\Tests\oe_webtools\Behat\WebtoolsCookieConsentContext:
selectors:
oembed_video: 'iframe'
- Drupal\Tests\oe_webtools\Behat\WebtoolsCleanupContext
- Drupal\Tests\oe_webtools\Behat\WebtoolsExtensionsContext
- Drupal\Tests\oe_webtools\Behat\WebtoolsGlobanContext
Expand Down
41 changes: 39 additions & 2 deletions tests/Behat/WebtoolsCookieConsentContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,23 @@ class WebtoolsCookieConsentContext extends RawDrupalContext {
*/
protected $configContext;

/**
* A list of css selectors needed by this context, keyed by name.
*
* @var array
*/
protected $selectors = [];

/**
* WebtoolsCookieConsentContext constructor.
*
* @param array $selectors
* An array of css selectors, keyed by name.
*/
public function __construct(array $selectors) {
$this->selectors = $selectors;
}

/**
* Gathers some other contexts.
*
Expand Down Expand Up @@ -94,7 +111,7 @@ public function iVisitTheRemoteVideoEntityPage(TableNode $mediasTable): void {
* @Then I should see the oEmbed video iframe with Cookie Consent
*/
public function assertOembedIframeWithCckUsage(): void {
$iframe_url = $this->getSession()->getPage()->find('css', 'iframe')->getAttribute('src');
$iframe_url = $this->getSession()->getPage()->find('css', $this->getSelector('oembed_video'))->getAttribute('src');
$this->visitPath(str_replace(rtrim($this->getDrupalParameter('drupal')['drupal_root'], '/'), '', $iframe_url));
$this->assertSession()->elementExists('css', "iframe[src^='" . OE_WEBTOOLS_COOKIE_CONSENT_EMBED_COOKIE_URL . "?oriurl=']");
}
Expand All @@ -105,7 +122,7 @@ public function assertOembedIframeWithCckUsage(): void {
* @Then I should not see the oEmbed video iframe with Cookie Consent
*/
public function assertNoOembedIframeWithCckUsage(): void {
$iframe_url = $this->getSession()->getPage()->find('css', 'iframe')->getAttribute('src');
$iframe_url = $this->getSession()->getPage()->find('css', $this->getSelector('oembed_video'))->getAttribute('src');
$this->visitPath(str_replace(rtrim($this->getDrupalParameter('drupal')['drupal_root'], '/'), '', $iframe_url));
$this->assertSession()->elementNotExists('css', "iframe[src^='" . OE_WEBTOOLS_COOKIE_CONSENT_EMBED_COOKIE_URL . "?oriurl=']");
}
Expand Down Expand Up @@ -172,4 +189,24 @@ protected function webtoolsJsonSnippetExists(string $snippet): bool {
return FALSE;
}

/**
* Returns a css selector from the context configuration.
*
* @param string $name
* The selector name.
*
* @return string
* The css selector.
*
* @throws \Exception
* Thrown when the selector is not found.
*/
protected function getSelector(string $name): string {
if (!array_key_exists($name, $this->selectors)) {
throw new \Exception(sprintf('Missing selector "%s".', $name));
}

return $this->selectors[$name];
}

}