From 11b7ff678d9c7a67fe66cf394b4f8b4002cec9c1 Mon Sep 17 00:00:00 2001 From: "Eloy Lafuente (stronk7)" Date: Mon, 10 Oct 2022 17:39:58 +0200 Subject: [PATCH 1/3] MDL-78934 behat: Move from mink goutte to browserkit driver In order to get compatibility with PHP 8.1 there are 2 options: 1) Move to the Goutte 2 mink driver, that uses Goutte 4. 2) Move to the BrowserKit mink driver. While 1) could sound like the easier alternative, and that is what we are doing right now, there are a few points to take into consideration. a) Goutte 4 is a complete wrapper over BrowserKit. 100%. See its source code: https://github.com/FriendsOfPHP/Goutte/blob/master/Goutte/Client.php b) The mink extension still doesn't support Goutte 4, but supports BrowserKit. See https://github.com/FriendsOfBehat/MinkExtension (PR#16) (we could workaround this by forking the package again) c) Last, but not least, recently (June 2023) both the MinkGoutteDriver and Goutte itself have been archived/abandoned: - https://packagist.org/packages/behat/mink-goutte-driver - https://packagist.org/packages/fabpot/goutte So, given the points above, this is an attempt to move away completely from Goutte and straight use the BrowserKit alternative that, in practice, is the very same code that we are already using (you can see that, in the .lock changes there isn't any new thing being installed, because, as said, we are using it already). Let's see how complex it is, I imagine it won't be hard. Surely killing all references everywhere about Goutte will be the most complex task. --- composer.json | 4 +- composer.lock | 131 +++----------------------------------------------- 2 files changed, 10 insertions(+), 125 deletions(-) diff --git a/composer.json b/composer.json index 91ebfdeb061..30e88be0666 100644 --- a/composer.json +++ b/composer.json @@ -9,8 +9,10 @@ "mikey179/vfsstream": "1.6.*", "behat/mink": "^1.10.0", "friends-of-behat/mink-extension": "^2.7.2", - "behat/mink-goutte-driver": "^2.0", + "behat/mink-browserkit-driver": "^2.1.0", "symfony/process": "^4.4 || ^5.0 || ^6.0", + "symfony/http-client": "^4.4 || ^5.0 || ^6.0", + "symfony/mime": "^4.4 || ^5.0 || ^6.0", "behat/behat": "3.13.*", "oleg-andreyev/mink-phpwebdriver": "1.2.*" }, diff --git a/composer.lock b/composer.lock index d2ca6ca4678..6368c1a76b7 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "b3dfd36fbddf431cd0cc54c3c4f6b4fd", + "content-hash": "3a0d2ff60a75e1c5c42b16fd989bbe24", "packages": [], "packages-dev": [ { @@ -286,66 +286,6 @@ }, "time": "2022-03-28T14:33:51+00:00" }, - { - "name": "behat/mink-goutte-driver", - "version": "v2.0.0", - "source": { - "type": "git", - "url": "https://github.com/minkphp/MinkGoutteDriver.git", - "reference": "a60fba46520c17d39b839151831cbc0710764b56" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/minkphp/MinkGoutteDriver/zipball/a60fba46520c17d39b839151831cbc0710764b56", - "reference": "a60fba46520c17d39b839151831cbc0710764b56", - "shasum": "" - }, - "require": { - "behat/mink-browserkit-driver": "^2.0@dev", - "fabpot/goutte": "^4.0", - "php": ">=7.2" - }, - "require-dev": { - "mink/driver-testsuite": "dev-master", - "symfony/error-handler": "^4.4 || ^5.0" - }, - "type": "mink-driver", - "extra": { - "branch-alias": { - "dev-master": "2.x-dev" - } - }, - "autoload": { - "psr-4": { - "Behat\\Mink\\Driver\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Konstantin Kudryashov", - "email": "ever.zet@gmail.com", - "homepage": "http://everzet.com" - } - ], - "description": "Goutte driver for Mink framework", - "homepage": "https://mink.behat.org/", - "keywords": [ - "browser", - "goutte", - "headless", - "testing" - ], - "support": { - "issues": "https://github.com/minkphp/MinkGoutteDriver/issues", - "source": "https://github.com/minkphp/MinkGoutteDriver/tree/v2.0.0" - }, - "abandoned": "behat/mink-browserkit-driver", - "time": "2021-12-29T10:56:50+00:00" - }, { "name": "behat/transliterator", "version": "v1.5.0", @@ -465,63 +405,6 @@ ], "time": "2022-12-30T00:15:36+00:00" }, - { - "name": "fabpot/goutte", - "version": "v4.0.3", - "source": { - "type": "git", - "url": "https://github.com/FriendsOfPHP/Goutte.git", - "reference": "e3f28671c87a48a0f13ada1baea0d95acc2138c3" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/FriendsOfPHP/Goutte/zipball/e3f28671c87a48a0f13ada1baea0d95acc2138c3", - "reference": "e3f28671c87a48a0f13ada1baea0d95acc2138c3", - "shasum": "" - }, - "require": { - "php": ">=7.1.3", - "symfony/browser-kit": "^4.4|^5.0|^6.0", - "symfony/css-selector": "^4.4|^5.0|^6.0", - "symfony/deprecation-contracts": "^2.1|^3", - "symfony/dom-crawler": "^4.4|^5.0|^6.0", - "symfony/http-client": "^4.4|^5.0|^6.0", - "symfony/mime": "^4.4|^5.0|^6.0" - }, - "require-dev": { - "symfony/phpunit-bridge": "^6.0" - }, - "type": "application", - "autoload": { - "psr-4": { - "Goutte\\": "Goutte" - }, - "exclude-from-classmap": [ - "Goutte/Tests" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - } - ], - "description": "A simple PHP Web Scraper", - "homepage": "https://github.com/FriendsOfPHP/Goutte", - "keywords": [ - "scraper" - ], - "support": { - "issues": "https://github.com/FriendsOfPHP/Goutte/issues", - "source": "https://github.com/FriendsOfPHP/Goutte/tree/v4.0.3" - }, - "abandoned": "symfony/browser-kit", - "time": "2023-04-01T09:05:33+00:00" - }, { "name": "friends-of-behat/mink-extension", "version": "v2.7.2", @@ -2075,16 +1958,16 @@ }, { "name": "sebastian/global-state", - "version": "5.0.5", + "version": "5.0.6", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/global-state.git", - "reference": "0ca8db5a5fc9c8646244e629625ac486fa286bf2" + "reference": "bde739e7565280bda77be70044ac1047bc007e34" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/0ca8db5a5fc9c8646244e629625ac486fa286bf2", - "reference": "0ca8db5a5fc9c8646244e629625ac486fa286bf2", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/bde739e7565280bda77be70044ac1047bc007e34", + "reference": "bde739e7565280bda77be70044ac1047bc007e34", "shasum": "" }, "require": { @@ -2127,7 +2010,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/global-state/issues", - "source": "https://github.com/sebastianbergmann/global-state/tree/5.0.5" + "source": "https://github.com/sebastianbergmann/global-state/tree/5.0.6" }, "funding": [ { @@ -2135,7 +2018,7 @@ "type": "github" } ], - "time": "2022-02-14T08:28:10+00:00" + "time": "2023-08-02T09:26:13+00:00" }, { "name": "sebastian/lines-of-code", From 7d37b29248f70a2f02cf204603fe9e8563ce9adc Mon Sep 17 00:00:00 2001 From: "Eloy Lafuente (stronk7)" Date: Mon, 10 Oct 2022 23:31:51 +0200 Subject: [PATCH 2/3] MDL-78934 behat: Move to BrowserKit in extension and other custom code --- admin/tool/behat/upgrade.txt | 8 ++++++++ behat.yml.dist | 2 +- lib/behat/classes/behat_config_util.php | 2 +- lib/behat/classes/behat_session_trait.php | 2 +- .../Output/Formatter/MoodleScreenshotFormatter.php | 2 +- lib/behat/form_field/behat_form_field.php | 2 +- lib/tests/behat/behat_hooks.php | 2 +- 7 files changed, 14 insertions(+), 6 deletions(-) diff --git a/admin/tool/behat/upgrade.txt b/admin/tool/behat/upgrade.txt index a57220479a1..8dc97229a99 100644 --- a/admin/tool/behat/upgrade.txt +++ b/admin/tool/behat/upgrade.txt @@ -1,10 +1,18 @@ This files describes API changes in the tool_behat code. +=== 4.3 === +* The goutte behat mink driver has been replaced by the browserkit one because the former has been abandoned. The change should + be completely transparent for (near) everybody. Only if you are using some custom-generated behat.yml file or other configuration + alternatives different from the Moodle default one, then, any "goutte" browser occurrence needs to be changed to "browserkit_http" + when configuring the behat mink extension. See MDL-78934 for more details and changes applied. + === 4.2 === * Behat is initialised with Axe accessibility tests enabled by default, if you want to disable them please use the --no-axe option. + === 3.7 === * Behat will now look for behat step definitions in the current theme and any parents the theme may have. + === 2.7 === * Constants behat_base::cap_allow, behat_base::cap_prevent and behat_base::cap_prohibit have been removed in favour of the diff --git a/behat.yml.dist b/behat.yml.dist index 1da8a97436a..4041c559f04 100644 --- a/behat.yml.dist +++ b/behat.yml.dist @@ -6,7 +6,7 @@ default: extensions: Behat\MinkExtension: base_url: 'http://localhost:8000' - goutte: null + browserkit_http: null webdriver: null Moodle\BehatExtension: moodledirroot: /Should/Change/To/Moodle/www/dir diff --git a/lib/behat/classes/behat_config_util.php b/lib/behat/classes/behat_config_util.php index b0091944911..87b4a8bb8ad 100644 --- a/lib/behat/classes/behat_config_util.php +++ b/lib/behat/classes/behat_config_util.php @@ -552,7 +552,7 @@ class behat_config_util { 'extensions' => array( 'Behat\MinkExtension' => array( 'base_url' => $CFG->behat_wwwroot, - 'goutte' => null, + 'browserkit_http' => null, 'webdriver' => $webdriverwdhost ), 'Moodle\BehatExtension' => array( diff --git a/lib/behat/classes/behat_session_trait.php b/lib/behat/classes/behat_session_trait.php index 9eff111fbde..ea76d0e795e 100644 --- a/lib/behat/classes/behat_session_trait.php +++ b/lib/behat/classes/behat_session_trait.php @@ -528,7 +528,7 @@ trait behat_session_trait { * @return boolean */ protected static function running_javascript_in_session(Session $session): bool { - return get_class($session->getDriver()) !== 'Behat\Mink\Driver\GoutteDriver'; + return get_class($session->getDriver()) !== 'Behat\Mink\Driver\BrowserKitDriver'; } /** diff --git a/lib/behat/extension/Moodle/BehatExtension/Output/Formatter/MoodleScreenshotFormatter.php b/lib/behat/extension/Moodle/BehatExtension/Output/Formatter/MoodleScreenshotFormatter.php index c08d48dbe84..376292150a1 100644 --- a/lib/behat/extension/Moodle/BehatExtension/Output/Formatter/MoodleScreenshotFormatter.php +++ b/lib/behat/extension/Moodle/BehatExtension/Output/Formatter/MoodleScreenshotFormatter.php @@ -230,7 +230,7 @@ class MoodleScreenshotFormatter implements Formatter { protected function take_screenshot(AfterStepTested $event, $context) { // Goutte can't save screenshots. if ($context->getMink()->isSessionStarted($context->getMink()->getDefaultSessionName())) { - if (get_class($context->getMink()->getSession()->getDriver()) === 'Behat\Mink\Driver\GoutteDriver') { + if (get_class($context->getMink()->getSession()->getDriver()) === 'Behat\Mink\Driver\BrowserKitDriver') { return false; } list ($dir, $filename) = $this->get_faildump_filename($event, 'png'); diff --git a/lib/behat/form_field/behat_form_field.php b/lib/behat/form_field/behat_form_field.php index 5f58d2aab1a..b01ed794bbf 100644 --- a/lib/behat/form_field/behat_form_field.php +++ b/lib/behat/form_field/behat_form_field.php @@ -203,7 +203,7 @@ class behat_form_field implements behat_session_interface { * @return bool */ protected function running_javascript() { - return get_class($this->session->getDriver()) !== 'Behat\Mink\Driver\GoutteDriver'; + return get_class($this->session->getDriver()) !== 'Behat\Mink\Driver\BrowserKitDriver'; } /** diff --git a/lib/tests/behat/behat_hooks.php b/lib/tests/behat/behat_hooks.php index bed501645cb..be966036aa2 100644 --- a/lib/tests/behat/behat_hooks.php +++ b/lib/tests/behat/behat_hooks.php @@ -310,7 +310,7 @@ EOF; * @BeforeScenario @~javascript * @param BeforeScenarioScope $scope scope passed by event fired before scenario. */ - public function before_goutte_scenarios(BeforeScenarioScope $scope) { + public function before_browserkit_scenarios(BeforeScenarioScope $scope) { if ($this->running_javascript()) { // A bug in the BeforeScenario filtering prevents the @~javascript filter on this hook from working // properly. From 731f64226d12269d89aa33f6442404c01a74d21d Mon Sep 17 00:00:00 2001 From: "Eloy Lafuente (stronk7)" Date: Fri, 4 Aug 2023 18:13:18 +0200 Subject: [PATCH 3/3] MDL-78934 behat: Replace all the rest of goutte by browserkit Basically all them are comments. Only remaining occurrence remaining is in composer.lock file, because friends-of-behat/mink-extension still has the old goutte as dev requirement, but that doesn't affect us at all (no goutte is installed anymore, see the vendor directory and/or the lock file). --- course/format/classes/base.php | 2 +- editmode.php | 2 +- .../Output/Formatter/MoodleScreenshotFormatter.php | 2 +- lib/behat/form_field/behat_form_radio.php | 2 +- lib/tests/behat/behat_general.php | 4 ++-- lib/tests/behat/behat_hooks.php | 2 +- my/templates/dropdown.mustache | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/course/format/classes/base.php b/course/format/classes/base.php index fdb4657e553..f8c61492d61 100644 --- a/course/format/classes/base.php +++ b/course/format/classes/base.php @@ -743,7 +743,7 @@ abstract class base { /** * Return the old non-ajax activity action url. * - * Goutte behats tests cannot trigger javascript events, + * BrowserKit behats tests cannot trigger javascript events, * so we must translate to an old non-ajax url while non-ajax * course editing is still supported. * diff --git a/editmode.php b/editmode.php index 8ea0cac991d..3f9b2d42b8f 100644 --- a/editmode.php +++ b/editmode.php @@ -28,7 +28,7 @@ $setmode = optional_param('setmode', false, PARAM_BOOL); $contextid = required_param('context', PARAM_INT); $pageurl = required_param('pageurl', PARAM_LOCALURL); -// Behat requires JS to get the session. To allow goutte +// Behat requires JS to get the session. To allow browserkit // to enable edit mode sesskey validation is skipped for behat scripts. if (!defined('BEHAT_SITE_RUNNING')) { require_sesskey(); diff --git a/lib/behat/extension/Moodle/BehatExtension/Output/Formatter/MoodleScreenshotFormatter.php b/lib/behat/extension/Moodle/BehatExtension/Output/Formatter/MoodleScreenshotFormatter.php index 376292150a1..da213e1e021 100644 --- a/lib/behat/extension/Moodle/BehatExtension/Output/Formatter/MoodleScreenshotFormatter.php +++ b/lib/behat/extension/Moodle/BehatExtension/Output/Formatter/MoodleScreenshotFormatter.php @@ -228,7 +228,7 @@ class MoodleScreenshotFormatter implements Formatter { * @param Context $context */ protected function take_screenshot(AfterStepTested $event, $context) { - // Goutte can't save screenshots. + // BrowserKit can't save screenshots. if ($context->getMink()->isSessionStarted($context->getMink()->getDefaultSessionName())) { if (get_class($context->getMink()->getSession()->getDriver()) === 'Behat\Mink\Driver\BrowserKitDriver') { return false; diff --git a/lib/behat/form_field/behat_form_radio.php b/lib/behat/form_field/behat_form_radio.php index 22e064c17c5..853cd3a3983 100644 --- a/lib/behat/form_field/behat_form_radio.php +++ b/lib/behat/form_field/behat_form_radio.php @@ -83,7 +83,7 @@ class behat_form_radio extends behat_form_checkbox { $this->trigger_on_change(); } } else { - // Goutte does not accept a check nor a click in an input[type=radio]. + // BrowserKit does not accept a check nor a click in an input[type=radio]. $this->field->setValue($this->field->getAttribute('value')); } } diff --git a/lib/tests/behat/behat_general.php b/lib/tests/behat/behat_general.php index 81b916c2e7a..8921a258e4f 100644 --- a/lib/tests/behat/behat_general.php +++ b/lib/tests/behat/behat_general.php @@ -1455,7 +1455,7 @@ EOF; // Check if value exists in specific row/column. // Get row xpath. - // GoutteDriver uses DomCrawler\Crawler and it is making XPath relative to the current context, so use descendant. + // Some drivers make XPath relative to the current context, so use descendant. $rowxpath = $tablexpath . "/tbody/tr[descendant::*[@class='rowtitle'][normalize-space(.)=" . $rowliteral . "] | " . " descendant::th[normalize-space(.)=" . $rowliteral . "] | descendant::td[normalize-space(.)=" . $rowliteral . "]]"; @@ -1802,7 +1802,7 @@ EOF; /** * Presses a given button in the browser. - * NOTE: Phantomjs and goutte driver reloads page while navigating back and forward. + * NOTE: Phantomjs and browserkit driver reloads page while navigating back and forward. * * @Then /^I press the "(back|forward|reload)" button in the browser$/ * @param string $button the button to press. diff --git a/lib/tests/behat/behat_hooks.php b/lib/tests/behat/behat_hooks.php index be966036aa2..81d99f0253d 100644 --- a/lib/tests/behat/behat_hooks.php +++ b/lib/tests/behat/behat_hooks.php @@ -702,7 +702,7 @@ EOF; * @param AfterStepScope $scope scope passed by event after step. */ protected function take_screenshot(AfterStepScope $scope) { - // Goutte can't save screenshots. + // BrowserKit can't save screenshots. if (!$this->running_javascript()) { return false; } diff --git a/my/templates/dropdown.mustache b/my/templates/dropdown.mustache index 6afe6ea8bcd..0ef52258554 100644 --- a/my/templates/dropdown.mustache +++ b/my/templates/dropdown.mustache @@ -27,7 +27,7 @@ } }}
- +