View source
<?php
namespace Drupal\Tests\workspace\Functional;
use Drupal\multiversion\Entity\Workspace;
use Drupal\replication\ReplicationTask\ReplicationTask;
use Drupal\Tests\BrowserTestBase;
use Drupal\workspace\Entity\Replication;
use Drupal\workspace\Entity\WorkspacePointer;
class ReplicationSettingsPageTest extends BrowserTestBase {
use WorkspaceTestUtilities;
public static $modules = [
'multiversion',
'user',
'replication',
'workspace',
'node',
];
protected $user;
protected $entityTypeManager;
protected function setUp() {
parent::setUp();
$this
->createNodeType('Test', 'test');
$permissions = [
'access administration pages',
'create_workspace',
'edit_own_workspace',
'view_own_workspace',
'view_any_workspace',
'create test content',
];
$this->user = $this
->drupalCreateUser($permissions);
$this->entityTypeManager = \Drupal::entityTypeManager();
}
public function testReplicationConfigurationForms() {
$this
->drupalLogin($this->user);
$this
->drupalGet('admin/config/replication/settings');
$this
->assertText("Unblock replication");
$submit_is_disabled = $this
->cssSelect('form.unblock-replication-form input[type="submit"]:disabled');
$this
->assertTrue(count($submit_is_disabled) === 1, 'The Unblock replication button is disabled.');
$this
->assertText('Clear replication queue');
$this
->assertText('Replication settings');
$this
->assertText('Replication configuration');
$this
->assertFieldByName('mapping_type', 'uid_1');
$this
->assertFieldByName('uid', '');
$this
->assertFieldByName('changes_limit', 100);
$this
->assertFieldByName('bulk_docs_limit', 100);
$this
->assertFieldByName('replication_execution_limit', 1);
$this
->assertFieldByName('verbose_logging', FALSE);
$edit = [
'mapping_type' => 'uid',
'uid' => $this->user
->id(),
'changes_limit' => 200,
'bulk_docs_limit' => 200,
'replication_execution_limit' => 4,
'verbose_logging' => TRUE,
];
$this
->drupalPostForm(NULL, $edit, 'Save configuration');
$this
->assertText('The configuration options have been saved.');
$this
->assertText('Replication settings');
$this
->assertText('Replication configuration');
$this
->assertFieldByName('mapping_type', 'uid');
$this
->assertFieldByName('uid', $this->user
->id());
$this
->assertFieldByName('changes_limit', 200);
$this
->assertFieldByName('bulk_docs_limit', 200);
$this
->assertFieldByName('replication_execution_limit', 4);
$this
->assertFieldByName('verbose_logging', TRUE);
\Drupal::state()
->set('workspace.last_replication_failed', TRUE);
$this
->drupalGet('admin/config/replication/settings');
$submit_is_disabled = $this
->cssSelect('form.unblock-replication-form input[type="submit"]:disabled');
$this
->assertTrue(count($submit_is_disabled) === 0, 'The Unblock replication button is disabled.');
$this
->drupalPostForm(NULL, [], 'Unblock replication');
$this
->assertText('Replications have been unblocked.');
$submit_is_disabled = $this
->cssSelect('form.unblock-replication-form input[type="submit"]:disabled');
$this
->assertTrue(count($submit_is_disabled) === 1, 'The Unblock replication button is disabled.');
$this
->drupalPostForm(NULL, [], 'Clear queue');
$this
->assertText('Are you sure you want to clear the replication queue?');
$this
->assertText('All replications will be marked as failed and removed from the cron queue, except those that are in progress. This action cannot be undone.');
$this
->drupalPostForm(NULL, [], 'Clear queue');
$this
->assertText('There were not any queued deployments in the replication queue.');
$this
->assertText("Unblock replication");
$earth = Workspace::create([
'label' => 'Earth',
'machine_name' => 'earth',
'type' => 'basic',
]);
$earth
->save();
$mars = Workspace::create([
'label' => 'Mars',
'machine_name' => 'mars',
'type' => 'basic',
]);
$mars
->save();
$earth
->set('upstream', $mars
->id())
->save();
$workspace_manager = \Drupal::service('workspace.manager');
$workspace_manager
->setActiveWorkspace($earth);
$this
->drupalCreateNode([
'type' => 'test',
'title' => 'Elon',
]);
$this
->drupalCreateNode([
'type' => 'test',
'title' => 'Claire',
]);
$big_falcon = \Drupal::service('workspace.replicator_manager');
$colonize_mars_task = new ReplicationTask();
$big_falcon
->replicate(WorkspacePointer::loadFromWorkspace($earth), WorkspacePointer::loadFromWorkspace($mars), $colonize_mars_task);
$missions = $this->entityTypeManager
->getStorage('replication')
->loadMultiple();
$this
->assertTrue(count($missions) === 2);
foreach ($missions as $mission) {
$this
->assertEquals(Replication::QUEUED, $mission
->getReplicationStatus());
}
$this
->drupalGet('admin/config/replication/settings');
$this
->drupalPostForm(NULL, [], 'Clear queue');
$this
->assertText('Are you sure you want to clear the replication queue?');
$this
->drupalPostForm(NULL, [], 'Clear queue');
$this
->assertText('All the queued deployments have been marked as failed and have been removed from the replication queue.');
$missions = $this->entityTypeManager
->getStorage('replication')
->loadMultiple();
$this
->assertTrue(count($missions) === 2);
foreach ($missions as $mission) {
$this
->assertEquals(Replication::FAILED, $mission
->getReplicationStatus());
$this
->assertEquals('This deployment has been marked as failed manually, when clearing the replication queue.', $mission
->getReplicationFailInfo());
}
\Drupal::service('cron')
->run();
$workspace_manager
->setActiveWorkspace($mars);
$entities = $this->entityTypeManager
->getStorage('node')
->loadMultiple();
$this
->assertEmpty($entities);
}
}