From 1e6071b0c05b9dcb6d8a1df3d7d7af949b9949e1 Mon Sep 17 00:00:00 2001 From: Rasmus Werling Date: Fri, 28 Jan 2022 14:16:53 +0200 Subject: [PATCH 01/12] Added DrupalAcceptance::selectNthOptionFromList(), updated readme. --- README.md | 10 +++++++++- src/Codeception/Module/DrupalAcceptance.php | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 87772be..b230249 100644 --- a/README.md +++ b/README.md @@ -196,8 +196,16 @@ modules: // Fill title. $i->fillTextField(FormField::title(), 'Mans nosukums'); -// Select english language for content. +// Select option from select list by key or value. +// For custom fields, target (last parameter) usually needs to be set to an +// empty string. $i->selectOptionFromList(FormField::langcode(), 'en'); +$i->selectOptionFromList(FormField::langcode(), 'English'); +$i->selectOptionFromList(FormField::field_my_list(), 'Apple', ''); + +// Select the nth option from a select list. +$i->selectOptionFromList(FormField::langcode()); +$i->selectNthOptionFromList(MTOFormField::field_my_list(), 2, ''); // Fill first paragraph of type text. $page_elements = ParagraphFormField::field_page_elements(); diff --git a/src/Codeception/Module/DrupalAcceptance.php b/src/Codeception/Module/DrupalAcceptance.php index 305de85..f5f0c6f 100644 --- a/src/Codeception/Module/DrupalAcceptance.php +++ b/src/Codeception/Module/DrupalAcceptance.php @@ -122,6 +122,24 @@ public function selectOptionFromList(IdentifiableFormFieldInterface $field, $opt $this->webdriver->selectOption($field->$target, $option); } + /** + * Select nth option from select list. + * + * Useful if you don't know what the options in the list are, and just want + * to select the first one, second one etc. + * + * @param \Codeception\Util\IdentifiableFormFieldInterface $field + * Select list form field. + * @param int $nth + * Nth option to get. Default to first option. + * @param string $target + * Target field. + */ + public function selectNthOptionFromList(IdentifiableFormFieldInterface $field, $nth = 1, $target = 'value') { + $option = $this->webdriver->grabTextFrom($field->{$target} . '/option[' . $nth . ']'); + $this->selectOptionFromList($field, $option, $target); + } + /** * Click on element. * From 7cc1c22cbd25531ceec75f057a6d93b944b4169c Mon Sep 17 00:00:00 2001 From: Rasmus Werling Date: Fri, 28 Jan 2022 14:19:11 +0200 Subject: [PATCH 02/12] Fixed __get() methods in FormField and MTOFormField, as the dash '-' would be added even if there was no suffix, for example when calling $field->{$target} with an empty target. --- src/Codeception/Util/Drupal/FormField.php | 9 +++++---- src/Codeception/Util/Drupal/MTOFormField.php | 10 ++++------ 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/Codeception/Util/Drupal/FormField.php b/src/Codeception/Util/Drupal/FormField.php index 68945e5..5fd6411 100644 --- a/src/Codeception/Util/Drupal/FormField.php +++ b/src/Codeception/Util/Drupal/FormField.php @@ -90,15 +90,16 @@ public function __toString() { /** * Returns xpath of current identifiers element. * - * @param string $name + * @param string $element * Name of element. * * @return string * Returns path with current identifier plus requested subfield. */ - public function __get($name) { + public function __get($element = '') { + $suffix = $element ? '-' . $this->normalise($element) : ''; return $this->getXpath([ - 'identifier' => $this->getCurrentIdentifier() . '-' . $this->normalise($name), + 'identifier' => $this->getCurrentIdentifier() . $suffix, ]); } @@ -142,7 +143,7 @@ public function getCurrentIdentifier() { * @param string $element * Name of element. * - * @return mixed + * @return string * Returns path with identifier plus requested subfield. */ public function get($element = '') { diff --git a/src/Codeception/Util/Drupal/MTOFormField.php b/src/Codeception/Util/Drupal/MTOFormField.php index 4758e71..b6abde4 100644 --- a/src/Codeception/Util/Drupal/MTOFormField.php +++ b/src/Codeception/Util/Drupal/MTOFormField.php @@ -80,16 +80,14 @@ public function __toString() { /** * Returns xpath of current identifiers element. * - * @param string $name + * @param string $element * Name of element. * * @return string * Returns path with current identifier plus requested subfield. */ - public function __get($name) { - return $this->getXpath([ - 'identifier' => $this->getIdentifier() . '-' . $this->normalise($name), - ]); + public function __get($element = '') { + return $this->get($element); } /** @@ -132,7 +130,7 @@ public function getCurrentIdentifier() { * @param string $element * Name of element. * - * @return mixed + * @return string * Returns path with identifier plus requested subfield. */ public function get($element = '') { From 8eb8f6a8ac7e3fc6c073efc7b48aaf607f7ca6dc Mon Sep 17 00:00:00 2001 From: Rasmus Werling Date: Fri, 4 Feb 2022 13:09:37 +0200 Subject: [PATCH 03/12] Added timeout setting for drush, since default timeout of 60 seconds might not be enough for some time-consuming commands. Also added new parameter $return_process. --- src/Codeception/Module/DrupalDrush.php | 12 ++++++++---- src/Codeception/Module/DrupalUser.php | 2 +- src/Codeception/Util/Drush.php | 20 ++++++++++++++++---- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/Codeception/Module/DrupalDrush.php b/src/Codeception/Module/DrupalDrush.php index 046e3b2..3a49dc3 100644 --- a/src/Codeception/Module/DrupalDrush.php +++ b/src/Codeception/Module/DrupalDrush.php @@ -13,6 +13,7 @@ * modules: * - DrupalDrush: * working_directory: './web' + * timeout: 120 * drush: './vendor/bin/drush' * alias: '@mysite.com' * options: @@ -42,11 +43,14 @@ class DrupalDrush extends Module { * e.g. "en devel -y". * @param array $options * Associative array of options. + * @param bool $return_process + * If TRUE, the Process object will be returned. If false, the output of + * Process::getOutput() will be returned. Defaults to FALSE. * - * @return string - * The process output. + * @return string|\Symfony\Component\Process\Process + * The process output, or the process itself. */ - public function runDrush($command, array $options = []) { + public function runDrush($command, array $options = [], $return_process = FALSE) { if ($alias = $this->_getConfig('alias')) { $command = $alias . ' ' . $command; } @@ -56,7 +60,7 @@ public function runDrush($command, array $options = []) { elseif ($this->_getConfig('options')) { $command = $this->normalizeOptions($this->_getConfig('options')) . $command; } - return Drush::runDrush($command, $this->_getConfig('drush'), $this->_getConfig('working_directory')); + return Drush::runDrush($command, $this->_getConfig('drush'), $this->_getConfig('working_directory'), $this->_getConfig('timeout'), $return_process); } /** diff --git a/src/Codeception/Module/DrupalUser.php b/src/Codeception/Module/DrupalUser.php index 9aac7c4..f5aa69b 100644 --- a/src/Codeception/Module/DrupalUser.php +++ b/src/Codeception/Module/DrupalUser.php @@ -142,7 +142,7 @@ public function createUserWithRoles(array $roles = [], $password = FALSE) { */ public function logInAs($username) { $alias = $this->_getConfig('alias') ? $this->_getConfig('alias') . ' ' : ''; - $output = Drush::runDrush($alias. 'uli --name=' . $username, $this->_getConfig('drush'), $this->_getConfig('working_directory')); + $output = Drush::runDrush($alias. 'uli --name=' . $username, $this->_getConfig('drush'), $this->_getConfig('working_directory'), $this->_getConfig('timeout')); $gen_url = str_replace(PHP_EOL, '', $output); $url = substr($gen_url, strpos($gen_url, '/user/reset')); $this->driver->amOnPage($url); diff --git a/src/Codeception/Util/Drush.php b/src/Codeception/Util/Drush.php index 9ee75cc..cb2d01b 100644 --- a/src/Codeception/Util/Drush.php +++ b/src/Codeception/Util/Drush.php @@ -21,11 +21,16 @@ class Drush { * The drush command to use. * @param string $pwd * Working directory. + * @param int|float $timeout. + * Drush execution timeout. + * @param bool $return_process + * If TRUE, the Process object will be returned. If false, the output of + * Process::getOutput() will be returned. Defaults to FALSE. * - * @return string - * The process output. + * @return string|\Symfony\Component\Process\Process + * The process output, or the process object itself. */ - public static function runDrush($command, $drush = 'drush', $pwd = NULL) { + public static function runDrush($command, $drush = 'drush', $pwd = NULL, $timeout = NULL, $return_process = FALSE) { $command_args = array_merge([$drush], explode(' ', $command)); $process = new Process($command_args); @@ -34,7 +39,14 @@ public static function runDrush($command, $drush = 'drush', $pwd = NULL) { $process->setWorkingDirectory($pwd); } - return $process->mustRun()->getOutput(); + // Set timeout if configured. + if (isset($timeout)) { + $process->setTimeout($timeout); + } + + $process->mustRun(); + + return $return_process ? $process : $process->getOutput(); } } From 6e2eded18550d0f66ce065ed9fcd34f65daa5916 Mon Sep 17 00:00:00 2001 From: Rasmus Werling Date: Fri, 4 Feb 2022 13:31:02 +0200 Subject: [PATCH 04/12] Updated readme. --- README.md | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 87772be..0c2515c 100644 --- a/README.md +++ b/README.md @@ -47,11 +47,13 @@ Provides drush (`runDrush`) command. ### Configuration - working_directory: Working directory where drush should be executed. Defaults to codeception root. +- timeout: Timeout in seconds for drush command. Set to 0 for no timeout. Default to 60 seconds. - drush: Drush executable. Defaults to `drush`. ``` modules: - DrupalDrush: working_directory: './web' + timeout: 120 drush: './vendor/bin/drush' options: uri: http://mydomain.com @@ -60,9 +62,17 @@ modules: ### Usage -Run drush config import and store output. +Run drush status and store output. -`$output = $i->runDrush('cim -y');` +`$output = $i->runDrush('status');` + +Run drush config import and store output from STDERR. + +`$output = $i->runDrush('cim -y', [], TRUE)->getErrorOutput();` + +Run drush cache rebuild and store the exit code. + +`$exit_code = $i->runDrush('cr', [], TRUE)->getExitCode();` Get one-time login url. From d6944506a0d4921ca54674bae46acc55e7476633 Mon Sep 17 00:00:00 2001 From: Juhani Moilanen Date: Mon, 20 Jun 2022 14:14:07 +0300 Subject: [PATCH 05/12] Replace fzaninotto/faker with fakerphp/faker, update other dependencies --- composer.json | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index 001a5cc..28e1cad 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "guncha25/drupal-codeception", + "name": "wunderio/drupal-codeception", "description": "Codeception toolset for Drupal testing.", "type": "package", "repositories": [ @@ -9,14 +9,14 @@ } ], "require": { - "codeception/codeception": "^4.0", - "fzaninotto/faker": "^1.8", - "codeception/module-webdriver": "^1.1", - "webflo/drupal-finder": "^1.2" + "codeception/codeception": "^4.2", + "codeception/module-webdriver": "^2.0", + "webflo/drupal-finder": "^1.2", + "fakerphp/faker": "^1.19" }, "require-dev": { - "composer/installers": "^1", - "drupal/core": "^8" + "composer/installers": "^2", + "drupal/core": "^9" }, "license": "GPL-2.0", "authors": [ @@ -30,5 +30,10 @@ "psr-4": { "Codeception\\": "src/Codeception" } + }, + "config": { + "allow-plugins": { + "composer/installers": true + } } } From ed83a297555c98ed416e81878d32a1baa3b27644 Mon Sep 17 00:00:00 2001 From: Jaap Jan Date: Wed, 14 Jun 2023 10:08:31 +0200 Subject: [PATCH 06/12] Replace fzaninotto/faker with phpfaker/faker --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 001a5cc..08e6598 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ ], "require": { "codeception/codeception": "^4.0", - "fzaninotto/faker": "^1.8", + "fakerphp/faker": "^1.23", "codeception/module-webdriver": "^1.1", "webflo/drupal-finder": "^1.2" }, From abfc1cd4e3c43f02568d7a878ebd3389465d462c Mon Sep 17 00:00:00 2001 From: Guntis Jakovins Date: Wed, 11 Oct 2023 08:55:00 +0300 Subject: [PATCH 07/12] D10 prep --- .gitignore | 1 + composer.json | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 1b10983..90b961a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .idea/ +.lando.yml composer.lock vendor/ core/ \ No newline at end of file diff --git a/composer.json b/composer.json index e88187d..43db591 100644 --- a/composer.json +++ b/composer.json @@ -9,14 +9,14 @@ } ], "require": { - "codeception/codeception": "^4.2", - "codeception/module-webdriver": "^2.0", + "codeception/codeception": "^4 || ^5", + "codeception/module-webdriver": "^3 || ^4", "webflo/drupal-finder": "^1.2", "fakerphp/faker": "^1.23" }, "require-dev": { "composer/installers": "^2", - "drupal/core": "^9" + "drupal/core": "^9 || ^10" }, "license": "GPL-2.0", "authors": [ From a9b39d998968abfbb5e2937b6283c2755c65a685 Mon Sep 17 00:00:00 2001 From: Guntis Jakovins Date: Wed, 11 Oct 2023 09:10:34 +0300 Subject: [PATCH 08/12] D10 support --- composer.json | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 43db591..07d163b 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "wunderio/drupal-codeception", + "name": "guncha25/drupal-codeception", "description": "Codeception toolset for Drupal testing.", "type": "package", "repositories": [ @@ -12,7 +12,9 @@ "codeception/codeception": "^4 || ^5", "codeception/module-webdriver": "^3 || ^4", "webflo/drupal-finder": "^1.2", - "fakerphp/faker": "^1.23" + "fakerphp/faker": "^1.23", + "codeception/module-phpbrowser": "*", + "codeception/module-asserts": "*" }, "require-dev": { "composer/installers": "^2", From a306bd457d64fe625dd5f3c935f365f9a0deb1f5 Mon Sep 17 00:00:00 2001 From: Guntis Jakovins Date: Wed, 11 Oct 2023 10:04:22 +0300 Subject: [PATCH 09/12] D10 version --- composer.json | 4 +-- src/Codeception/Module/DrupalBootstrap.php | 8 +++--- src/Codeception/Module/DrupalDrush.php | 16 +++++------ src/Codeception/Module/DrupalEntity.php | 20 ++++++++------ src/Codeception/Module/DrupalUser.php | 32 ++++++++++++---------- src/Codeception/Module/DrupalWatchdog.php | 2 +- src/Codeception/TestDrupalKernel.php | 6 ++-- 7 files changed, 46 insertions(+), 42 deletions(-) diff --git a/composer.json b/composer.json index 07d163b..285b394 100644 --- a/composer.json +++ b/composer.json @@ -9,8 +9,8 @@ } ], "require": { - "codeception/codeception": "^4 || ^5", - "codeception/module-webdriver": "^3 || ^4", + "codeception/codeception": "^5", + "codeception/module-webdriver": "^4", "webflo/drupal-finder": "^1.2", "fakerphp/faker": "^1.23", "codeception/module-phpbrowser": "*", diff --git a/src/Codeception/Module/DrupalBootstrap.php b/src/Codeception/Module/DrupalBootstrap.php index 8a93e05..f4f2a39 100644 --- a/src/Codeception/Module/DrupalBootstrap.php +++ b/src/Codeception/Module/DrupalBootstrap.php @@ -17,9 +17,9 @@ * #### Example (DrupalBootstrap) * modules: * - DrupalBootstrap: - * root: './web' - * site_path: 'sites/default' - * http_host: 'mysite.local' + * root: './web' + * site_path: 'sites/default' + * http_host: 'mysite.local' * * @package Codeception\Module */ @@ -30,7 +30,7 @@ class DrupalBootstrap extends Module { * * @var array */ - protected $config = [ + protected array $config = [ 'site_path' => 'sites/default', ]; diff --git a/src/Codeception/Module/DrupalDrush.php b/src/Codeception/Module/DrupalDrush.php index 3a49dc3..574b345 100644 --- a/src/Codeception/Module/DrupalDrush.php +++ b/src/Codeception/Module/DrupalDrush.php @@ -12,13 +12,13 @@ * #### Example (DrupalDrush) * modules: * - DrupalDrush: - * working_directory: './web' - * timeout: 120 - * drush: './vendor/bin/drush' - * alias: '@mysite.com' - * options: - * uri: http://mydomain.com - * root: /app/web + * working_directory: './web' + * timeout: 120 + * drush: './vendor/bin/drush' + * alias: '@mysite.com' + * options: + * uri: http://mydomain.com + * root: /app/web * * @package Codeception\Module */ @@ -29,7 +29,7 @@ class DrupalDrush extends Module { * * @var array */ - protected $config = [ + protected array $config = [ 'drush' => 'drush', 'alias' => '', 'options' => [], diff --git a/src/Codeception/Module/DrupalEntity.php b/src/Codeception/Module/DrupalEntity.php index 0d1b84a..3acc604 100644 --- a/src/Codeception/Module/DrupalEntity.php +++ b/src/Codeception/Module/DrupalEntity.php @@ -3,9 +3,11 @@ namespace Codeception\Module; use Codeception\Module; +use Codeception\TestInterface; use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\Core\Url; use Codeception\TestCase; +use Exception; /** * Class DrupalEntity. @@ -14,12 +16,12 @@ * #### Example (DrupalEntity) * modules: * - DrupalEntity: - * cleanup_test: true - * cleanup_failed: false - * cleanup_suite: true - * route_entities: - * - node - * - taxonomy_term. + * cleanup_test: true + * cleanup_failed: false + * cleanup_suite: true + * route_entities: + * - node + * - taxonomy_term. * * @package Codeception\Module */ @@ -30,7 +32,7 @@ class DrupalEntity extends Module { * * @var array */ - protected $config = [ + protected array $config = [ 'cleanup_test' => TRUE, 'cleanup_failed' => TRUE, 'cleanup_suite' => TRUE, @@ -60,7 +62,7 @@ public function _afterSuite() { // @codingStandardsIgnoreLine /** * {@inheritdoc} */ - public function _after(TestCase $test) { // @codingStandardsIgnoreLine + public function _after(TestInterface $test) { // @codingStandardsIgnoreLine if ($this->config['cleanup_test']) { $this->doEntityCleanup(); } @@ -69,7 +71,7 @@ public function _after(TestCase $test) { // @codingStandardsIgnoreLine /** * {@inheritdoc} */ - public function _failed(TestCase $test, $fail) { // @codingStandardsIgnoreLine + public function _failed(TestInterface $test, Exception $fail) { // @codingStandardsIgnoreLine if ($this->config['cleanup_failed']) { $this->doEntityCleanup(); } diff --git a/src/Codeception/Module/DrupalUser.php b/src/Codeception/Module/DrupalUser.php index 7d919c0..be31328 100644 --- a/src/Codeception/Module/DrupalUser.php +++ b/src/Codeception/Module/DrupalUser.php @@ -3,11 +3,13 @@ namespace Codeception\Module; use Codeception\Module; +use Codeception\TestInterface; use Drupal\Core\Config\StorageInterface; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\user\Entity\User; use Faker\Factory; use Codeception\Util\Drush; +use Exception; /** * Class DrupalUser. @@ -16,17 +18,17 @@ * #### Example (DrupalUser) * modules: * - DrupalUser: - * default_role: 'authenticated' - * driver: 'PhpBrowser' - * drush: './vendor/bin/drush' - * cleanup_entities: - * - media - * - file - * - paragraph - * cleanup_test: false - * cleanup_failed: false - * cleanup_suite: true - * alias: @site.com + * default_role: 'authenticated' + * driver: 'PhpBrowser' + * drush: './vendor/bin/drush' + * cleanup_entities: + * - media + * - file + * - paragraph + * cleanup_test: false + * cleanup_failed: false + * cleanup_suite: true + * alias: @site.com * * @package Codeception\Module */ @@ -51,7 +53,7 @@ class DrupalUser extends Module { * * @var array */ - protected $config = [ + protected array $config = [ 'alias' => '', 'default_role' => 'authenticated', 'driver' => 'WebDriver', @@ -65,7 +67,7 @@ class DrupalUser extends Module { /** * {@inheritdoc} */ - public function _beforeSuite($settings = []) { // @codingStandardsIgnoreLine + public function _beforeSuite(array $settings = []) { // @codingStandardsIgnoreLine $this->driver = null; if (!$this->hasModule($this->_getConfig('driver'))) { $this->fail('User driver module not found.'); @@ -77,7 +79,7 @@ public function _beforeSuite($settings = []) { // @codingStandardsIgnoreLine /** * {@inheritdoc} */ - public function _after(\Codeception\TestCase $test) { // @codingStandardsIgnoreLine + public function _after(TestInterface $test) { // @codingStandardsIgnoreLine if ($this->_getConfig('cleanup_test')) { $this->userCleanup(); } @@ -86,7 +88,7 @@ public function _after(\Codeception\TestCase $test) { // @codingStandardsIgnoreL /** * {@inheritdoc} */ - public function _failed(\Codeception\TestCase $test, $fail) { // @codingStandardsIgnoreLine + public function _failed(TestInterface $test, Exception $fail) { // @codingStandardsIgnoreLine if ($this->_getConfig('cleanup_failed')) { $this->userCleanup(); } diff --git a/src/Codeception/Module/DrupalWatchdog.php b/src/Codeception/Module/DrupalWatchdog.php index 2398476..19273c8 100644 --- a/src/Codeception/Module/DrupalWatchdog.php +++ b/src/Codeception/Module/DrupalWatchdog.php @@ -35,7 +35,7 @@ class DrupalWatchdog extends Module { * * @var array */ - protected $config = [ + protected array $config = [ 'channels' => [], 'level' => 'ERROR', 'enabled' => TRUE, diff --git a/src/Codeception/TestDrupalKernel.php b/src/Codeception/TestDrupalKernel.php index 4ee4164..8e16f92 100644 --- a/src/Codeception/TestDrupalKernel.php +++ b/src/Codeception/TestDrupalKernel.php @@ -4,11 +4,11 @@ use Drupal\Core\DrupalKernel; use Drupal\Core\Site\Settings; -use Symfony\Cmf\Component\Routing\RouteObjectInterface; +use Drupal\Core\Routing\RouteObjectInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Route; -class TestDrupalKernel extends DrupalKernel{ +class TestDrupalKernel extends DrupalKernel { /** * TestDrupalKernel constructor. @@ -44,4 +44,4 @@ public function bootTestEnvironment($sitePath, Request $request){ $this->container->get('router.request_context')->fromRequest($request); } -} \ No newline at end of file +} From 4d0dc471e2408492782be13715a17c9c9665c9a7 Mon Sep 17 00:00:00 2001 From: Guntis Jakovins Date: Wed, 11 Oct 2023 10:16:29 +0300 Subject: [PATCH 10/12] Update dependencies --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 285b394..ccdceea 100644 --- a/composer.json +++ b/composer.json @@ -10,11 +10,11 @@ ], "require": { "codeception/codeception": "^5", - "codeception/module-webdriver": "^4", + "codeception/module-webdriver": "^3 || ^4", "webflo/drupal-finder": "^1.2", "fakerphp/faker": "^1.23", - "codeception/module-phpbrowser": "*", - "codeception/module-asserts": "*" + "codeception/module-phpbrowser": "^3", + "codeception/module-asserts": "^3" }, "require-dev": { "composer/installers": "^2", From 95be4a1442226286c4e53c6cdd4dbf303abc10d1 Mon Sep 17 00:00:00 2001 From: Guntis Jakovins Date: Wed, 11 Oct 2023 13:37:30 +0300 Subject: [PATCH 11/12] Fix invalid namespaces. --- src/Codeception/Module/DrupalEntity.php | 1 - src/Codeception/Module/DrupalUser.php | 1 - 2 files changed, 2 deletions(-) diff --git a/src/Codeception/Module/DrupalEntity.php b/src/Codeception/Module/DrupalEntity.php index 3acc604..e04f99c 100644 --- a/src/Codeception/Module/DrupalEntity.php +++ b/src/Codeception/Module/DrupalEntity.php @@ -6,7 +6,6 @@ use Codeception\TestInterface; use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\Core\Url; -use Codeception\TestCase; use Exception; /** diff --git a/src/Codeception/Module/DrupalUser.php b/src/Codeception/Module/DrupalUser.php index be31328..46da663 100644 --- a/src/Codeception/Module/DrupalUser.php +++ b/src/Codeception/Module/DrupalUser.php @@ -4,7 +4,6 @@ use Codeception\Module; use Codeception\TestInterface; -use Drupal\Core\Config\StorageInterface; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\user\Entity\User; use Faker\Factory; From 50acc63d7bcbf99b02c89e2cdc599ac23195c6c7 Mon Sep 17 00:00:00 2001 From: Kalvis Kazoks Date: Fri, 8 Dec 2023 20:22:09 +0200 Subject: [PATCH 12/12] Add support for CKEditor5 in DrupalAcceptance->fillWysiwygEditor --- src/Codeception/Module/DrupalAcceptance.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Codeception/Module/DrupalAcceptance.php b/src/Codeception/Module/DrupalAcceptance.php index 17e910c..c163e87 100644 --- a/src/Codeception/Module/DrupalAcceptance.php +++ b/src/Codeception/Module/DrupalAcceptance.php @@ -176,6 +176,12 @@ public function addReferenceFieldItem(FormField $field) { public function fillWysiwygEditor(IdentifiableFormFieldInterface $field, $content) { $selector = $this->webdriver->grabAttributeFrom($field->value, 'id'); $script = "jQuery(function(){CKEDITOR.instances[\"$selector\"].setData(\"$content\")});"; + // Check if CKEditor5 is in use. If so, override the script as global + // registry of editor instances is no longer available and a different + // approach is used to access them via DOM. + if (!empty($this->webdriver->grabAttributeFrom($field->value, 'data-ckeditor5-id'))) { + $script = "document.querySelector(\"#$selector\").nextSibling.querySelector(\".ck-editor__editable_inline\").ckeditorInstance.setData(\"$content\")"; + } $this->webdriver->executeInSelenium(function (RemoteWebDriver $webDriver) use ($script) { $webDriver->executeScript($script); });