diff --git a/core/modules/system/lib/Drupal/system/Tests/Actions/NodeTest.php b/core/modules/system/lib/Drupal/system/Tests/Actions/NodeTest.php new file mode 100644 index 0000000..59578eb --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Tests/Actions/NodeTest.php @@ -0,0 +1,121 @@ + 'Actions defined by the Node module', + 'description' => 'Test coverage for node actions.', + 'group' => 'Actions', + ); + } + + /** + * Test the node publish, sticky, promote and assign owner actions + */ + function testNodePropertiesActions() { + // Publish actions + $node = $this->_createNode(); + + // Trigger publish action + actions_do('node_publish_action', $node); + $this->assertEqual($node->status, NODE_PUBLISHED, 'Node reference got updated and published.'); + + // Trigger unpublish action + actions_do('node_unpublish_action', $node); + $this->assertEqual($node->status, NODE_NOT_PUBLISHED, 'Node reference got updated and unpublished.'); + + // Sticky actions + $node = $this->_createNode(); + + // Trigger sticky action + actions_do('node_make_sticky_action', $node); + $this->assertEqual($node->sticky, NODE_STICKY, 'Node reference got updated and made sticky.'); + + // Trigger unsticky action + actions_do('node_make_unsticky_action', $node); + $this->assertEqual($node->sticky, NODE_NOT_STICKY, 'Node reference got updated and unmade sticky.'); + + // Promote actions + $node = $this->_createNode(); + + // Trigger promote action + actions_do('node_promote_action', $node); + $this->assertEqual($node->promote, NODE_PROMOTED, 'Node reference got updated and promoted.'); + + // Trigger unpromote action + actions_do('node_unpromote_action', $node); + $this->assertEqual($node->promote, NODE_NOT_PROMOTED, 'Node reference got updated and upromoted.'); + + // Change owner + $node = $this->_createNode(); + $user = $this->drupalCreateUser(array('administer nodes')); + $old_uid = $node->uid; + + // Check owners are currently different + $this->assertNotEqual($old_uid, $user->uid, 'Current owner is different from new one.'); + + // Change the node owner + actions_do('node_assign_owner_action', $node, array('owner_uid' => $user->uid)); + + $this->assertEqual($node->uid, $user->uid, 'Node reference got updated and owner got changed.'); + } + + /** + * Test node save action + */ + function testNodeSaveAction() { + $node = $this->_createNode(); + $old_status = $node->status; + $node->status = (int) !$old_status; + + // Trigger node save action + actions_do('node_save_action', $node); + + $new_node = node_load($node->nid); // Reload node to check + + $this->assertNotEqual($new_node->status, $old_status, 'Status got successfully updated to the database.'); + } + + /** + * Test node unpublish by keyword action + */ + function testNodeUnpublishByKeywordAction() { + $node = $this->_createNode(); + // Publish the node + $node->status = NODE_PUBLISHED; + $keyword = substr($node->title, rand(0, strlen($node->title) / 2), strlen($node->title) / 2); + + // Trigger the action + actions_do('node_unpublish_by_keyword_action', $node, array('keywords' => array($keyword))); + + $this->assertEqual($node->status, NODE_NOT_PUBLISHED, t('Node reference got unpublished based on the !key keyword.', array('!key' => $keyword))); + } + + /** + * Create a simple, unpublished, non-sticky and non-promoted node. + * + * @return Node + */ + function _createNode() { + return $this->drupalCreateNode(array( + 'title' => $this->randomName(8), + 'promote' => 0, + 'status' => 0, + 'sticky' => 0, + )); + } + +}