當前位置: 首頁>>代碼示例>>PHP>>正文


PHP RendererInterface::expects方法代碼示例

本文整理匯總了PHP中Drupal\Core\Render\RendererInterface::expects方法的典型用法代碼示例。如果您正苦於以下問題:PHP RendererInterface::expects方法的具體用法?PHP RendererInterface::expects怎麽用?PHP RendererInterface::expects使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Drupal\Core\Render\RendererInterface的用法示例。


在下文中一共展示了RendererInterface::expects方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: setUp

 /**
  * {@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);
 }
開發者ID:scratch,項目名稱:gai,代碼行數:28,代碼來源:ViewAjaxControllerTest.php

示例2: testUrlBubbleableMetadataBubbling

 /**
  * 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);
 }
開發者ID:aWEBoLabs,項目名稱:taxi,代碼行數:24,代碼來源:MetadataBubblingUrlGeneratorTest.php

示例3: setUp

 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);
 }
開發者ID:Nikola-xiii,項目名稱:d8intranet,代碼行數:13,代碼來源:ViewAjaxControllerTest.php

示例4: testMailInRenderContext

 /**
  * 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', 'to@example.org', 'en');
 }
開發者ID:eigentor,項目名稱:tommiblog,代碼行數:15,代碼來源:MailManagerTest.php

示例5: testRenderAsLinkWithPathAndTokens

 /**
  * 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);
 }
開發者ID:nstielau,項目名稱:drops-8,代碼行數:20,代碼來源:FieldPluginBaseTest.php

示例6: testRenderAsExternalLinkWithPathAndTokens

  /**
   * 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);
  }
開發者ID:Greg-Boggs,項目名稱:electric-dev,代碼行數:38,代碼來源:FieldPluginBaseTest.php


注:本文中的Drupal\Core\Render\RendererInterface::expects方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。