/**
  * @covers ::form
  *
  * @dataProvider providerTestForm
  */
 public function testForm($has_owner)
 {
     $payment_method_configuration_entity_id = $this->randomMachineName();
     $payment_method_configuration_entity_is_new = FALSE;
     $payment_method_configuration_entity_label = $this->randomMachineName();
     $payment_method_configuration_entity_status = TRUE;
     $payment_method_configuration_plugin_form = array('#type' => $this->randomMachineName());
     $payment_method_configuration_plugin_id = $this->randomMachineName();
     $payment_method_configuration_plugin_configuration = array('foo' => $this->randomMachineName());
     $payment_method_configuration_plugin_label = $this->randomMachineName();
     $payment_method_configuration_plugin_definition = array('label' => $payment_method_configuration_plugin_label);
     $owner = $this->getMock(UserInterface::class);
     $payment_method_configuration_plugin = $this->getMock(PaymentMethodConfigurationInterfacePlugin::class);
     $form = array('plugin_form' => []);
     $form_state = new FormState();
     $payment_method_configuration_plugin->expects($this->atLeastOnce())->method('buildConfigurationForm')->with([], $form_state)->willReturn($payment_method_configuration_plugin_form);
     $this->paymentMethodConfigurationManager->expects($this->atLeastOnce())->method('getDefinition')->willReturn($payment_method_configuration_plugin_definition);
     $language = $this->getMock(LanguageInterface::class);
     $this->paymentMethodConfiguration->expects($this->atLeastOnce())->method('getOwner')->willReturn($has_owner ? $owner : NULL);
     $this->paymentMethodConfiguration->expects($this->atLeastOnce())->method('getPluginConfiguration')->willReturn($payment_method_configuration_plugin_configuration);
     $this->paymentMethodConfiguration->expects($this->any())->method('getPluginId')->willReturn($payment_method_configuration_plugin_id);
     $this->paymentMethodConfiguration->expects($this->any())->method('id')->willReturn($payment_method_configuration_entity_id);
     $this->paymentMethodConfiguration->expects($this->any())->method('label')->willReturn($payment_method_configuration_entity_label);
     $this->paymentMethodConfiguration->expects($this->any())->method('language')->willReturn($language);
     $this->paymentMethodConfiguration->expects($this->any())->method('status')->willReturn($payment_method_configuration_entity_status);
     $this->paymentMethodConfigurationManager->expects($this->once())->method('createInstance')->with($payment_method_configuration_plugin_id, $payment_method_configuration_plugin_configuration)->willReturn($payment_method_configuration_plugin);
     $build = $this->sut->form($form, $form_state);
     // Make sure the payment method configuration plugin is instantiated only
     // once by building the form twice.
     $this->sut->form($form, $form_state);
     unset($build['#process']);
     unset($build['langcode']);
     $expected_build = array('type' => array('#type' => 'item', '#title' => 'Type', '#markup' => $payment_method_configuration_plugin_label), 'status' => array('#type' => 'checkbox', '#title' => 'Enabled', '#default_value' => $payment_method_configuration_entity_status), 'label' => array('#type' => 'textfield', '#title' => 'Label', '#default_value' => $payment_method_configuration_entity_label, '#maxlength' => 255, '#required' => TRUE), 'id' => array('#type' => 'machine_name', '#default_value' => $payment_method_configuration_entity_id, '#maxlength' => 255, '#required' => TRUE, '#machine_name' => array('source' => array('label'), 'exists' => array($this->sut, 'paymentMethodConfigurationIdExists')), '#disabled' => !$payment_method_configuration_entity_is_new), 'owner' => array('#target_type' => 'user', '#type' => 'entity_autocomplete', '#title' => 'Owner', '#default_value' => $has_owner ? $owner : $this->currentUser, '#required' => TRUE), 'plugin_form' => array('#tree' => TRUE) + $payment_method_configuration_plugin_form, '#after_build' => ['::afterBuild']);
     $this->assertEquals($expected_build, $build);
 }
 /**
  * @covers ::access
  */
 public function testAccess()
 {
     $definitions = ['payment_unavailable' => [], 'foo' => ['description' => $this->randomMachineName(), 'label' => $this->randomMachineName()], 'bar' => ['description' => $this->randomMachineName(), 'label' => $this->randomMachineName()]];
     $this->paymentMethodConfigurationManager->expects($this->exactly(2))->method('getDefinitions')->willReturn($definitions);
     $access_control_handler = $this->getMock(EntityAccessControlHandlerInterface::class);
     $access_control_handler->expects($this->at(0))->method('createAccess')->with('foo', $this->currentUser, [], TRUE)->willReturn(AccessResult::allowed());
     $access_control_handler->expects($this->at(1))->method('createAccess')->with('foo', $this->currentUser, [], TRUE)->willReturn(AccessResult::forbidden());
     $access_control_handler->expects($this->at(2))->method('createAccess')->with('bar', $this->currentUser, [], TRUE)->willReturn(AccessResult::forbidden());
     $this->entityManager->expects($this->exactly(2))->method('getAccessControlHandler')->with('payment_method_configuration')->willReturn($access_control_handler);
     $this->assertTrue($this->sut->access()->isAllowed());
     $this->assertFalse($this->sut->access()->isAllowed());
 }
 /**
  * @covers ::buildRow
  */
 function testBuildRow()
 {
     $payment_method_configuration_entity_label = $this->randomMachineName();
     $payment_method_configuration_entity_status = FALSE;
     $payment_method_configuration_plugin_id = $this->randomMachineName();
     $payment_method_configuration_plugin_label = $this->randomMachineName();
     $payment_method_configuration_plugin_definition = array('label' => $payment_method_configuration_plugin_label);
     $this->paymentMethodConfigurationManager->expects($this->any())->method('getDefinition')->with($payment_method_configuration_plugin_id)->willReturn($payment_method_configuration_plugin_definition);
     $owner = $this->getMockBuilder(UserInterface::class);
     $payment_method_configuration = $this->getMock(PaymentMethodConfigurationInterface::class);
     $payment_method_configuration->expects($this->any())->method('getOwner')->willReturn($owner);
     $payment_method_configuration->expects($this->any())->method('getPluginId')->willReturn($payment_method_configuration_plugin_id);
     $payment_method_configuration->expects($this->any())->method('getPaymentStatus')->willReturn($payment_method_configuration_entity_status);
     $payment_method_configuration->expects($this->any())->method('label')->willReturn($payment_method_configuration_entity_label);
     $this->moduleHandler->expects($this->any())->method('invokeAll')->willReturn([]);
     $build = $this->sut->buildRow($payment_method_configuration);
     unset($build['data']['operations']['data']['#attached']);
     $expected_build = array('data' => array('label' => $payment_method_configuration_entity_label, 'plugin' => $payment_method_configuration_plugin_label, 'owner' => array('data' => array('#theme' => 'username', '#account' => $owner)), 'operations' => array('data' => array('#type' => 'operations', '#links' => []))), 'class' => array('payment-method-configuration-disabled'));
     $this->assertInstanceOf(TranslatableMarkup::class, $build['data']['status']);
     unset($build['data']['status']);
     $this->assertSame($expected_build, $build);
 }
 /**
  * @covers ::getDerivativeDefinitions
  */
 public function testGetDerivativeDefinitions()
 {
     $id_enabled_basic = $this->randomMachineName();
     $id_disabled_basic = $this->randomMachineName();
     $brand_label = $this->randomMachineName();
     $message_text = $this->randomMachineName();
     $message_text_format = $this->randomMachineName();
     $execute_status_id = $this->randomMachineName();
     $capture = TRUE;
     $capture_status_id = $this->randomMachineName();
     $refund = TRUE;
     $refund_status_id = $this->randomMachineName();
     $payment_method_enabled_basic = $this->getMock(PaymentMethodConfigurationInterface::class);
     $payment_method_enabled_basic->expects($this->any())->method('status')->willReturn(TRUE);
     $payment_method_enabled_basic->expects($this->any())->method('id')->willReturn($id_enabled_basic);
     $payment_method_enabled_basic->expects($this->any())->method('getPluginConfiguration')->willReturn(['brand_label' => $brand_label, 'message_text' => $message_text, 'message_text_format' => $message_text_format, 'execute_status_id' => $execute_status_id, 'capture' => $capture, 'capture_status_id' => $capture_status_id, 'refund' => $refund, 'refund_status_id' => $refund_status_id]);
     $payment_method_enabled_basic->expects($this->any())->method('getPluginId')->willReturn('payment_basic');
     $payment_method_disabled_basic = $this->getMock(PaymentMethodConfigurationInterface::class);
     $payment_method_disabled_basic->expects($this->any())->method('status')->willReturn(FALSE);
     $payment_method_disabled_basic->expects($this->any())->method('id')->willReturn($id_disabled_basic);
     $payment_method_disabled_basic->expects($this->any())->method('getPluginConfiguration')->willReturn(['brand_label' => $brand_label, 'message_text' => $message_text, 'message_text_format' => $message_text_format, 'execute_status_id' => $execute_status_id, 'capture' => $capture, 'capture_status_id' => $capture_status_id, 'refund' => $refund, 'refund_status_id' => $refund_status_id]);
     $payment_method_disabled_basic->expects($this->any())->method('getPluginId')->willReturn('payment_basic');
     $payment_method_enabled_no_basic = $this->getMock(PaymentMethodConfigurationInterface::class);
     $payment_method_enabled_no_basic->expects($this->any())->method('status')->willReturn(TRUE);
     $payment_method_enabled_no_basic->expects($this->any())->method('getPluginId')->willReturn($this->randomMachineName());
     $this->paymentMethodConfigurationStorage->expects($this->once())->method('loadMultiple')->willReturn(array($payment_method_enabled_basic, $payment_method_enabled_no_basic, $payment_method_disabled_basic));
     $payment_method_plugin = $this->getMockBuilder(Basic::class)->disableOriginalConstructor()->getMock();
     $payment_method_plugin->expects($this->any())->method('getBrandLabel')->willReturn($brand_label);
     $payment_method_plugin->expects($this->any())->method('getMessageText')->willReturn($message_text);
     $payment_method_plugin->expects($this->any())->method('getMessageTextFormat')->willReturn($message_text_format);
     $payment_method_plugin->expects($this->any())->method('getExecuteStatusId')->willReturn($execute_status_id);
     $payment_method_plugin->expects($this->any())->method('getCaptureStatusId')->willReturn($capture_status_id);
     $payment_method_plugin->expects($this->any())->method('getCapture')->willReturn($capture);
     $payment_method_plugin->expects($this->any())->method('getRefundStatusId')->willReturn($refund_status_id);
     $payment_method_plugin->expects($this->any())->method('getRefund')->willReturn($refund);
     $this->paymentMethodConfigurationManager->expects($this->any())->method('createInstance')->with('payment_basic')->willReturn($payment_method_plugin);
     $class = $this->randomMachineName();
     $derivatives = $this->sut->getDerivativeDefinitions(array('class' => $class, 'id' => $this->randomMachineName()));
     $this->assertInternalType('array', $derivatives);
     $this->assertCount(2, $derivatives);
     $map = array($id_enabled_basic => TRUE, $id_disabled_basic => FALSE);
     foreach ($map as $id => $active) {
         $this->assertArrayHasKey($id, $derivatives);
         $this->assertArrayHasKey('active', $derivatives[$id]);
         $this->assertSame($active, $derivatives[$id]['active']);
         $this->assertArrayHasKey('class', $derivatives[$id]);
         $this->assertSame($class, $derivatives[$id]['class']);
         $this->assertArrayHasKey('label', $derivatives[$id]);
         $this->assertSame($brand_label, $derivatives[$id]['label']);
         $this->assertArrayHasKey('message_text', $derivatives[$id]);
         $this->assertSame($message_text, $derivatives[$id]['message_text']);
         $this->assertArrayHasKey('message_text_format', $derivatives[$id]);
         $this->assertSame($message_text_format, $derivatives[$id]['message_text_format']);
         $this->assertArrayHasKey('execute_status_id', $derivatives[$id]);
         $this->assertSame($execute_status_id, $derivatives[$id]['execute_status_id']);
         $this->assertArrayHasKey('capture', $derivatives[$id]);
         $this->assertSame($capture, $derivatives[$id]['capture']);
         $this->assertArrayHasKey('capture_status_id', $derivatives[$id]);
         $this->assertSame($capture_status_id, $derivatives[$id]['capture_status_id']);
     }
 }
 /**
  * @covers ::title
  */
 public function testTitle()
 {
     $plugin_id = $this->randomMachineName();
     $this->paymentMethodConfigurationManager->expects($this->atLeastOnce())->method('getDefinition')->with($plugin_id)->willReturn(['label' => $this->randomMachineName()]);
     $this->assertInstanceOf(TranslatableMarkup::class, $this->sut->title($plugin_id));
 }