protected function setUp() {
    // Mock the TypedDataManager to return a TypedDataInterface mock.
    $this->typedData = $this->getMock('Drupal\Core\TypedData\TypedDataInterface');
    $typed_data_manager = $this->getMock(TypedDataManagerInterface::class);
    $typed_data_manager->expects($this->any())
      ->method('getPropertyInstance')
      ->will($this->returnValue($this->typedData));

    // Set up a mock container as ItemList() will call for the 'typed_data_manager'
    // service.
    $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')
      ->setMethods(array('get'))
      ->getMock();
    $container->expects($this->any())
      ->method('get')
      ->with($this->equalTo('typed_data_manager'))
      ->will($this->returnValue($typed_data_manager));

    \Drupal::setContainer($container);

    $this->normalizer = new ListNormalizer();

    $this->list = new ItemList(new DataDefinition());
    $this->list->setValue($this->expectedListValues);
  }
Exemplo n.º 2
0
 /**
  * Tests inline templates.
  */
 public function testInlineTemplate()
 {
     /** @var \Drupal\Core\Render\RendererInterface $renderer */
     $renderer = $this->container->get('renderer');
     /** @var \Drupal\Core\Template\TwigEnvironment $environment */
     $environment = \Drupal::service('twig');
     $this->assertEqual($environment->renderInline('test-no-context'), 'test-no-context');
     $this->assertEqual($environment->renderInline('test-with-context {{ llama }}', array('llama' => 'muuh')), 'test-with-context muuh');
     $element = array();
     $unsafe_string = '<script>alert(\'Danger! High voltage!\');</script>';
     $element['test'] = array('#type' => 'inline_template', '#template' => 'test-with-context <label>{{ unsafe_content }}</label>', '#context' => array('unsafe_content' => $unsafe_string));
     $this->assertEqual($renderer->renderRoot($element), 'test-with-context <label>' . SafeMarkup::checkPlain($unsafe_string) . '</label>');
     // Enable twig_auto_reload and twig_debug.
     $settings = Settings::getAll();
     $settings['twig_debug'] = TRUE;
     $settings['twig_auto_reload'] = TRUE;
     new Settings($settings);
     $this->container = $this->kernel->rebuildContainer();
     \Drupal::setContainer($this->container);
     $element = array();
     $element['test'] = array('#type' => 'inline_template', '#template' => 'test-with-context {{ llama }}', '#context' => array('llama' => 'muuh'));
     $element_copy = $element;
     // Render it twice so that twig caching is triggered.
     $this->assertEqual($renderer->renderRoot($element), 'test-with-context muuh');
     $this->assertEqual($renderer->renderRoot($element_copy), 'test-with-context muuh');
 }
Exemplo n.º 3
0
 public function setUp()
 {
     $this->request = Request::create('/');
     $this->account = $this->getMock('\\Drupal\\Core\\Session\\AccountInterface');
     $this->container = $this->getMock('\\Symfony\\Component\\DependencyInjection\\ContainerInterface');
     $this->manager = $this->getMock('\\Drupal\\Core\\Entity\\EntityManagerInterface');
     $this->entityInfo = $this->getMock('\\Drupal\\Core\\Entity\\EntityTypeInterface');
     $this->manager->expects($this->any())->method('getDefinition')->will($this->returnValue($this->entityInfo));
     $this->linkGenerator = $this->getMock('\\Drupal\\Core\\Utility\\LinkGeneratorInterface');
     $this->map = array(array('current_user', Container::EXCEPTION_ON_INVALID_REFERENCE, $this->account), array('entity.manager', Container::EXCEPTION_ON_INVALID_REFERENCE, $this->manager), array('link_generator', Container::EXCEPTION_ON_INVALID_REFERENCE, $this->linkGenerator));
     $this->container->expects($this->any())->method('get')->will($this->returnValueMap($this->map));
     $this->date = $this->getMockBuilder('\\Drupal\\Core\\Datetime\\Date')->disableOriginalConstructor()->getMock();
     \Drupal::setContainer($this->container);
     $this->entityManager = $this->getMock('\\Drupal\\Core\\Entity\\EntityManagerInterface');
     $this->config = $this->getMockBuilder('\\Drupal\\Core\\Config\\Config')->disableOriginalConstructor()->getMock();
     $this->translation = $this->getStringTranslationStub();
     $this->controller = new FeedFormController($this->entityManager, $this->config, $this->date);
     $this->controller->setTranslationManager($this->translation);
     $this->controller->setRequest($this->request);
     $this->fetcher = new MockFetcher();
     $this->parser = new MockParser();
     $this->processor = new MockProcessor();
     $this->importer = $this->getMock('\\Drupal\\feeds\\ImporterInterface');
     $this->importer->expects($this->any())->method('getPlugins')->will($this->returnValue(array('fetcher' => $this->fetcher, 'parser' => $this->parser, 'processor' => $this->processor)));
     $this->entityLanguage = $this->getMock('\\Drupal\\Core\\Language\\Language');
     $this->feed = $this->getMock('\\Drupal\\feeds\\FeedInterface');
     $this->feed->expects($this->any())->method('language')->will($this->returnValue($this->entityLanguage));
     $this->feed->expects($this->any())->method('getImporter')->will($this->returnValue($this->importer));
     $this->feed->expects($this->any())->method('getAuthor')->will($this->returnValue($this->account));
     $this->feed->expects($this->any())->method('entityInfo')->will($this->returnValue($this->entityInfo));
     $this->controller->setEntity($this->feed);
 }
 /**
  * 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);
 }
Exemplo n.º 5
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);
 }
Exemplo n.º 6
0
 /**
  * {@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');
 }
Exemplo n.º 7
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     $this->viewStorage = $this->getMock('Drupal\\Core\\Entity\\EntityStorageInterface');
     $this->executableFactory = $this->getMockBuilder('Drupal\\views\\ViewExecutableFactory')->disableOriginalConstructor()->getMock();
     $this->renderer = $this->getMock('\\Drupal\\Core\\Render\\RendererInterface');
     $this->renderer->expects($this->any())->method('render')->will($this->returnCallback(function (array &$elements) {
         $elements['#attached'] = [];
         return isset($elements['#markup']) ? $elements['#markup'] : '';
     }));
     $this->renderer->expects($this->any())->method('executeInRenderContext')->willReturnCallback(function (RenderContext $context, callable $callable) {
         return $callable();
     });
     $this->currentPath = $this->getMockBuilder('Drupal\\Core\\Path\\CurrentPathStack')->disableOriginalConstructor()->getMock();
     $this->redirectDestination = $this->getMock('\\Drupal\\Core\\Routing\\RedirectDestinationInterface');
     $this->viewAjaxController = new ViewAjaxController($this->viewStorage, $this->executableFactory, $this->renderer, $this->currentPath, $this->redirectDestination);
     $element_info_manager = $this->getMock('\\Drupal\\Core\\Render\\ElementInfoManagerInterface');
     $element_info_manager->expects($this->any())->method('getInfo')->with('markup')->willReturn(['#pre_render' => [[Markup::class, 'ensureMarkupIsSafe']], '#defaults_loaded' => TRUE]);
     $request_stack = new RequestStack();
     $request_stack->push(new Request());
     $args = [$this->getMock('\\Drupal\\Core\\Controller\\ControllerResolverInterface'), $this->getMock('\\Drupal\\Core\\Theme\\ThemeManagerInterface'), $element_info_manager, $this->getMock('\\Drupal\\Core\\Render\\RenderCacheInterface'), $request_stack, ['required_cache_contexts' => ['languages:language_interface', 'theme']]];
     $this->renderer = $this->getMockBuilder('Drupal\\Core\\Render\\Renderer')->setConstructorArgs($args)->setMethods(NULL)->getMock();
     $container = new ContainerBuilder();
     $container->set('renderer', $this->renderer);
     \Drupal::setContainer($container);
 }
 /**
  * Tests creating an AnonymousUserSession when the request is not available.
  *
  * @covers ::__construct()
  */
 public function testAnonymousUserSessionWithNoRequest()
 {
     $container = new ContainerBuilder();
     \Drupal::setContainer($container);
     $anonymous_user = new AnonymousUserSession();
     $this->assertSame('', $anonymous_user->getHostname());
 }
 /**
  * {@inheritdoc}
  */
 public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE)
 {
     if (\Drupal::state()->get('error_service_test.break_bare_html_renderer')) {
         // Let the bedlam begin.
         // 1) Force a container rebuild.
         /** @var \Drupal\Core\DrupalKernelInterface $kernel */
         $kernel = \Drupal::service('kernel');
         $kernel->rebuildContainer();
         // 2) Fetch the in-situ container builder.
         $container = ErrorServiceTestServiceProvider::$containerBuilder;
         // Ensure the compiler pass worked.
         if (!$container) {
             throw new \Exception('Oh oh, monkeys stole the ServiceProvider.');
         }
         // Stop the theme manager from being found - and triggering error
         // maintenance mode.
         $container->removeDefinition('theme.manager');
         // Mash. Mash. Mash.
         \Drupal::setContainer($container);
         throw new \Exception('Oh oh, bananas in the instruments.');
     }
     if (\Drupal::state()->get('error_service_test.break_logger')) {
         throw new \Exception('Deforestation');
     }
     return $this->app->handle($request, $type, $catch);
 }
 /**
  * {@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);
 }
Exemplo n.º 11
0
 /**
  * {@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()));
 }
Exemplo n.º 12
0
 /**
  * {@inheritdoc}
  */
 protected function tearDown()
 {
     parent::tearDown();
     // Restore the previous container.
     $this->container = $this->previousContainer;
     \Drupal::setContainer($this->previousContainer);
 }
Exemplo n.º 13
0
 /**
  * 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);
 }
Exemplo n.º 14
0
 /**
  * {@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);
 }
 /**
  * {@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);
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     $container = new ContainerBuilder();
     $config_factory = $this->getConfigFactoryStub(array());
     $container->set('config.factory', $config_factory);
     \Drupal::setContainer($container);
     $this->container = $container;
 }
Exemplo n.º 17
0
 /**
  * {@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);
 }
 /**
  * @covers ::pluginManager
  */
 public function testPluginManager()
 {
     $container = new Container();
     $plugin_manager = $this->getMock('\\Drupal\\Component\\Plugin\\PluginManagerInterface');
     $container->set('plugin.manager.userprotect.user_protection', $plugin_manager);
     \Drupal::setContainer($container);
     $this->assertSame($plugin_manager, UserProtect::pluginManager());
 }
 /**
  * @covers ::factory
  */
 public function testFactory()
 {
     $container = new Container();
     $factory = $this->getMock(PaymentFactoryInterface::class);
     $container->set('payment_reference.payment_factory', $factory);
     \Drupal::setContainer($container);
     $this->assertSame($factory, PaymentReference::factory());
 }
Exemplo n.º 20
0
 /**
  * @covers ::merge
  * @dataProvider providerTestMerge
  *
  * This only tests at a high level, because it reuses existing logic. Detailed
  * tests exist for the existing logic:
  *
  * @see \Drupal\Tests\Core\Cache\CacheTest::testMergeTags()
  * @see \Drupal\Tests\Core\Cache\CacheTest::testMergeMaxAges()
  * @see \Drupal\Tests\Core\Cache\CacheContextsTest
  */
 public function testMerge(CacheableMetadata $a, CacheableMetadata $b, CacheableMetadata $expected)
 {
     $cache_contexts_manager = $this->getMockBuilder('Drupal\\Core\\Cache\\CacheContextsManager')->disableOriginalConstructor()->getMock();
     $container = new ContainerBuilder();
     $container->set('cache_contexts_manager', $cache_contexts_manager);
     \Drupal::setContainer($container);
     $this->assertEquals($expected, $a->merge($b));
 }
Exemplo n.º 21
0
 /**
  * {@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);
 }
Exemplo n.º 22
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->requestStack = new RequestStack();
     $this->container = new ContainerBuilder();
     $this->container->set('request_stack', $this->requestStack);
     \Drupal::setContainer($this->container);
 }
Exemplo n.º 23
0
 /**
  * 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}
  */
 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);
 }
Exemplo n.º 25
0
 /**
  * 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}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->requestContext = $this->getMockBuilder('Drupal\\Core\\Routing\\RequestContext')->disableOriginalConstructor()->getMock();
     $this->requestContext->expects($this->any())->method('getCompleteBaseUrl')->willReturn('http://example.com/drupal');
     $container = new Container();
     $container->set('router.request_context', $this->requestContext);
     \Drupal::setContainer($container);
 }
Exemplo n.º 27
0
 /**
  * {@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);
 }
 /**
  * @covers ::addCacheableDependency
  * @dataProvider providerTestMerge
  *
  * This only tests at a high level, because it reuses existing logic. Detailed
  * tests exist for the existing logic:
  *
  * @see \Drupal\Tests\Core\Cache\CacheTest::testMergeTags()
  * @see \Drupal\Tests\Core\Cache\CacheTest::testMergeMaxAges()
  * @see \Drupal\Tests\Core\Cache\CacheContextsTest
  */
 public function testAddCacheableDependency(CacheableMetadata $a, CacheableMetadata $b, CacheableMetadata $expected)
 {
     $cache_contexts_manager = $this->getMockBuilder('Drupal\\Core\\Cache\\Context\\CacheContextsManager')->disableOriginalConstructor()->getMock();
     $cache_contexts_manager->method('assertValidTokens')->willReturn(TRUE);
     $container = new ContainerBuilder();
     $container->set('cache_contexts_manager', $cache_contexts_manager);
     \Drupal::setContainer($container);
     $this->assertEquals($expected, $a->addCacheableDependency($b));
 }
Exemplo n.º 29
0
 /**
  * {@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 setUp()
 {
     parent::setUp();
     $cache_contexts_manager = $this->getMockBuilder('Drupal\\Core\\Cache\\Context\\CacheContextsManager')->disableOriginalConstructor()->getMock();
     $cache_contexts_manager->method('assertValidTokens')->willReturn(TRUE);
     $container = new Container();
     $container->set('cache_contexts_manager', $cache_contexts_manager);
     \Drupal::setContainer($container);
 }