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

Port https://www.drupal.org/project/drupal/issues/3175718 #629

Merged
merged 11 commits into from
Jan 5, 2023
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@
"minimum-stability": "dev",
"require": {
"behat/behat": "~3.2",
"friends-of-behat/mink-extension": "^2.7.1",
"behat/mink-browserkit-driver": "^2.1.0",
"behat/mink-selenium2-driver": "~1.1",
"drupal/drupal-driver": "^2.2.1",
"friends-of-behat/mink-extension": "^2.7.1",
"symfony/http-client": "~4.4 || ^5 || ^6",
"webflo/drupal-finder": "^1.2"
},
"require-dev": {
"composer/installers": "^2",
"drupal/coder": "^8.3",
"drupal/core-composer-scaffold": "^9.4 || ^10.0",
"drupal/core": "^9.4 || ^10.0",
"drupal/core-composer-scaffold": "^9.4 || ^10.0",
"drush/drush": "^11.0",
"php-parallel-lint/php-parallel-lint": "^1.3",
"phpspec/phpspec": "^4.0 || ^6.0 || ^7.0"
Expand Down Expand Up @@ -76,6 +76,7 @@
"composer/installers": true,
"dealerdirect/phpcodesniffer-composer-installer": true,
"drupal/core-composer-scaffold": true
}
},
"sort-packages": true
}
}
8 changes: 8 additions & 0 deletions features/blackbox.feature
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,11 @@ Feature: Test DrupalContext
Then the "scenariotag" tag should be present
And the "blackbox" tag should be present
But the "nonexisting" tag should not be present

Scenario: Regression test. See:
- https://github.com/minkphp/MinkBrowserKitDriver/issues/153
- https://www.drupal.org/project/drupal/issues/3175718
- https://www.drupal.org/project/drupal/issues/3295472
- https://github.com/jhedstrom/drupalextension/pull/612
Given I am on the homepage
Then I should not see "This text shouldn't be visible"
2 changes: 1 addition & 1 deletion features/mail.feature
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Feature: MailContext
| subject | test link |
| body | A link to Google: http://www.Google.com |
And I follow the link to "google" from the mail with the subject "test link"
Then I should see "Search"
Then the response should contain "Search"

Scenario: We try to be order insensitive
When Drupal sends an email:
Expand Down
3 changes: 3 additions & 0 deletions fixtures/blackbox/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<html>
<head>
<title>Drupal - Open Source CMS | Drupal.org</title>
<script type="application/json">{
"description": "This text shouldn't be visible"
}</script>
</head>
<body>
<div id="nav-header">
Expand Down
13 changes: 13 additions & 0 deletions src/Drupal/DrupalExtension/ServiceContainer/DrupalExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Behat\Testwork\ServiceContainer\ServiceProcessor;
use Drupal\DrupalExtension\Compiler\DriverPass;
use Drupal\DrupalExtension\Compiler\EventSubscriberPass;
use DrupalFinder\DrupalFinder;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand Down Expand Up @@ -63,6 +64,18 @@ public function initialize(ExtensionManager $extensionManager)
*/
public function load(ContainerBuilder $container, array $config)
{
// Workaround a bug in BrowserKitDriver that wrongly considers as text
// of the page, pieces of texts inside the <head> section.
// @see https://github.com/minkphp/MinkBrowserKitDriver/issues/153
// @see https://www.drupal.org/project/drupal/issues/3175718
$drupalFinder = new DrupalFinder();
if (!$drupalFinder->locateRoot(getcwd())) {
throw new \RuntimeException('Cannot locate Drupal');
}
$drupalRoot = $drupalFinder->getDrupalRoot();
require_once($drupalRoot . '/core/tests/Drupal/Tests/DocumentElement.php');
class_alias('\Drupal\Tests\DocumentElement', '\Behat\Mink\Element\DocumentElement', true);

$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/config'));
$loader->load('services.yml');
$container->setParameter('drupal.drupal.default_driver', $config['default_driver']);
Expand Down