public function CurrencyFormTest::testForm in Currency 8.3
@covers ::form
File
- tests/
src/ Unit/ Entity/ Currency/ CurrencyFormTest.php, line 179
Class
- CurrencyFormTest
- @coversDefaultClass \Drupal\currency\Entity\Currency\CurrencyForm
Namespace
Drupal\Tests\currency\Unit\Entity\CurrencyCode
public function testForm() {
$currency_code = $this
->randomMachineName();
$currency_number = $this
->randomMachineName();
$currency_label = $this
->randomMachineName();
$currency_sign = $this
->randomMachineName();
$currency_subunits = mt_rand();
$currency_rounding_step = mt_rand();
$currency_status = TRUE;
$this->currency
->expects($this
->any())
->method('getCurrencyCode')
->willReturn($currency_code);
$this->currency
->expects($this
->any())
->method('getCurrencyNumber')
->willReturn($currency_number);
$this->currency
->expects($this
->any())
->method('label')
->willReturn($currency_label);
$this->currency
->expects($this
->any())
->method('getSign')
->willReturn($currency_sign);
$this->currency
->expects($this
->any())
->method('getSubunits')
->willReturn($currency_subunits);
$this->currency
->expects($this
->any())
->method('getRoundingStep')
->willReturn($currency_rounding_step);
$this->currency
->expects($this
->any())
->method('status')
->willReturn($currency_status);
$language = $this
->createMock(LanguageInterface::class);
$this->currency
->expects($this
->any())
->method('language')
->willReturn($language);
$form = array();
$form_state = $this
->createMock(FormStateInterface::class);
$build = $this->sut
->form($form, $form_state);
unset($build['langcode']);
unset($build['#process']);
$expected['currency_code'] = [
'#default_value' => $currency_code,
'#disabled' => TRUE,
'#element_validate' => array(
array(
$this->sut,
'validateCurrencyCode',
),
),
'#maxlength' => 3,
'#pattern' => '[a-zA-Z]{3}',
'#placeholder' => 'XXX',
'#required' => TRUE,
'#size' => 3,
'#type' => 'textfield',
];
unset($build['currency_code']['#title']);
$expected['currency_number'] = [
'#default_value' => $currency_number,
'#element_validate' => array(
array(
$this->sut,
'validateCurrencyNumber',
),
),
'#maxlength' => 3,
'#pattern' => '[\\d]{3}',
'#placeholder' => '999',
'#size' => 3,
'#type' => 'textfield',
];
unset($build['currency_number']['#title']);
$expected['status'] = [
'#default_value' => $currency_status,
'#type' => 'checkbox',
];
unset($build['status']['#title']);
$expected['label'] = [
'#default_value' => $currency_label,
'#maxlength' => 255,
'#required' => TRUE,
'#type' => 'textfield',
];
unset($build['label']['#title']);
$expected['sign'] = [
'#currency_code' => $currency_code,
'#default_value' => $currency_sign,
'#type' => 'currency_sign',
];
unset($build['sign']['#title']);
$expected['subunits'] = [
'#default_value' => $currency_subunits,
'#min' => 0,
'#required' => TRUE,
'#type' => 'number',
];
unset($build['subunits']['#title']);
$expected['rounding_step'] = [
'#default_value' => $currency_rounding_step,
'#element_validate' => array(
array(
$this->sut,
'validateRoundingStep',
),
),
'#required' => TRUE,
'#type' => 'textfield',
];
unset($build['rounding_step']['#title']);
$expected['#after_build'] = [
'::afterBuild',
];
$this
->assertSame($expected, $build);
}