NodePostSettingsTest.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace Drupal\Tests\node\Functional;
  3. /**
  4. * Tests that the post information (submitted by Username on date) text displays
  5. * appropriately.
  6. *
  7. * @group node
  8. */
  9. class NodePostSettingsTest extends NodeTestBase {
  10. protected function setUp() {
  11. parent::setUp();
  12. $web_user = $this->drupalCreateUser(['create page content', 'administer content types', 'access user profiles']);
  13. $this->drupalLogin($web_user);
  14. }
  15. /**
  16. * Confirms "Basic page" content type and post information is on a new node.
  17. */
  18. public function testPagePostInfo() {
  19. // Set "Basic page" content type to display post information.
  20. $edit = [];
  21. $edit['display_submitted'] = TRUE;
  22. $this->drupalPostForm('admin/structure/types/manage/page', $edit, t('Save content type'));
  23. // Create a node.
  24. $edit = [];
  25. $edit['title[0][value]'] = $this->randomMachineName(8);
  26. $edit['body[0][value]'] = $this->randomMachineName(16);
  27. $this->drupalPostForm('node/add/page', $edit, t('Save'));
  28. // Check that the post information is displayed.
  29. $node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
  30. $elements = $this->xpath('//div[contains(@class, :class)]', [':class' => 'node__submitted']);
  31. $this->assertEqual(count($elements), 1, 'Post information is displayed.');
  32. $node->delete();
  33. // Set "Basic page" content type to display post information.
  34. $edit = [];
  35. $edit['display_submitted'] = FALSE;
  36. $this->drupalPostForm('admin/structure/types/manage/page', $edit, t('Save content type'));
  37. // Create a node.
  38. $edit = [];
  39. $edit['title[0][value]'] = $this->randomMachineName(8);
  40. $edit['body[0][value]'] = $this->randomMachineName(16);
  41. $this->drupalPostForm('node/add/page', $edit, t('Save'));
  42. // Check that the post information is displayed.
  43. $elements = $this->xpath('//div[contains(@class, :class)]', [':class' => 'node__submitted']);
  44. $this->assertEqual(count($elements), 0, 'Post information is not displayed.');
  45. }
  46. }