From 400181d646807b4e25dec48a6cec38e06624d290 Mon Sep 17 00:00:00 2001 From: sindurigf Date: Wed, 17 Jan 2024 15:19:50 +0100 Subject: [PATCH 1/4] LDP-2328: add optional moderation state to the function cloneNodeByTitle --- src/Drush/Commands/PlaywrightDrushCommands.php | 6 ++++-- tests/helpers/drupal-commands.js | 8 ++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Drush/Commands/PlaywrightDrushCommands.php b/src/Drush/Commands/PlaywrightDrushCommands.php index b20ece8..8d9e729 100644 --- a/src/Drush/Commands/PlaywrightDrushCommands.php +++ b/src/Drush/Commands/PlaywrightDrushCommands.php @@ -28,6 +28,8 @@ class PlaywrightDrushCommands extends DrushCommands { * The title of node to be cloned. * @param string $new_node_title * Title of the clone. + * @param string $moderation_state + * Moderation state of the clone. * * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException @@ -36,7 +38,7 @@ class PlaywrightDrushCommands extends DrushCommands { * @command test:node-clone * @aliases nc */ - public function cloneNodeByTitle($node_type, $node_title, $new_node_title) { + public function cloneNodeByTitle($node_type, $node_title, $new_node_title, $moderation_state) { $storage = $this->getEntityTypeManager()->getStorage('node'); $nodes = $storage->loadByProperties([ 'title' => $node_title, @@ -48,7 +50,7 @@ public function cloneNodeByTitle($node_type, $node_title, $new_node_title) { $clone = $node->createDuplicate(); $clone->title = $new_node_title; if ($clone->hasField('moderation_state')) { - $clone->set('moderation_state', "published"); + $clone->set('moderation_state', $moderation_state); } $clone->save(); } diff --git a/tests/helpers/drupal-commands.js b/tests/helpers/drupal-commands.js index 6e3d53b..db6e5af 100644 --- a/tests/helpers/drupal-commands.js +++ b/tests/helpers/drupal-commands.js @@ -106,12 +106,12 @@ module.exports = { /** * Clones node with given title to a new node with new title. - * @param {Array<{page: Page, node_title: String, new_node_title: String}>} - * array Page object and node title + * @param {Array<{page: Page, node_title: String, new_node_title: String, moderation_state: String}>} + * array Page object, node title and moderation_state with default published status. * @return {string} The output of the command run. */ - cloneNodeByTitle: async ([page, node_type, node_title, new_node_title]) => { - return drush(`test:node-clone "${node_type}" "${node_title}" "${new_node_title}"`); + cloneNodeByTitle: async ([page, node_type, node_title, new_node_title, moderation_state = "published"]) => { + return drush(`test:node-clone "${node_type}" "${node_title}" "${new_node_title}" "${moderation_state}"`); }, /** From 54bc16bdccf855ad1cb4b4ce75b79f4babe37f47 Mon Sep 17 00:00:00 2001 From: Roderik Muit Date: Wed, 17 Jan 2024 16:35:36 +0100 Subject: [PATCH 2/4] LDP-2328: make visitNodeEditPage definition consistent with this change. --- tests/helpers/drupal-commands.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/helpers/drupal-commands.js b/tests/helpers/drupal-commands.js index db6e5af..7bde001 100644 --- a/tests/helpers/drupal-commands.js +++ b/tests/helpers/drupal-commands.js @@ -5,15 +5,14 @@ function drush(command) { module.exports = { /** * Finds node ID via drush and visits node edit page. - * @param {Array<{page: Page, node_title: String}>} array Page object and - * node title - * @param {string} langcode Optional language code prefix for the URL. + * @param {Array<{page: Page, node_title: String, langcode: String}>} array + * Page object, node title and optional language code prefix for the URL. * Note the node title must be in the original language. The visited page * will edit the node's translation if it exists, otherwise the original * language node (just in another UI language). * @return {Response} The response. */ - visitNodeEditPage: async ([page, node_title], langcode = '') => { + visitNodeEditPage: async ([page, node_title, langcode = '']) => { const lang_prefix = langcode ? `/${langcode}` : ''; const result = drush(`test:node-get-id "${node_title}"`); const nid = result.toString().replace(/\s+$/,''); From c3e30905318bdef80371bc6e05f5f31c2cefff65 Mon Sep 17 00:00:00 2001 From: Roderik Muit Date: Wed, 17 Jan 2024 16:37:08 +0100 Subject: [PATCH 3/4] LDP-2328: slight improvement to enable passing empty moderation state for "no change" --- src/Drush/Commands/PlaywrightDrushCommands.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Drush/Commands/PlaywrightDrushCommands.php b/src/Drush/Commands/PlaywrightDrushCommands.php index 8d9e729..d64f8ee 100644 --- a/src/Drush/Commands/PlaywrightDrushCommands.php +++ b/src/Drush/Commands/PlaywrightDrushCommands.php @@ -49,7 +49,7 @@ public function cloneNodeByTitle($node_type, $node_title, $new_node_title, $mode } $clone = $node->createDuplicate(); $clone->title = $new_node_title; - if ($clone->hasField('moderation_state')) { + if ($moderation_state && $clone->hasField('moderation_state')) { $clone->set('moderation_state', $moderation_state); } $clone->save(); From e66d5446d0ae1a6a097fefda3ff3cb5de38c1fab Mon Sep 17 00:00:00 2001 From: Roderik Muit Date: Wed, 17 Jan 2024 17:27:43 +0100 Subject: [PATCH 4/4] LDP-2328: make moderation_state optional in the drush command too, --- src/Drush/Commands/PlaywrightDrushCommands.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Drush/Commands/PlaywrightDrushCommands.php b/src/Drush/Commands/PlaywrightDrushCommands.php index d64f8ee..57d543f 100644 --- a/src/Drush/Commands/PlaywrightDrushCommands.php +++ b/src/Drush/Commands/PlaywrightDrushCommands.php @@ -29,7 +29,7 @@ class PlaywrightDrushCommands extends DrushCommands { * @param string $new_node_title * Title of the clone. * @param string $moderation_state - * Moderation state of the clone. + * (Optional) moderation state of the clone. * * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException @@ -38,7 +38,7 @@ class PlaywrightDrushCommands extends DrushCommands { * @command test:node-clone * @aliases nc */ - public function cloneNodeByTitle($node_type, $node_title, $new_node_title, $moderation_state) { + public function cloneNodeByTitle($node_type, $node_title, $new_node_title, $moderation_state = 'published') { $storage = $this->getEntityTypeManager()->getStorage('node'); $nodes = $storage->loadByProperties([ 'title' => $node_title,