public function PaymentStatusFormTest::testForm in Payment 8.2
Same name in this branch
- 8.2 tests/src/Unit/Entity/PaymentStatus/PaymentStatusFormTest.php \Drupal\Tests\payment\Unit\Entity\PaymentStatus\PaymentStatusFormTest::testForm()
- 8.2 tests/src/Unit/Entity/Payment/PaymentStatusFormTest.php \Drupal\Tests\payment\Unit\Entity\Payment\PaymentStatusFormTest::testForm()
@covers ::form
File
- tests/
src/ Unit/ Entity/ PaymentStatus/ PaymentStatusFormTest.php, line 139
Class
- PaymentStatusFormTest
- @coversDefaultClass \Drupal\payment\Entity\PaymentStatus\PaymentStatusForm
Namespace
Drupal\Tests\payment\Unit\Entity\PaymentStatusCode
public function testForm() {
$label = $this
->randomMachineName();
$id = $this
->randomMachineName();
$is_new = FALSE;
$parent_id = $this
->randomMachineName();
$description = $this
->randomMachineName();
$form_state = $this
->createMock(FormStateInterface::class);
$language = $this
->createMock(LanguageInterface::class);
$parent_selector_form = [
'#foo' => $this
->randomMachineName(),
];
$parent_selector = $this
->createMock(PluginSelectorInterface::class);
$parent_selector
->expects($this
->atLeastOnce())
->method('buildSelectorForm')
->with([], $form_state)
->willReturn($parent_selector_form);
$this->pluginSelectorManager
->expects($this
->atLeastOnce())
->method('createInstance')
->willReturn($parent_selector);
$this->paymentStatus
->expects($this
->any())
->method('id')
->willReturn($id);
$this->paymentStatus
->expects($this
->any())
->method('getDescription')
->willReturn($description);
$this->paymentStatus
->expects($this
->any())
->method('getParentId')
->willReturn($parent_id);
$this->paymentStatus
->expects($this
->any())
->method('isNew')
->willReturn($is_new);
$this->paymentStatus
->expects($this
->any())
->method('label')
->willReturn($label);
$this->paymentStatus
->expects($this
->any())
->method('language')
->willReturn($language);
$build = $this->sut
->form([], $form_state);
unset($build['#process']);
unset($build['langcode']);
$expected_build['label'] = [
'#type' => 'textfield',
'#default_value' => $label,
'#maxlength' => 255,
'#required' => TRUE,
];
unset($build['label']['#title']);
$expected_build['id'] = [
'#default_value' => $id,
'#disabled' => !$is_new,
'#machine_name' => array(
'source' => array(
'label',
),
'exists' => array(
$this->sut,
'PaymentStatusIdExists',
),
),
'#maxlength' => 255,
'#type' => 'machine_name',
'#required' => TRUE,
];
unset($build['id']['#title']);
$expected_build['parent_id'] = $parent_selector_form;
$expected_build['description'] = [
'#type' => 'textarea',
'#default_value' => $description,
'#maxlength' => 255,
];
unset($build['description']['#title']);
$expected_build['#after_build'] = [
'::afterBuild',
];
$this
->assertSame($expected_build, $build);
}