本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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');
}
示例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);
}
示例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);
}