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

ISAICP-5450: Make Cookie Consent step definitions reusable #101

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Move non-reusable step definitions into the private FeatureContext.
  • Loading branch information
pfrenssen committed Sep 30, 2019
commit aa389713d39accaabbbfb60e1b72a268fa251a09
1 change: 1 addition & 0 deletions behat.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ default:
- Drupal\Tests\oe_webtools\Behat\WebtoolsCookieConsentContext
- Drupal\Tests\oe_webtools\Behat\WebtoolsCleanupContext
- Drupal\Tests\oe_webtools\Behat\WebtoolsGlobanContext
- FeatureContext
- OpenEuropa\Behat\TransformationContext:
pages:
Webtools Analytics configuration: '/admin/config/system/oe_webtools_analytics'
Expand Down
74 changes: 0 additions & 74 deletions tests/Behat/WebtoolsCookieConsentContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@

namespace Drupal\Tests\oe_webtools\Behat;

use Behat\Behat\Hook\Scope\AfterScenarioScope;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\Gherkin\Node\TableNode;
use Drupal\DrupalExtension\Context\RawDrupalContext;
use Drupal\media\Entity\Media;

define('OE_WEBTOOLS_COOKIE_CONSENT_EMBED_COOKIE_URL', '//europa.eu/webtools/crs/iframe/');
define('OE_WEBTOOLS_COOKIE_CONSENT_BANNER_COOKIE_URL', '//ec.europa.eu/wel/cookie-consent/consent.js');
Expand All @@ -18,76 +14,6 @@
*/
class WebtoolsCookieConsentContext extends RawDrupalContext {

/**
* The config context.
*
* @var \Drupal\DrupalExtension\Context\ConfigContext
*/
protected $configContext;

/**
* Gathers some other contexts.
*
* @param \Behat\Behat\Hook\Scope\BeforeScenarioScope $scope
* The before scenario scope.
*
* @BeforeScenario
*/
public function gatherContexts(BeforeScenarioScope $scope) {
$environment = $scope->getEnvironment();
$this->configContext = $environment->getContext('Drupal\DrupalExtension\Context\ConfigContext');
}

/**
* Enables the Media module.
*
* @param \Behat\Behat\Hook\Scope\BeforeScenarioScope $scope
* The scope.
*
* @beforeScenario @remote-video
*/
public function enableModule(BeforeScenarioScope $scope): void {
\Drupal::service('module_installer')->install(['oe_media']);

$this->configContext->setConfig('media.settings', 'standalone_url', TRUE);
\Drupal::service('router.builder')->rebuild();
}

/**
* Disables the Media module.
*
* @param \Behat\Behat\Hook\Scope\AfterScenarioScope $scope
* The scope.
*
* @afterScenario @remote-video
*/
public function disableModule(AfterScenarioScope $scope): void {
\Drupal::service('module_installer')->uninstall(['oe_media']);
}

/**
* Create remote video entity and go to detail page of media.
*
* @param \Behat\Gherkin\Node\TableNode $mediasTable
* Table of media data.
*
* @Given I visit the remote video entity page:
*/
public function iVisitTheRemoteVideoEntityPage(TableNode $mediasTable): void {
$hash = $mediasTable->getColumnsHash();
$media_data = reset($hash);
if ($media_data) {
$media = Media::create([
'bundle' => 'remote_video',
'name' => $media_data['title'],
'oe_media_oembed_video' => $media_data['url'],
'path' => $media_data['path'],
]);
$media->save();
$this->visitPath($media_data['path']);
}
}

/**
* Checks that an OEmbed iframe url uses CCK service.
*
Expand Down
94 changes: 94 additions & 0 deletions tests/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

/**
* @file
* Contains step definitions specific to the internal scenarios of OE Webtools.
*/

declare(strict_types = 1);

use Behat\Behat\Hook\Scope\AfterScenarioScope;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\Gherkin\Node\TableNode;
use Drupal\DrupalExtension\Context\RawDrupalContext;
use Drupal\media\Entity\Media;

/**
* Defines non-reusable step definitions to use with OpenEuropa Webtools.
*/
class FeatureContext extends RawDrupalContext {

/**
* The config context.
*
* @var \Drupal\DrupalExtension\Context\ConfigContext
*/
protected $configContext;

/**
* Gathers some other contexts.
*
* @param \Behat\Behat\Hook\Scope\BeforeScenarioScope $scope
* The before scenario scope.
*
* @BeforeScenario
*/
public function gatherContexts(BeforeScenarioScope $scope) {
$environment = $scope->getEnvironment();
$this->configContext = $environment->getContext('Drupal\DrupalExtension\Context\ConfigContext');
}

/**
* Enables the Media module.
*
* @param \Behat\Behat\Hook\Scope\BeforeScenarioScope $scope
* The scope.
*
* @beforeScenario @remote-video
*/
public function enableModule(BeforeScenarioScope $scope): void {
\Drupal::service('module_installer')->install(['oe_media']);

$this->configContext->setConfig('media.settings', 'standalone_url', TRUE);
\Drupal::service('router.builder')->rebuild();
}

/**
* Disables the Media module.
*
* @param \Behat\Behat\Hook\Scope\AfterScenarioScope $scope
* The scope.
*
* @afterScenario @remote-video
*/
public function disableModule(AfterScenarioScope $scope): void {
\Drupal::service('module_installer')->uninstall(['oe_media']);
}

/**
* Create remote video entity and go to detail page of media.
*
* @param \Behat\Gherkin\Node\TableNode $mediasTable
* Table of media data.
*
* @throws \Drupal\Core\Entity\EntityStorageException
* Thrown when the entity cannot be created.
*
* @Given I visit the remote video entity page:
*/
public function iVisitTheRemoteVideoEntityPage(TableNode $mediasTable): void {
$hash = $mediasTable->getColumnsHash();
$media_data = reset($hash);
if ($media_data) {
$media = Media::create([
'bundle' => 'remote_video',
'name' => $media_data['title'],
'oe_media_oembed_video' => $media_data['url'],
'path' => $media_data['path'],
]);
$media->save();
$this->visitPath($media_data['path']);
}
}

}