Beispiel #1
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 bubbling of cacheable metadata for URLs.
  *
  * @param bool $collect_bubbleable_metadata
  *   Whether bubbleable metadata should be collected.
  * @param int $invocations
  *   The expected amount of invocations for the ::bubble() method.
  * @param array $options
  *   The URL options.
  *
  * @covers ::bubble
  *
  * @dataProvider providerUrlBubbleableMetadataBubbling
  */
 public function testUrlBubbleableMetadataBubbling($collect_bubbleable_metadata, $invocations, array $options)
 {
     $self = $this;
     $this->renderer->expects($this->exactly($invocations))->method('render')->willReturnCallback(function ($build) use($self) {
         $self->assertTrue(!empty($build['#cache']));
     });
     $url = new Url('test_1', [], $options);
     $url->setUrlGenerator($this->generator);
     $url->toString($collect_bubbleable_metadata);
 }
 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->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);
 }
Beispiel #4
0
 /**
  * Tests that mails are sent in a separate render context.
  *
  * @covers ::mail
  */
 public function testMailInRenderContext()
 {
     $interface = array('default' => 'php_mail', 'example_testkey' => 'test_mail_collector');
     $this->setUpMailManager($interface);
     $this->renderer->expects($this->exactly(1))->method('executeInRenderContext')->willReturnCallback(function (RenderContext $render_context, $callback) {
         $message = $callback();
         $this->assertEquals('example', $message['module']);
     });
     $this->mailManager->mail('example', 'key', '*****@*****.**', 'en');
 }
 /**
  * Test rendering of a link with a path and options.
  *
  * @dataProvider providerTestRenderAsLinkWithPathAndTokens
  * @covers ::renderAsLink
  */
 public function testRenderAsLinkWithPathAndTokens($path, $tokens, $link_html)
 {
     $alter = ['make_link' => TRUE, 'path' => $path];
     $this->setUpUrlIntegrationServices();
     $this->setupDisplayWithEmptyArgumentsAndFields();
     $this->executable->build_info['substitutions'] = $tokens;
     $field = $this->setupTestField(['alter' => $alter]);
     $field->field_alias = 'key';
     $row = new ResultRow(['key' => 'value']);
     $build = ['#type' => 'inline_template', '#template' => 'base:test-path/' . explode('/', $path)[1], '#context' => ['foo' => 123]];
     $this->renderer->expects($this->once())->method('render')->with($build, FALSE)->willReturn('base:test-path/123');
     $result = $field->advancedRender($row);
     $this->assertEquals($link_html, $result);
 }
  /**
   * Test rendering of a link with a path and options.
   *
   * @dataProvider providerTestRenderAsExternalLinkWithPathAndTokens
   * @covers ::renderAsLink
   */
  public function testRenderAsExternalLinkWithPathAndTokens($path, $tokens, $link_html, $context) {
    $alter = [
      'make_link' => TRUE,
      'path' => $path,
      'url' => '',
    ];
    if (isset($context['alter'])) {
      $alter += $context['alter'];
    }

    $this->setUpUrlIntegrationServices();
    $this->setupDisplayWithEmptyArgumentsAndFields();
    $this->executable->build_info['substitutions'] = $tokens;
    $field = $this->setupTestField(['alter' => $alter]);
    $field->field_alias = 'key';
    $row = new ResultRow(['key' => 'value']);

    $build = [
      '#type' => 'inline_template',
      '#template' => $path,
      '#context' => ['foo' => $context['context_path']],
      '#post_render' => [function() {}],
    ];

    $this->renderer->expects($this->once())
      ->method('renderPlain')
      ->with($build)
      ->willReturn($context['context_path']);

    $result = $field->advancedRender($row);
    $this->assertEquals($link_html, $result);
  }