本文整理汇总了PHP中Drupal\Core\Config\ConfigFactoryInterface::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP ConfigFactoryInterface::expects方法的具体用法?PHP ConfigFactoryInterface::expects怎么用?PHP ConfigFactoryInterface::expects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Config\ConfigFactoryInterface
的用法示例。
在下文中一共展示了ConfigFactoryInterface::expects方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
/**
* {@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);
}
示例2: setUp
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
$this->aliasProcessor = $this->getMockBuilder('Drupal\Core\PathProcessor\PathProcessorAlias')
->disableOriginalConstructor()
->getMock();
$this->languageManager = $this->getMock('Drupal\Core\Language\LanguageManagerInterface');
$this->languageManager->expects($this->any())
->method('getCurrentLanguage')
->willReturn(new Language(Language::$defaultValues));
$this->pathValidator = $this->getMock('Drupal\Core\Path\PathValidatorInterface');
$this->subPathautoSettings = $this->getMock('Drupal\Core\Config\ConfigBase');
$this->configFactory = $this->getMock('Drupal\Core\Config\ConfigFactoryInterface');
$this->configFactory->expects($this->any())
->method('get')
->with('subpathauto.settings')
->willReturn($this->subPathautoSettings);
$this->sut = new PathProcessor($this->aliasProcessor, $this->languageManager, $this->configFactory);
$this->sut->setPathValidator($this->pathValidator);
}
示例3: testDeleteNothing
/**
* @covers ::delete
* @covers ::doDelete
*/
public function testDeleteNothing()
{
$this->moduleHandler->expects($this->never())->method($this->anything());
$this->configFactory->expects($this->never())->method('get');
$this->cacheTagsInvalidator->expects($this->never())->method('invalidateTags');
$this->entityStorage->delete(array());
}
示例4: deleteTemporaryAssetsDeletesAssetsWhenAgeIsGreaterThanZero
/**
* Tests deleteTemporaryAssets() when the config item for age is 0.
*
* @covers ::deleteTemporaryAssets
*
* @test
*/
public function deleteTemporaryAssetsDeletesAssetsWhenAgeIsGreaterThanZero()
{
$mock_config = $this->getMockBuilder(ImmutableConfig::class)->disableOriginalConstructor()->getMock();
$age = 123456;
$mock_config->expects($this->once())->method('get')->with('temporary_maximum_age')->willReturn($age);
$this->configFactory->expects($this->once())->method('get')->with('system.file')->willReturn($mock_config);
$mock_query = $this->getMock('\\Drupal\\Core\\Entity\\Query\\QueryInterface');
$map = [['status', FILE_STATUS_PERMANENT, '<>'], ['changed', MOCK_TIMESTAMP - $age, '<']];
$mock_query->expects($this->exactly(2))->method('condition')->will($this->returnValueMap($map));
$mock_query->expects($this->once())->method('range')->with(0, 50)->will($this->returnSelf());
$mock_asset_ids = [123, 456, 789];
$mock_asset_ids = array_combine($mock_asset_ids, $mock_asset_ids);
$mock_query->expects($this->once())->method('execute')->willReturn($mock_asset_ids);
$mock_entity_storage = $this->getMock(EntityStorageInterface::class);
$mock_entity_storage->expects($this->once())->method('getQuery')->willReturn($mock_query);
$mock_assets = [];
$log_map = [];
foreach ($mock_asset_ids as $id) {
$mock_asset = $this->getMockBuilder('\\Drupal\\embridge\\EmbridgeAssetEntityInterface')->disableOriginalConstructor()->getMock();
$mock_asset->expects($this->once())->method('delete');
$filename = 'Mock Asset ' . $id;
$mock_asset->expects($this->once())->method('getFilename')->willReturn($filename);
$mock_asset->expects($this->once())->method('id')->willReturn($id);
$log_map[] = ['Embridge Asset "%filename" [%id] garbage collected during cron.', ['%filename' => $filename, '%id' => $id]];
$mock_assets[$id] = $mock_asset;
}
$this->logger->expects($this->exactly(count($mock_asset_ids)))->method('notice')->will($this->returnValueMap($log_map));
$mock_entity_storage->expects($this->once())->method('loadMultiple')->with($mock_asset_ids)->willReturn($mock_assets);
$this->entityTypeManager->expects($this->once())->method('getStorage')->with('embridge_asset_entity')->willReturn($mock_entity_storage);
$this->emdbHelper->deleteTemporaryAssets();
}
示例5: testSetDefaultSearchPage
/**
* Tests the setDefaultSearchPage() method.
*/
public function testSetDefaultSearchPage()
{
$id = 'bananas';
$config = $this->getMockBuilder('Drupal\\Core\\Config\\Config')->disableOriginalConstructor()->getMock();
$config->expects($this->once())->method('set')->with('default_page', $id)->will($this->returnValue($config));
$config->expects($this->once())->method('save')->will($this->returnValue($config));
$this->configFactory->expects($this->once())->method('getEditable')->with('search.settings')->will($this->returnValue($config));
$search_page = $this->getMock('Drupal\\search\\SearchPageInterface');
$search_page->expects($this->once())->method('id')->will($this->returnValue($id));
$search_page->expects($this->once())->method('enable')->will($this->returnValue($search_page));
$search_page->expects($this->once())->method('save')->will($this->returnValue($search_page));
$this->searchPageRepository->setDefaultSearchPage($search_page);
}
示例6: testSubmitForm
/**
* @covers ::submitForm
*/
public function testSubmitForm()
{
$plugin_id = $this->randomMachineName();
$values = ['default_plugin_id' => $plugin_id];
$form = [];
$form_state = new FormState();
$form_state->setValues($values);
$config = $this->getMockBuilder(Config::class)->disableOriginalConstructor()->getMock();
$config->expects($this->atLeastOnce())->method('set')->with('plugin_id', $plugin_id);
$config->expects($this->atLeastOnce())->method('save');
$this->configFactory->expects($this->atLeastOnce())->method('getEditable')->with('currency.amount_formatting')->willReturn($config);
$this->controller->submitForm($form, $form_state);
}
示例7: setUp
/**
* Sets up the test.
*/
protected function setUp()
{
parent::setUp();
$this->client = $this->getMockBuilder(ClientInterface::class)->disableOriginalConstructor()->getMock();
$this->serializer = new Json();
$mock_config = $this->getMockBuilder(ImmutableConfig::class)->disableOriginalConstructor()->getMock();
// Create a map of arguments to return values.
$sample_config = ['uri' => 'http://www.example.com', 'username' => 'admin', 'password' => 'admin', 'timeout' => self::EXAMPLE_TIMEOUT];
$this->sampleConfig = $sample_config;
// Configure the stub.
$mock_config->expects($this->any())->method('get')->will($this->returnValueMap([['uri', $sample_config['uri']], ['username', $sample_config['username']], ['password', $sample_config['password']], ['timeout', $sample_config['timeout']]]));
$this->configFactory = $this->getMock(ConfigFactoryInterface::class);
$this->configFactory->expects($this->any())->method('get')->with('embridge.settings')->willReturn($mock_config);
$this->fileSystem = $this->getMockBuilder(FileSystem::class)->disableOriginalConstructor()->getMock();
$this->emdbClient = new EnterMediaDbClient($this->configFactory, $this->client, $this->serializer, $this->fileSystem);
$this->defaultOptions = ['timeout' => self::EXAMPLE_TIMEOUT, 'cookies' => new SessionCookieJar('SESSION_STORAGE', TRUE)];
$this->defaultLoginOptions = $this->defaultOptions + ['json' => ['id' => $this->sampleConfig['username'], 'password' => $this->sampleConfig['password']]];
}
示例8: testLoad
/**
* @covers ::load
*/
public function testLoad()
{
$currency_code_from = 'EUR';
$currency_code_to = 'NLG';
$rate = new ExchangeRate($currency_code_from, $currency_code_to, '2.20371');
$exchange_rate_provider_id_a = $this->randomMachineName();
$exchange_rate_provider_id_b = $this->randomMachineName();
$exchange_rate_provider_b = $this->getMock('\\Commercie\\CurrencyExchange\\ExchangeRateProviderInterface');
$exchange_rate_provider_b->expects($this->once())->method('load')->with($currency_code_from, $currency_code_to)->willReturn($rate);
$plugin_definitions = [$exchange_rate_provider_id_a => ['id' => $exchange_rate_provider_id_a], $exchange_rate_provider_id_b => ['id' => $exchange_rate_provider_id_b]];
$this->currencyExchangeRateProviderManager->expects($this->once())->method('createInstance')->with($exchange_rate_provider_id_b)->willReturn($exchange_rate_provider_b);
$this->currencyExchangeRateProviderManager->expects($this->once())->method('getDefinitions')->willReturn($plugin_definitions);
$config_value = [['plugin_id' => $exchange_rate_provider_id_a, 'status' => FALSE], ['plugin_id' => $exchange_rate_provider_id_b, 'status' => TRUE]];
$config = $this->getMockBuilder('\\Drupal\\Core\\Config\\Config')->disableOriginalConstructor()->getMock();
$config->expects($this->once())->method('get')->with('plugins')->will($this->returnValue($config_value));
$this->configFactory->expects($this->once())->method('get')->with('currency.exchange_rate_provider')->will($this->returnValue($config));
$this->assertSame($rate, $this->sut->load($currency_code_from, $currency_code_to));
}
示例9: testBuildOptionsForm
/**
* @covers ::buildOptionsForm
*/
public function testBuildOptionsForm()
{
$this->viewsDisplayHandler->expects($this->atLeastOnce())->method('getFieldLabels')->willReturn([]);
$this->viewsDisplayHandler->expects($this->atLeastOnce())->method('getHandlers')->with('argument')->willReturn([]);
$views_settings_config = $this->getMockBuilder(Config::class)->disableOriginalConstructor()->getMock();
$views_settings_config->expects($this->atLeastOnce())->method('get')->with('field_rewrite_elements')->willReturn([]);
$this->configFactory->expects($this->atLeastOnce())->method('get')->with('views.settings')->willReturn($views_settings_config);
$unrouted_url_assembler = $this->getMock(UnroutedUrlAssemblerInterface::class);
$unrouted_url_assembler->expects($this->atLeastOnce())->method('assemble')->willReturn($this->randomMachineName());
$container = new ContainerBuilder();
$container->set('config.factory', $this->configFactory);
$container->set('unrouted_url_assembler', $unrouted_url_assembler);
\Drupal::setContainer($container);
$form = [];
$form_state = new FormState();
$this->sut->buildOptionsForm($form, $form_state);
foreach ($form as $element) {
$this->assertInternalType('array', $element);
}
}