diff --git a/composer.json b/composer.json index df6e95d4..d41c07c1 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,8 @@ "behat/mink-browserkit-driver": "^2.1.0", "behat/mink-selenium2-driver": "~1.1", "drupal/drupal-driver": "dev-master", - "symfony/http-client": "~4.4 || ^5 || ^6" + "symfony/http-client": "~4.4 || ^5 || ^6", + "webflo/drupal-finder": "^1.2" }, "require-dev": { "composer/installers": "^2", diff --git a/src/Drupal/DocumentElement.php b/src/Drupal/DocumentElement.php deleted file mode 100644 index ebf086ba..00000000 --- a/src/Drupal/DocumentElement.php +++ /dev/null @@ -1,88 +0,0 @@ -getDriver()->getContent()); - } - - /** - * Check whether document has specified content. - * - * @param string $content - * - * @return bool - */ - public function hasContent($content) - { - return $this->has('named', ['content', $content]); - } - - /** - * {@inheritdoc} - */ - public function getText() - { - if ($this->getDriver() instanceof BrowserKitDriver) { - // Work around https://github.com/minkphp/MinkBrowserKitDriver/issues/153. - // To simulate what the user sees, it removes: - // - all text inside the head tags - // - Drupal settings json. - $raw_content = preg_replace([ - '@(.+?)@si', - '@@', - ], '', $this->getContent()); - // Filter out all HTML tags, as they are not visible in a normal browser. - $text = strip_tags($raw_content); - // To preserve BC and match \Behat\Mink\Element\Element::getText() include - // the page title. - $title_element = $this->find('css', 'title'); - if ($title_element) { - $text = $title_element->getText() . ' ' . $text; - } - // To match what the user sees and \Behat\Mink\Element\Element::getText() - // decode HTML entities. - $text = html_entity_decode($text, ENT_QUOTES); - // To match \Behat\Mink\Element\Element::getText() remove new lines and - // normalize spaces. - $text = str_replace("\n", ' ', $text); - $text = preg_replace('/ {2,}/', ' ', $text); - return trim($text); - } - - // If using a real browser fallback to the \Behat\Mink\Element\Element - // implementation. - return parent::getText(); - } -} diff --git a/src/Drupal/DrupalExtension/ServiceContainer/DrupalExtension.php b/src/Drupal/DrupalExtension/ServiceContainer/DrupalExtension.php index 5f44f61a..a72a406f 100644 --- a/src/Drupal/DrupalExtension/ServiceContainer/DrupalExtension.php +++ b/src/Drupal/DrupalExtension/ServiceContainer/DrupalExtension.php @@ -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; @@ -67,8 +68,13 @@ public function load(ContainerBuilder $container, array $config) // of the page, pieces of texts inside the section. // @see https://github.com/minkphp/MinkBrowserKitDriver/issues/153 // @see https://www.drupal.org/project/drupal/issues/3175718 - require_once(__DIR__ . '/../../DocumentElement.php'); - class_alias('\Drupal\DocumentElement', '\Behat\Mink\Element\DocumentElement', true); + $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');