public function ReplicatorTest::testSelectiveContentReplication in Workspace 8
Test selective content replication.
File
- tests/
src/ Functional/ ReplicatorTest.php, line 184
Class
- ReplicatorTest
- Test the workspace entity.
Namespace
Drupal\Tests\workspace\FunctionalCode
public function testSelectiveContentReplication() {
$live = $this
->getOneEntityByLabel('workspace', 'Live');
// Create 4 nodes and 4 menu links on Live workspace.
$node1 = $this
->drupalCreateNode([
'type' => 'test',
'title' => 'Node 1',
]);
$node2 = $this
->drupalCreateNode([
'type' => 'test',
'title' => 'Node 2',
]);
$node3 = $this
->drupalCreateNode([
'type' => 'test',
'title' => 'Node 3',
]);
$node4 = $this
->drupalCreateNode([
'type' => 'test',
'title' => 'Node 4',
]);
$this
->drupalGet('/admin/content');
$session = $this
->getSession();
$this
->assertEquals(200, $session
->getStatusCode());
$page = $session
->getPage();
$this
->assertTrue($page
->hasContent($node1
->label()));
$this
->assertTrue($page
->hasContent($node2
->label()));
$this
->assertTrue($page
->hasContent($node3
->label()));
$this
->assertTrue($page
->hasContent($node4
->label()));
$menu_link_content1 = MenuLinkContent::create([
'link' => [
'uri' => 'entity:node/' . $node1
->id(),
],
'menu_name' => 'main',
'title' => 'Test link 1',
]);
$menu_link_content1
->save();
$menu_link_content2 = MenuLinkContent::create([
'link' => [
'uri' => 'entity:node/' . $node2
->id(),
],
'menu_name' => 'main',
'title' => 'Test link 2',
]);
$menu_link_content2
->save();
$menu_link_content3 = MenuLinkContent::create([
'link' => [
'uri' => 'entity:node/' . $node3
->id(),
],
'menu_name' => 'main',
'title' => 'Test link 3',
]);
$menu_link_content3
->save();
$menu_link_content4 = MenuLinkContent::create([
'link' => [
'uri' => 'entity:node/' . $node4
->id(),
],
'menu_name' => 'main',
'title' => 'Test link 4',
]);
$menu_link_content4
->save();
$this
->drupalGet('/admin/structure/menu/manage/main');
$session = $this
->getSession();
$this
->assertEquals(200, $session
->getStatusCode());
$page = $session
->getPage();
$this
->assertTrue($page
->hasContent($menu_link_content1
->label()));
$this
->assertTrue($page
->hasContent($menu_link_content2
->label()));
$this
->assertTrue($page
->hasContent($menu_link_content3
->label()));
$this
->assertTrue($page
->hasContent($menu_link_content4
->label()));
$target = $this
->createWorkspaceThroughUI('Target', 'target');
// Set the Target workspace as upstream for Live.
$live
->set('upstream', $target
->id());
$live
->save();
// Make sure we have correct changes on Changes page.
$this
->drupalGet("admin/structure/workspace/{$live->id()}/changes");
$session = $this
->getSession();
$this
->assertEquals(200, $session
->getStatusCode());
$page = $session
->getPage();
$this
->assertTrue($page
->hasContent($node1
->label()));
$this
->assertTrue($page
->hasContent($node2
->label()));
$this
->assertTrue($page
->hasContent($node3
->label()));
$this
->assertTrue($page
->hasContent($node4
->label()));
$this
->assertTrue($page
->hasContent($menu_link_content1
->label()));
$this
->assertTrue($page
->hasContent($menu_link_content2
->label()));
$this
->assertTrue($page
->hasContent($menu_link_content3
->label()));
$this
->assertTrue($page
->hasContent($menu_link_content4
->label()));
// Switch to Target workspace and make sure 4 nodes and 4 menu links
// from Live workspace don't exist there yet.
$this
->switchToWorkspace($target);
$this
->drupalGet('/admin/content');
$session = $this
->getSession();
$this
->assertEquals(200, $session
->getStatusCode());
$page = $session
->getPage();
$this
->assertFalse($page
->hasContent($node1
->label()));
$this
->assertFalse($page
->hasContent($node2
->label()));
$this
->assertFalse($page
->hasContent($node3
->label()));
$this
->assertFalse($page
->hasContent($node4
->label()));
$this
->drupalGet('/admin/structure/menu/manage/main');
$session = $this
->getSession();
$this
->assertEquals(200, $session
->getStatusCode());
$page = $session
->getPage();
$this
->assertFalse($page
->hasContent($menu_link_content1
->label()));
$this
->assertFalse($page
->hasContent($menu_link_content2
->label()));
$this
->assertFalse($page
->hasContent($menu_link_content3
->label()));
$this
->assertFalse($page
->hasContent($menu_link_content4
->label()));
// Switch back to Live.
$this
->switchToWorkspace($live);
/** @var \Drupal\workspace\ReplicatorManager $rm */
$rm = \Drupal::service('workspace.replicator_manager');
$task = new ReplicationTask();
// Select to be deployed only Node 1 and Test link 1 on next replication.
$task
->setDocIds([
$node1
->uuid(),
$menu_link_content1
->uuid(),
]);
$rm
->replicate(WorkspacePointer::loadFromWorkspace($live), WorkspacePointer::loadFromWorkspace($target), $task);
\Drupal::service('cron')
->run();
// Make sure we have correct changes on Changes page.
$this
->drupalGet("admin/structure/workspace/{$live->id()}/changes");
$session = $this
->getSession();
$this
->assertEquals(200, $session
->getStatusCode());
$page = $session
->getPage();
$this
->assertFalse($page
->hasContent($node1
->label()));
$this
->assertTrue($page
->hasContent($node2
->label()));
$this
->assertTrue($page
->hasContent($node3
->label()));
$this
->assertTrue($page
->hasContent($node4
->label()));
$this
->assertFalse($page
->hasContent($menu_link_content1
->label()));
$this
->assertTrue($page
->hasContent($menu_link_content2
->label()));
$this
->assertTrue($page
->hasContent($menu_link_content3
->label()));
$this
->assertTrue($page
->hasContent($menu_link_content4
->label()));
// Switch back to Target and check if Node 1 and Menu link 1 have been
// replicated.
$this
->switchToWorkspace($target);
$this
->drupalGet('/admin/content');
$session = $this
->getSession();
$this
->assertEquals(200, $session
->getStatusCode());
$page = $session
->getPage();
$this
->assertTrue($page
->hasContent($node1
->label()));
$this
->assertFalse($page
->hasContent($node2
->label()));
$this
->assertFalse($page
->hasContent($node3
->label()));
$this
->assertFalse($page
->hasContent($node4
->label()));
$this
->drupalGet('/admin/structure/menu/manage/main');
$session = $this
->getSession();
$this
->assertEquals(200, $session
->getStatusCode());
$page = $session
->getPage();
$this
->assertTrue($page
->hasContent($menu_link_content1
->label()));
$this
->assertFalse($page
->hasContent($menu_link_content2
->label()));
$this
->assertFalse($page
->hasContent($menu_link_content3
->label()));
$this
->assertFalse($page
->hasContent($menu_link_content4
->label()));
// Switch back to Live.
$this
->switchToWorkspace($live);
$task = new ReplicationTask();
// Select to be deployed only Node 2, Node 3, Test link 2 and Test link 3 on
// next replication.
$task
->setDocIds([
$node2
->uuid(),
$node3
->uuid(),
$menu_link_content2
->uuid(),
$menu_link_content3
->uuid(),
]);
$rm
->replicate(WorkspacePointer::loadFromWorkspace($live), WorkspacePointer::loadFromWorkspace($target), $task);
\Drupal::service('cron')
->run();
// Make sure we have correct changes on Changes page.
$this
->drupalGet("admin/structure/workspace/{$live->id()}/changes");
$session = $this
->getSession();
$this
->assertEquals(200, $session
->getStatusCode());
$page = $session
->getPage();
$this
->assertFalse($page
->hasContent($node1
->label()));
$this
->assertFalse($page
->hasContent($node2
->label()));
$this
->assertFalse($page
->hasContent($node3
->label()));
$this
->assertTrue($page
->hasContent($node4
->label()));
$this
->assertFalse($page
->hasContent($menu_link_content1
->label()));
$this
->assertFalse($page
->hasContent($menu_link_content2
->label()));
$this
->assertFalse($page
->hasContent($menu_link_content3
->label()));
$this
->assertTrue($page
->hasContent($menu_link_content4
->label()));
// Switch back to Target and check if Node 1 and Menu link 1 have been
// replicated.
$this
->switchToWorkspace($target);
$this
->drupalGet('/admin/content');
$session = $this
->getSession();
$this
->assertEquals(200, $session
->getStatusCode());
$page = $session
->getPage();
$this
->assertTrue($page
->hasContent($node1
->label()));
$this
->assertTrue($page
->hasContent($node2
->label()));
$this
->assertTrue($page
->hasContent($node3
->label()));
$this
->assertFalse($page
->hasContent($node4
->label()));
$this
->drupalGet('/admin/structure/menu/manage/main');
$session = $this
->getSession();
$this
->assertEquals(200, $session
->getStatusCode());
$page = $session
->getPage();
$this
->assertTrue($page
->hasContent($menu_link_content1
->label()));
$this
->assertTrue($page
->hasContent($menu_link_content2
->label()));
$this
->assertTrue($page
->hasContent($menu_link_content3
->label()));
$this
->assertFalse($page
->hasContent($menu_link_content4
->label()));
// Switch back to Live.
$this
->switchToWorkspace($live);
$task = new ReplicationTask();
// Do normal replication, without selecting content, this will deploy
// remaining Node 4 and Menu link 4.
$rm
->replicate(WorkspacePointer::loadFromWorkspace($live), WorkspacePointer::loadFromWorkspace($target), $task);
\Drupal::service('cron')
->run();
// Make sure we have correct changes on Changes page.
$this
->drupalGet("admin/structure/workspace/{$live->id()}/changes");
$session = $this
->getSession();
$this
->assertEquals(200, $session
->getStatusCode());
$page = $session
->getPage();
$this
->assertFalse($page
->hasContent($node1
->label()));
$this
->assertFalse($page
->hasContent($node2
->label()));
$this
->assertFalse($page
->hasContent($node3
->label()));
$this
->assertFalse($page
->hasContent($node4
->label()));
$this
->assertFalse($page
->hasContent($menu_link_content1
->label()));
$this
->assertFalse($page
->hasContent($menu_link_content2
->label()));
$this
->assertFalse($page
->hasContent($menu_link_content3
->label()));
$this
->assertFalse($page
->hasContent($menu_link_content4
->label()));
// Switch back to Target and check if Node 1 and Menu link 1 have been
// replicated.
$this
->switchToWorkspace($target);
$this
->drupalGet('/admin/content');
$session = $this
->getSession();
$this
->assertEquals(200, $session
->getStatusCode());
$page = $session
->getPage();
$this
->assertTrue($page
->hasContent($node1
->label()));
$this
->assertTrue($page
->hasContent($node2
->label()));
$this
->assertTrue($page
->hasContent($node3
->label()));
$this
->assertTrue($page
->hasContent($node4
->label()));
$this
->drupalGet('/admin/structure/menu/manage/main');
$session = $this
->getSession();
$this
->assertEquals(200, $session
->getStatusCode());
$page = $session
->getPage();
$this
->assertTrue($page
->hasContent($menu_link_content1
->label()));
$this
->assertTrue($page
->hasContent($menu_link_content2
->label()));
$this
->assertTrue($page
->hasContent($menu_link_content3
->label()));
$this
->assertTrue($page
->hasContent($menu_link_content4
->label()));
}