X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fnode%2Ftests%2Fsrc%2FFunctional%2FNodeEditFormTest.php;fp=web%2Fcore%2Fmodules%2Fnode%2Ftests%2Fsrc%2FFunctional%2FNodeEditFormTest.php;h=c15ca70bbe3beeb27754b07997325a6dbc9ee52d;hp=ea2a168635dafd659a3da6431b57cb17a080aff1;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hpb=aea91e65e895364e460983b890e295aa5d5540a5 diff --git a/web/core/modules/node/tests/src/Functional/NodeEditFormTest.php b/web/core/modules/node/tests/src/Functional/NodeEditFormTest.php index ea2a16863..c15ca70bb 100644 --- a/web/core/modules/node/tests/src/Functional/NodeEditFormTest.php +++ b/web/core/modules/node/tests/src/Functional/NodeEditFormTest.php @@ -98,7 +98,7 @@ class NodeEditFormTest extends NodeTestBase { $edit['title[0][value]'] = $this->randomMachineName(8); $edit[$body_key] = $this->randomMachineName(16); $edit['revision'] = TRUE; - $this->drupalPostForm(NULL, $edit, t('Save and keep published')); + $this->drupalPostForm(NULL, $edit, t('Save')); // Ensure that the node revision has been created. $revised_node = $this->drupalGetNodeByTitle($edit['title[0][value]'], TRUE); @@ -124,12 +124,21 @@ class NodeEditFormTest extends NodeTestBase { $edit['created[0][value][date]'] = $this->randomMachineName(8); // Get the current amount of open details elements. $open_details_elements = count($this->cssSelect('details[open="open"]')); - $this->drupalPostForm(NULL, $edit, t('Save and keep published')); + $this->drupalPostForm(NULL, $edit, t('Save')); // The node author details must be open. $this->assertRaw('
'); // Only one extra details element should now be open. $open_details_elements++; $this->assertEqual(count($this->cssSelect('details[open="open"]')), $open_details_elements, 'Exactly one extra open <details> element found.'); + + // Edit the same node, save it and verify it's unpublished after unchecking + // the 'Published' boolean_checkbox and clicking 'Save'. + $this->drupalGet("node/" . $node->id() . "/edit"); + $edit = ['status[value]' => FALSE]; + $this->drupalPostForm(NULL, $edit, t('Save')); + $this->nodeStorage->resetCache([$node->id()]); + $node = $this->nodeStorage->load($node->id()); + $this->assertFalse($node->isPublished(), 'Node is unpublished'); } /** @@ -143,7 +152,7 @@ class NodeEditFormTest extends NodeTestBase { $edit = []; $edit['title[0][value]'] = $this->randomMachineName(8); $edit[$body_key] = $this->randomMachineName(16); - $this->drupalPostForm('node/add/page', $edit, t('Save and publish')); + $this->drupalPostForm('node/add/page', $edit, t('Save')); // Check that the node was authored by the currently logged in user. $node = $this->drupalGetNodeByTitle($edit['title[0][value]']); @@ -172,7 +181,7 @@ class NodeEditFormTest extends NodeTestBase { $this->drupalLogin($this->adminUser); // Save the node without making any changes. - $this->drupalPostForm('node/' . $node->id() . '/edit', [], t('Save and keep published')); + $this->drupalPostForm('node/' . $node->id() . '/edit', [], t('Save')); $this->nodeStorage->resetCache([$node->id()]); $node = $this->nodeStorage->load($node->id()); $this->assertIdentical($this->webUser->id(), $node->getOwner()->id()); @@ -184,12 +193,49 @@ class NodeEditFormTest extends NodeTestBase { // Check that saving the node without making any changes keeps the proper // author ID. - $this->drupalPostForm('node/' . $node->id() . '/edit', [], t('Save and keep published')); + $this->drupalPostForm('node/' . $node->id() . '/edit', [], t('Save')); $this->nodeStorage->resetCache([$node->id()]); $node = $this->nodeStorage->load($node->id()); $this->assertIdentical($this->webUser->id(), $node->getOwner()->id()); } + /** + * Tests the node meta information. + */ + public function testNodeMetaInformation() { + // Check that regular users (i.e. without the 'administer nodes' permission) + // can not see the meta information. + $this->drupalLogin($this->webUser); + $this->drupalGet('node/add/page'); + $this->assertNoText('Not saved yet'); + + // Create node to edit. + $edit['title[0][value]'] = $this->randomMachineName(8); + $edit['body[0][value]'] = $this->randomMachineName(16); + $this->drupalPostForm(NULL, $edit, t('Save')); + + $node = $this->drupalGetNodeByTitle($edit['title[0][value]']); + $this->drupalGet("node/" . $node->id() . "/edit"); + $this->assertNoText('Published'); + $this->assertNoText(format_date($node->getChangedTime(), 'short')); + + // Check that users with the 'administer nodes' permission can see the meta + // information. + $this->drupalLogin($this->adminUser); + $this->drupalGet('node/add/page'); + $this->assertText('Not saved yet'); + + // Create node to edit. + $edit['title[0][value]'] = $this->randomMachineName(8); + $edit['body[0][value]'] = $this->randomMachineName(16); + $this->drupalPostForm(NULL, $edit, t('Save')); + + $node = $this->drupalGetNodeByTitle($edit['title[0][value]']); + $this->drupalGet("node/" . $node->id() . "/edit"); + $this->assertText('Published'); + $this->assertText(format_date($node->getChangedTime(), 'short')); + } + /** * Checks that the "authored by" works correctly with various values. * @@ -203,13 +249,13 @@ class NodeEditFormTest extends NodeTestBase { $edit = [ $form_element_name => 'invalid-name', ]; - $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save and keep published')); + $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save')); $this->assertRaw(t('There are no entities matching "%name".', ['%name' => 'invalid-name'])); // Change the authored by field to an empty string, which should assign // authorship to the anonymous user (uid 0). $edit[$form_element_name] = ''; - $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save and keep published')); + $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save')); $this->nodeStorage->resetCache([$node->id()]); $node = $this->nodeStorage->load($node->id()); $uid = $node->getOwnerId(); @@ -228,7 +274,7 @@ class NodeEditFormTest extends NodeTestBase { // Change the authored by field to another user's name (that is not // logged in). $edit[$form_element_name] = $this->webUser->getUsername(); - $this->drupalPostForm(NULL, $edit, t('Save and keep published')); + $this->drupalPostForm(NULL, $edit, t('Save')); $this->nodeStorage->resetCache([$node->id()]); $node = $this->nodeStorage->load($node->id()); $this->assertIdentical($node->getOwnerId(), $this->webUser->id(), 'Node authored by normal user.');