/** * {@inheritdoc} */ public function register(ContainerBuilder $container) { $container->addCompilerPass(new StoragePass()); if (FALSE !== $container->hasDefinition('profiler')) { $container->register('webprofiler.xhprof', 'Drupal\\xhprof\\DataCollector\\XHProfDataCollector')->addArgument(new Reference('xhprof.profiler'))->addTag('data_collector', array('template' => '@xhprof/Collector/xhprof.html.twig', 'id' => 'xhprof', 'title' => 'XHProf', 'priority' => 50)); } }
/** * Tests the constructor assignment of actions. */ public function testConstructor() { $actions = array(); for ($i = 1; $i <= 2; $i++) { $action = $this->getMock('\\Drupal\\system\\ActionConfigEntityInterface'); $action->expects($this->any())->method('getType')->will($this->returnValue('user')); $actions[$i] = $action; } $action = $this->getMock('\\Drupal\\system\\ActionConfigEntityInterface'); $action->expects($this->any())->method('getType')->will($this->returnValue('node')); $actions[] = $action; $entity_storage = $this->getMock('Drupal\\Core\\Entity\\EntityStorageInterface'); $entity_storage->expects($this->any())->method('loadMultiple')->will($this->returnValue($actions)); $views_data = $this->getMockBuilder('Drupal\\views\\ViewsData')->disableOriginalConstructor()->getMock(); $views_data->expects($this->any())->method('get')->with('users')->will($this->returnValue(array('table' => array('entity type' => 'user')))); $container = new ContainerBuilder(); $container->set('views.views_data', $views_data); \Drupal::setContainer($container); $storage = $this->getMock('Drupal\\views\\ViewStorageInterface'); $storage->expects($this->any())->method('get')->with('base_table')->will($this->returnValue('users')); $executable = $this->getMockBuilder('Drupal\\views\\ViewExecutable')->disableOriginalConstructor()->getMock(); $executable->storage = $storage; $display = $this->getMockBuilder('Drupal\\views\\Plugin\\views\\display\\DisplayPluginBase')->disableOriginalConstructor()->getMock(); $definition['title'] = ''; $options = array(); $user_bulk_form = new UserBulkForm(array(), 'user_bulk_form', $definition, $entity_storage); $user_bulk_form->init($executable, $display, $options); $this->assertAttributeEquals(array_slice($actions, 0, -1, TRUE), 'actions', $user_bulk_form); }
/** * Tests the title_query method. * * @see \Drupal\user\Plugin\views\argument\RolesRid::title_query() */ public function testTitleQuery() { $role1 = new Role(array('id' => 'test_rid_1', 'label' => 'test rid 1'), 'user_role'); $role2 = new Role(array('id' => 'test_rid_2', 'label' => 'test <strong>rid 2</strong>'), 'user_role'); // Creates a stub entity storage; $role_storage = $this->getMockForAbstractClass('Drupal\\Core\\Entity\\EntityStorageInterface'); $role_storage->expects($this->any())->method('loadMultiple')->will($this->returnValueMap(array(array(array(), array()), array(array('test_rid_1'), array('test_rid_1' => $role1)), array(array('test_rid_1', 'test_rid_2'), array('test_rid_1' => $role1, 'test_rid_2' => $role2))))); $entity_type = $this->getMock('Drupal\\Core\\Entity\\EntityTypeInterface'); $entity_type->expects($this->any())->method('getKey')->with('label')->will($this->returnValue('label')); $entity_manager = $this->getMock('Drupal\\Core\\Entity\\EntityManagerInterface'); $entity_manager->expects($this->any())->method('getDefinition')->with($this->equalTo('user_role'))->will($this->returnValue($entity_type)); $entity_manager->expects($this->once())->method('getStorage')->with($this->equalTo('user_role'))->will($this->returnValue($role_storage)); // @todo \Drupal\Core\Entity\Entity::entityType() uses a global call to // entity_get_info(), which in turn wraps \Drupal::entityManager(). Set // the entity manager until this is fixed. $container = new ContainerBuilder(); $container->set('entity.manager', $entity_manager); \Drupal::setContainer($container); $roles_rid_argument = new RolesRid(array(), 'user__roles_rid', array(), $entity_manager); $roles_rid_argument->value = array(); $titles = $roles_rid_argument->title_query(); $this->assertEquals(array(), $titles); $roles_rid_argument->value = array('test_rid_1'); $titles = $roles_rid_argument->title_query(); $this->assertEquals(array('test rid 1'), $titles); $roles_rid_argument->value = array('test_rid_1', 'test_rid_2'); $titles = $roles_rid_argument->title_query(); $this->assertEquals(array('test rid 1', String::checkPlain('test <strong>rid 2</strong>')), $titles); }
/** * @covers ::registerWithSymfonyGuesser * * @see Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser */ public function testSymfonyGuesserRegistration() { // Make the guessers property accessible on Symfony's MimeTypeGuesser. $symfony_guesser = SymfonyMimeTypeGuesser::getInstance(); // Test that the Drupal mime type guess is not being used before the // override method is called. It is possible that the test environment does // not support the default guessers. $guessers = $this->readAttribute($symfony_guesser, 'guessers'); if (count($guessers)) { $this->assertNotInstanceOf('Drupal\\Core\\File\\MimeType\\MimeTypeGuesser', $guessers[0]); } $container = new ContainerBuilder(); $container->set('file.mime_type.guesser', new MimeTypeGuesser(new StreamWrapperManager())); MimeTypeGuesser::registerWithSymfonyGuesser($container); $symfony_guesser = SymfonyMimeTypeGuesser::getInstance(); $guessers = $this->readAttribute($symfony_guesser, 'guessers'); $this->assertSame($container->get('file.mime_type.guesser'), $guessers[0]); $this->assertInstanceOf('Drupal\\Core\\File\\MimeType\\MimeTypeGuesser', $guessers[0]); $count = count($guessers); $container = new ContainerBuilder(); $container->set('file.mime_type.guesser', new MimeTypeGuesser(new StreamWrapperManager())); MimeTypeGuesser::registerWithSymfonyGuesser($container); $symfony_guesser = SymfonyMimeTypeGuesser::getInstance(); $guessers = $this->readAttribute($symfony_guesser, 'guessers'); $this->assertSame($container->get('file.mime_type.guesser'), $guessers[0]); $this->assertInstanceOf('Drupal\\Core\\File\\MimeType\\MimeTypeGuesser', $guessers[0]); $new_count = count($guessers); $this->assertEquals($count, $new_count, 'The count of mime type guessers remains the same after container re-init.'); }
/** * @covers ::create * @covers ::__construct */ public function testCreate() { $container = new ContainerBuilder(); $container->set('keyvalue.expirable', $this->prophesize('Drupal\\Core\\KeyValueStore\\KeyValueExpirableFactoryInterface')->reveal()); $container->set('entity.manager', $this->entityManager->reveal()); $this->assertInstanceOf('Drupal\\feeds\\Controller\\SubscriptionController', SubscriptionController::create($container)); }
/** * Tests the set() method. * * @covers ::set */ public function testSet() { $container = new ContainerBuilder(); $class = new BarClass(); $container->set('bar', $class); $this->assertEquals('bar', $class->_serviceId); }
/** * {@inheritdoc} */ public function register(ContainerBuilder $container) { // Add a compiler pass for adding Normalizers and Encoders to Serializer. $container->addCompilerPass(new RegisterSerializationClassesCompilerPass()); // Add a compiler pass for adding concrete Resolvers to chain Resolver. $container->addCompilerPass(new RegisterEntityResolversCompilerPass()); }
/** * {@inheritdoc} */ protected function setUp() { // Create a config mock which does not mock the clear(), set() and get() methods. $methods = get_class_methods('Drupal\\Core\\Config\\Config'); unset($methods[array_search('set', $methods)]); unset($methods[array_search('get', $methods)]); unset($methods[array_search('clear', $methods)]); $config_mock = $this->getMockBuilder('Drupal\\Core\\Config\\Config')->disableOriginalConstructor()->setMethods($methods)->getMock(); // Create the config factory we use in the submitForm() function. $this->configFactory = $this->getMock('Drupal\\Core\\Config\\ConfigFactoryInterface'); $this->configFactory->expects($this->any())->method('getEditable')->will($this->returnValue($config_mock)); // Create a MailsystemManager mock. $this->mailManager = $this->getMock('\\Drupal\\mailsystem\\MailsystemManager', array(), array(), '', FALSE); $this->mailManager->expects($this->any())->method('getDefinition')->will($this->returnValueMap(array(array('mailsystem_test', TRUE, array('label' => 'Test Mail-Plugin')), array('mailsystem_demo', TRUE, array('label' => 'Demo Mail-Plugin'))))); $this->mailManager->expects($this->any())->method('getDefinitions')->will($this->returnValue(array(array('id' => 'mailsystem_test', 'label' => 'Test Mail-Plugin'), array('id' => 'mailsystem_demo', 'label' => 'Demo Mail-Plugin')))); // Create a module handler mock. $this->moduleHandler = $this->getMock('\\Drupal\\Core\\Extension\\ModuleHandlerInterface'); $this->moduleHandler->expects($this->any())->method('getImplementations')->with('mail')->will($this->returnValue(array('mailsystem_test', 'mailsystem_demo'))); $this->moduleHandler->expects($this->any())->method('moduleExists')->withAnyParameters()->will($this->returnValue(FALSE)); // Create a theme handler mock. $this->themeHandler = $this->getMock('\\Drupal\\Core\\Extension\\ThemeHandlerInterface'); $this->themeHandler->expects($this->any())->method('listInfo')->will($this->returnValue(array('test_theme' => (object) array('status' => 1, 'info' => array('name' => 'test theme name')), 'demo_theme' => (object) array('status' => 1, 'info' => array('name' => 'test theme name demo')), 'inactive_theme' => (object) array('status' => 0, 'info' => array('name' => 'inactive test theme'))))); // Inject a language-manager into \Drupal. $this->languageManager = $this->getMock('\\Drupal\\Core\\StringTranslation\\TranslationInterface'); $this->languageManager->expects($this->any())->method('translate')->withAnyParameters()->will($this->returnArgument(0)); $container = new ContainerBuilder(); $container->set('string_translation', $this->languageManager); \Drupal::setContainer($container); }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); // TODO: Change the autogenerated stub $condition_plugin_manager = $this->getMock('Drupal\\Core\\Executable\\ExecutableManagerInterface'); $condition_plugin_manager->expects($this->any())->method('getDefinitions')->will($this->returnValue(array())); $container = new ContainerBuilder(); $container->set('plugin.manager.condition', $condition_plugin_manager); \Drupal::setContainer($container); $this->executable = $this->getMockBuilder('Drupal\\views\\ViewExecutable')->disableOriginalConstructor()->setMethods(['buildRenderable', 'setDisplay', 'setItemsPerPage'])->getMock(); $this->executable->expects($this->any())->method('setDisplay')->with('block_1')->will($this->returnValue(TRUE)); $this->executable->expects($this->any())->method('getShowAdminLinks')->willReturn(FALSE); $this->executable->display_handler = $this->getMockBuilder('Drupal\\views\\Plugin\\views\\display\\Block')->disableOriginalConstructor()->setMethods(NULL)->getMock(); $this->view = $this->getMockBuilder('Drupal\\views\\Entity\\View')->disableOriginalConstructor()->getMock(); $this->view->expects($this->any())->method('id')->willReturn('test_view'); $this->executable->storage = $this->view; $this->executableFactory = $this->getMockBuilder('Drupal\\views\\ViewExecutableFactory')->disableOriginalConstructor()->getMock(); $this->executableFactory->expects($this->any())->method('get')->with($this->view)->will($this->returnValue($this->executable)); $this->displayHandler = $this->getMockBuilder('Drupal\\views\\Plugin\\views\\display\\Block')->disableOriginalConstructor()->getMock(); $this->displayHandler->expects($this->any())->method('blockSettings')->willReturn([]); $this->displayHandler->expects($this->any())->method('getPluginId')->willReturn('block'); $this->executable->display_handler = $this->displayHandler; $this->storage = $this->getMockBuilder('Drupal\\Core\\Config\\Entity\\ConfigEntityStorage')->disableOriginalConstructor()->getMock(); $this->storage->expects($this->any())->method('load')->with('test_view')->will($this->returnValue($this->view)); $this->account = $this->getMock('Drupal\\Core\\Session\\AccountInterface'); }
/** * 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(); $this->pathValidator = $this->getMock('Drupal\\Core\\Path\\PathValidatorInterface'); $container = new ContainerBuilder(); $container->set('path.validator', $this->pathValidator); \Drupal::setContainer($container); }
/** * Tests the get method. * * @see \Drupal\Core\DependencyInjection\Container::get() */ public function testGet() { $container = new ContainerBuilder(); $container->register('bar', 'BarClass'); $result = $container->get('bar'); $this->assertTrue($result instanceof \BarClass); $this->assertEquals('bar', $result->_serviceId); }
/** * {@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'); } }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $container = new ContainerBuilder(); $this->manager = $this->prophesize(PluginManagerInterface::class); $container->set('plugin.manager.display_variant', $this->manager->reveal()); \Drupal::setContainer($container); }
public function test() { $container = new ContainerBuilder(); $container->set('event_dispatcher', $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface')); $mock = $this->getMockForAbstractClass('Drupal\\feeds\\FeedHandlerBase', [], '', FALSE); $mock_class = get_class($mock); $hander = $mock_class::createInstance($container, $this->getMock('Drupal\\Core\\Entity\\EntityTypeInterface')); }
/** * {@inheritdoc} */ public function alter(ContainerBuilder $container) { $definition = $container->getDefinition('menu.active_trail'); $definition->setClass('Drupal\\menu_trail_by_path\\MenuTrailByPathActiveTrail'); $definition->addArgument(new Reference('language_manager')); $definition->addArgument(new Reference('path.current')); $definition->addArgument(new Reference('path.alias_manager')); }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $this->cacheContextsManager = $this->getMockBuilder('Drupal\\Core\\Cache\\Context\\CacheContextsManager')->disableOriginalConstructor()->getMock(); $container = new ContainerBuilder(); $container->set('cache_contexts_manager', $this->cacheContextsManager); \Drupal::setContainer($container); }
/** * Tests the listing of displays on a views list builder. * * @see \Drupal\views_ui\ViewListBuilder::getDisplaysList() * @covers ::buildRow */ public function testBuildRowEntityList() { $storage = $this->getMockBuilder('Drupal\\Core\\Config\\Entity\\ConfigEntityStorage')->disableOriginalConstructor()->getMock(); $display_manager = $this->getMockBuilder('\\Drupal\\views\\Plugin\\ViewsPluginManager')->disableOriginalConstructor()->getMock(); $display_manager->expects($this->any())->method('getDefinition')->will($this->returnValueMap(array(array('default', TRUE, array('id' => 'default', 'title' => 'Master', 'theme' => 'views_view', 'no_ui' => TRUE, 'admin' => '')), array('page', TRUE, array('id' => 'page', 'title' => 'Page', 'uses_menu_links' => TRUE, 'uses_route' => TRUE, 'contextual_links_locations' => array('page'), 'theme' => 'views_view', 'admin' => 'Page admin label')), array('embed', TRUE, array('id' => 'embed', 'title' => 'embed', 'theme' => 'views_view', 'admin' => 'Embed admin label'))))); $default_display = $this->getMock('Drupal\\views\\Plugin\\views\\display\\DefaultDisplay', array('initDisplay'), array(array(), 'default', $display_manager->getDefinition('default'))); $route_provider = $this->getMock('Drupal\\Core\\Routing\\RouteProviderInterface'); $state = $this->getMock('\\Drupal\\Core\\State\\StateInterface'); $menu_storage = $this->getMock('\\Drupal\\Core\\Entity\\EntityStorageInterface'); $page_display = $this->getMock('Drupal\\views\\Plugin\\views\\display\\Page', array('initDisplay', 'getPath'), array(array(), 'default', $display_manager->getDefinition('page'), $route_provider, $state, $menu_storage)); $page_display->expects($this->any())->method('getPath')->will($this->onConsecutiveCalls($this->returnValue('test_page'), $this->returnValue('<object>malformed_path</object>'), $this->returnValue('<script>alert("placeholder_page/%")</script>'))); $embed_display = $this->getMock('Drupal\\views\\Plugin\\views\\display\\Embed', array('initDisplay'), array(array(), 'default', $display_manager->getDefinition('embed'))); $values = array(); $values['status'] = FALSE; $values['display']['default']['id'] = 'default'; $values['display']['default']['display_title'] = 'Display'; $values['display']['default']['display_plugin'] = 'default'; $values['display']['page_1']['id'] = 'page_1'; $values['display']['page_1']['display_title'] = 'Page 1'; $values['display']['page_1']['display_plugin'] = 'page'; $values['display']['page_1']['display_options']['path'] = 'test_page'; $values['display']['page_2']['id'] = 'page_2'; $values['display']['page_2']['display_title'] = 'Page 2'; $values['display']['page_2']['display_plugin'] = 'page'; $values['display']['page_2']['display_options']['path'] = '<object>malformed_path</object>'; $values['display']['page_3']['id'] = 'page_3'; $values['display']['page_3']['display_title'] = 'Page 3'; $values['display']['page_3']['display_plugin'] = 'page'; $values['display']['page_3']['display_options']['path'] = '<script>alert("placeholder_page/%")</script>'; $values['display']['embed']['id'] = 'embed'; $values['display']['embed']['display_title'] = 'Embedded'; $values['display']['embed']['display_plugin'] = 'embed'; $display_manager->expects($this->any())->method('createInstance')->will($this->returnValueMap(array(array('default', $values['display']['default'], $default_display), array('page', $values['display']['page_1'], $page_display), array('page', $values['display']['page_2'], $page_display), array('page', $values['display']['page_3'], $page_display), array('embed', $values['display']['embed'], $embed_display)))); $container = new ContainerBuilder(); $user = $this->getMock('Drupal\\Core\\Session\\AccountInterface'); $request_stack = new RequestStack(); $request_stack->push(new Request()); $views_data = $this->getMockBuilder('Drupal\\views\\ViewsData')->disableOriginalConstructor()->getMock(); $route_provider = $this->getMock('Drupal\\Core\\Routing\\RouteProviderInterface'); $executable_factory = new ViewExecutableFactory($user, $request_stack, $views_data, $route_provider); $container->set('views.executable', $executable_factory); $container->set('plugin.manager.views.display', $display_manager); \Drupal::setContainer($container); // Setup a view list builder with a mocked buildOperations method, // because t() is called on there. $entity_type = $this->getMock('Drupal\\Core\\Entity\\EntityTypeInterface'); $view_list_builder = new TestViewListBuilder($entity_type, $storage, $display_manager); $view_list_builder->setStringTranslation($this->getStringTranslationStub()); $view = new View($values, 'view'); $row = $view_list_builder->buildRow($view); $expected_displays = array('Embed admin label', 'Page admin label', 'Page admin label', 'Page admin label'); $this->assertEquals($expected_displays, $row['data']['view_name']['data']['#displays']); $display_paths = $row['data']['path']['data']['#items']; // These values will be escaped by Twig when rendered. $this->assertEquals('/test_page, /<object>malformed_path</object>, /<script>alert("placeholder_page/%")</script>', implode(', ', $display_paths)); $this->assertFalse(SafeMarkup::isSafe('/<object>malformed_path</object>'), '/<script>alert("/<object>malformed_path</object> is not marked safe.'); $this->assertFalse(SafeMarkup::isSafe('/<script>alert("placeholder_page/%")'), '/<script>alert("/<script>alert("placeholder_page/%") is not marked safe.'); }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $this->menuLinkTree = new MenuLinkTree($this->getMock('\\Drupal\\Core\\Menu\\MenuTreeStorageInterface'), $this->getMock('\\Drupal\\Core\\Menu\\MenuLinkManagerInterface'), $this->getMock('\\Drupal\\Core\\Routing\\RouteProviderInterface'), $this->getMock('\\Drupal\\Core\\Menu\\MenuActiveTrailInterface'), $this->getMock('\\Drupal\\Core\\Controller\\ControllerResolverInterface')); $cache_contexts_manager = $this->getMockBuilder('Drupal\\Core\\Cache\\Context\\CacheContextsManager')->disableOriginalConstructor()->getMock(); $container = new ContainerBuilder(); $container->set('cache_contexts_manager', $cache_contexts_manager); \Drupal::setContainer($container); }
/** * @inheritdoc */ public function alter(ContainerBuilder $container) { drush_log(dt("service modifier alter"), LogLevel::DEBUG); // http://symfony.com/doc/2.7/components/dependency_injection/tags.html#register-the-pass-with-the-container $container->register('drush.service.consolecommands', 'Drush\\Command\\ServiceCommandlist'); $container->addCompilerPass(new FindCommandsCompilerPass('drush.service.consolecommands', 'console.command')); $container->register('drush.service.consolidationcommands', 'Drush\\Command\\ServiceCommandlist'); $container->addCompilerPass(new FindCommandsCompilerPass('drush.service.consolidationcommands', 'consolidation.commandhandler')); }
/** * {@inheritdoc} */ public function setUp() { $config = $this->getMockBuilder('Drupal\\Core\\Config\\Config')->disableOriginalConstructor()->getMock(); $mock_factory = $this->getMock('Drupal\\Core\\Config\\ConfigFactoryInterface'); $mock_factory->method('get')->willReturn($config); $container = new ContainerBuilder(); $container->set('config.factory', $mock_factory); \Drupal::setContainer($container); }
/** * {@inheritdoc} */ public function alter(ContainerBuilder $container) { $definition = $container->getDefinition('country_manager'); // Overrides country_manager class to add additional functionality. $definition->setClass('Drupal\\uc_country\\CountryManager'); // Inject the entity_type.manager service, which is not available in // the core country_manager. $definition->addArgument(new Reference('entity_type.manager')); }
/** * {@inheritdoc} */ public function alter(ContainerBuilder $container) { $definition = $container->getDefinition('asset.resolver'); $argument = new Reference('cache.null'); $definition->replaceArgument(5, $argument); $definition = $container->getDefinition('library.discovery.collector'); $argument = new Reference('cache.null'); $definition->replaceArgument(0, $argument); }
/** * Setup access plugin manager and config factory in the Drupal class. */ public function setupContainer() { $this->accessPluginManager = $this->getMockBuilder('\\Drupal\\views\\Plugin\\ViewsPluginManager')->disableOriginalConstructor()->getMock(); $container = new ContainerBuilder(); $container->set('plugin.manager.views.access', $this->accessPluginManager); $config = array('views.settings' => array('skip_cache' => TRUE, 'display_extenders' => array())); $container->set('config.factory', $this->getConfigFactoryStub($config)); \Drupal::setContainer($container); }
/** * {@inheritdoc} */ public function setUp() { $this->entityManager = $this->getMock('\\Drupal\\Core\\Entity\\EntityManagerInterface'); $this->uuid = $this->getMock('\\Drupal\\Component\\Uuid\\UuidInterface'); $container = new ContainerBuilder(); $container->set('entity.manager', $this->entityManager); $container->set('uuid', $this->uuid); \Drupal::setContainer($container); }
/** * @covers ::get * * @dataProvider providerTestGet */ public function testGet(array $values, $expected) { $container = new ContainerBuilder(); $container->set('string_translation', $this->translationManager); \Drupal::setContainer($container); $arguments = isset($values['arguments']) ? $values['arguments'] : array(); $options = isset($values['context']) ? array('context' => $values['context']) : array(); $annotation = new Translation($values); $this->assertSame($expected, (string) $annotation->get()); }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $this->entityManager = $this->getMock('Drupal\\Core\\Entity\\EntityManagerInterface'); $this->urlGenerator = $this->getMock('Drupal\\Core\\Routing\\UrlGeneratorInterface'); $container = new ContainerBuilder(); $container->set('entity.manager', $this->entityManager); $container->set('url_generator', $this->urlGenerator); \Drupal::setContainer($container); }
/** * @covers ::weekDaysOrdered * @dataProvider providerTestWeekDaysOrdered */ public function testWeekDaysOrdered($first_day, $expected) { $container = new ContainerBuilder(); $config = ['system.date' => ['first_day' => $first_day]]; $container->set('config.factory', $this->getConfigFactoryStub($config)); \Drupal::setContainer($container); $weekdays = DateHelper::weekDaysUntranslated(); // self::assertSame() MUST be used here as it checks for array key order. $this->assertSame($expected, DateHelper::weekDaysOrdered($weekdays)); }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $this->typedDataManager = $this->prophesize(TypedDataManager::class); $this->entityRepository = $this->prophesize(EntityRepositoryInterface::class); $this->staticContext = new ContextMapper($this->entityRepository->reveal()); $container = new ContainerBuilder(); $container->set('typed_data_manager', $this->typedDataManager->reveal()); \Drupal::setContainer($container); }
/** * {@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>'); }