You are here

public function ReplicationFilterTest::testPublishedFilter in Replication 8

Same name and namespace in other branches
  1. 8.2 tests/src/Functional/ReplicationFilterTest.php \Drupal\Tests\replication\Functional\ReplicationFilterTest::testPublishedFilter()

Test filtering the changeset with the published filter.

File

tests/src/Functional/ReplicationFilterTest.php, line 82

Class

ReplicationFilterTest
Tests replication filters.

Namespace

Drupal\Tests\replication\Functional

Code

public function testPublishedFilter() {
  $container = \Drupal::getContainer();
  $changes_factory = $container
    ->get('replication.changes_factory');
  $workspace = Workspace::create([
    'machine_name' => 'default',
    'type' => 'basic',
  ]);
  $workspace
    ->save();
  $entity1 = Node::create([
    'type' => 'article',
    'title' => 'Test Entity 1',
    'uid' => $this->user
      ->id(),
    'status' => TRUE,
  ]);
  $entity1->workspace = $workspace;
  $entity1
    ->save();
  $entity2 = Node::create([
    'type' => 'article',
    'title' => 'Test Entity 2',
    'uid' => $this->user
      ->id(),
    'status' => FALSE,
  ]);
  $entity2->workspace = $workspace;
  $entity2
    ->save();
  $changes = $changes_factory
    ->get($workspace)
    ->filter('published')
    ->getNormal();
  $this
    ->assertCount(1, $changes, 'Expect there is 1 entity in the changeset for published filter.');
}