Random fails due to drupal-settings-json being counted as page text

Created on 8 October 2020, about 4 years ago
Updated 19 March 2023, over 1 year ago

Problem/Motivation

I have a test for a custom module that does

$assert->pageTextNotContains('SBS');

This fails randomly if the theme token generated for drupal settings contains the string SBS. Unfortunately, \Behat\Mink\Element\Element::getText will return the text included inside the script tags in the body. The problematic one is:

<script type="application/json" data-drupal-selector="drupal-settings-json">{"path":{"baseUrl":"\/","scriptPath":null,"pathPrefix":"en\/","currentPath":"admin\/telus","currentPathIsAdmin":true,"isFront":false,"currentLanguage":"en"},"pluralDelimiter":"\u0003","suppressDeprecationErrors":true,"ajaxPageState":{"libraries":"admin_toolbar\/toolbar.tree,admin_toolbar_search\/search,admin_toolbar_tools\/toolbar.icon,classy\/base,classy\/messages,core\/drupal.active-link,core\/html5shiv,core\/normalize,seven\/global-styling,telus_toolbar\/toolbar,toolbar\/toolbar,toolbar\/toolbar.escapeAdmin,toolbar_menu\/icons,user\/drupal.user.icons","theme":"seven","theme_token":"qmmJrXPeEdpihFizSBSnD-kZanHo-4WzDf3L2F63puk"},"ajaxTrustedUrl":[],"toolbar":{"breakpoints":{"toolbar.narrow":"only screen and (min-width: 16.5em)","toolbar.standard":"only screen and (min-width: 38.125em)","toolbar.wide":"only screen and (min-width: 61em)"},"subtreesHash":"6pedNI4W-Gv5uhLYRwkHwC5MGZxlWKDbctxk3jJqFuM"},"adminToolbarSearch":{"loadExtraLinks":true},"user":{"uid":"2","permissionsHash":"d8e278451f423cb7d81f32499f7dc040316897215570611b7c41419636a2f629"}}</script>

as it contains a number of cryptographic strings that can contain any set of characters.

Steps to reproduce

Proposed resolution

I think this requires an upstream fix. I'll check Behat / Symfony's crawler for issues. The problem is that eventually this is getting the \DOMNode::$nodeValue for the page - see we're talking about core PHP functionality - see \Symfony\Component\DomCrawler\Crawler::text()

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Fixed

Version

9.2

Component
PHPUnit 

Last updated about 10 hours ago

Created by

🇬🇧United Kingdom alexpott 🇪🇺🌍

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇺🇸United States fkelly

    After upgrading from 9.5.4 to 9.5.5 (including fixing some composer validation errors in an attempt to lay the foundation for 10.0.5) I started to encounter the error listed here:

    Error : Class "Behat\Mink\Driver\BrowserKitDriver" not found

    Looking in my vendor directory, behat only had the geckodriver.exe program and no mink subdirectory. I ran the fix listed in #51 and now I have a mink subdirectory under the behat directory. There is a new line in composer.json after the require:

    "require-dev": {
    "behat/mink": "^1.10"

    However, I still get the

    Error : Class "Behat\Mink\Driver\BrowserKitDriver" not found message when doing PHPunit testing under PHPstorm. I have been running those tests successfully for several months trying to fix tests in a contrib module.

    I can see that the patch listed in #47 has been applied. Looking on my hosted production system (where I don't run tests or need Behat) there is no behat directory at all under vendor.

    Since it's been 8 months since the last post in this thread, I am wondering if this issue just resurfaced between 9.5.4 and 9.5.5. There has never been a response to #54 nor do I have any way to know if it would fix my immediate problem.

Production build 0.71.5 2024