/**
  * @covers ::buildForm
  */
 public function testBuildForm()
 {
     $plugin_id_a = $this->randomMachineName();
     $plugin_id_b = $this->randomMachineName();
     $plugin_id_c = $this->randomMachineName();
     $plugin_definitions = [$plugin_id_a => ['description' => NULL, 'label' => $this->randomMachineName(), 'operations' => []], $plugin_id_b => ['description' => $this->randomMachineName(), 'label' => $this->randomMachineName(), 'operations' => []], $plugin_id_c => ['description' => $this->randomMachineName(), 'label' => $this->randomMachineName(), 'operations' => [['href' => $this->randomMachineName(), 'title' => $this->randomMachineName()]]]];
     $configuration = [$plugin_id_a => TRUE, $plugin_id_b => FALSE, $plugin_id_c => TRUE];
     $this->exchangeRateProvider->expects($this->atLeastOnce())->method('loadConfiguration')->willReturn($configuration);
     $this->currencyExchangeRateProviderManager->expects($this->atLeastOnce())->method('getDefinitions')->willReturn($plugin_definitions);
     $form = [];
     $form_state = new FormState();
     $build = $this->sut->buildForm($form, $form_state);
     foreach ([$plugin_id_a, $plugin_id_b, $plugin_id_c] as $weight => $plugin_id) {
         $this->assertInternalType('array', $build['exchange_rate_providers'][$plugin_id]['weight']);
         $this->assertInternalType('array', $build['exchange_rate_providers'][$plugin_id]['label']);
         $this->assertSame($plugin_definitions[$plugin_id]['label'], $build['exchange_rate_providers'][$plugin_id]['label']['#markup']);
         $this->assertInternalType('array', $build['exchange_rate_providers'][$plugin_id]['weight']);
         $this->assertSame($weight + 1, $build['exchange_rate_providers'][$plugin_id]['weight']['#default_value']);
     }
     $this->assertInternalType('array', $build['actions']);
 }
コード例 #2
0
 /**
  * @covers ::submitForm
  */
 public function testSubmitFormWitDelete()
 {
     $currency_code_from = $this->randomMachineName();
     $currency_code_to = $this->randomMachineName();
     $values = ['currency_code_from' => $currency_code_from, 'currency_code_to' => $currency_code_to];
     $form = ['actions' => ['save' => ['#name' => 'save', '#foo' => $this->randomMachineName()], 'delete' => ['#name' => 'delete', '#foo' => $this->randomMachineName()]]];
     $form_state = $this->getMock(FormStateInterface::class);
     $form_state->expects($this->atLeastOnce())->method('getTriggeringElement')->willReturn($form['actions']['delete']);
     $form_state->expects($this->atLeastOnce())->method('getValues')->willReturn($values);
     $form_state->expects($this->atLeastOnce())->method('setRedirect')->with('currency.exchange_rate_provider.fixed_rates.overview');
     $exchange_rate_provider = $this->getMockBuilder(FixedRates::class)->disableOriginalConstructor()->getMock();
     $exchange_rate_provider->expects($this->once())->method('delete')->with($currency_code_from, $currency_code_to);
     $this->currencyExchangeRateProviderManager->expects($this->once())->method('createInstance')->with('currency_fixed_rates')->willReturn($exchange_rate_provider);
     $currency_from = $this->getMock(CurrencyInterface::class);
     $currency_to = $this->getMock(CurrencyInterface::class);
     $map = [[$currency_code_from, $currency_from], [$currency_code_to, $currency_to]];
     $this->currencyStorage->expects($this->atLeastOnce())->method('load')->willReturnMap($map);
     $this->sut->submitForm($form, $form_state);
 }
コード例 #3
0
 /**
  * @covers ::overview
  */
 public function testOverview()
 {
     $currency_code_from = 'EUR';
     $currency_code_to = 'NLG';
     $rate = '2.20371';
     $currency_from = $this->getMock(CurrencyInterface::class);
     $currency_from->expects($this->once())->method('label');
     $currency_to = $this->getMock(CurrencyInterface::class);
     $currency_to->expects($this->once())->method('label');
     $map = array(array($currency_code_from, $currency_from), array($currency_code_to, $currency_to));
     $this->currencyStorage->expects($this->any())->method('load')->willReturnMap($map);
     $rates_configuration = array($currency_code_from => array($currency_code_to => $rate));
     $fixed_rates = $this->getMockBuilder(FixedRates::class)->disableOriginalConstructor()->getMock();
     $fixed_rates->expects($this->once())->method('loadAll')->willReturn($rates_configuration);
     $this->currencyExchangeRateProviderManager->expects($this->once())->method('createInstance')->with('currency_fixed_rates')->willReturn($fixed_rates);
     $this->urlGenerator->expects($this->once())->method('generateFromRoute')->with('currency.exchange_rate_provider.fixed_rates.add');
     $amount_formatter = $this->getMock(AmountFormatterInterface::class);
     $amount_formatter->expects($this->once())->method('formatAmount')->with($currency_to, $rate);
     $this->currencyAmountFormatterManager->expects($this->once())->method('getDefaultPlugin')->willReturn($amount_formatter);
     $build = $this->sut->overview();
     $this->assertInternalType('array', $build);
 }