public function CustomerProfileAlterTest::testAlter in Drupal Commerce Connector for AvaTax 8
@covers ::alter @dataProvider alterDataProvider
File
- tests/
src/ Unit/ CustomerProfileAlterTest.php, line 50
Class
- CustomerProfileAlterTest
- @group commerce_avatax @coversDefaultClass \Drupal\commerce_avatax\CustomerProfileAlter
Namespace
Drupal\Tests\commerce_avatax\UnitCode
public function testAlter(bool $rendered, array $mocked_address) {
$url_generator = $this
->prophesize(UrlGenerator::class);
$url_generator
->generateFromRoute('commerce_avatax.address_validator', [], [
'query' => [
'token' => NULL,
],
'absolute' => TRUE,
], FALSE)
->willReturn('http://example.com/commerce-avatax/address-validator');
$container = new ContainerBuilder();
$container
->set('url_generator', $url_generator
->reveal());
\Drupal::setContainer($container);
$sut = $this
->getCustomerProfileAlter([
'address_validation' => [
'enable' => TRUE,
'countries' => [
'US',
'RS',
],
],
]);
$customer_profile = $this
->prophesize(CustomerProfile::class);
$shipping_profile = $this
->prophesize(ProfileInterface::class);
$address_field_item = $this
->prophesize(AddressItem::class);
$address_field_item
->getCountryCode()
->willReturn($mocked_address['country_code']);
$address_field_item
->toArray()
->willReturn($mocked_address);
$address_field_list = $this
->prophesize(FieldItemListInterface::class);
$address_field_list
->first()
->willReturn($address_field_item
->reveal());
$shipping_profile
->get('address')
->willReturn($address_field_list
->reveal());
$customer_profile
->getEntity()
->willReturn($shipping_profile
->reveal());
$inline_form = [
'#inline_form' => $customer_profile
->reveal(),
'#profile_scope' => 'shipping',
'#id' => 'foobar-inline',
'address' => [
'widget' => [
[
'address' => [
'#default_value' => [
'country_code' => 'US',
],
],
],
],
],
];
if ($rendered) {
$inline_form['rendered'] = [];
}
$form_state = new FormState();
$sut
->alter($inline_form, $form_state);
$this
->assertEquals([
'library' => [
'commerce_avatax/address',
],
'drupalSettings' => [
'commerceAvatax' => [
'inline_id' => 'foobar-inline',
'countries' => [
'US',
'RS',
],
'rendered' => $rendered,
'endpoint' => 'http://example.com/commerce-avatax/address-validator',
'address' => $mocked_address,
'country' => 'US',
'fields' => [
'address_line1',
'address_line2',
'locality',
'administrative_area',
'country_code',
'postal_code',
],
],
],
], $inline_form['#attached']);
}