Verified Commit f668443b authored by Andrei Mateescu's avatar Andrei Mateescu
Browse files

task: #3612413 Workspaces tests use createNodeThroughUi excessively

By: mstrelan
By: smustgrave
parent 9a20b9c4
Loading
Loading
Loading
Loading
Loading
+6 −1
Changes for core/modules/workspaces/tests/src/Functional/WorkspaceBypassTest.php: 6 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@

namespace Drupal\Tests\workspaces\Functional;

use Drupal\node\NodeInterface;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\node\Traits\ContentTypeCreationTrait;
use PHPUnit\Framework\Attributes\Group;
@@ -51,7 +52,11 @@ public function testBypassOwnWorkspace(): void {
    $bears = $this->createAndActivateWorkspaceThroughUi('Bears', 'bears');

    // Now create a node in the Bears workspace, as the owner of that workspace.
    $coach_bears_node = $this->createNodeThroughUi('Ditka Bears node', 'test');
    $coach_bears_node = $this->drupalCreateNode([
      'title' => 'Ditka Bears node',
      'type' => 'test',
      'status' => NodeInterface::PUBLISHED,
    ]);
    $coach_bears_node_id = $coach_bears_node->id();

    // Editing both nodes should be possible.
+6 −1
Changes for core/modules/workspaces/tests/src/Functional/WorkspaceConcurrentEditingTest.php: 6 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@

namespace Drupal\Tests\workspaces\Functional;

use Drupal\node\NodeInterface;
use Drupal\Tests\BrowserTestBase;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;
@@ -45,7 +46,11 @@ public function testConcurrentEditing(): void {
    $mayer = $this->drupalCreateUser($permissions);
    $this->drupalLogin($mayer);

    $test_node = $this->createNodeThroughUi('Test node', 'test');
    $test_node = $this->drupalCreateNode([
      'title' => 'Test node',
      'type' => 'test',
      'status' => NodeInterface::PUBLISHED,
    ]);

    // Check that the user can edit the node.
    $page = $this->getSession()->getPage();
+26 −6
Changes for core/modules/workspaces/tests/src/Functional/WorkspaceEntityDeleteTest.php: 26 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@

namespace Drupal\Tests\workspaces\Functional;

use Drupal\node\NodeInterface;
use Drupal\Tests\BrowserTestBase;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;
@@ -61,13 +62,28 @@ public function testEntityDelete(): void {
    $dev = $this->createWorkspaceThroughUi('Dev', 'dev', 'stage');

    // Create a published and an unpublished node in Live.
    $published_live = $this->createNodeThroughUi('Test 1 published - live', 'article');
    $unpublished_live = $this->createNodeThroughUi('Test 2 unpublished - live', 'article', FALSE);

    $published_live = $this->drupalCreateNode([
      'title' => 'Test 1 published - live',
      'type' => 'article',
      'status' => NodeInterface::PUBLISHED,
    ]);
    $unpublished_live = $this->drupalCreateNode([
      'title' => 'Test 2 unpublished - live',
      'type' => 'article',
      'status' => NodeInterface::NOT_PUBLISHED,
    ]);
    // Create a published and an unpublished node in Stage.
    $this->switchToWorkspace($stage);
    $published_stage = $this->createNodeThroughUi('Test 3 published - stage', 'article');
    $unpublished_stage = $this->createNodeThroughUi('Test 4 unpublished - stage', 'article', FALSE);
    $published_stage = $this->drupalCreateNode([
      'title' => 'Test 3 published - stage',
      'type' => 'article',
      'status' => NodeInterface::PUBLISHED,
    ]);
    $unpublished_stage = $this->drupalCreateNode([
      'title' => 'Test 4 published - live',
      'type' => 'article',
      'status' => NodeInterface::NOT_PUBLISHED,
    ]);

    // Check that the Live nodes (both published and unpublished) can not be
    // deleted, while the Stage nodes can be.
@@ -140,7 +156,11 @@ public function testNodeDeleteWithBypassAccessPermission(): void {
    $this->drupalLogin($editor);

    // Create a published node in Live.
    $published_live = $this->createNodeThroughUi('Test 1 published - live', 'article');
    $published_live = $this->drupalCreateNode([
      'title' => 'Test 1 published - live',
      'type' => 'article',
      'status' => NodeInterface::PUBLISHED,
    ]);

    $this->createAndActivateWorkspaceThroughUi('Stage', 'stage');

+31 −4
Changes for core/modules/workspaces/tests/src/Functional/WorkspaceTest.php: 31 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -208,8 +208,14 @@ public function testWorkspaceManagePage(): void {
    $assert_session->linkExists('Switch to this workspace');

    // Create some test content.
    $this->createNodeThroughUi('Node 1', 'test');
    $this->createNodeThroughUi('Node 2', 'test');
    $this->drupalCreateNode([
      'title' => 'Node 1',
      'type' => 'test',
    ]);
    $this->drupalCreateNode([
      'title' => 'Node 2',
      'type' => 'test',
    ]);
    $edit = [
      'name[0][value]' => 'Term 1',
    ];
@@ -224,7 +230,10 @@ public function testWorkspaceManagePage(): void {

    // Create 50 more nodes to test the pagination.
    for ($i = 3; $i < 53; $i++) {
      $this->createNodeThroughUi('Node ' . $i, 'test');
      $this->drupalCreateNode([
        'title' => 'Node ' . $i,
        'type' => 'test',
      ]);
    }

    $this->drupalGet($test_1->toUrl()->toString());
@@ -287,7 +296,10 @@ public function testDeleteWorkspaceWithExistingContent(): void {
    $this->createAndActivateWorkspaceThroughUi('May 4', 'may_4');

    // Create a node in the workspace.
    $this->createNodeThroughUi('A mayfly flies / In May or June', 'test');
    $this->drupalCreateNode([
      'title' => 'A mayfly flies / In May or June',
      'type' => 'test',
    ]);

    // Delete the workspace.
    $this->drupalGet('/admin/config/workflow/workspaces/manage/may_4/delete');
@@ -391,4 +403,19 @@ public function testPublishWorkspace(): void {
    $this->assertSession()->pageTextContains('Successful publication.');
  }

  /**
   * Tests that nodes created inside a workspace are assigned to the workspace.
   */
  public function testNodeCreation(): void {
    $this->createContentType(['type' => 'test', 'label' => 'Test']);
    $this->drupalLogin($this->drupalCreateUser([
      'create workspace',
      'view own workspace',
      'create test content',
    ]));
    $workspace = $this->createAndActivateWorkspaceThroughUi('Test', 'test');
    $node = $this->createNodeThroughUi('Test', 'test');
    $this->assertSame($node->workspace->entity->id(), $workspace->id());
  }

}