예제 #1
0
 /**
  * Loads a Yaml file.
  *
  * @param mixed  $file The resource
  */
 public function load($file)
 {
     // Load from the file cache, fall back to loading the file.
     // @todo Refactor this to cache parsed definition objects in
     //   https://www.drupal.org/node/2464053
     $content = $this->fileCache->get($file);
     if (!$content) {
         $content = $this->loadFile($file);
         $this->fileCache->set($file, $content);
     }
     // Not supported.
     //$this->container->addResource(new FileResource($path));
     // empty file
     if (null === $content) {
         return;
     }
     // imports
     // Not supported.
     //$this->parseImports($content, $file);
     // parameters
     if (isset($content['parameters'])) {
         foreach ($content['parameters'] as $key => $value) {
             $this->container->setParameter($key, $this->resolveServices($value));
         }
     }
     // extensions
     // Not supported.
     //$this->loadFromExtensions($content);
     // services
     $this->parseDefinitions($content, $file);
 }
예제 #2
0
 /**
  * Loads a Yaml file.
  *
  * @param mixed  $file The resource
  */
 public function load($file)
 {
     // Load from the file cache, fall back to loading the file.
     // @todo Refactor this to cache parsed definition objects in
     //   https://www.drupal.org/node/2464053
     $content = $this->fileCache->get($file);
     if (!$content) {
         $content = $this->loadFile($file);
         $this->fileCache->set($file, $content);
     }
     // Not supported.
     //$this->container->addResource(new FileResource($path));
     // empty file
     if (null === $content) {
         return;
     }
     // imports
     // Not supported.
     //$this->parseImports($content, $file);
     // parameters
     if (isset($content['parameters'])) {
         if (!is_array($content['parameters'])) {
             throw new InvalidArgumentException(sprintf('The "parameters" key should contain an array in %s. Check your YAML syntax.', $file));
         }
         foreach ($content['parameters'] as $key => $value) {
             $this->container->setParameter($key, $this->resolveServices($value));
         }
     }
     // extensions
     // Not supported.
     //$this->loadFromExtensions($content);
     // services
     $this->parseDefinitions($content, $file);
 }
 /**
  * {@inheritdoc}
  */
 public function alter(ContainerBuilder $container)
 {
     if ($container->has('file.usage')) {
         // Override the class used for the file.usage service.
         $definition = $container->getDefinition('file.usage');
         $definition->setClass('Drupal\\service_provider_test\\TestFileUsage');
     }
     if ($indicator = Settings::get('deployment_identifier')) {
         $container->setParameter('container_rebuild_indicator', $indicator);
     }
     if ($parameter = Settings::get('container_rebuild_test_parameter')) {
         $container->setParameter('container_rebuild_test_parameter', $parameter);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function register(ContainerBuilder $container)
 {
     $container->setParameter('app.root', DRUPAL_ROOT);
     $this->registerUuid($container);
     $this->registerTest($container);
     // Add the compiler pass that lets service providers modify existing
     // service definitions. This pass must come first so that later
     // list-building passes are operating on the post-alter services list.
     $container->addCompilerPass(new ModifyServiceDefinitionsPass());
     $container->addCompilerPass(new BackendCompilerPass());
     $container->addCompilerPass(new StackedKernelPass());
     // Collect tagged handler services as method calls on consumer services.
     $container->addCompilerPass(new TaggedHandlersPass());
     $container->addCompilerPass(new RegisterStreamWrappersPass());
     // Add a compiler pass for registering event subscribers.
     $container->addCompilerPass(new RegisterKernelListenersPass(), PassConfig::TYPE_AFTER_REMOVING);
     $container->addCompilerPass(new RegisterAccessChecksPass());
     // Add a compiler pass for registering services needing destruction.
     $container->addCompilerPass(new RegisterServicesForDestructionPass());
     // Add the compiler pass that will process the tagged services.
     $container->addCompilerPass(new ListCacheBinsPass());
     $container->addCompilerPass(new CacheContextsPass());
     // Register plugin managers.
     $container->addCompilerPass(new PluginManagerPass());
 }
 /**
  * Registers services to the container.
  *
  * @param ContainerBuilder $container
  *   The ContainerBuilder to register services to.
  */
 public function register(ContainerBuilder $container)
 {
     static::$container = $container;
     $class_map = $this->AutoloaderInit();
     $ns = [];
     foreach ($class_map as $name => $path) {
         $path = preg_replace("/\\.php\$/i", '', $path);
         $path = explode(DIRECTORY_SEPARATOR, $path);
         $name = explode('\\', $name);
         while (end($path) === end($name)) {
             array_pop($path);
             array_pop($name);
         }
         $path = implode(DIRECTORY_SEPARATOR, $path);
         $name = implode('\\', $name);
         if (is_dir($path)) {
             if (is_dir($path . '/Plugin') || is_dir($path . '/Entity') || is_dir($path . '/Element')) {
                 $ns[$name][] = $path;
             }
         }
     }
     foreach ($ns as $name => $path) {
         $path = array_unique($path);
         $ns[$name] = count($path) == 1 ? reset($path) : $path;
     }
     $ns += $container->getParameter('container.namespaces');
     $container->setParameter('container.namespaces', $ns);
     $yaml_loader = new YamlFileLoader($container);
     foreach (static::getFiles('/^.+\\.services\\.yml$/i') as $file) {
         $yaml_loader->load($file);
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $container = new ContainerBuilder();
     $container->setParameter('workspace.default', 1);
     \Drupal::setContainer($container);
     $this->workspaceNegotiator = new DefaultWorkspaceNegotiator();
     $this->workspaceNegotiator->setContainer($container);
     $this->request = Request::create('<front>');
 }
예제 #7
0
 /**
  * {@inheritdoc}
  */
 public function alter(ContainerBuilder $container)
 {
     $definition = $container->getDefinition('language_manager');
     $definition->setClass('Drupal\\language\\ConfigurableLanguageManager')->addArgument(new Reference('config.factory'))->addArgument(new Reference('module_handler'))->addArgument(new Reference('language.config_factory_override'))->addArgument(new Reference('request_stack'));
     if ($default_language_values = $this->getDefaultLanguageValues()) {
         $container->setParameter('language.default_values', $default_language_values);
     }
     // For monolingual sites, we explicitly set the default language for the
     // language config override service as there is no language negotiation.
     if (!$this->isMultilingual()) {
         $container->getDefinition('language.config_factory_override')->addMethodCall('setLanguageFromDefault', array(new Reference('language.default')));
     }
 }
예제 #8
0
 public function setMinimalContainerPreKernel()
 {
     // Create a minimal mocked container to support calls to t() in the pre-kernel
     // base system verification code paths below. The strings are not actually
     // used or output for these calls.
     $container = new ContainerBuilder();
     $container->setParameter('language.default_values', Language::$defaultValues);
     $container->register('language.default', 'Drupal\\Core\\Language\\LanguageDefault')->addArgument('%language.default_values%');
     $container->register('string_translation', 'Drupal\\Core\\StringTranslation\\TranslationManager')->addArgument(new Reference('language.default'));
     // Register the stream wrapper manager.
     $container->register('stream_wrapper_manager', 'Drupal\\Core\\StreamWrapper\\StreamWrapperManager')->addMethodCall('setContainer', array(new Reference('service_container')));
     $container->register('file_system', 'Drupal\\Core\\File\\FileSystem')->addArgument(new Reference('stream_wrapper_manager'))->addArgument(Settings::getInstance())->addArgument((new LoggerChannelFactory())->get('file'));
     \Drupal::setContainer($container);
 }
예제 #9
0
 /**
  * {@inheritdoc}
  */
 public function alter(ContainerBuilder $container)
 {
     // Disable Twig cache (php storage does not exist yet).
     $twig_config = $container->getParameter('twig.config');
     $twig_config['cache'] = FALSE;
     $container->setParameter('twig.config', $twig_config);
     // No service may persist when the early installer kernel is rebooted into
     // the production environment.
     // @todo The DrupalKernel reboot performed by drupal_install_system() is
     //   actually not a "regular" reboot (like ModuleHandler::install()), so
     //   services are not actually persisted.
     foreach ($container->findTaggedServiceIds('persist') as $id => $tags) {
         $definition = $container->getDefinition($id);
         $definition->clearTag('persist');
     }
 }
예제 #10
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $container = new ContainerBuilder();
     $request = $this->getMockBuilder('\\Symfony\\Component\\HttpFoundation\\Request')->disableOriginalConstructor()->getMock();
     $this->view = $this->getMock('\\Drupal\\views\\Entity\\View', array('initHandlers'), array(array('id' => 'test_view'), 'view'));
     $view_executable = $this->getMock('\\Drupal\\views\\ViewExecutable', array('initHandlers', 'getTitle'), array(), '', FALSE);
     $view_executable->expects($this->any())->method('getTitle')->willReturn('View title');
     $view_executable->storage = $this->view;
     $view_executable->argument = array();
     $display_manager = $this->getMockBuilder('\\Drupal\\views\\Plugin\\ViewsPluginManager')->disableOriginalConstructor()->getMock();
     $container->set('plugin.manager.views.display', $display_manager);
     $access_manager = $this->getMockBuilder('\\Drupal\\views\\Plugin\\ViewsPluginManager')->disableOriginalConstructor()->getMock();
     $container->set('plugin.manager.views.access', $access_manager);
     $route_provider = $this->getMockBuilder('\\Drupal\\Core\\Routing\\RouteProviderInterface')->disableOriginalConstructor()->getMock();
     $container->set('router.route_provider', $route_provider);
     $container->setParameter('authentication_providers', ['basic_auth' => 'basic_auth']);
     $state = $this->getMock('\\Drupal\\Core\\State\\StateInterface');
     $container->set('state', $state);
     $style_manager = $this->getMockBuilder('\\Drupal\\views\\Plugin\\ViewsPluginManager')->disableOriginalConstructor()->getMock();
     $container->set('plugin.manager.views.style', $style_manager);
     $container->set('renderer', $this->getMock('Drupal\\Core\\Render\\RendererInterface'));
     $authentication_collector = $this->getMock('\\Drupal\\Core\\Authentication\\AuthenticationCollectorInterface');
     $container->set('authentication_collector', $authentication_collector);
     $authentication_collector->expects($this->any())->method('getSortedProviders')->will($this->returnValue(['basic_auth' => 'data', 'cookie' => 'data']));
     \Drupal::setContainer($container);
     $this->restExport = RestExport::create($container, array(), "test_routes", array());
     $this->restExport->view = $view_executable;
     // Initialize a display.
     $this->restExport->display = array('id' => 'page_1');
     // Set the style option.
     $this->restExport->setOption('style', array('type' => 'serializer'));
     // Set the auth option.
     $this->restExport->setOption('auth', ['basic_auth']);
     $display_manager->expects($this->once())->method('getDefinition')->will($this->returnValue(array('id' => 'test', 'provider' => 'test')));
     $none = $this->getMockBuilder('\\Drupal\\views\\Plugin\\views\\access\\None')->disableOriginalConstructor()->getMock();
     $access_manager->expects($this->once())->method('createInstance')->will($this->returnValue($none));
     $style_plugin = $this->getMock('\\Drupal\\rest\\Plugin\\views\\style\\Serializer', array('getFormats', 'init'), array(), '', FALSE);
     $style_plugin->expects($this->once())->method('getFormats')->will($this->returnValue(array('json')));
     $style_plugin->expects($this->once())->method('init')->with($view_executable)->will($this->returnValue(TRUE));
     $style_manager->expects($this->once())->method('createInstance')->will($this->returnValue($style_plugin));
     $this->routes = new RouteCollection();
     $this->routes->add('test_1', new Route('/test/1'));
     $this->routes->add('view.test_view.page_1', new Route('/test/2'));
     $this->view->addDisplay('page', NULL, 'page_1');
 }
예제 #11
0
 /**
  * Test the lock behavior.
  */
 public function testLocks()
 {
     $container = new ContainerBuilder();
     $container->set('module_handler', $this->getMock('Drupal\\Core\\Extension\\ModuleHandlerInterface'));
     $container->set('current_user', $this->getMock('Drupal\\Core\\Session\\AccountInterface'));
     $container->set('cache.test', $this->getMock('Drupal\\Core\\Cache\\CacheBackendInterface'));
     $container->set('comment.statistics', $this->getMock('Drupal\\comment\\CommentStatisticsInterface'));
     $request_stack = new RequestStack();
     $request_stack->push(Request::create('/'));
     $container->set('request_stack', $request_stack);
     $container->setParameter('cache_bins', array('cache.test' => 'test'));
     $lock = $this->getMock('Drupal\\Core\\Lock\\LockBackendInterface');
     $cid = 2;
     $lock_name = "comment:{$cid}:.00/";
     $lock->expects($this->at(0))->method('acquire')->with($lock_name, 30)->will($this->returnValue(TRUE));
     $lock->expects($this->at(1))->method('release')->with($lock_name);
     $lock->expects($this->exactly(2))->method($this->anything());
     $container->set('lock', $lock);
     $cache_tag_invalidator = $this->getMock('Drupal\\Core\\Cache\\CacheTagsInvalidator');
     $container->set('cache_tags.invalidator', $cache_tag_invalidator);
     \Drupal::setContainer($container);
     $methods = get_class_methods('Drupal\\comment\\Entity\\Comment');
     unset($methods[array_search('preSave', $methods)]);
     unset($methods[array_search('postSave', $methods)]);
     $methods[] = 'invalidateTagsOnSave';
     $comment = $this->getMockBuilder('Drupal\\comment\\Entity\\Comment')->disableOriginalConstructor()->setMethods($methods)->getMock();
     $comment->expects($this->once())->method('isNew')->will($this->returnValue(TRUE));
     $comment->expects($this->once())->method('hasParentComment')->will($this->returnValue(TRUE));
     $comment->expects($this->once())->method('getParentComment')->will($this->returnValue($comment));
     $comment->expects($this->once())->method('getCommentedEntityId')->will($this->returnValue($cid));
     $comment->expects($this->any())->method('getThread')->will($this->returnValue(''));
     $parent_entity = $this->getMock('\\Drupal\\Core\\Entity\\ContentEntityInterface');
     $parent_entity->expects($this->atLeastOnce())->method('getCacheTagsToInvalidate')->willReturn(['node:1']);
     $comment->expects($this->once())->method('getCommentedEntity')->willReturn($parent_entity);
     $entity_type = $this->getMock('\\Drupal\\Core\\Entity\\EntityTypeInterface');
     $comment->expects($this->any())->method('getEntityType')->will($this->returnValue($entity_type));
     $comment->expects($this->at(1))->method('get')->with('status')->will($this->returnValue((object) array('value' => NULL)));
     $storage = $this->getMock('Drupal\\comment\\CommentStorageInterface');
     // preSave() should acquire the lock. (This is what's really being tested.)
     $comment->preSave($storage);
     // Release the acquired lock before exiting the test.
     $comment->postSave($storage);
 }
 /**
  * {@inheritdoc}
  */
 public function alter(ContainerBuilder $container)
 {
     // Disable Twig cache (php storage does not exist yet).
     $twig_config = $container->getParameter('twig.config');
     $twig_config['cache'] = FALSE;
     $container->setParameter('twig.config', $twig_config);
     // Disable configuration overrides.
     // ConfigFactory would to try to load language overrides and InstallStorage
     // throws an exception upon trying to load a non-existing file.
     $container->get('config.factory')->setOverrideState(FALSE);
     // No service may persist when the early installer kernel is rebooted into
     // the production environment.
     // @todo The DrupalKernel reboot performed by drupal_install_system() is
     //   actually not a "regular" reboot (like ModuleHandler::install()), so
     //   services are not actually persisted.
     foreach ($container->findTaggedServiceIds('persist') as $id => $tags) {
         $definition = $container->getDefinition($id);
         $definition->clearTag('persist');
     }
 }
예제 #13
0
 /**
  * Test the lock behavior.
  */
 public function testLocks()
 {
     $container = new ContainerBuilder();
     $container->set('module_handler', $this->getMock('Drupal\\Core\\Extension\\ModuleHandlerInterface'));
     $container->set('current_user', $this->getMock('Drupal\\Core\\Session\\AccountInterface'));
     $container->set('cache.test', $this->getMock('Drupal\\Core\\Cache\\CacheBackendInterface'));
     $request_stack = new RequestStack();
     $request_stack->push(Request::create('/'));
     $container->set('request_stack', $request_stack);
     $container->setParameter('cache_bins', array('cache.test' => 'test'));
     $lock = $this->getMock('Drupal\\Core\\Lock\\LockBackendInterface');
     $cid = 2;
     $lock_name = "comment:{$cid}:.00/";
     $lock->expects($this->at(0))->method('acquire')->with($lock_name, 30)->will($this->returnValue(TRUE));
     $lock->expects($this->at(1))->method('release')->with($lock_name);
     $lock->expects($this->exactly(2))->method($this->anything());
     $container->set('lock', $lock);
     \Drupal::setContainer($container);
     $methods = get_class_methods('Drupal\\comment\\Entity\\Comment');
     unset($methods[array_search('preSave', $methods)]);
     unset($methods[array_search('postSave', $methods)]);
     $methods[] = 'onSaveOrDelete';
     $methods[] = 'onUpdateBundleEntity';
     $comment = $this->getMockBuilder('Drupal\\comment\\Entity\\Comment')->disableOriginalConstructor()->setMethods($methods)->getMock();
     $comment->expects($this->once())->method('isNew')->will($this->returnValue(TRUE));
     $comment->expects($this->once())->method('hasParentComment')->will($this->returnValue(TRUE));
     $comment->expects($this->once())->method('getParentComment')->will($this->returnValue($comment));
     $comment->expects($this->once())->method('getCommentedEntityId')->will($this->returnValue($cid));
     $comment->expects($this->any())->method('getThread')->will($this->returnValue(''));
     $entity_type = $this->getMock('\\Drupal\\Core\\Entity\\EntityTypeInterface');
     $comment->expects($this->any())->method('getEntityType')->will($this->returnValue($entity_type));
     $comment->expects($this->at(1))->method('get')->with('status')->will($this->returnValue((object) array('value' => NULL)));
     $comment->expects($this->once())->method('getCacheTag')->will($this->returnValue(array('comment' => array($cid))));
     $comment->expects($this->once())->method('getListCacheTags')->will($this->returnValue(array('comments' => TRUE)));
     $storage = $this->getMock('Drupal\\comment\\CommentStorageInterface');
     $comment->preSave($storage);
     $comment->postSave($storage);
 }
 /**
  * {@inheritdoc}
  */
 public function alter(ContainerBuilder $container)
 {
     if ($container->has('config.factory')) {
         // The configuration factory depends on the cache factory, but that
         // depends on the 'cache_default_bin_backends' parameter that has not yet
         // been set by \Drupal\Core\Cache\ListCacheBinsPass::process() at this
         // point.
         $parameter_name = 'cache_default_bin_backends';
         if (!$container->hasParameter($parameter_name)) {
             $container->setParameter($parameter_name, []);
         }
         /** @var \Drupal\Core\Config\ConfigFactoryInterface $config_factory */
         $config_factory = $container->get('config.factory');
         $config = $config_factory->get('libraries.settings');
         if (!$config->isNew()) {
             // Set the local definition path.
             $container->getDefinition('libraries.definition.discovery.local')->replaceArgument(1, $config->get('definition.local.path'));
             // Set the remote definition URL. Note that this is set even if
             // the remote discovery is not enabled below in case the
             // 'libraries.definition.discovery.remote' service is used explicitly.
             $container->getDefinition('libraries.definition.discovery.remote')->replaceArgument(2, $config->get('definition.remote.url'));
             // Because it is less convenient to remove a method call than to add
             // one, the remote discovery is not registered in libraries.services.yml
             // and instead added here, even though the 'definition.remote.enable'
             // configuration value is TRUE by default.
             if ($config->get('definition.remote.enable')) {
                 // Add the remote discovery to the list of chained discoveries.
                 $container->getDefinition('libraries.definition.discovery')->addMethodCall('addDiscovery', [new Reference('libraries.definition.discovery.remote')]);
             }
         }
         // At this point the event dispatcher has not yet been populated with
         // event subscribers by RegisterEventSubscribersPass::process() but has
         // already bin injected in the configuration factory. Reset those services
         // accordingly.
         $container->set('event_dispatcher', NULL);
         $container->set('config.factory', NULL);
     }
 }
 public function alter(ContainerBuilder $container)
 {
     // Override the password_migrate class with a new class.
     try {
         $definition = $container->getDefinition('password_migrate');
         $definition->setClass('Drupal\\multiversion\\MigratePassword');
     } catch (InvalidArgumentException $e) {
         // Do nothing, migrate module is not installed.
     }
     $renderer_config = $container->getParameter('renderer.config');
     $renderer_config['required_cache_contexts'][] = 'workspace';
     $container->setParameter('renderer.config', $renderer_config);
     // Switch the menu tree storage to our own that respect Workspace cache
     // contexts.
     $definition = $container->getDefinition('menu.tree_storage');
     $definition->setClass('Drupal\\multiversion\\MenuTreeStorage');
     // Override the comment.statistics class with a new class.
     try {
         $definition = $container->getDefinition('comment.statistics');
         $definition->setClass('Drupal\\multiversion\\CommentStatistics');
     } catch (InvalidArgumentException $e) {
         // Do nothing, comment module is not installed.
     }
 }
예제 #16
0
 /**
  * {@inheritdoc}
  */
 public function alter(ContainerBuilder $container)
 {
     if (isset($this->corsConfig)) {
         $container->setParameter('cors.config', $this->corsConfig);
     }
 }
예제 #17
0
 /**
  * Sets up the base service container for this test.
  *
  * Extend this method in your test to register additional service overrides
  * that need to persist a DrupalKernel reboot. This method is called whenever
  * the kernel is rebuilt.
  *
  * @see \Drupal\simpletest\KernelTestBase::setUp()
  * @see \Drupal\simpletest\KernelTestBase::enableModules()
  * @see \Drupal\simpletest\KernelTestBase::disableModules()
  */
 public function containerBuild(ContainerBuilder $container)
 {
     // Keep the container object around for tests.
     $this->container = $container;
     // Set the default language on the minimal container.
     $this->container->setParameter('language.default_values', $this->defaultLanguageData());
     $container->register('lock', 'Drupal\\Core\\Lock\\NullLockBackend');
     $container->register('cache_factory', 'Drupal\\Core\\Cache\\MemoryBackendFactory');
     $container->register('config.storage', 'Drupal\\Core\\Config\\DatabaseStorage')->addArgument(Database::getConnection())->addArgument('config');
     if ($this->strictConfigSchema) {
         $container->register('simpletest.config_schema_checker', 'Drupal\\Core\\Config\\Testing\\ConfigSchemaChecker')->addArgument(new Reference('config.typed'))->addArgument($this->getConfigSchemaExclusions())->addTag('event_subscriber');
     }
     $keyvalue_options = $container->getParameter('factory.keyvalue') ?: array();
     $keyvalue_options['default'] = 'keyvalue.memory';
     $container->setParameter('factory.keyvalue', $keyvalue_options);
     $container->set('keyvalue.memory', $this->keyValueFactory);
     if (!$container->has('keyvalue')) {
         // TestBase::setUp puts a completely empty container in
         // $this->container which is somewhat the mirror of the empty
         // environment being set up. Unit tests need not to waste time with
         // getting a container set up for them. Drupal Unit Tests might just get
         // away with a simple container holding the absolute bare minimum. When
         // a kernel is overridden then there's no need to re-register the keyvalue
         // service but when a test is happy with the superminimal container put
         // together here, it still might a keyvalue storage for anything using
         // \Drupal::state() -- that's why a memory service was added in the first
         // place.
         $container->register('settings', 'Drupal\\Core\\Site\\Settings')->setFactoryClass('Drupal\\Core\\Site\\Settings')->setFactoryMethod('getInstance');
         $container->register('keyvalue', 'Drupal\\Core\\KeyValueStore\\KeyValueFactory')->addArgument(new Reference('service_container'))->addArgument(new Parameter('factory.keyvalue'));
         $container->register('state', 'Drupal\\Core\\State\\State')->addArgument(new Reference('keyvalue'));
     }
     if ($container->hasDefinition('path_processor_alias')) {
         // Prevent the alias-based path processor, which requires a url_alias db
         // table, from being registered to the path processor manager. We do this
         // by removing the tags that the compiler pass looks for. This means the
         // url generator can safely be used within tests.
         $definition = $container->getDefinition('path_processor_alias');
         $definition->clearTag('path_processor_inbound')->clearTag('path_processor_outbound');
     }
     if ($container->hasDefinition('password')) {
         $container->getDefinition('password')->setArguments(array(1));
     }
     // Register the stream wrapper manager.
     $container->register('stream_wrapper_manager', 'Drupal\\Core\\StreamWrapper\\StreamWrapperManager')->addArgument(new Reference('module_handler'))->addMethodCall('setContainer', array(new Reference('service_container')));
     $request = Request::create('/');
     $container->get('request_stack')->push($request);
 }
예제 #18
0
 /**
  * Registers test-specific services.
  *
  * Extend this method in your test to register additional services. This
  * method is called whenever the kernel is rebuilt.
  *
  * @param \Drupal\Core\DependencyInjection\ContainerBuilder $container
  *   The service container to enhance.
  *
  * @see \Drupal\Tests\KernelTestBase::bootKernel()
  */
 public function register(ContainerBuilder $container)
 {
     // Keep the container object around for tests.
     $this->container = $container;
     $container->register('flood', 'Drupal\\Core\\Flood\\MemoryBackend')->addArgument(new Reference('request_stack'));
     $container->register('lock', 'Drupal\\Core\\Lock\\NullLockBackend');
     $container->register('cache_factory', 'Drupal\\Core\\Cache\\MemoryBackendFactory');
     $container->register('keyvalue.memory', 'Drupal\\Core\\KeyValueStore\\KeyValueMemoryFactory')->addTag('persist');
     $container->setAlias('keyvalue', 'keyvalue.memory');
     // Set the default language on the minimal container.
     $container->setParameter('language.default_values', Language::$defaultValues);
     if ($this->strictConfigSchema) {
         $container->register('simpletest.config_schema_checker', 'Drupal\\Core\\Config\\Testing\\ConfigSchemaChecker')->addArgument(new Reference('config.typed'))->addArgument($this->getConfigSchemaExclusions())->addTag('event_subscriber');
     }
     if ($container->hasDefinition('path_processor_alias')) {
         // Prevent the alias-based path processor, which requires a url_alias db
         // table, from being registered to the path processor manager. We do this
         // by removing the tags that the compiler pass looks for. This means the
         // url generator can safely be used within tests.
         $container->getDefinition('path_processor_alias')->clearTag('path_processor_inbound')->clearTag('path_processor_outbound');
     }
     if ($container->hasDefinition('password')) {
         $container->getDefinition('password')->setArguments(array(1));
     }
     TestServiceProvider::addRouteProvider($container);
 }
 /**
  * Runs the install database tasks for the driver used by the test runner.
  */
 protected function runDbTasks()
 {
     // Create a minimal container so that t() works.
     // @see install_begin_request()
     $container = new ContainerBuilder();
     $container->setParameter('language.default_values', Language::$defaultValues);
     $container->register('language.default', 'Drupal\\Core\\Language\\LanguageDefault')->addArgument('%language.default_values%');
     $container->register('language_manager', 'Drupal\\Core\\Language\\LanguageManager')->addArgument(new Reference('language.default'));
     $container->register('string_translation', 'Drupal\\Core\\StringTranslation\\TranslationManager')->addArgument(new Reference('language_manager'));
     \Drupal::setContainer($container);
     require_once __DIR__ . '/../../../../../includes/install.inc';
     $connection = Database::getConnection();
     $errors = db_installer_object($connection->driver())->runTasks();
     if (!empty($errors)) {
         $this->fail('Failed to run installer database tasks: ' . implode(', ', $errors));
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     $this->id = $this->randomMachineName();
     $values = array('id' => $this->id, 'langcode' => 'en', 'uuid' => '3bb9ee60-bea5-4622-b89b-a63319d10b3a');
     $this->entityTypeId = $this->randomMachineName();
     $this->provider = $this->randomMachineName();
     $this->entityType = $this->getMock('\\Drupal\\Core\\Entity\\EntityTypeInterface');
     $this->entityType->expects($this->any())->method('getProvider')->will($this->returnValue($this->provider));
     $this->entityManager = $this->getMock('\\Drupal\\Core\\Entity\\EntityManagerInterface');
     $this->entityManager->expects($this->any())->method('getDefinition')->with($this->entityTypeId)->will($this->returnValue($this->entityType));
     $this->uuid = $this->getMock('\\Drupal\\Component\\Uuid\\UuidInterface');
     $this->languageManager = $this->getMock('\\Drupal\\Core\\Language\\LanguageManagerInterface');
     $this->languageManager->expects($this->any())->method('getLanguage')->with('en')->will($this->returnValue(new Language(array('id' => 'en'))));
     $this->cacheBackend = $this->getMock('Drupal\\Core\\Cache\\CacheBackendInterface');
     $this->typedConfigManager = $this->getMock('Drupal\\Core\\Config\\TypedConfigManagerInterface');
     $container = new ContainerBuilder();
     $container->set('entity.manager', $this->entityManager);
     $container->set('uuid', $this->uuid);
     $container->set('language_manager', $this->languageManager);
     $container->set('cache.test', $this->cacheBackend);
     $container->set('config.typed', $this->typedConfigManager);
     $container->setParameter('cache_bins', array('cache.test' => 'test'));
     \Drupal::setContainer($container);
     $this->entity = $this->getMockForAbstractClass('\\Drupal\\Core\\Config\\Entity\\ConfigEntityBase', array($values, $this->entityTypeId));
 }
 /**
  * Prepares the key value entity storage.
  *
  * @covers ::__construct()
  *
  * @param string $uuid_key
  *   (optional) The entity key used for the UUID. Defaults to 'uuid'.
  */
 protected function setUpKeyValueEntityStorage($uuid_key = 'uuid')
 {
     $this->entityType->expects($this->atLeastOnce())->method('getKey')->will($this->returnValueMap(array(array('id', 'id'), array('uuid', $uuid_key))));
     $this->entityType->expects($this->atLeastOnce())->method('id')->will($this->returnValue('test_entity_type'));
     $this->entityType->expects($this->any())->method('getListCacheTags')->willReturn(array('test_entity_type_list'));
     $this->entityManager = $this->getMock('Drupal\\Core\\Entity\\EntityManagerInterface');
     $this->entityManager->expects($this->any())->method('getDefinition')->with('test_entity_type')->will($this->returnValue($this->entityType));
     $this->cacheBackend = $this->getMock('Drupal\\Core\\Cache\\CacheBackendInterface');
     $this->keyValueStore = $this->getMock('Drupal\\Core\\KeyValueStore\\KeyValueStoreInterface');
     $this->moduleHandler = $this->getMock('Drupal\\Core\\Extension\\ModuleHandlerInterface');
     $this->uuidService = $this->getMock('Drupal\\Component\\Uuid\\UuidInterface');
     $this->languageManager = $this->getMock('Drupal\\Core\\Language\\LanguageManagerInterface');
     $language = new Language(array('langcode' => 'en'));
     $this->languageManager->expects($this->any())->method('getDefaultLanguage')->will($this->returnValue($language));
     $this->languageManager->expects($this->any())->method('getCurrentLanguage')->will($this->returnValue($language));
     $this->entityStorage = new KeyValueEntityStorage($this->entityType, $this->keyValueStore, $this->uuidService, $this->languageManager);
     $this->entityStorage->setModuleHandler($this->moduleHandler);
     $container = new ContainerBuilder();
     $container->set('entity.manager', $this->entityManager);
     $container->set('language_manager', $this->languageManager);
     $container->set('cache.test', $this->cacheBackend);
     $container->setParameter('cache_bins', array('cache.test' => 'test'));
     \Drupal::setContainer($container);
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->entityTypeId = 'workspace';
     $second_id = $this->randomMachineName();
     $this->values = [['id' => 1, 'machine_name' => $this->defaultMachineName, 'label' => $this->defaultMachineName], ['id' => 2, 'machine_name' => $second_id, 'label' => $second_id]];
     foreach ($this->values as $value) {
         $entity = $this->getMockBuilder('Drupal\\multiversion\\Entity\\Workspace')->disableOriginalConstructor()->getMock();
         $entity->expects($this->any())->method('create')->with($value)->will($this->returnValue($this->entityType));
         $this->entities[] = $entity;
     }
     $this->path = '<front>';
     $this->request = Request::create($this->path);
     $this->entityType = $this->getMock('Drupal\\multiversion\\Entity\\WorkspaceInterface');
     $this->entityManager = $this->getMock('Drupal\\Core\\Entity\\EntityManagerInterface');
     $this->cacheRender = $this->getMock('Drupal\\Core\\Cache\\CacheBackendInterface');
     $this->entityManager->expects($this->any())->method('getDefinition')->with($this->entityTypeId)->will($this->returnValue($this->entityType));
     $this->requestStack = $this->getMock('Symfony\\Component\\HttpFoundation\\RequestStack');
     $this->workspaceManager = $this->getMock('Drupal\\multiversion\\Workspace\\WorkspaceManagerInterface');
     $container = new ContainerBuilder();
     $container->setParameter('workspace.default', 1);
     $container->set('entity.manager', $this->entityManager);
     $container->set('workspace.manager', $this->workspaceManager);
     $container->set('request_stack', $this->requestStack);
     $container->set('cache.render', $this->cacheRender);
     \Drupal::setContainer($container);
     $this->workspaceNegotiator = new SessionWorkspaceNegotiator();
     $this->workspaceNegotiator->setContainer($container);
 }
예제 #23
0
 /**
  * @covers ::setParameter
  * @expectedException \InvalidArgumentException
  * @expectedExceptionMessage Parameter names must be lowercase: Buzz
  */
 public function testSetParameterException()
 {
     $container = new ContainerBuilder();
     $container->setParameter('Buzz', 'buzz');
 }