You are here

public function CurrencyFormTest::testValidateRoundingStep in Currency 8.3

@covers ::validateRoundingStep @dataProvider providerTestValidateRoundingStep

File

tests/src/Unit/Entity/Currency/CurrencyFormTest.php, line 453

Class

CurrencyFormTest
@coversDefaultClass \Drupal\currency\Entity\Currency\CurrencyForm

Namespace

Drupal\Tests\currency\Unit\Entity\Currency

Code

public function testValidateRoundingStep($valid, $input_value, $parsed_value) {
  $element = array(
    '#value' => $input_value,
  );
  $form = array();
  $form_state = $this
    ->createMock(FormStateInterface::class);
  $this->inputParser
    ->expects($this
    ->once())
    ->method('parseAmount')
    ->with($input_value)
    ->willReturn($parsed_value);
  if (!$valid) {
    $form_state
      ->expects($this
      ->once())
      ->method('setError')
      ->with($element, 'The rounding step is not numeric.');
  }
  else {
    $form_state
      ->expects($this
      ->never())
      ->method('setError');
    $form_state
      ->expects($this
      ->never())
      ->method('setErrorByName');
  }
  $form_state
    ->expects($this
    ->once())
    ->method('setValueForElement')
    ->with($element, $parsed_value);
  $this->sut
    ->validateRoundingStep($element, $form_state, $form);
}