/** * Tests the destruct method. * * @covers ::destruct */ public function testDestruct() { $this->libraryDiscoveryParser->expects($this->once())->method('buildByExtension')->with('test')->will($this->returnValue($this->libraryData)); $lock_key = 'library_info:Drupal\\Core\\Cache\\CacheCollector'; $this->lock->expects($this->once())->method('acquire')->with($lock_key)->will($this->returnValue(TRUE)); $this->cache->expects($this->exactly(2))->method('get')->with('library_info')->will($this->returnValue(FALSE)); $this->cache->expects($this->once())->method('set')->with('library_info', array('test' => $this->libraryData), Cache::PERMANENT, array('library_info')); $this->lock->expects($this->once())->method('release')->with($lock_key); // This should get data and persist the key. $this->libraryDiscoveryCollector->get('test'); $this->libraryDiscoveryCollector->destruct(); }
/** * {@inheritdoc} */ protected function setUp() { $this->storage = $this->getMock('Drupal\\locale\\StringStorageInterface'); $this->cache = $this->getMock('Drupal\\Core\\Cache\\CacheBackendInterface'); $this->lock = $this->getMock('Drupal\\Core\\Lock\\LockBackendInterface'); $this->lock->expects($this->never())->method($this->anything()); $this->user = $this->getMock('Drupal\\Core\\Session\\AccountInterface'); $this->user->expects($this->any())->method('getRoles')->will($this->returnValue(array('anonymous'))); $this->configFactory = $this->getConfigFactoryStub(array('locale.settings' => array('cache_strings' => FALSE))); $this->languageManager = $this->getMock('Drupal\\Core\\Language\\LanguageManagerInterface'); $container = new ContainerBuilder(); $container->set('current_user', $this->user); \Drupal::setContainer($container); }
/** * Tests the deleteIfOwner() method. * * @covers ::deleteIfOwner() */ public function testDeleteIfOwner() { $this->lock->expects($this->once())->method('acquire')->with('test_2')->will($this->returnValue(TRUE)); $this->keyValue->expects($this->at(0))->method('get')->with('test_1')->will($this->returnValue(FALSE)); $this->keyValue->expects($this->at(1))->method('get')->with('test_2')->will($this->returnValue($this->ownObject)); $this->keyValue->expects($this->at(2))->method('delete')->with('test_2'); $this->keyValue->expects($this->at(3))->method('get')->with('test_3')->will($this->returnValue($this->otherObject)); $this->assertTrue($this->tempStore->deleteIfOwner('test_1')); $this->assertTrue($this->tempStore->deleteIfOwner('test_2')); $this->assertFalse($this->tempStore->deleteIfOwner('test_3')); }
/** * Tests \Drupal\Core\Routing\RouteBuilder::rebuildIfNeeded() method. */ public function testRebuildIfNeeded() { $this->lock->expects($this->once())->method('acquire')->with('router_rebuild')->will($this->returnValue(TRUE)); $this->lock->expects($this->once())->method('release')->with('router_rebuild'); $this->yamlDiscovery->expects($this->any())->method('findAll')->will($this->returnValue(array())); $this->routeBuilder->setRebuildNeeded(); // This will trigger a successful rebuild. $this->assertTrue($this->routeBuilder->rebuildIfNeeded()); // This will not trigger a rebuild. $this->assertFalse($this->routeBuilder->rebuildIfNeeded()); }
/** * Tests \Drupal\Core\Routing\RouteBuilder::rebuildIfNeeded() method. */ public function testRebuildIfNecessary() { $this->lock->expects($this->once())->method('acquire')->with('router_rebuild')->will($this->returnValue(TRUE)); $this->lock->expects($this->once())->method('release')->with('router_rebuild'); $this->routeBuilderIndicator->expects($this->once())->method('setRebuildNeeded'); $this->routeBuilderIndicator->expects($this->once())->method('setRebuildDone'); $this->routeBuilderIndicator->expects($this->exactly(2))->method('isRebuildNeeded')->will($this->onConsecutiveCalls(TRUE, FALSE)); $this->yamlDiscovery->expects($this->any())->method('findAll')->will($this->returnValue(array())); $this->routeBuilder->setRebuildNeeded(); // This will trigger a successful rebuild. $this->assertTrue($this->routeBuilder->rebuildIfNeeded()); // This will not trigger a rebuild. $this->assertFalse($this->routeBuilder->rebuildIfNeeded()); }
/** * Tests the destruct method. * * @covers ::destruct */ public function testDestruct() { $this->activeTheme = $this->getMockBuilder('Drupal\\Core\\Theme\\ActiveTheme')->disableOriginalConstructor()->getMock(); $this->themeManager->expects($this->once())->method('getActiveTheme')->willReturn($this->activeTheme); $this->activeTheme->expects($this->once())->method('getName')->willReturn('kitten_theme'); $this->libraryDiscoveryCollector = new LibraryDiscoveryCollector($this->cache, $this->lock, $this->libraryDiscoveryParser, $this->themeManager); $this->libraryDiscoveryParser->expects($this->once())->method('buildByExtension')->with('test')->willReturn($this->libraryData); $lock_key = 'library_info:kitten_theme:Drupal\\Core\\Cache\\CacheCollector'; $this->lock->expects($this->once())->method('acquire')->with($lock_key)->will($this->returnValue(TRUE)); $this->cache->expects($this->exactly(2))->method('get')->with('library_info:kitten_theme')->willReturn(FALSE); $this->cache->expects($this->once())->method('set')->with('library_info:kitten_theme', array('test' => $this->libraryData), Cache::PERMANENT, ['library_info']); $this->lock->expects($this->once())->method('release')->with($lock_key); // This should get data and persist the key. $this->libraryDiscoveryCollector->get('test'); $this->libraryDiscoveryCollector->destruct(); }
/** * Tests getCid() * * @covers ::getCid */ public function testGetCid() { $data = $this->provider()[1]; /** @var \Symfony\Component\HttpFoundation\Request $request */ $request = $data[0]; /** @var \Symfony\Component\Routing\Route $route */ $route = $request->attributes->get(RouteObjectInterface::ROUTE_OBJECT); $route->setPath('/test/{b}/{a}'); $request->attributes->get('_raw_variables')->add(['b' => 1, 'a' => 0]); $this->requestStack->push($request); $this->menuLinkManager->expects($this->any())->method('loadLinksbyRoute')->with('baby_llama')->will($this->returnValue($data[1])); $expected_link = $data[3]; $expected_trail = $data[4]; $expected_trail_ids = array_combine($expected_trail, $expected_trail); $this->menuLinkManager->expects($this->any())->method('getParentIds')->will($this->returnValueMap(array(array($expected_link->getPluginId(), $expected_trail_ids)))); $this->assertSame($expected_trail_ids, $this->menuActiveTrail->getActiveTrailIds($data[2])); $this->cache->expects($this->once())->method('set')->with('active-trail:route:baby_llama:route_parameters:' . serialize(['a' => 0, 'b' => 1])); $this->lock->expects($this->any())->method('acquire')->willReturn(TRUE); $this->menuActiveTrail->destruct(); }