Comments (12)
I haven't done a lot of multilinugual work, but on the few sites with that requirement, I've always switched languages with clean URLs, so I've not run into the problem you're experiencing. It was my understanding that the taking the clean url approach was better for search engine indexing, and it was better for communicating URLs to others outloud.
That aside, the behavior you're describing is part of Mink, and I think it's probably best addressed there. https://github.com/Behat/Mink/issues/566 is related, although it has not been updated since May, it looks like.
from drupalextension.
Thanks for your feedback but I wasn't quite clear in building the URL. We are of course using clean URLs, so the destination we want to check is http://www.example.com/user to test the login form. This page is only available as /user and not like other content as /en/page/title-1 or /de/seite/titel-1
So, system pages like /user follow other hints to find out which page should be used. By default it check for domain, sub-path, query parameter, browser settings in that given order. As domain and sub-path are not different for the /user page, the next two options should be tried. I used the language=en query which is causing problems with Mink. The fourth one would be looking into the browser language settings and I wonder if we had a chance to provide those settings via the behat.yml file somehow.
from drupalextension.
Thank you for clarifying! (It's still early here.) I see what you're saying now.
from drupalextension.
After some digging in Drupal 7 I found locale_language_from_browser() in /includes/locale.inc and there they are negotiating the current language from the $_SERVER['HTTP_ACCEPT_LANGUAGE'] variable and if we could set this variable in the Behat context, that would provide much more control.
from drupalextension.
Here is how it can be modified to work as expected. In my FeatureContext I added the following function:
/**
* @BeforeStep
*/
public function beforeEachStep($event) {
/* @var $event Behat\Behat\Hook\Scope\BeforeStepScope */
/* @var $environment Behat\Behat\Context\Environment\InitializedContextEnvironment */
/* @var $mink Drupal\DrupalExtension\Context\MinkContext */
$environment = $event->getEnvironment();
if ($environment->hasContextClass('Drupal\DrupalExtension\Context\MinkContext')) {
$mink = $environment->getContext('Drupal\DrupalExtension\Context\MinkContext');
$mink->getSession()->setRequestHeader('ACCEPT_LANGUAGE', 'de,en-US;q=0.7,en;q=0.3');
}
}
This is forcing the content to be in German. Of course this can now be forced to English by simply changing the value of "Accept Language".
May I suggest that this could be added to the Drupal Extension as a feature so that a language property (defaulting to en-US) can be added to the behat.yml file and then be used globally?
from drupalextension.
Thinking about it even more, it would be great if we could extend the idea of testing multilingual sites with multiple contexts in a way that we could use placeholders in our feature files for all the strings we're going to test and replace them with the proper strings matching the language that we are about to test.
I'd be happy to contribute to such a framework if that's something you would like to get into the drupal extension.
from drupalextension.
This is definitely Jonathan's decision, but especially with Multilingual in Drupal 8 core, a coherent approach to multilingual testing seems very much in order.
from drupalextension.
Good point well made. I'd like to offer my help for this, i.e. I'm happy to contribute code to address this in case Jonathan is up for it too. But I'd require someone to discuss the best approach then.
from drupalextension.
I'm certainly up for helping this along. The solution you posted above looks like a good start. Similar url manipulation was needed for dealing with sites behind basic auth, so that might also be an approach to consider.
from drupalextension.
From your code sample I can certainly improve my approach from above. However, as mentioned afterwards there is more to multilingual site testing. Let's assume the feature files are all written in English and the tests are using strings for button labels, messages and other content they are testing for. This makes sense of course and nobody wants to write all those tests over and over again if they had to test the same site in multiple languages. Instead, they might want to maintain the feature files in English only and then in their behat.yml file they want to set a language parameter to define which language should be tested.
If that's reasonable, the following extensions are required:
- a new Drupal (or Mink) parameter for the language, defaulting to "en"
- additional translation maps where the translated strings from the feature files can be found
If that's a good approach, I would like to chat about a good starting point on how to get started.
What do you think?
from drupalextension.
You should be able to use the @transform
tag for the method that actually does the mapping. I bet this could go into a new context, say TranslationContext
. The new option defaulting to en
makes sense. In the docs we should be careful to clarify the difference between using this, and the already existing xliff translation of steps.
Feel free to ping me on #behat
irc if you want to talk through any of this.
from drupalextension.
Closing this out for now. Let's open new issues to further this along. Thanks!
from drupalextension.
Related Issues (20)
- Circular reference detected for Drupal::service('url_generator') HOT 3
- Drupal 10 / Drush 11 / Symfony 6 Support
- Drop Drupal 7 support
- PHP 8.1 compatibility error: "$this" can no longer be used in a plain function or method since PHP 7.1
- Guzzle 7 issue HOT 3
- New step for press button in row HOT 1
- Error when tried to update to 5.0.0 alpha, conflicts with drupal/core-dev HOT 13
- DrupalAuthenticationManager is confused about login state across scenario's
- Escaping in createNode() changed with PHP 8.1
- Test on PHP 8.2
- Creating a node with a certain URL alias HOT 1
- Disable automatic cleanup HOT 1
- Add a .readthedocs.yml configuration file HOT 4
- Fix failing D10 tests HOT 2
- Remove DrupalFinder HOT 2
- Write an upgrade guide to 5.x? HOT 1
- Drupal finder exception causes error - Cannot locate Drupal on a standalone behat installation. HOT 2
- PHP Fatal Error with PHP 8.2 when using `drupal` api driver HOT 2
- Content loaded via BigPipe is sometimes not available by the time steps are executed, leading to random failures
- Add step definition for dragging one element onto another
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from drupalextension.