You are here

public function WorkspaceManagerTest::testSetActiveWorkspace in Multiversion 8

Tests that setActiveWorkspace() sets the workspace on the negotiator.

File

tests/src/Unit/WorkspaceManagerTest.php, line 201

Class

WorkspaceManagerTest
@coversDefaultClass \Drupal\multiversion\Workspace\WorkspaceManager @group multiversion

Namespace

Drupal\Tests\multiversion\Unit

Code

public function testSetActiveWorkspace() {

  // Create the request we will use.
  $request = $this
    ->getMock('Symfony\\Component\\HttpFoundation\\Request');
  $this->requestStack
    ->method('getCurrentRequest')
    ->willReturn($request);

  // Create the workspace that we will set.
  $workspace = $this
    ->getMockBuilder('Drupal\\multiversion\\Entity\\Workspace')
    ->disableOriginalConstructor()
    ->getMock();
  $workspace
    ->expects($this
    ->any())
    ->method("isPublished")
    ->willReturn(TRUE);
  $workspace
    ->expects($this
    ->any())
    ->method("access")
    ->willReturn(TRUE);

  // Spy on the negotiator and stub the applies and persist methods.
  $negotiator = $this
    ->prophesize('Drupal\\multiversion\\Workspace\\DefaultWorkspaceNegotiator');
  $negotiator
    ->applies(Argument::any())
    ->willReturn(TRUE);
  $negotiator
    ->persist(Argument::any())
    ->will(function () {
    return $this;
  });

  // Create the workspace manager.
  $workspace_manager = new WorkspaceManager($this->requestStack, $this->entityTypeManager, $this->currentUser, $this->logger);
  $workspace_manager
    ->addNegotiator($negotiator
    ->reveal(), 1);

  // Execute the code under test.
  $workspace_manager
    ->setActiveWorkspace($workspace);

  // Ensure persist with the workspace was called on the negotiator.
  $negotiator
    ->persist($workspace)
    ->shouldHaveBeenCalled();
}