PathContentModerationTest.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. namespace Drupal\Tests\path\Functional;
  3. use Drupal\node\Entity\NodeType;
  4. use Drupal\Tests\BrowserTestBase;
  5. use Drupal\Tests\content_moderation\Traits\ContentModerationTestTrait;
  6. /**
  7. * Tests path aliases with Content Moderation.
  8. *
  9. * @group content_moderation
  10. * @group path
  11. */
  12. class PathContentModerationTest extends BrowserTestBase {
  13. use ContentModerationTestTrait;
  14. /**
  15. * Modules to install.
  16. *
  17. * @var array
  18. */
  19. public static $modules = ['node', 'path', 'content_moderation'];
  20. /**
  21. * {@inheritdoc}
  22. */
  23. protected function setUp() {
  24. parent::setUp();
  25. // Created a content type.
  26. $node_type = NodeType::create(['name' => 'moderated', 'type' => 'moderated']);
  27. $node_type->save();
  28. // Set the content type as moderated.
  29. $workflow = $this->createEditorialWorkflow();
  30. $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'moderated');
  31. $workflow->save();
  32. $this->drupalLogin($this->rootUser);
  33. }
  34. /**
  35. * Tests node path aliases on a moderated content type.
  36. */
  37. public function testNodePathAlias() {
  38. // Create some moderated content with a path alias.
  39. $this->drupalGet('node/add/moderated');
  40. $this->assertSession()->fieldValueEquals('path[0][alias]', '');
  41. $this->drupalPostForm(NULL, [
  42. 'title[0][value]' => 'moderated content',
  43. 'path[0][alias]' => '/moderated-content',
  44. 'moderation_state[0][state]' => 'published',
  45. ], t('Save'));
  46. $node = $this->getNodeByTitle('moderated content');
  47. // Add a pending revision with the same alias.
  48. $this->drupalGet('node/' . $node->id() . '/edit');
  49. $this->assertSession()->fieldValueEquals('path[0][alias]', '/moderated-content');
  50. $this->drupalPostForm(NULL, [
  51. 'title[0][value]' => 'pending revision',
  52. 'path[0][alias]' => '/moderated-content',
  53. 'moderation_state[0][state]' => 'draft',
  54. ], t('Save'));
  55. $this->assertSession()->pageTextNotContains('You can only change the URL alias for the published version of this content.');
  56. // Create some moderated content with no path alias.
  57. $this->drupalGet('node/add/moderated');
  58. $this->assertSession()->fieldValueEquals('path[0][alias]', '');
  59. $this->drupalPostForm(NULL, [
  60. 'title[0][value]' => 'moderated content 2',
  61. 'path[0][alias]' => '',
  62. 'moderation_state[0][state]' => 'published',
  63. ], t('Save'));
  64. $node = $this->getNodeByTitle('moderated content 2');
  65. // Add a pending revision with a new alias.
  66. $this->drupalGet('node/' . $node->id() . '/edit');
  67. $this->assertSession()->fieldValueEquals('path[0][alias]', '');
  68. $this->drupalPostForm(NULL, [
  69. 'title[0][value]' => 'pending revision',
  70. 'path[0][alias]' => '/pending-revision',
  71. 'moderation_state[0][state]' => 'draft',
  72. ], t('Save'));
  73. $this->assertSession()->pageTextContains('You can only change the URL alias for the published version of this content.');
  74. // Create some moderated content with no path alias.
  75. $this->drupalGet('node/add/moderated');
  76. $this->assertSession()->fieldValueEquals('path[0][alias]', '');
  77. $this->drupalPostForm(NULL, [
  78. 'title[0][value]' => 'moderated content 3',
  79. 'path[0][alias]' => '',
  80. 'moderation_state[0][state]' => 'published',
  81. ], t('Save'));
  82. $node = $this->getNodeByTitle('moderated content 3');
  83. // Add a pending revision with no path alias.
  84. $this->drupalGet('node/' . $node->id() . '/edit');
  85. $this->assertSession()->fieldValueEquals('path[0][alias]', '');
  86. $this->drupalPostForm(NULL, [
  87. 'title[0][value]' => 'pending revision',
  88. 'path[0][alias]' => '',
  89. 'moderation_state[0][state]' => 'draft',
  90. ], t('Save'));
  91. $this->assertSession()->pageTextNotContains('You can only change the URL alias for the published version of this content.');
  92. }
  93. }