/**
  * @covers ::render
  */
 public function testRender()
 {
     $plugin_id = $this->randomMachineName();
     $plugin_label = $this->randomMachineName();
     $plugin_definition = ['label' => $plugin_label];
     $this->paymentStatusManager->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->paymentStatusManager->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());
 }
 /**
  * @covers ::doRefundPayment
  */
 public function testDoRefundPayment()
 {
     $payment_status = $this->getMock(PaymentStatusInterface::class);
     $this->paymentStatusManager->expects($this->once())->method('createInstance')->with($this->pluginDefinition['refund_status_id'])->willReturn($payment_status);
     $payment = $this->getMock(PaymentInterface::class);
     $payment->expects($this->once())->method('save');
     $payment->expects($this->once())->method('setPaymentStatus')->with($payment_status);
     $this->sut->setPayment($payment);
     $method = new \ReflectionMethod($this->sut, 'doRefundPayment');
     $method->setAccessible(TRUE);
     $method->invoke($this->sut, $payment);
 }
 /**
  * @covers ::execute
  */
 public function testExecute()
 {
     $plugin_id = $this->randomMachineName();
     $status = $this->getMock(PaymentStatusInterface::class);
     $this->paymentStatusManager->expects($this->once())->method('createInstance')->with($plugin_id)->willReturn($status);
     $payment = $this->getMock(PaymentInterface::class);
     $payment->expects($this->once())->method('setPaymentStatus')->with($status);
     $this->sut->setConfiguration(array('payment_status_plugin_id' => $plugin_id));
     // Test execution without an argument to make sure it fails silently.
     $this->sut->execute();
     $this->sut->execute($payment);
 }
 /**
  * @covers ::execute
  * @covers ::buildListingLevel
  * @covers ::buildHierarchy
  * @covers ::buildHierarchyLevel
  * @covers ::sort
  */
 function testListing()
 {
     $plugin_id_a = $this->randomMachineName();
     $plugin_id_b = $this->randomMachineName();
     $definitions = [$plugin_id_a => ['label' => $this->randomMachineName(), 'description' => $this->randomMachineName()], $plugin_id_b => ['label' => $this->randomMachineName(), 'description' => $this->randomMachineName(), 'parent_id' => $plugin_id_a]];
     $operations_a = ['title' => $this->randomMachineName()];
     $operations_provider_a = $this->getMock(PluginOperationsProviderInterface::class);
     $operations_provider_a->expects($this->once())->method('getOperations')->with($plugin_id_a)->willReturn($operations_a);
     $map = [[$plugin_id_a, TRUE, $definitions[$plugin_id_a]], [$plugin_id_b, TRUE, $definitions[$plugin_id_b]]];
     $this->paymentStatusManager->expects($this->exactly(count($map)))->method('getDefinition')->willReturnMap($map);
     $this->paymentStatusManager->expects($this->atLeastOnce())->method('getDefinitions')->willReturn($definitions);
     $map = [[$plugin_id_a, $operations_provider_a], [$plugin_id_b, NULL]];
     $this->paymentStatusManager->expects($this->exactly(2))->method('getOperationsProvider')->willReturnMap($map);
     $this->stringTranslation->expects($this->any())->method('translate')->will($this->returnArgument(0));
     $build = $this->sut->execute();
     foreach ($build['#header'] as $key => $label) {
         $build['#header'][$key] = (string) $label;
     }
     $expected = ['#header' => ['Title', 'Description', 'Operations'], '#type' => 'table', $plugin_id_a => ['label' => ['#markup' => $definitions[$plugin_id_a]['label']], 'description' => ['#markup' => $definitions[$plugin_id_a]['description']], 'operations' => ['#type' => 'operations', '#links' => $operations_a]], $plugin_id_b => ['label' => ['#markup' => $definitions[$plugin_id_b]['label']], 'description' => ['#markup' => $definitions[$plugin_id_b]['description']], 'operations' => ['#type' => 'operations', '#links' => []]]];
     $this->assertSame($expected, $build);
 }
 /**
  * @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 ::isOrHasAncestor
  */
 public function testIsOrHasAncestor()
 {
     $expected = TRUE;
     $this->paymentStatusManager->expects($this->once())->method('isOrHasAncestor')->with($this->pluginId)->willReturn($expected);
     $this->assertSame($expected, $this->sut->isOrHasAncestor($this->pluginId));
 }