/**
  * {@inheritdoc}
  */
 public function getDerivativeDefinitions($base_plugin_definition)
 {
     foreach ($this->pluginSelectorManager->getDefinitions() as $plugin_id => $plugin_definition) {
         $this->derivatives[$plugin_id] = array('description' => isset($plugin_definition['description']) ? $plugin_definition['description'] : NULL, 'label' => $plugin_definition['label'], 'plugin_selector_id' => $plugin_id) + $base_plugin_definition;
     }
     return parent::getDerivativeDefinitions($base_plugin_definition);
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, $allowed_selectable_plugin_ids = NULL, $plugin_id = NULL, $tree = FALSE)
 {
     if ($form_state->has('plugin_selector')) {
         $plugin_selector = $form_state->get('plugin_selector');
     } else {
         $selectable_plugin_discovery = new LimitedPluginDiscoveryDecorator($this->selectablePluginType->getPluginManager());
         $selectable_plugin_discovery->setDiscoveryLimit(explode(',', $allowed_selectable_plugin_ids));
         $selectable_plugin_manager = new PluginManagerDecorator($this->selectablePluginType->getPluginManager(), $selectable_plugin_discovery);
         $plugin_selector = $this->pluginSelectorManager->createInstance($plugin_id);
         $plugin_selector->setSelectablePluginType($this->selectablePluginType);
         $plugin_selector->setSelectablePluginDiscovery($selectable_plugin_manager);
         $plugin_selector->setSelectablePluginFactory($selectable_plugin_manager);
         $plugin_selector->setRequired();
         $form_state->set('plugin_selector', $plugin_selector);
     }
     $form['plugin'] = $plugin_selector->buildSelectorForm([], $form_state);
     // Nest the selector in a tree if that's required.
     if ($tree) {
         $form['tree'] = array('#tree' => TRUE);
         $form['tree']['plugin'] = $form['plugin'];
         unset($form['plugin']);
     }
     $form['actions'] = array('#type' => 'actions');
     $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Submit'));
     return $form;
 }
 /**
  * @covers ::copyFormValuesToEntity
  */
 public function testCopyFormValuesToEntity()
 {
     $description = $this->randomMachineName();
     $id = $this->randomMachineName();
     $label = $this->randomMachineName();
     $parent_id = $this->randomMachineName();
     $this->paymentStatus->expects($this->once())->method('setDescription')->with($description);
     $this->paymentStatus->expects($this->once())->method('setId')->with($id);
     $this->paymentStatus->expects($this->once())->method('setLabel')->with($label);
     $this->paymentStatus->expects($this->once())->method('setParentId')->with($parent_id);
     $parent_status = $this->getMock(PluginSelectorInterface::class);
     $parent_status->expects($this->atLeastOnce())->method('getPluginId')->willReturn($parent_id);
     $parent_selector = $this->getMock(PluginSelectorInterface::class);
     $parent_selector->expects($this->atLeastOnce())->method('getSelectedPlugin')->willReturn($parent_status);
     $this->pluginSelectorManager->expects($this->atLeastOnce())->method('createInstance')->willReturn($parent_selector);
     $form = [];
     $form_state = new FormState();
     $form_state->setValue('description', $description);
     $form_state->setValue('id', $id);
     $form_state->setValue('label', $label);
     $form_state->setValue('parent_id', $parent_id);
     $method = new \ReflectionMethod($this->sut, 'copyFormValuesToEntity');
     $method->setAccessible(TRUE);
     $method->invokeArgs($this->sut, array($this->paymentStatus, $form, $form_state));
 }
 /**
  * @covers ::submitForm
  * @covers ::getPluginSelector
  */
 public function testSubmitForm()
 {
     $form = ['plugin_selector' => ['foo' => $this->randomMachineName()]];
     $form_state = new FormState();
     $form_state->setValues(['plugin_selector_id' => $this->configFactoryConfiguration['payment_form.payment_type']['plugin_selector_id'], 'allowed_plugin_ids' => $this->configFactoryConfiguration['payment_form.payment_type']['allowed_plugin_ids'], 'limit_allowed_plugins' => $this->configFactoryConfiguration['payment_form.payment_type']['limit_allowed_plugins']]);
     $map = [['payment_radios', [], $this->pluginSelector], [$this->configFactoryConfiguration['payment_form.payment_type']['plugin_selector_id'], [], $this->selectedPluginSelector]];
     $this->pluginSelectorManager->expects($this->atLeast(count($map)))->method('createInstance')->willReturnMap($map);
     $this->pluginSelector->expects($this->once())->method('submitSelectorForm')->with($form['plugin_selector'], $form_state);
     $this->pluginSelector->expects($this->once())->method('getSelectedPlugin')->willReturn($this->selectedPluginSelector);
     $this->sut->submitForm($form, $form_state);
 }
Ejemplo n.º 5
0
 /**
  * Gets the plugin selector.
  *
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  *
  * @return \Drupal\plugin\Plugin\Plugin\PluginSelector\PluginSelectorInterface
  */
 protected function getPluginSelector(FormStateInterface $form_state)
 {
     if (!$form_state->has('plugin_selector')) {
         $plugin_selector = $this->pluginSelectorManager->createInstance('payment_select_list');
         $plugin_selector->setSelectablePluginType($this->paymentStatusType);
         $plugin_selector->setRequired();
         $plugin_selector->setLabel($this->t('Payment status'));
         $plugin_selector->setCollectPluginConfiguration(FALSE);
         $form_state->set('plugin_selector', $plugin_selector);
     }
     return $form_state->get('plugin_selector');
 }
 /**
  * Gets the parent payment status selector.
  *
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  *
  * @return \Drupal\plugin\Plugin\Plugin\PluginSelector\PluginSelectorInterface
  */
 protected function getParentPaymentStatusSelector(FormStateInterface $form_state)
 {
     $key = 'parent_payment_status_selector';
     if ($form_state->has($key)) {
         $plugin_selector = $form_state->get($key);
     } else {
         $plugin_selector = $this->pluginSelectorManager->createInstance('payment_select_list');
         $plugin_selector->setSelectablePluginType($this->pluginTypeManager->getPluginType('payment_status'));
         $plugin_selector->setCollectPluginConfiguration(FALSE);
         $plugin_selector->setLabel($this->t('Parent status'));
         $form_state->set($key, $plugin_selector);
     }
     return $plugin_selector;
 }
Ejemplo n.º 7
0
 /**
  * Gets the payment status selector.
  *
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  * @param string $type
  * @param string $default_plugin_id
  *
  * @return \Drupal\plugin\Plugin\Plugin\PluginSelector\PluginSelectorInterface
  */
 protected function getPaymentStatusSelector(FormStateInterface $form_state, $type, $default_plugin_id)
 {
     $key = 'payment_status_selector_' . $type;
     if ($form_state->has($key)) {
         $plugin_selector = $form_state->get($key);
     } else {
         $plugin_selector = $this->pluginSelectorManager->createInstance('payment_select_list');
         $plugin_selector->setSelectablePluginType($this->paymentStatusType);
         $plugin_selector->setRequired(TRUE);
         $plugin_selector->setCollectPluginConfiguration(FALSE);
         $plugin_selector->setSelectedPlugin($this->paymentStatusType->getPluginManager()->createInstance($default_plugin_id));
         $form_state->set($key, $plugin_selector);
     }
     return $plugin_selector;
 }
 /**
  * @covers ::getDerivativeDefinitions
  */
 function testGetDerivativeDefinitions()
 {
     $provider = $this->randomMachineName();
     $plugin_selector_id_a = $this->randomMachineName();
     $plugin_selector_label_a = $this->randomMachineName();
     $plugin_selector_description_a = $this->randomMachineName();
     $plugin_selector_definition_a = ['id' => $plugin_selector_id_a, 'label' => $plugin_selector_label_a, 'description' => $plugin_selector_description_a];
     $plugin_selector_id_b = $this->randomMachineName();
     $plugin_selector_label_b = $this->randomMachineName();
     $plugin_selector_description_b = '';
     $plugin_selector_definition_b = ['id' => $plugin_selector_id_b, 'label' => $plugin_selector_label_b, 'description' => $plugin_selector_description_b];
     $plugin_selector_definitions = [$plugin_selector_id_a => $plugin_selector_definition_a, $plugin_selector_id_b => $plugin_selector_definition_b];
     $this->pluginSelectorManager->expects($this->atLeastOnce())->method('getDefinitions')->willReturn($plugin_selector_definitions);
     $base_plugin_definition = ['provider' => $provider];
     $derivative_definitions = $this->sut->getDerivativeDefinitions($base_plugin_definition);
     $this->assertSame($plugin_selector_label_a, (string) $derivative_definitions[$plugin_selector_id_a]['label']);
     $this->assertSame($plugin_selector_description_a, (string) $derivative_definitions[$plugin_selector_id_a]['description']);
     $this->assertSame($provider, $derivative_definitions[$plugin_selector_id_a]['provider']);
     $this->assertSame($plugin_selector_id_a, $derivative_definitions[$plugin_selector_id_a]['plugin_selector_id']);
     $this->assertSame($plugin_selector_label_b, (string) $derivative_definitions[$plugin_selector_id_b]['label']);
     $this->assertSame($plugin_selector_description_b, (string) $derivative_definitions[$plugin_selector_id_b]['description']);
     $this->assertSame($provider, $derivative_definitions[$plugin_selector_id_b]['provider']);
     $this->assertSame($plugin_selector_id_b, $derivative_definitions[$plugin_selector_id_b]['plugin_selector_id']);
 }
 /**
  * @covers ::submitConfigurationForm
  * @covers ::getPluginSelector
  *
  * @depends testBuildConfigurationForm
  */
 public function testSubmitConfigurationForm()
 {
     $form = ['payment_status_plugin_id' => ['#foo' => $this->randomMachineName()]];
     $form_state = new FormState();
     $plugin_id = $this->randomMachineName();
     $payment_status = $this->getMock(PaymentStatusInterface::class);
     $payment_status->expects($this->atLeastOnce())->method('getPluginId')->willReturn($plugin_id);
     $plugin_selector = $this->getMock(PluginSelectorInterface::class);
     $plugin_selector->expects($this->once())->method('getSelectedPlugin')->willReturn($payment_status);
     $plugin_selector->expects($this->once())->method('submitSelectorForm')->with($form['payment_status_plugin_id'], $form_state);
     $this->pluginSelectorManager->expects($this->atLeastOnce())->method('createInstance')->willReturn($plugin_selector);
     $this->sut->submitConfigurationForm($form, $form_state);
     $configuration = $this->sut->getConfiguration();
     $this->assertSame($plugin_id, $configuration['payment_status_plugin_id']);
 }
 /**
  * @covers ::submitForm
  * @covers ::getPluginSelector
  */
 public function testSubmitForm()
 {
     $form = ['payment_status' => ['foo' => $this->randomMachineName()]];
     $form_state = new FormState();
     $payment_status = $this->getMock(PaymentStatusInterface::class);
     $this->pluginSelectorManager->expects($this->once())->method('createInstance')->willReturn($this->pluginSelector);
     $this->pluginSelector->expects($this->atLeastOnce())->method('getSelectedPlugin')->willReturn($payment_status);
     $this->pluginSelector->expects($this->atLeastOnce())->method('submitSelectorForm')->with($form['payment_status'], $form_state);
     $url = new Url($this->randomMachineName());
     $this->payment->expects($this->once())->method('setPaymentStatus')->with($payment_status);
     $this->payment->expects($this->once())->method('save');
     $this->payment->expects($this->once())->method('urlInfo')->with('canonical')->willReturn($url);
     $this->sut->submitForm($form, $form_state);
     $this->assertSame($url, $form_state->getRedirect());
 }
Ejemplo n.º 11
0
 /**
  * Gets the plugin selector.
  *
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  *
  * @return \Drupal\plugin\Plugin\Plugin\PluginSelector\PluginSelectorInterface
  */
 protected function getPluginSelector(FormStateInterface $form_state)
 {
     if ($form_state->has('plugin_selector')) {
         $plugin_selector = $form_state->get('plugin_selector');
     } else {
         $config = $this->config('payment_form.payment_type');
         $plugin_selector_id = $config->get('plugin_selector_id');
         $plugin_selector = $this->pluginSelectorManager->createInstance($plugin_selector_id);
         $plugin_selector->setSelectablePluginType($this->paymentMethodType);
         $plugin_selector->setSelectablePluginDiscovery($this->getPaymentMethodManager());
         $plugin_selector->setSelectablePluginFactory($this->getPaymentMethodManager());
         $plugin_selector->setRequired();
         $plugin_selector->setLabel($this->t('Payment method'));
         $form_state->set('plugin_selector', $plugin_selector);
     }
     return $plugin_selector;
 }
 /**
  * Gets the plugin selector.
  *
  * @param mixed[] $element
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  *
  * @return \Drupal\plugin\Plugin\Plugin\PluginSelector\PluginSelectorInterface
  */
 protected function getPluginSelector(array $element, FormStateInterface $form_state)
 {
     $key = 'payment_reference.element.payment_reference.plugin_selector.' . $element['#name'];
     if (!$form_state->has($key)) {
         $plugin_selector = $this->pluginSelectorManager->createInstance($element['#plugin_selector_id']);
         $payment_method_discovery = $this->paymentMethodType->getPluginManager();
         if (!is_null($element['#limit_allowed_plugin_ids'])) {
             $payment_method_discovery = (new LimitedPluginDiscoveryDecorator($payment_method_discovery))->setDiscoveryLimit($element['#limit_allowed_plugin_ids']);
         }
         $payment_method_manager = new PaymentExecutionPaymentMethodManager($this->getPayment($element, $form_state), $this->currentUser, $this->paymentMethodType->getPluginManager(), $payment_method_discovery);
         $plugin_selector->setSelectablePluginType($this->paymentMethodType);
         $plugin_selector->setSelectablePluginDiscovery($payment_method_manager);
         $plugin_selector->setSelectablePluginFactory($payment_method_manager);
         $plugin_selector->setRequired($element['#required']);
         $form_state->set($key, $plugin_selector);
     }
     return $form_state->get($key);
 }
Ejemplo n.º 13
0
 /**
  * Gets the plugin selector.
  *
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  *
  * @return \Drupal\plugin\Plugin\Plugin\PluginSelector\PluginSelectorInterface
  */
 protected function getPluginSelector(FormStateInterface $form_state)
 {
     if ($form_state->has('plugin_selector')) {
         return $form_state->get('plugin_selector');
     }
     $plugin_selector = $this->pluginSelectorManager->createInstance('plugin_select_list');
     $plugin_selector->setSelectablePluginType($this->entityReferenceSelectionPluginType);
     $entity_reference_selection_manager = $this->getPluginManager();
     $plugin_selector->setSelectablePluginDiscovery($entity_reference_selection_manager);
     $plugin_selector->setSelectablePluginFactory($entity_reference_selection_manager);
     $entity_reference_selection_configuration = ['handler_settings' => $this->options['entity_reference_selection_handler_settings']];
     $selected_entity_reference_selection = $entity_reference_selection_manager->createInstance($this->options['entity_reference_selection_id'], $entity_reference_selection_configuration);
     $plugin_selector->setSelectedPlugin($selected_entity_reference_selection);
     $plugin_selector->setRequired();
     $plugin_selector->setLabel($this->t('Selection method'));
     $form_state->set('plugin_selector', $plugin_selector);
     return $plugin_selector;
 }
Ejemplo n.º 14
0
 /**
  * @covers ::submitConfigurationForm
  * @covers ::getExecutePaymentStatusSelector
  * @covers ::getCapturePaymentStatusSelector
  * @covers ::getRefundPaymentStatusSelector
  * @covers ::getPaymentStatusSelector
  */
 public function testSubmitConfigurationForm()
 {
     $brand_label = $this->randomMachineName();
     $message = $this->randomMachineName();
     $execute_status_id = $this->randomMachineName();
     $capture = TRUE;
     $capture_status_id = $this->randomMachineName();
     $refund = TRUE;
     $refund_status_id = $this->randomMachineName();
     $payment_status = $this->getMock(PaymentStatusInterface::class);
     $this->paymentStatusManager->expects($this->atLeastOnce())->method('createInstance')->willReturn($payment_status);
     $payment_status_selector = $this->getMock(PluginSelectorInterface::class);
     $payment_status_selector->expects($this->atLeastOnce())->method('getSelectedPlugin')->willReturn($payment_status);
     $this->pluginSelectorManager->expects($this->atLeastOnce())->method('createInstance')->willReturn($payment_status_selector);
     $form = array('message' => array('#parents' => array('foo', 'bar', 'message')), 'plugin_form' => array('brand_label' => array('#parents' => array('foo', 'bar', 'status')), 'execute' => ['execute_status' => ['#foo' => $this->randomMachineName()]], 'capture' => ['plugin_form' => ['capture_status' => ['#foo' => $this->randomMachineName()]]], 'refund' => ['plugin_form' => ['refund_status' => ['#foo' => $this->randomMachineName()]]]));
     $form_state = new FormState();
     $form_state->setValues(['foo' => array('bar' => array('brand_label' => $brand_label, 'message' => $message, 'execute' => array('execute_status_id' => $execute_status_id), 'capture' => array('capture' => $capture, 'capture_status_id' => $capture_status_id), 'refund' => array('refund' => $refund, 'refund_status_id' => $refund_status_id)))]);
     $this->sut->submitConfigurationForm($form, $form_state);
     $this->assertSame($brand_label, $this->sut->getBrandLabel());
     $this->assertSame($capture, $this->sut->getCapture());
     $this->assertSame($refund, $this->sut->getRefund());
 }
 /**
  * Gets the plugin selector.
  *
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  *
  * @return \Drupal\plugin\Plugin\Plugin\PluginSelector\PluginSelectorInterface
  */
 protected function getPluginSelector(FormStateInterface $form_state)
 {
     if ($form_state->has('plugin_selector')) {
         $plugin_selector = $form_state->get('plugin_selector');
     } else {
         /** @var \Drupal\payment\Entity\PaymentInterface $payment */
         $payment = $this->getEntity();
         $plugin_type = $this->pluginTypeManager->getPluginType('payment_method');
         $payment_method = $payment->getPaymentMethod();
         $payment_status_discovery = new LimitedPluginDiscoveryDecorator($plugin_type->getPluginManager());
         if ($payment_method instanceof PaymentMethodUpdatePaymentStatusInterface) {
             $payment_status_discovery->setDiscoveryLimit($payment_method->getSettablePaymentStatuses($this->currentUser, $payment));
         }
         $payment_status_manager = new PaymentAwarePluginManagerDecorator($payment, $plugin_type->getPluginManager(), $payment_status_discovery);
         $plugin_selector = $this->pluginSelectorManager->createInstance('payment_select_list');
         $plugin_selector->setSelectablePluginType($plugin_type, $payment_status_manager);
         $plugin_selector->setRequired();
         $plugin_selector->setLabel($this->t('Payment status'));
         $form_state->set('plugin_selector', $plugin_selector);
     }
     return $plugin_selector;
 }
 /**
  * @covers ::submitForm
  * @covers ::getPluginSelector
  * @covers ::getPaymentMethodManager
  */
 public function testSubmitForm()
 {
     $redirect_url = new Url($this->randomMachineName());
     $response = new Response($redirect_url);
     $result = $this->getMock(OperationResultInterface::class);
     $result->expects($this->atLeastOnce())->method('getCompletionResponse')->willReturn($response);
     $form = ['payment_method' => ['#type' => $this->randomMachineName()]];
     $form_state = new FormState();
     $payment_method = $this->getMock(PaymentMethodInterface::class);
     $this->pluginSelectorManager->expects($this->once())->method('createInstance')->with($this->configFactoryConfiguration['payment_form.payment_type']['plugin_selector_id'])->willReturn($this->pluginSelector);
     $this->pluginSelector->expects($this->atLeastOnce())->method('getSelectedPlugin')->willReturn($payment_method);
     $this->pluginSelector->expects($this->atLeastOnce())->method('submitSelectorForm')->with($form['payment_method'], $form_state);
     $this->payment->expects($this->atLeastOnce())->method('setPaymentMethod')->with($payment_method);
     $this->payment->expects($this->atLeastOnce())->method('save');
     $this->payment->expects($this->atLeastOnce())->method('execute')->willReturn($result);
     $this->sut->submitForm($form, $form_state);
     $this->assertSame($redirect_url, $form_state->getRedirect());
 }
 /**
  * @covers ::buildRefreshButton
  */
 public function testBuildRefreshButton()
 {
     $limit_allowed_plugin_ids = [$this->randomMachineName()];
     $plugin_selector_id = $this->randomMachineName();
     $plugin_selector = $this->getMock(PluginSelectorInterface::class);
     $this->pluginSelectorManager->expects($this->atLeastOnce())->method('createInstance')->with($plugin_selector_id)->willReturn($plugin_selector);
     $payment = $this->getMock(PaymentInterface::class);
     $payment->expects($this->atLeastOnce())->method('createDuplicate')->willReturnSelf();
     $element = array('#default_value' => mt_rand(), 'container' => array('#id' => $this->randomMachineName()), '#limit_allowed_plugin_ids' => $limit_allowed_plugin_ids, '#name' => $this->randomMachineName(), '#plugin_selector_id' => $plugin_selector_id, '#prototype_payment' => $payment, '#required' => (bool) mt_rand(0, 1));
     $form_state = new FormState();
     $method = new \ReflectionMethod($this->sut, 'buildRefreshButton');
     $method->setAccessible(TRUE);
     $build = $method->invoke($this->sut, $element, $form_state);
     $this->assertInternalType('array', $build);
     $this->assertTrue(is_callable($build['#ajax']['callback']));
     $this->assertSame($build['#submit'][0][0], $this->pluginDefinition['class']);
 }