/** * {@inheritdoc} */ public function __wakeup() { // Tests in isolation potentially unserialize in the parent process. if (isset($GLOBALS['__PHPUNIT_BOOTSTRAP']) && !\Drupal::hasContainer()) { return; } $container = \Drupal::getContainer(); foreach ($this->_serviceIds as $key => $service_id) { $this->{$key} = $container->get($service_id); } $this->_serviceIds = array(); }
/** * Tests that drupal_get_filename() works when the file is not in database. */ function testDrupalGetFilename() { // drupal_get_profile() is using obtaining the profile from state if the // install_state global is not set. global $install_state; $install_state['parameters']['profile'] = 'testing'; // Assert that this test is meaningful. $this->assertNull($this->container); $this->assertFalse(\Drupal::hasContainer()); // Retrieving the location of a module. $this->assertIdentical(drupal_get_filename('module', 'system'), 'core/modules/system/system.info.yml'); // Retrieving the location of a theme. $this->assertIdentical(drupal_get_filename('theme', 'stark'), 'core/themes/stark/stark.info.yml'); // Retrieving the location of a theme engine. $this->assertIdentical(drupal_get_filename('theme_engine', 'phptemplate'), 'core/themes/engines/phptemplate/phptemplate.info.yml'); // Retrieving the location of a profile. Profiles are a special case with // a fixed location and naming. $this->assertIdentical(drupal_get_filename('profile', 'standard'), 'core/profiles/standard/standard.info.yml'); // Searching for an item that does not exist returns NULL. $this->assertNull(drupal_get_filename('module', uniqid("", TRUE)), 'Searching for an item that does not exist returns NULL.'); }
/** * {@inheritdoc} */ public function unserialize($serialized) { list($storage, $current_display, $args, $current_page, $exposed_input, $exposed_raw_input, $exposed_data, $dom_id, $executed) = unserialize($serialized); // There are cases, like in testing, where we don't have a container // available. if (\Drupal::hasContainer()) { $this->setRequest(\Drupal::request()); $this->user = \Drupal::currentUser(); $this->storage = \Drupal::entityManager()->getStorage('view')->load($storage); $this->setDisplay($current_display); $this->setArguments($args); $this->setCurrentPage($current_page); $this->setExposedInput($exposed_input); $this->exposed_data = $exposed_data; $this->exposed_raw_input = $exposed_raw_input; $this->dom_id = $dom_id; $this->initHandlers(); // If the display was previously executed, execute it now. if ($executed) { $this->execute($this->current_display); } } }
/** * Sets up the entity type manager in the container. * * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager * The entity type manager. */ protected function setupEntityTypeManager(EntityTypeManagerInterface $entity_type_manager) { $container = \Drupal::hasContainer() ? \Drupal::getContainer() : new ContainerBuilder(); $container->set('entity_type.manager', $entity_type_manager); $container->set('entity.manager', $entity_type_manager); \Drupal::setContainer($container); }
protected function setupNullCacheabilityMetadataValidation() { $container = \Drupal::hasContainer() ? \Drupal::getContainer() : new ContainerBuilder(); $cache_context_manager = $this->prophesize(CacheContextsManager::class); $container->set('cache_contexts_manager', $cache_context_manager->reveal()); \Drupal::setContainer($container); }
protected function setupNullCacheabilityMetadataValidation() { $container = \Drupal::hasContainer() ? \Drupal::getContainer() : new ContainerBuilder(); $cache_context_manager = $this->prophesize(CacheContextsManager::class); foreach ([NULL, ['user.permissions'], ['route'], ['route', 'context.example1'], ['context.example1', 'route'], ['context.example1', 'route', 'context.example2'], ['context.example1', 'context.example2', 'route'], ['context.example1', 'context.example2', 'route', 'user.permissions']] as $argument) { $cache_context_manager->assertValidTokens($argument)->willReturn(TRUE); } $container->set('cache_contexts_manager', $cache_context_manager->reveal()); \Drupal::setContainer($container); }