diff --git a/src/Drush/Commands/PlaywrightDrushCommands.php b/src/Drush/Commands/PlaywrightDrushCommands.php index b20ece8..57d543f 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 + * (Optional) 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 = 'published') { $storage = $this->getEntityTypeManager()->getStorage('node'); $nodes = $storage->loadByProperties([ 'title' => $node_title, @@ -47,8 +49,8 @@ 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"); + if ($moderation_state && $clone->hasField('moderation_state')) { + $clone->set('moderation_state', $moderation_state); } $clone->save(); } diff --git a/tests/helpers/drupal-commands.js b/tests/helpers/drupal-commands.js index 6e3d53b..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+$/,''); @@ -106,12 +105,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}"`); }, /**