/** * @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); }
/** * @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()); }
/** * @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()); }
/** * @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']); }