Пример #1
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     $cache_contexts_manager = $this->prophesize(CacheContextsManager::class)->reveal();
     $container = new Container();
     $container->set('cache_contexts_manager', $cache_contexts_manager);
     \Drupal::setContainer($container);
 }
 /**
  * {@inheritdoc}
  */
 public function setUp()
 {
     parent::setUp();
     $cache_contexts_manager = $this->prophesize(CacheContextsManager::class);
     $cache_contexts_manager->assertValidTokens()->willReturn(TRUE);
     $cache_contexts_manager->reveal();
     $container = new Container();
     $container->set('cache_contexts_manager', $cache_contexts_manager);
     \Drupal::setContainer($container);
     $this->viewer = $this->getMock('\\Drupal\\Core\\Session\\AccountInterface');
     $this->viewer->expects($this->any())->method('hasPermission')->will($this->returnValue(FALSE));
     $this->viewer->expects($this->any())->method('id')->will($this->returnValue(1));
     $this->owner = $this->getMock('\\Drupal\\Core\\Session\\AccountInterface');
     $this->owner->expects($this->any())->method('hasPermission')->will($this->returnValueMap(array(array('administer users', FALSE), array('change own username', TRUE))));
     $this->owner->expects($this->any())->method('id')->will($this->returnValue(2));
     $this->admin = $this->getMock('\\Drupal\\Core\\Session\\AccountInterface');
     $this->admin->expects($this->any())->method('hasPermission')->will($this->returnValue(TRUE));
     $entity_type = $this->getMock('Drupal\\Core\\Entity\\EntityTypeInterface');
     $this->accessControlHandler = new UserAccessControlHandler($entity_type);
     $module_handler = $this->getMock('Drupal\\Core\\Extension\\ModuleHandlerInterface');
     $module_handler->expects($this->any())->method('getImplementations')->will($this->returnValue(array()));
     $this->accessControlHandler->setModuleHandler($module_handler);
     $this->items = $this->getMockBuilder('Drupal\\Core\\Field\\FieldItemList')->disableOriginalConstructor()->getMock();
     $this->items->expects($this->any())->method('defaultAccess')->will($this->returnValue(AccessResult::allowed()));
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     $this->editAccessCheck = new EditEntityFieldAccessCheck();
     $cache_contexts_manager = $this->prophesize(CacheContextsManager::class)->reveal();
     $container = new Container();
     $container->set('cache_contexts_manager', $cache_contexts_manager);
     \Drupal::setContainer($container);
 }
Пример #4
0
 /**
  * @covers ::set
  */
 public function testSet()
 {
     $container = new Container();
     $class = new BarClass();
     $container->set('bar', $class);
     // Ensure that _serviceId is set on the object.
     $this->assertEquals('bar', $class->_serviceId);
 }
 /**
  * Tests the get method.
  *
  * @see \Drupal\Core\DependencyInjection\Container::get()
  */
 public function testGet()
 {
     $service = new \stdClass();
     $service->key = 'value';
     $this->container->set('test_service', $service);
     $result = $this->container->get('test_service');
     $this->assertSame($service, $result);
     $this->assertEquals('test_service', $result->_serviceId);
 }
Пример #6
0
 /**
  * @covers ::process
  */
 public function testProcessWithHttpKernel()
 {
     $kernel = new Definition('Symfony\\Component\\HttpKernel\\HttpKernelInterface');
     $this->containerBuilder->setDefinition('http_kernel', $kernel);
     $this->stackedKernelPass->process($this->containerBuilder);
     $unprocessed_kernel = $this->containerBuilder->getDefinition('http_kernel');
     $this->assertSame($kernel, $unprocessed_kernel);
     $this->assertSame($kernel->getArguments(), $unprocessed_kernel->getArguments());
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     $this->currencyFormHelper = $this->getMock(FormHelperInterface::class);
     $this->stringTranslation = $this->getStringTranslationStub();
     $container = new Container();
     $container->set('currency.form_helper', $this->currencyFormHelper);
     $container->set('string_translation', $this->stringTranslation);
     \Drupal::setContainer($container);
     $this->sut = $this->getMockBuilder(PaymentForm::class)->disableOriginalConstructor()->setMethods(['getSetting'])->getMock();
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $cache_contexts_manager = $this->prophesize(CacheContextsManager::class);
     $cache_contexts_manager->assertValidTokens()->willReturn(TRUE);
     $cache_contexts_manager->reveal();
     $container = new Container();
     $container->set('cache_contexts_manager', $cache_contexts_manager);
     \Drupal::setContainer($container);
 }
 /**
  * {@inheritdoc}
  */
 public function setUp()
 {
     $cache_context_manager = $this->getMockBuilder(CacheContextsManager::class)->disableOriginalConstructor()->getMock();
     $cache_context_manager->expects($this->any())->method('assertValidTokens')->willReturn(TRUE);
     $container = new Container();
     $container->set('cache_contexts_manager', $cache_context_manager);
     \Drupal::setContainer($container);
     $entity_type = $this->getMock(EntityTypeInterface::class);
     $this->sut = new PaymentAccessControlHandler($entity_type);
 }
Пример #10
0
 /**
  * Sets up a display variant plugin for testing.
  *
  * @param array $configuration
  *   An array of plugin configuration.
  * @param array $definition
  *   The plugin definition array.
  *
  * @return \Drupal\block\Plugin\DisplayVariant\BlockPageVariant|\PHPUnit_Framework_MockObject_MockObject
  *   A mocked display variant plugin.
  */
 public function setUpDisplayVariant($configuration = array(), $definition = array())
 {
     $container = new Container();
     $cache_context_manager = $this->getMockBuilder('Drupal\\Core\\Cache\\CacheContextsManager')->disableOriginalConstructor()->getMock();
     $container->set('cache_contexts_manager', $cache_context_manager);
     $cache_context_manager->expects($this->any())->method('assertValidTokens')->willReturn(TRUE);
     \Drupal::setContainer($container);
     $this->blockRepository = $this->getMock('Drupal\\block\\BlockRepositoryInterface');
     $this->blockViewBuilder = $this->getMock('Drupal\\Core\\Entity\\EntityViewBuilderInterface');
     return $this->getMockBuilder('Drupal\\block\\Plugin\\DisplayVariant\\BlockPageVariant')->setConstructorArgs(array($configuration, 'test', $definition, $this->blockRepository, $this->blockViewBuilder, ['config:block_list']))->setMethods(array('getRegionNames'))->getMock();
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->accessManager = $this->getMock('\\Drupal\\Core\\Access\\AccessManagerInterface');
     $this->currentUser = $this->getMock('Drupal\\Core\\Session\\AccountInterface');
     $this->queryFactory = $this->getMockBuilder('Drupal\\Core\\Entity\\Query\\QueryFactory')->disableOriginalConstructor()->getMock();
     $this->defaultMenuTreeManipulators = new DefaultMenuLinkTreeManipulators($this->accessManager, $this->currentUser, $this->queryFactory);
     $cache_contexts_manager = $this->prophesize(CacheContextsManager::class)->reveal();
     $container = new Container();
     $container->set('cache_contexts_manager', $cache_contexts_manager);
     \Drupal::setContainer($container);
 }
 /**
  * {@inheritdoc}
  */
 public function setUp()
 {
     $this->paymentLineItemManager = $this->getMock(PaymentLineItemManagerInterface::class);
     $this->renderer = $this->getMock(RendererInterface::class);
     $this->stringTranslation = $this->getStringTranslationStub();
     $container = new Container();
     $container->set('renderer', $this->renderer);
     \Drupal::setContainer($container);
     $configuration = [];
     $plugin_id = $this->randomMachineName();
     $plugin_definition = [];
     $this->sut = new PaymentLineItemsInput($configuration, $plugin_id, $plugin_definition, $this->stringTranslation, $this->renderer, $this->paymentLineItemManager);
 }
 /**
  * {@inheritdoc}
  */
 public function setUp()
 {
     parent::setUp();
     $this->eventDispatcher = $this->getMock(EventDispatcherInterface::class);
     $this->moduleHandler = $this->getMock(ModuleHandlerInterface::class);
     $this->paymentStatusManager = $this->getMock(PaymentStatusManagerInterface::class);
     $this->token = $this->getMockBuilder(Token::class)->disableOriginalConstructor()->getMock();
     $this->pluginDefinition = ['active' => TRUE, 'message_text' => $this->randomMachineName(), 'message_text_format' => $this->randomMachineName()];
     $this->pluginId = $this->randomMachineName();
     $this->cacheCContextManager = $this->getMockBuilder(CacheContextsManager::class)->disableOriginalConstructor()->getMock();
     $container = new Container();
     $container->set('cache_contexts_manager', $this->cacheCContextManager);
     \Drupal::setContainer($container);
 }
 /**
  * {@inheritdoc}
  */
 public function setUp()
 {
     $configuration = [];
     $plugin_id = $this->randomMachineName();
     $this->pluginDefinition = ['cache' => TRUE, 'provider' => $this->randomMachineName()];
     $this->cacheContextsManager = $this->getMockBuilder(CacheContextsManager::class)->disableOriginalConstructor()->getMock();
     $this->cacheContextsManager->expects($this->any())->method('assertValidTokens')->willReturn(TRUE);
     $this->currencyStorage = $this->getMock(EntityStorageInterface::class);
     $this->input = $this->getMock(InputInterface::class);
     $this->stringTranslation = $this->getStringTranslationStub();
     $container = new Container();
     $container->set('cache_contexts_manager', $this->cacheContextsManager);
     \Drupal::setContainer($container);
     $this->sut = new CurrencyLocalize($configuration, $plugin_id, $this->pluginDefinition, $this->stringTranslation, $this->currencyStorage, $this->input);
 }
Пример #15
0
 /**
  * {@inheritdoc}
  */
 public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE)
 {
     if ($id === 'http_kernel') {
         throw new \Exception('Thrown exception during Container::get');
     } else {
         return parent::get($id, $invalidBehavior);
     }
 }
Пример #16
0
 /**
  * Tests the method for checking access to routes.
  */
 public function testAccess()
 {
     $cache_contexts_manager = $this->prophesize(CacheContextsManager::class)->reveal();
     $container = new Container();
     $container->set('cache_contexts_manager', $cache_contexts_manager);
     \Drupal::setContainer($container);
     $route = new Route('/foo', array(), array('_entity_access' => 'node.update'));
     $upcasted_arguments = new ParameterBag();
     $route_match = $this->getMock('Drupal\\Core\\Routing\\RouteMatchInterface');
     $route_match->expects($this->once())->method('getParameters')->will($this->returnValue($upcasted_arguments));
     $node = $this->getMockBuilder('Drupal\\node\\Entity\\Node')->disableOriginalConstructor()->getMock();
     $node->expects($this->any())->method('access')->will($this->returnValue(AccessResult::allowed()->cachePerPermissions()));
     $access_check = new EntityAccessCheck();
     $upcasted_arguments->set('node', $node);
     $account = $this->getMock('Drupal\\Core\\Session\\AccountInterface');
     $access = $access_check->access($route, $route_match, $account);
     $this->assertEquals(AccessResult::allowed()->cachePerPermissions(), $access);
 }
 /**
  * @covers ::__sleep
  * @covers ::__wakeup
  */
 public function testSerialization()
 {
     // Create a pseudo service and dependency injected object.
     $service = new \stdClass();
     $service->_serviceId = 'test_service';
     $container = new Container();
     $container->set('test_service', $service);
     $container->set('service_container', $container);
     \Drupal::setContainer($container);
     $dependencySerialization = new DependencySerializationTestDummy($service);
     $dependencySerialization->setContainer($container);
     $string = serialize($dependencySerialization);
     /** @var \Drupal\Tests\Core\DependencyInjection\DependencySerializationTestDummy $dependencySerialization */
     $dependencySerialization = unserialize($string);
     $this->assertSame($service, $dependencySerialization->service);
     $this->assertSame($container, $dependencySerialization->container);
     $this->assertEmpty($dependencySerialization->getServiceIds());
 }
 /**
  * Tests role requirements on routes.
  *
  * @param string $path
  *   The path to check access for.
  * @param array $grant_accounts
  *   A list of accounts which should have access to the given path.
  * @param array $deny_accounts
  *   A list of accounts which should not have access to the given path.
  *
  * @see \Drupal\Tests\Core\Route\RouterRoleTest::getTestRouteCollection
  * @see \Drupal\Tests\Core\Route\RouterRoleTest::roleAccessProvider
  *
  * @dataProvider roleAccessProvider
  */
 public function testRoleAccess($path, $grant_accounts, $deny_accounts)
 {
     $cache_contexts_manager = $this->prophesize(CacheContextsManager::class)->reveal();
     $container = new Container();
     $container->set('cache_contexts_manager', $cache_contexts_manager);
     \Drupal::setContainer($container);
     $role_access_check = new RoleAccessCheck();
     $collection = $this->getTestRouteCollection();
     foreach ($grant_accounts as $account) {
         $message = sprintf('Access granted for user with the roles %s on path: %s', implode(', ', $account->getRoles()), $path);
         $this->assertEquals(AccessResult::allowed()->addCacheContexts(['user.roles']), $role_access_check->access($collection->get($path), $account), $message);
     }
     // Check all users which don't have access.
     foreach ($deny_accounts as $account) {
         $message = sprintf('Access denied for user %s with the roles %s on path: %s', $account->id(), implode(', ', $account->getRoles()), $path);
         $has_access = $role_access_check->access($collection->get($path), $account);
         $this->assertEquals(AccessResult::neutral()->addCacheContexts(['user.roles']), $has_access, $message);
     }
 }
Пример #19
0
 /**
  * {@inheritdoc}
  */
 public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE)
 {
     if ($id === 'http_kernel') {
         // Enforce a recoverable error.
         $callable = function (ErrorContainer $container) {
         };
         $callable(1);
     } else {
         return parent::get($id, $invalidBehavior);
     }
 }
Пример #20
0
 /**
  * @covers ::invalidateTags
  * @covers ::addInvalidator
  */
 public function testInvalidateTags()
 {
     $cache_tags_invalidator = new CacheTagsInvalidator();
     // This does not actually implement,
     // \Drupal\Cache\Cache\CacheBackendInterface but we can not mock from two
     // interfaces, we would need a test class for that.
     $invalidator_cache_bin = $this->getMock('\\Drupal\\Core\\Cache\\CacheTagsInvalidator');
     $invalidator_cache_bin->expects($this->once())->method('invalidateTags')->with(array('node:1'));
     // We do not have to define that invalidateTags() is never called as the
     // interface does not define that method, trying to call it would result in
     // a fatal error.
     $non_invalidator_cache_bin = $this->getMock('\\Drupal\\Core\\Cache\\CacheBackendInterface');
     $container = new Container();
     $container->set('cache.invalidator_cache_bin', $invalidator_cache_bin);
     $container->set('cache.non_invalidator_cache_bin', $non_invalidator_cache_bin);
     $container->setParameter('cache_bins', array('cache.invalidator_cache_bin' => 'invalidator_cache_bin', 'cache.non_invalidator_cache_bin' => 'non_invalidator_cache_bin'));
     $cache_tags_invalidator->setContainer($container);
     $invalidator = $this->getMock('\\Drupal\\Core\\Cache\\CacheTagsInvalidator');
     $invalidator->expects($this->once())->method('invalidateTags')->with(array('node:1'));
     $cache_tags_invalidator->addInvalidator($invalidator);
     $cache_tags_invalidator->invalidateTags(array('node:1'));
 }
Пример #21
0
 /**
  * Setup the mock data needed to make language renderers work.
  *
  * @param \Drupal\views\Plugin\views\field\Field $handler
  *   The field handler.
  * @param $definition
  *   An array with entity type definition data.
  */
 protected function setupLanguageRenderer(Field $handler, $definition)
 {
     $display_handler = $this->getMockBuilder('\\Drupal\\views\\Plugin\\views\\display\\DisplayPluginBase')->disableOriginalConstructor()->getMock();
     $display_handler->expects($this->any())->method('getOption')->with($this->equalTo('rendering_language'))->willReturn('en');
     $handler->view->display_handler = $display_handler;
     $data['table']['entity type'] = $definition['entity_type'];
     $views_data = $this->getMockBuilder('\\Drupal\\views\\ViewsData')->disableOriginalConstructor()->getMock();
     $views_data->expects($this->any())->method('get')->willReturn($data);
     $this->container->set('views.views_data', $views_data);
     $entity_type = $this->getMock('\\Drupal\\Core\\Entity\\EntityTypeInterface');
     $entity_type->expects($this->any())->method('id')->willReturn($definition['entity_type']);
     $this->entityManager->expects($this->any())->method('getDefinition')->willReturn($entity_type);
 }
Пример #22
0
 /**
  * @param string $id
  * @param int $invalidBehavior
  *
  * @return object
  */
 public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE)
 {
     if (!$this->stopwatch && $this->has('stopwatch')) {
         $this->stopwatch = parent::get('stopwatch');
         $this->stopwatch->openSection();
         $this->hasStopwatch = TRUE;
     }
     if ('stopwatch' === $id) {
         return $this->stopwatch;
     }
     Timer::start($id);
     if ($this->hasStopwatch) {
         $e = $this->stopwatch->start($id, 'service');
     }
     $service = parent::get($id, $invalidBehavior);
     $this->tracedData[$id] = Timer::stop($id);
     if ($this->hasStopwatch && $e->isStarted()) {
         $e->stop();
     }
     return $service;
 }
Пример #23
0
 /**
  * Tests the set() method.
  *
  * @covers ::set
  */
 public function testSet()
 {
     $class = new BarClass();
     $this->container->set('bar', $class);
     $this->assertEquals('bar', $class->_serviceId);
 }
 /**
  * {@inheritdoc}
  */
 public function setUp()
 {
     $this->currentUser = $this->getMock(AccountInterface::class);
     $this->dateFormatter = $this->getMockBuilder(DateFormatter::class)->disableOriginalConstructor()->getMock();
     $this->linkGenerator = $this->getMock(LinkGeneratorInterface::class);
     $this->paymentMethodManager = $this->getMock(PaymentMethodManagerInterface::class);
     $class_resolver = $this->getMock(ClassResolverInterface::class);
     $this->stringTranslation = $this->getStringTranslationStub();
     $plugin_type_definition = ['id' => $this->randomMachineName(), 'label' => $this->randomMachineName(), 'provider' => $this->randomMachineName()];
     $this->paymentMethodType = new PluginType($plugin_type_definition, $this->stringTranslation, $class_resolver, $this->paymentMethodManager);
     $this->paymentQueue = $this->getMock(QueueInterface::class);
     $this->paymentStorage = $this->getMock(EntityStorageInterface::class);
     $this->pluginSelectorManager = $this->getMock(PluginSelectorManagerInterface::class);
     $this->renderer = $this->getMock(RendererInterface::class);
     $this->requestStack = $this->getMockBuilder(RequestStack::class)->disableOriginalConstructor()->getMock();
     $this->urlGenerator = $this->getMock(UrlGeneratorInterface::class);
     $container = new Container();
     $container->set('renderer', $this->renderer);
     \Drupal::setContainer($container);
     $configuration = [];
     $plugin_id = $this->randomMachineName();
     $this->pluginDefinition['class'] = $this->randomMachineName();
     $this->sut = $this->getMockBuilder(PaymentReferenceBase::class)->setConstructorArgs(array($configuration, $plugin_id, $this->pluginDefinition, $this->requestStack, $this->paymentStorage, $this->stringTranslation, $this->dateFormatter, $this->linkGenerator, $this->renderer, $this->currentUser, $this->pluginSelectorManager, $this->paymentMethodType, new Random()))->getMockForAbstractClass();
     $this->sut->expects($this->any())->method('getPaymentQueue')->willReturn($this->paymentQueue);
 }
Пример #25
0
 /**
  * Returns the current renderer.
  *
  * @return \Drupal\views\Entity\Render\RendererBase
  *   The configured renderer.
  */
 protected function getRenderer()
 {
     if (!isset($this->renderer)) {
         $class = '\\Drupal\\views\\Entity\\Render\\' . Container::camelize($this->options['rendering_language']);
         $this->renderer = new $class($this->view, $this->entityType);
     }
     return $this->renderer;
 }