You are here

public function CurrencyLocaleFormTest::testValidateForm in Currency 8.3

@covers ::validateForm @dataProvider providerTestValidate

File

tests/src/Unit/Entity/CurrencyLocale/CurrencyLocaleFormTest.php, line 291

Class

CurrencyLocaleFormTest
@coversDefaultClass \Drupal\currency\Entity\CurrencyLocale\CurrencyLocaleForm

Namespace

Drupal\Tests\currency\Unit\Entity\CurrencyLocale

Code

public function testValidateForm($input_value_language_code, $input_value_country_code, $locale, $currency_locale_is_new, $locale_is_used) {
  $form = array(
    'locale' => array(
      '#foo' => $this
        ->randomMachineName(),
    ),
  );
  $form_state = $this
    ->createMock(FormStateInterface::class);
  $form_state
    ->expects($this
    ->any())
    ->method('getValues')
    ->willReturn(array(
    'country_code' => $input_value_country_code,
    'language_code' => $input_value_language_code,
  ));
  $this->currencyLocale
    ->expects($this
    ->atLeastOnce())
    ->method('isNew')
    ->willReturn($currency_locale_is_new);
  if ($currency_locale_is_new) {
    if ($locale_is_used) {
      $loaded_currency_locale = $this
        ->createMock(CurrencyLocaleInterface::class);
      $this->currencyLocaleStorage
        ->expects($this
        ->once())
        ->method('load')
        ->with($locale)
        ->willReturn($loaded_currency_locale);
      $form_state
        ->expects($this
        ->once())
        ->method('setError')
        ->with($form['locale'], 'A pattern for this locale already exists.');
    }
    else {
      $this->currencyLocaleStorage
        ->expects($this
        ->once())
        ->method('load')
        ->with($locale)
        ->willReturn(FALSE);
      $form_state
        ->expects($this
        ->never())
        ->method('setError');
    }
  }
  else {
    $this->currencyLocaleStorage
      ->expects($this
      ->never())
      ->method('load');
    $form_state
      ->expects($this
      ->never())
      ->method('setError');
  }
  $this->sut
    ->validateForm($form, $form_state);
}