コード例 #1
0
 /**
  * @covers ::setDefaultPluginId
  */
 public function testSetDefaultPluginId()
 {
     $plugin_id = $this->randomMachineName();
     $config = $this->getMockBuilder(Config::class)->disableOriginalConstructor()->getMock();
     $config->expects($this->once())->method('set')->with('plugin_id', $plugin_id)->will($this->returnSelf());
     $config->expects($this->once())->method('save');
     $this->configFactory->expects($this->once())->method('get')->with('currency.amount_formatter')->willReturn($config);
     $this->assertSame(spl_object_hash($this->sut), spl_object_hash($this->sut->setDefaultPluginId($plugin_id)));
 }
コード例 #2
0
 /**
  * @covers ::resolveCurrencyLocale
  *
  * @expectedException \RuntimeException
  */
 function testResolveCurrencyLocaleMissingFallback()
 {
     $this->prepareLanguageManager();
     $config = $this->getMockBuilder(Config::class)->disableOriginalConstructor()->getMock();
     $config->expects($this->any())->method('get')->with('country.default')->willReturn(NULL);
     $this->configFactory->expects($this->once())->method('get')->with('system.data')->willReturn($config);
     $this->currencyLocaleStorage->expects($this->any())->method('load')->with(LocaleResolverInterface::DEFAULT_LOCALE)->willReturn(NULL);
     // Test loading the fallback locale.
     $this->sut->resolveCurrencyLocale();
 }
コード例 #3
0
ファイル: KeyTestBase.php プロジェクト: rlhawk/key
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     // Mock the Config object, but methods will be mocked in the test class.
     $this->config = $this->getMockBuilder('\\Drupal\\Core\\Config\\ImmutableConfig')->disableOriginalConstructor()->getMock();
     // Mock the ConfigFactory service.
     $this->configFactory = $this->getMockBuilder('\\Drupal\\Core\\Config\\ConfigFactory')->disableOriginalConstructor()->getMock();
     $this->configFactory->expects($this->any())->method('get')->with('key.default_config')->willReturn($this->config);
     // Mock ConfigEntityStorage object, but methods will be mocked in the test
     // class.
     $this->configStorage = $this->getMockBuilder('\\Drupal\\Core\\Config\\Entity\\ConfigEntityStorage')->disableOriginalConstructor()->getMock();
     // Mock EntityManager service.
     $this->entityManager = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityManager')->disableOriginalConstructor()->getMock();
     $this->entityManager->expects($this->any())->method('getStorage')->with('key')->willReturn($this->configStorage);
     // Create a dummy container.
     $this->container = new ContainerBuilder();
     $this->container->set('entity.manager', $this->entityManager);
     $this->container->set('config.factory', $this->configFactory);
     // Each test class should call \Drupal::setContainer() in its own setUp
     // method so that test classes can add mocked services to the container
     // without affecting other test classes.
 }
コード例 #4
0
 /**
  * Stores random exchange rates in the mocked config and returns them.
  *
  * @return array
  *   An array of the same format as the return value of
  *   \Drupal\currency\Plugin\Currency\ExchangeRateProvider\FixedRates::loadAll().
  */
 protected function prepareExchangeRates()
 {
     $rates = array('EUR' => array('DEM' => '1.95583', 'NLG' => '2.20371'), 'NLG' => array('EUR' => '0.453780216'));
     $rates_data = array();
     foreach ($rates as $currency_code_from => $currency_code_from_rates) {
         foreach ($currency_code_from_rates as $currency_code_to => $rate) {
             $rates_data[] = array('currency_code_from' => $currency_code_from, 'currency_code_to' => $currency_code_to, 'rate' => $rate);
         }
     }
     $this->config = $this->getMockBuilder(Config::class)->disableOriginalConstructor()->getMock();
     $this->config->expects($this->any())->method('get')->with('rates')->willReturn($rates_data);
     $this->configFactory->expects($this->any())->method('get')->with('currency.exchanger.fixed_rates')->willReturn($this->config);
     $this->configFactory->expects($this->any())->method('getEditable')->with('currency.exchanger.fixed_rates')->willReturn($this->config);
     return array($rates, $rates_data);
 }