/** * @covers ::getDerivativeDefinitions */ function testGetDerivativeDefinitions() { $string_translation = $this->getStringTranslationStub(); $class_resolver = $this->getMock(ClassResolverInterface::class); $plugin_manager = $this->getMock(PluginManagerInterface::class); $provider = $this->randomMachineName(); $plugin_type_id_a = $this->randomMachineName(); $plugin_type_label_a = $this->randomMachineName(); $plugin_type_description_a = $this->randomMachineName(); $plugin_type_definition_a = ['id' => $plugin_type_id_a, 'label' => $plugin_type_label_a, 'description' => $plugin_type_description_a, 'provider' => $this->randomMachineName()]; $plugin_type_a = new PluginType($plugin_type_definition_a, $string_translation, $class_resolver, $plugin_manager); $plugin_type_id_b = $this->randomMachineName(); $plugin_type_label_b = $this->randomMachineName(); $plugin_type_description_b = ''; $plugin_type_definition_b = ['id' => $plugin_type_id_b, 'label' => $plugin_type_label_b, 'description' => $plugin_type_description_b, 'provider' => $this->randomMachineName()]; $plugin_type_b = new PluginType($plugin_type_definition_b, $string_translation, $class_resolver, $plugin_manager); $plugin_types = [$plugin_type_a, $plugin_type_b]; $this->pluginTypeManager->expects($this->atLeastOnce())->method('getPluginTypes')->willReturn($plugin_types); $base_plugin_definition = ['provider' => $provider]; $derivative_definitions = $this->sut->getDerivativeDefinitions($base_plugin_definition); $this->assertSame($plugin_type_label_a, (string) $derivative_definitions[$plugin_type_id_a]['label']); $this->assertSame($plugin_type_description_a, (string) $derivative_definitions[$plugin_type_id_a]['description']); $this->assertSame($provider, $derivative_definitions[$plugin_type_id_a]['provider']); $this->assertSame($plugin_type_id_a, $derivative_definitions[$plugin_type_id_a]['plugin_type_id']); $this->assertSame($plugin_type_label_b, (string) $derivative_definitions[$plugin_type_id_b]['label']); $this->assertSame($plugin_type_description_b, (string) $derivative_definitions[$plugin_type_id_b]['description']); $this->assertSame($provider, $derivative_definitions[$plugin_type_id_b]['provider']); $this->assertSame($plugin_type_id_b, $derivative_definitions[$plugin_type_id_b]['plugin_type_id']); }
/** * {@inheritdoc} */ public function getDerivativeDefinitions($base_plugin_definition) { foreach ($this->pluginTypeManager->getPluginTypes() as $plugin_type) { if ($plugin_type->isFieldType()) { $this->derivatives[$plugin_type->getId()] = array('description' => $plugin_type->getDescription(), 'label' => $plugin_type->getLabel(), 'plugin_type_id' => $plugin_type->getId()) + $base_plugin_definition; } } return parent::getDerivativeDefinitions($base_plugin_definition); }
/** * {@inheritdoc} */ public function setUp() { $this->paymentStatusManager = $this->getMock(PaymentStatusManagerInterface::class); $this->paymentStatusStorage = $this->getMock(EntityStorageInterface::class); $this->paymentStatus = $this->getMock(PaymentStatusInterface::class); $this->pluginSelectorManager = $this->getMock(PluginSelectorManagerInterface::class); $class_resolver = $this->getMock(ClassResolverInterface::class); $this->stringTranslation = $this->getStringTranslationStub(); $this->pluginTypeManager = $this->getMock(PluginTypeManagerInterface::class); $plugin_type_definition = ['id' => $this->randomMachineName(), 'label' => $this->randomMachineName(), 'provider' => $this->randomMachineName()]; $plugin_type = new PluginType($plugin_type_definition, $this->stringTranslation, $class_resolver, $this->paymentStatusManager); $this->pluginTypeManager->expects($this->any())->method('getPluginType')->with('payment_status')->willReturn($plugin_type); $this->sut = new PaymentStatusForm($this->stringTranslation, $this->paymentStatusStorage, $this->pluginSelectorManager, $this->pluginTypeManager); $this->sut->setEntity($this->paymentStatus); }
/** * @covers ::execute */ public function testExecute() { $plugin_manager = $this->getMock(PluginManagerInterface::class); $plugin_definition_id_a = $this->randomMachineName(); $plugin_definition_label_a = $this->randomMachineName(); $plugin_definition_a = $this->getMock(PluginLabelDefinitionInterface::class); $plugin_definition_a->expects($this->atLeastOnce())->method('getId')->willReturn($plugin_definition_id_a); $plugin_definition_a->expects($this->atLeastOnce())->method('getLabel')->willReturn($plugin_definition_label_a); $plugin_definition_id_b = $this->randomMachineName(); $plugin_definition_description_b = $this->randomMachineName(); $plugin_definition_b = $this->getMock(PluginDescriptionDefinitionInterface::class); $plugin_definition_b->expects($this->atLeastOnce())->method('getId')->willReturn($plugin_definition_id_b); $plugin_definition_b->expects($this->atLeastOnce())->method('getDescription')->willReturn($plugin_definition_description_b); $plugin_definitions = [$plugin_definition_id_a => $plugin_definition_a, $plugin_definition_id_b => $plugin_definition_b]; $plugin_manager->expects($this->atLeastOnce())->method('getDefinitions')->willReturn($plugin_definitions); $plugin_type_id = $this->randomMachineName(); $plugin_type = $this->getMock(PluginTypeInterface::class); $plugin_type->expects($this->atLeastOnce())->method('ensureTypedPluginDefinition')->willReturnArgument(0); $plugin_type->expects($this->atLeastOnce())->method('getPluginManager')->willReturn($plugin_manager); $this->pluginTypeManager->expects($this->atLeastOnce())->method('getPluginType')->with($plugin_type_id)->willReturn($plugin_type); $this->pluginTypeManager->expects($this->atLeastOnce())->method('hasPluginType')->with($plugin_type_id)->willReturn(TRUE); $build = $this->sut->execute($plugin_type_id); $this->assertSame($plugin_definition_label_a, (string) $build[$plugin_definition_id_a]['label']['#markup']); $this->assertNull($build[$plugin_definition_id_a]['description']['#markup']); $this->assertSame($plugin_definition_id_b, (string) $build[$plugin_definition_id_b]['label']['#markup']); $this->assertSame($plugin_definition_description_b, (string) $build[$plugin_definition_id_b]['description']['#markup']); }
/** * 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; }
/** * 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 ::execute */ public function testExecute() { $class_resolver = $this->getMock(ClassResolverInterface::class); $plugin_manager = $this->getMock(PluginManagerInterface::class); $plugin_type_id_a = $this->randomMachineName(); $plugin_type_label_a = $this->randomMachineName(); $plugin_type_description_a = $this->randomMachineName(); $plugin_type_definition_a = ['id' => $plugin_type_id_a, 'label' => $plugin_type_label_a, 'description' => $plugin_type_description_a, 'provider' => $this->randomMachineName()]; $plugin_type_a = new PluginType($plugin_type_definition_a, $this->stringTranslation, $class_resolver, $plugin_manager); $plugin_type_id_b = $this->randomMachineName(); $plugin_type_label_b = $this->randomMachineName(); $plugin_type_description_b = ''; $plugin_type_definition_b = ['id' => $plugin_type_id_b, 'label' => $plugin_type_label_b, 'description' => $plugin_type_description_b, 'provider' => $this->randomMachineName()]; $plugin_type_b = new PluginType($plugin_type_definition_b, $this->stringTranslation, $class_resolver, $plugin_manager); $plugin_types = [$plugin_type_id_a => $plugin_type_a, $plugin_type_id_b => $plugin_type_b]; $this->pluginTypeManager->expects($this->atLeastOnce())->method('getPluginTypes')->willReturn($plugin_types); $build = $this->sut->execute(); $this->assertSame((string) $build[$plugin_type_id_a]['label']['#markup'], $plugin_type_label_a); $this->assertSame((string) $build[$plugin_type_id_a]['description']['#markup'], $plugin_type_description_a); $this->assertSame((string) $build[$plugin_type_id_b]['label']['#markup'], $plugin_type_label_b); $this->assertSame((string) $build[$plugin_type_id_b]['description']['#markup'], $plugin_type_description_b); }