Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/Drush/Commands/PlaywrightDrushCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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();
}
Expand Down
15 changes: 7 additions & 8 deletions tests/helpers/drupal-commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '']) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing @sindurigf 's change made me realize that I don't know Javascript (well I knew that part) and that it is fine to have an optional part of an array, inside an array parameter.

In other words, this change is possible and does not change anything - and that means the recent addition that I did of langcode outside of the array is unnecessary... and inconsistent.

So I 'fixed' that in this same PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None of the current visitNodeEditPage() calls pass the optional langcode, so nothing breaks. (This was added for LDP-1787 which isn't merged yet.)

const lang_prefix = langcode ? `/${langcode}` : '';
const result = drush(`test:node-get-id "${node_title}"`);
const nid = result.toString().replace(/\s+$/,'');
Expand Down Expand Up @@ -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}"`);
},

/**
Expand Down