diff --git a/core/modules/system/lib/Drupal/system/Tests/Actions/NodeTest.php b/core/modules/system/lib/Drupal/system/Tests/Actions/NodeTest.php index 59578eb..b57f66e 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Actions/NodeTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Actions/NodeTest.php @@ -2,7 +2,7 @@ /** * @file - * Definition of Drupal\system\Tests\Actions\LoopTest. + * Contains \Drupal\system\Tests\Actions\NodeTest. */ namespace Drupal\system\Tests\Actions; @@ -21,89 +21,80 @@ public static function getInfo() { 'group' => 'Actions', ); } - + /** * Test the node publish, sticky, promote and assign owner actions */ function testNodePropertiesActions() { - // Publish actions $node = $this->_createNode(); - - // Trigger publish action + + // Test the publish action. actions_do('node_publish_action', $node); $this->assertEqual($node->status, NODE_PUBLISHED, 'Node reference got updated and published.'); - - // Trigger unpublish action + + // Test the 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 + + // Test the make 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 + + // Test the make 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 + + // Test the promote action. actions_do('node_promote_action', $node); $this->assertEqual($node->promote, NODE_PROMOTED, 'Node reference got updated and promoted.'); - - // Trigger unpromote action + + // Test the 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(); + + // Test the assign owner action. $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 + // Ensure that the owner of the node is not the test user. + $this->assertNotEqual($node->uid, $user->uid, 'Current owner is different from new one.'); + // Assign the test user as the owner of the node. 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 + * Test the node save action. */ function testNodeSaveAction() { $node = $this->_createNode(); + + // Save the original node status and give it a new one. $old_status = $node->status; $node->status = (int) !$old_status; - - // Trigger node save action + + // Save the node by triggering the 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.'); + + // Reload the node to ensure we retrieve the value in the database. + $new_node = node_load($node->nid); + $this->assertNotEqual($new_node->status, $old_status, 'Node status was successfully updated in the database.'); } - + /** - * Test node unpublish by keyword action + * Test the node unpublish by keyword action. */ function testNodeUnpublishByKeywordAction() { $node = $this->_createNode(); - // Publish the node + + // Publish the node. $node->status = NODE_PUBLISHED; + // Generate a pseudo-random keyword based on the title of the node. $keyword = substr($node->title, rand(0, strlen($node->title) / 2), strlen($node->title) / 2); - - // Trigger the action + + // Trigger the node unpublish by keyword 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. * @@ -112,10 +103,10 @@ function testNodeUnpublishByKeywordAction() { function _createNode() { return $this->drupalCreateNode(array( 'title' => $this->randomName(8), - 'promote' => 0, - 'status' => 0, - 'sticky' => 0, + 'promote' => 0, + 'status' => 0, + 'sticky' => 0, )); } - + } diff --git a/core/modules/system/lib/Drupal/system/Tests/Actions/UserTest.php b/core/modules/system/lib/Drupal/system/Tests/Actions/UserTest.php index 0d22712..5e91169 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Actions/UserTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Actions/UserTest.php @@ -2,7 +2,7 @@ /** * @file - * Definition of Drupal\system\Tests\Actions\UserTest. + * Contains \Drupal\system\Tests\Actions\UserTest. */ namespace Drupal\system\Tests\Actions; @@ -21,30 +21,19 @@ public static function getInfo() { 'group' => 'Actions', ); } - + /** * Test the user block action. */ function testUserBlockAction() { $user = $this->drupalCreateUser(array('access content')); - - // Trigger action on a user entity + + // Block user by triggering the block user action. actions_do('user_block_user_action', $user); - - // Reload user from database - $user = user_load($user->uid); - $this->assertEqual($user->status, 0, 'User in database got updated and blocked.'); - - // Create an entity to check on - $user = $this->drupalCreateUser(array('access content')); - $node = $this->drupalCreateNode(array('uid' => $user->uid)); - - // Trigger action - actions_do('user_block_user_action', $node); - - // Reload user from database + + // Reload user object from database. $user = user_load($user->uid); - $this->assertEqual($user->status, 0, 'User in database got updated and blocked.'); + $this->assertEqual($user->status, 0, 'User blocked, status is 0 in the database.'); } - + }