/** * {@inheritdoc} */ public function getOperationsProvider($plugin_id) { if ($this->hasDefinition($plugin_id)) { return $this->decoratedPaymentMethodManager->getOperationsProvider($plugin_id); } else { throw new PluginNotFoundException($plugin_id); } }
/** * @covers ::execute */ public function testExecute() { $plugin_id_a = $this->randomMachineName(); $plugin_id_b = $this->randomMachineName(); $definitions = [$plugin_id_a => ['active' => TRUE, 'class' => $this->getMockClass(PaymentMethodInterface::class), 'label' => $this->randomMachineName()], $plugin_id_b => ['active' => FALSE, 'class' => $this->getMockClass(PaymentMethodInterface::class), 'label' => $this->randomMachineName()]]; $this->paymentMethodManager->expects($this->once())->method('getDefinitions')->willReturn($definitions); $build = $this->sut->execute(); $this->assertInternalType('array', $build); }
/** * {@inheritdoc} */ public function getValueOptions() { if (!isset($this->valueOptions)) { $this->valueTitle = $this->t('Payment method'); foreach ($this->paymentMethodManager->getDefinitions() as $plugin_id => $definition) { $this->valueOptions[$plugin_id] = $definition['label']; } } return $this->valueOptions; }
/** * @covers ::render */ public function testRender() { $plugin_id = $this->randomMachineName(); $plugin_label = $this->randomMachineName(); $plugin_definition = ['label' => $plugin_label]; $this->paymentMethodManager->expects($this->atLeastOnce())->method('getDefinition')->with($plugin_id)->willReturn($plugin_definition); $result_row = new ResultRow(); $result_row->{$this->sut->field_alias} = $plugin_id; $this->assertSame($plugin_label, $this->sut->render($result_row)); }
/** * @covers ::invoke */ public function testInvoke() { $payment_method = $this->getMock(PaymentMethodConfigurationInterface::class); $payment_method->expects($this->any())->method('getEntityTypeId')->willReturn('payment_method_configuration'); $payment_status = $this->getMock(PaymentStatusInterface::class); $payment_status->expects($this->any())->method('getEntityTypeId')->willReturn('payment_status'); $this->paymentMethodManager->expects($this->once())->method('clearCachedDefinitions'); $this->paymentStatusManager->expects($this->once())->method('clearCachedDefinitions'); $this->sut->invoke($payment_method); $this->sut->invoke($payment_status); }
/** * @covers ::getValueOptions */ public function testGetValueOptions() { $plugin_id_a = $this->randomMachineName(); $plugin_label_a = $this->randomMachineName(); $plugin_id_b = $this->randomMachineName(); $plugin_label_b = $this->randomMachineName(); $plugin_id_c = $this->randomMachineName(); $plugin_label_c = $this->randomMachineName(); $plugin_definitions = [$plugin_id_a => ['label' => $plugin_label_a], $plugin_id_b => ['label' => $plugin_label_b], $plugin_id_c => ['label' => $plugin_label_c]]; $this->paymentMethodManager->expects($this->atLeastOnce())->method('getDefinitions')->willReturn($plugin_definitions); $expected_options = [$plugin_id_a => $plugin_label_a, $plugin_id_b => $plugin_label_b, $plugin_id_c => $plugin_label_c]; $this->assertSame($expected_options, $this->sut->getValueOptions()); }
/** * Lists all available payment method plugins. * * @return array * A renderable array. */ public function execute() { $rows = []; foreach ($this->paymentMethodManager->getDefinitions() as $plugin_id => $definition) { $operations_provider = $this->paymentMethodManager->getOperationsProvider($plugin_id); $row = ['label' => ['#markup' => $definition['label']], 'status' => ['#markup' => $definition['active'] ? $this->t('Enabled') : $this->t('Disabled')], 'operations' => ['#type' => 'operations', '#links' => $operations_provider ? $operations_provider->getOperations($plugin_id) : []]]; if (!$definition['active']) { $row['#attributes']['class'] = ['payment-method-disabled']; } $rows[$plugin_id] = $row; } return ['#attached' => ['library' => ['payment/payment_method.list']], '#attributes' => ['class' => ['payment-method-list']], '#header' => [$this->t('Name'), $this->t('Status'), $this->t('Operations')], '#type' => 'table'] + $rows; }
/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { $config = $this->config('payment_form.payment_type'); $form['plugin_selector'] = $this->getPluginSelector($form_state)->buildSelectorForm([], $form_state); $limit_allowed_plugins_id = Html::getUniqueId('limit_allowed_plugins'); $form['limit_allowed_plugins'] = ['#default_value' => $config->get('limit_allowed_plugins'), '#id' => $limit_allowed_plugins_id, '#title' => $this->t('Limit allowed payment methods'), '#type' => 'checkbox']; $allowed_plugin_ids = $config->get('allowed_plugin_ids'); $options = []; foreach ($this->paymentMethodManager->getDefinitions() as $definition) { $options[$definition['id']] = $definition['label']; } $form['allowed_plugin_ids'] = ['#default_value' => $allowed_plugin_ids, '#multiple' => TRUE, '#options' => $options, '#states' => ['visible' => ['#' . $limit_allowed_plugins_id => ['checked' => TRUE]]], '#title' => $this->t('Allowed payment methods'), '#type' => 'select']; return $form + parent::buildForm($form, $form_state); }
/** * @covers ::actions * @covers ::getPaymentMethodManager */ public function testActionsWithoutAvailablePlugins() { $form = []; $form_state = new FormState(); $form_state->set('plugin_selector', $this->pluginSelector); $this->paymentMethodManager->expects($this->atLeastOnce())->method('getDefinitions')->willReturn([]); $method = new \ReflectionMethod($this->sut, 'actions'); $method->setAccessible(TRUE); $actions = $method->invokeArgs($this->sut, [$form, $form_state]); $this->assertTrue($actions['submit']['#disabled']); }
/** * @covers ::buildForm * @covers ::getPluginSelector */ public function testBuildForm() { $form = []; $form_state = new FormState(); $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('buildSelectorForm')->with([], $form_state)->willReturn($this->pluginSelector); $this->paymentMethodManager->expects($this->atLeastOnce())->method('getDefinitions')->willReturn([]); $build = $this->sut->buildForm($form, $form_state); $this->assertInternalType('array', $build); }
/** * @covers ::getOperationsProvider * * @expectedException \Drupal\Component\Plugin\Exception\PluginNotFoundException */ public function testGetOperationsProviderWithNonExistentPlugin() { $this->paymentMethodManager->expects($this->atLeastOnce())->method('getDefinitions')->willReturn([]); $this->sut->getOperationsProvider($this->randomMachineName()); }
/** * {@inheritdoc} */ public function render(ResultRow $values) { $plugin_id = $this->getValue($values); $plugin_definition = $this->paymentMethodManager->getDefinition($plugin_id); return $plugin_definition['label']; }