本文整理匯總了PHP中Drupal\Core\DependencyInjection\ContainerBuilder::set方法的典型用法代碼示例。如果您正苦於以下問題:PHP ContainerBuilder::set方法的具體用法?PHP ContainerBuilder::set怎麽用?PHP ContainerBuilder::set使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Drupal\Core\DependencyInjection\ContainerBuilder
的用法示例。
在下文中一共展示了ContainerBuilder::set方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testConstructor
/**
* 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('node'));
$actions[$i] = $action;
}
$action = $this->getMock('\\Drupal\\system\\ActionConfigEntityInterface');
$action->expects($this->any())->method('getType')->will($this->returnValue('user'));
$actions[] = $action;
$entity_storage = $this->getMock('Drupal\\Core\\Entity\\EntityStorageInterface');
$entity_storage->expects($this->any())->method('loadMultiple')->will($this->returnValue($actions));
$entity_manager = $this->getMock('Drupal\\Core\\Entity\\EntityManagerInterface');
$entity_manager->expects($this->once())->method('getStorage')->with('action')->will($this->returnValue($entity_storage));
$language_manager = $this->getMock('Drupal\\Core\\Language\\LanguageManagerInterface');
$views_data = $this->getMockBuilder('Drupal\\views\\ViewsData')->disableOriginalConstructor()->getMock();
$views_data->expects($this->any())->method('get')->with('node')->will($this->returnValue(array('table' => array('entity type' => 'node'))));
$container = new ContainerBuilder();
$container->set('views.views_data', $views_data);
$container->set('string_translation', $this->getStringTranslationStub());
\Drupal::setContainer($container);
$storage = $this->getMock('Drupal\\views\\ViewEntityInterface');
$storage->expects($this->any())->method('get')->with('base_table')->will($this->returnValue('node'));
$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();
$node_bulk_form = new NodeBulkForm(array(), 'node_bulk_form', $definition, $entity_manager, $language_manager);
$node_bulk_form->init($executable, $display, $options);
$this->assertAttributeEquals(array_slice($actions, 0, -1, TRUE), 'actions', $node_bulk_form);
}
示例2: testCreate
/**
* @covers ::create
* @covers ::__construct
*/
public function testCreate()
{
$container = new ContainerBuilder();
$container->set('keyvalue.expirable', $this->prophesize('Drupal\\Core\\KeyValueStore\\KeyValueExpirableFactoryInterface')->reveal());
$container->set('entity.manager', $this->entityManager->reveal());
$this->assertInstanceOf('Drupal\\feeds\\Controller\\SubscriptionController', SubscriptionController::create($container));
}
示例3: testBuildRowEntityList
/**
* 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.');
}
示例4: setupContainer
/**
* 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);
}
示例5: setUp
/**
* {@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);
}
示例6: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
$this->entityManager = $this->getMock('Drupal\\Core\\Entity\\EntityManagerInterface');
$this->urlGenerator = $this->getMock('Drupal\\Core\\Routing\\UrlGeneratorInterface');
$container = new ContainerBuilder();
$container->set('entity.manager', $this->entityManager);
$container->set('url_generator', $this->urlGenerator);
\Drupal::setContainer($container);
}
示例7: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
$this->urlGenerator = $this->getMock('Drupal\\Core\\Routing\\UrlGeneratorInterface');
$this->urlGenerator->expects($this->any())->method('generateFromPath')->will($this->returnArgument(0));
$this->router = $this->getMock('Drupal\\Tests\\Core\\Routing\\TestRouterInterface');
$container = new ContainerBuilder();
$container->set('router', $this->router);
$container->set('url_generator', $this->urlGenerator);
\Drupal::setContainer($container);
}
示例8: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
$this->typedDataManager = $this->prophesize(TypedDataManager::class);
$container = new ContainerBuilder();
$container->set('string_translation', $this->getStringTranslationStub());
$container->set('typed_data_manager', $this->typedDataManager->reveal());
\Drupal::setContainer($container);
$this->page = $this->prophesize(PageInterface::class);
$this->event = new PageManagerContextEvent($this->page->reveal());
}
示例9: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
$this->typedDataManager = $this->prophesize(TypedDataManager::class);
$container = new ContainerBuilder();
$container->set('string_translation', $this->getStringTranslationStub());
$container->set('typed_data_manager', $this->typedDataManager->reveal());
\Drupal::setContainer($container);
$this->executable = $this->getMockBuilder(PageExecutable::class)->disableOriginalConstructor()->setMethods(['getPage', 'addContext'])->getMock();
$this->event = new PageManagerContextEvent($this->executable);
}
示例10: setUp
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
// Organize our mock container.
$container = new ContainerBuilder();
$container->set('app.root', self::$root);
$file_system = $this->prophesize(FileSystemInterface::class);
// The simpletest directory wrapper will always point to /tmp.
$file_system->realpath('public://simpletest')->willReturn(sys_get_temp_dir());
$container->set('file_system', $file_system->reveal());
\Drupal::setContainer($container);
}
示例11: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
$this->entityManager = $this->getMock('\\Drupal\\Core\\Entity\\EntityManagerInterface');
$this->uuid = $this->getMock('\\Drupal\\Component\\Uuid\\UuidInterface');
$this->fieldTypeManager = $this->getMock(FieldTypePluginManagerInterface::class);
$container = new ContainerBuilder();
$container->set('entity.manager', $this->entityManager);
$container->set('uuid', $this->uuid);
$container->set('plugin.manager.field.field_type', $this->fieldTypeManager);
\Drupal::setContainer($container);
}
示例12: test
/**
* @expectedException \RuntimeException
*/
public function test()
{
$container = new ContainerBuilder();
$container->set('queue', $this->getMock('Drupal\\Core\\Queue\\QueueFactory', [], [], '', FALSE));
$container->set('event_dispatcher', new EventDispatcher());
$plugin = $this->getMockForAbstractClass('Drupal\\feeds\\Plugin\\QueueWorker\\FeedQueueWorkerBase', [], '', FALSE);
$plugin = $plugin::create($container, [], '', []);
$method = $this->getProtectedClosure($plugin, 'handleException');
$method($this->getMockFeed(), new EmptyFeedException());
$method($this->getMockFeed(), new \RuntimeException());
}
示例13: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
$this->urlAssembler = $this->getMock('Drupal\\Core\\Utility\\UnroutedUrlAssemblerInterface');
$this->urlAssembler->expects($this->any())->method('assemble')->will($this->returnArgument(0));
$this->router = $this->getMock('Drupal\\Tests\\Core\\Routing\\TestRouterInterface');
$container = new ContainerBuilder();
$container->set('router.no_access_checks', $this->router);
$container->set('unrouted_url_assembler', $this->urlAssembler);
\Drupal::setContainer($container);
}
示例14: setUp
public function setUp()
{
parent::setUp();
$container = new ContainerBuilder();
$this->dispatcher = new EventDispatcher();
$queue_factory = $this->getMock('Drupal\\Core\\Queue\\QueueFactory', [], [], '', FALSE);
$queue_factory->expects($this->any())->method('get')->with('feeds_feed_process:')->will($this->returnValue($this->getMock('Drupal\\Core\\Queue\\QueueInterface')));
$container->set('queue', $queue_factory);
$container->set('event_dispatcher', $this->dispatcher);
$this->plugin = FeedParse::create($container, [], 'feeds_feed_parse', []);
$this->feed = $this->getMockFeed();
}
示例15: testSetOnSynchronizedService
/**
* Tests set with a synchronized service.
*/
public function testSetOnSynchronizedService()
{
$container = new ContainerBuilder();
$container->register('baz', 'BazClass')->setSynchronized(TRUE);
$container->register('bar', 'BarClass')->addMethodCall('setBaz', array(new Reference('baz')));
// Ensure that we can set services on a compiled container.
$container->compile();
$container->set('baz', $baz = new \BazClass());
$this->assertSame($baz, $container->get('bar')->getBaz());
$container->set('baz', $baz = new \BazClass());
$this->assertSame($baz, $container->get('bar')->getBaz());
}