/** * Tests the getSortedNegotiators() method. */ public function testGetSortedNegotiators() { $workspace_manager = new WorkspaceManager($this->requestStack, $this->entityManager, $this->cacheRender); $workspace_manager->addNegotiator($this->workspaceNegotiators[0][0], 1); $workspace_manager->addNegotiator($this->workspaceNegotiators[1][0], 3); $method = new \ReflectionMethod('Drupal\\multiversion\\Workspace\\WorkspaceManager', 'getSortedNegotiators'); $method->setAccessible(TRUE); $sorted_negotiators = new \ReflectionProperty('Drupal\\multiversion\\Workspace\\WorkspaceManager', 'sortedNegotiators'); $sorted_negotiators->setAccessible(TRUE); $sorted_negotiators_value = $sorted_negotiators->getValue($workspace_manager); $negotiators = new \ReflectionProperty('Drupal\\multiversion\\Workspace\\WorkspaceManager', 'negotiators'); $negotiators->setAccessible(TRUE); $negotiators_value = $negotiators->getValue($workspace_manager); if (!isset($sorted_negotiators_value)) { // Sort the negotiators according to priority. krsort($negotiators_value); // Merge nested negotiators from $negotiators_value into // $sorted_negotiators_value. $sorted_negotiators_value = array(); foreach ($negotiators_value as $builders) { $sorted_negotiators_value = array_merge($sorted_negotiators_value, $builders); } } $this->assertSame($sorted_negotiators_value, $method->invoke($workspace_manager)); }
/** * Tests the getWorkspaceSwitchLinks() method. */ public function testGetWorkspaceSwitchLinks() { $second_machine_name = $this->values[1]['machine_name']; $url = Url::fromRoute($this->path); $expected_links = [1 => ['url' => $url, 'title' => $this->defaultMachineName, 'query' => ['workspace' => 1], 'attributes' => ['class' => ['session-active']]], 2 => ['url' => $url, 'title' => $second_machine_name, 'query' => ['workspace' => 2]]]; foreach ($this->values as $key => $value) { $this->entities[$key]->expects($this->any())->method('id')->will($this->returnValue($value['id'])); $this->entities[$key]->expects($this->any())->method('label')->will($this->returnValue($value['label'])); } $this->negotiator = $this->getMock('\\Drupal\\multiversion\\Workspace\\SessionWorkspaceNegotiator'); $this->negotiator->expects($this->any())->method('getActiveWorkspace')->with($this->requestStack, $this->entityManager)->will($this->returnValue($this->defaultMachineName)); $storage = $this->getMock('\\Drupal\\Core\\Entity\\EntityStorageInterface'); $storage->expects($this->any())->method('loadMultiple')->with()->will($this->returnValue($this->entities)); $this->entityManager->expects($this->any())->method('getStorage')->with('workspace')->will($this->returnValue($storage)); $this->workspaceManager->expects($this->any())->method('loadMultiple')->with()->will($this->returnValue(array($this->entities))); $workspace_manager = new WorkspaceManager($this->requestStack, $this->entityManager, $this->cacheRender); $workspace_manager->addNegotiator($this->workspaceNegotiator, 1); $workspace_manager->setActiveWorkspace($this->entities[0]); $negotiator = new SessionWorkspaceNegotiator(); $negotiator->setWorkspaceManager($workspace_manager); $links = $negotiator->getWorkspaceSwitchLinks($this->request, $url); $this->assertSame($expected_links, $links); }