/** * @covers ::validateCurrencyNumber * @dataProvider providerTestValidateCurrencyNumber */ public function testValidateCurrencyNumber($valid, $currency_number, $currency_is_new, $currency_number_exists = FALSE) { $element = array('#value' => $currency_number); $form = array(); $form_state = $this->getMock(FormStateInterface::class); $this->currency->expects($this->any())->method('isNew')->willReturn($currency_is_new); if (!$valid) { $form_state->expects($this->once())->method('setError')->with($element, 'The currency number must be three digits.'); } elseif ($currency_number_exists) { $loaded_currency_code = $this->randomMachineName(); $loaded_currency_label = $this->randomMachineName(); $loaded_currency_url = new Url($this->randomMachineName()); $loaded_currency = $this->getMock(CurrencyInterface::class); $loaded_currency->expects($this->any())->method('id')->willReturn($loaded_currency_code); $loaded_currency->expects($this->any())->method('label')->willReturn($loaded_currency_label); $loaded_currency->expects($this->atLeastOnce())->method('urlInfo')->willReturn($loaded_currency_url); $this->currencyStorage->expects($this->once())->method('loadByProperties')->with(array('currencyNumber' => $currency_number))->willReturn(array($loaded_currency)); $form_state->expects($this->once())->method('setError'); $this->linkGenerator->expects($this->once())->method('generate')->with($loaded_currency_label, $loaded_currency_url); } else { $this->currencyStorage->expects($this->once())->method('loadByProperties')->with(array('currencyNumber' => $currency_number))->willReturn(FALSE); $form_state->expects($this->never())->method('setError'); $form_state->expects($this->never())->method('setErrorByName'); } $this->sut->validateCurrencyNumber($element, $form_state, $form); }
/** * @covers ::submitForm */ function testSubmitForm() { $this->currency->expects($this->once())->method('delete'); $form = array(); $form_state = $this->getMock(FormStateInterface::class); $form_state->expects($this->once())->method('setRedirectUrl'); $this->sut->submitForm($form, $form_state); }