/**
  * @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));
 }
 /**
  * {@inheritdoc}
  */
 public function getValueOptions()
 {
     if (!isset($this->valueOptions)) {
         $this->valueTitle = $this->t('Payment status');
         foreach ($this->paymentStatusManager->getDefinitions() as $plugin_id => $definition) {
             $this->valueOptions[$plugin_id] = $definition['label'];
         }
     }
     return $this->valueOptions;
 }
 /**
  * {@inheritdoc}
  */
 public function create(array $values = [])
 {
     /** @var \Drupal\payment\Entity\PaymentInterface $payment */
     $payment = parent::create($values);
     $payment_type = $this->paymentTypeManager->createInstance($values['bundle']);
     $payment_type->setPayment($payment);
     $payment->get('payment_type')->setValue($payment_type);
     $status = $this->paymentStatusManager->createInstance('payment_created')->setCreated(time());
     $payment->setPaymentStatus($status);
     return $payment;
 }
 /**
  * @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());
 }
 /**
  * Tests queue service.
  */
 function testQueue()
 {
     $category_id_prefix = $this->randomMachineName();
     $category_id = $category_id_prefix . $this->randomMachineName();
     $payment = Generate::createPayment(2);
     $payment->setPaymentStatus($this->paymentStatusManager->createInstance('payment_success'));
     $payment->save();
     // Tests save().
     $this->queue->save($category_id, $payment->id());
     $payment_ids = $this->queue->loadPaymentIds($category_id, $payment->getOwnerId());
     $this->assertTrue(in_array($payment->id(), $payment_ids));
     // Tests claimPayment().
     $this->assertTrue(is_string($this->queue->claimPayment($payment->id())));
     $this->assertFalse($this->queue->claimPayment($payment->id()));
     $acquisition_code = $this->queue->claimPayment($payment->id());
     $this->assertTrue(is_string($acquisition_code));
     // Tests releaseClaim().
     $released = $this->queue->releaseClaim($payment->id(), $acquisition_code);
     $this->assertTrue($released);
     $acquisition_code = $this->queue->claimPayment($payment->id());
     $this->assertTrue(is_string($acquisition_code));
     // Tests acquirePayment().
     $acquired = $this->queue->acquirePayment($payment->id(), $acquisition_code);
     $this->assertTrue($acquired);
     $acquisition_code = $this->queue->claimPayment($payment->id());
     $this->assertFalse($acquisition_code);
     // Save another payment to the queue, because acquiring the previous one
     // deleted it.
     $payment = Generate::createPayment(2);
     $payment->setPaymentStatus($this->paymentStatusManager->createInstance('payment_success'));
     $payment->save();
     $this->queue->save($category_id, $payment->id());
     // Tests loadPaymentIds().
     $loaded_payment_ids = $this->queue->loadPaymentIds($category_id, $payment->getOwnerId());
     $this->assertEqual($loaded_payment_ids, array($payment->id()));
     // Tests deleteByPaymentId().
     $this->queue->deleteByPaymentId($payment->id());
     $payment_ids = $this->queue->loadPaymentIds($category_id, $payment->getOwnerId());
     $this->assertFalse(in_array($payment->id(), $payment_ids));
     // Tests deleteByCategoryIdPrefix().
     $this->queue->save($category_id, $payment->id());
     $this->queue->deleteByCategoryIdPrefix($category_id_prefix);
     $payment_ids = $this->queue->loadPaymentIds($category_id, $payment->getOwnerId());
     $this->assertFalse(in_array($payment->id(), $payment_ids));
     // Tests deleteByCategoryId().
     $this->queue->save($category_id, $payment->id());
     $this->queue->deleteByCategoryId($category_id);
     $payment_ids = $this->queue->loadPaymentIds($category_id, $payment->getOwnerId());
     $this->assertFalse(in_array($payment->id(), $payment_ids));
 }
 /**
  * Tests setPaymentStatuses() and getPaymentStatuses().
  */
 protected function testGetPaymentStatuses()
 {
     $statuses = array($this->statusManager->createInstance('payment_pending'), $this->statusManager->createInstance('payment_failed'));
     $this->assertEqual(spl_object_hash($this->payment->setPaymentStatuses($statuses)), spl_object_hash($this->payment));
     $retrieved_statuses = $this->payment->getPaymentStatuses();
     $this->assertEqual(spl_object_hash(reset($retrieved_statuses)), spl_object_hash(reset($statuses)));
     $this->assertEqual(spl_object_hash(end($retrieved_statuses)), spl_object_hash(end($statuses)));
     // Make sure we always get the last status.
     $this->assertEqual(spl_object_hash($this->payment->getPaymentStatus()), spl_object_hash(end($statuses)));
 }
 /**
  * @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);
 }
Пример #10
0
 /**
  * @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);
 }
 /**
  * {@inheritdoc}
  */
 function loadPaymentIds($category_id, $owner_id)
 {
     $allowed_payment_status_ids = [];
     foreach ($this->getAllowedPaymentStatusIds() as $payment_status_id) {
         $allowed_payment_status_ids = array_merge($allowed_payment_status_ids, array($payment_status_id), $this->paymentStatusManager->getDescendants($payment_status_id));
     }
     if (empty($allowed_payment_status_ids)) {
         throw new \RuntimeException('There are no allowed payment statuses. Use self::setAllowedPaymentStatusIds() to set the allowed payment statuses.');
     }
     $query = $this->database->select('payment_queue', 'pq');
     $query->addJoin('INNER', 'payment', 'p', 'p.id = pq.payment_id');
     $query->addJoin('INNER', 'payment__payment_statuses', 'p_ps', 'p.id = p_ps.entity_id AND p.current_payment_status_delta = p_ps.delta');
     $query->fields('pq', array('payment_id'))->condition('pq.category_id', $category_id)->condition('p_ps.payment_statuses_plugin_id', $allowed_payment_status_ids)->condition('p.owner', $owner_id)->condition('pq.queue_id', $this->queueId);
     $payment_ids = $query->execute()->fetchCol();
     return $this->eventDispatcher->alterQueueLoadedPaymentIds($this->queueId, $category_id, $owner_id, $payment_ids);
 }
 /**
  * Returns a hierarchical representation of payment statuses.
  *
  * @param string[]|null $limit_plugin_ids
  *   An array of plugin IDs to limit the statuses to, or NULL to allow all.
  *
  * @return array[]
  *   A possibly infinitely nested associative array. Keys are plugin IDs and
  *   values are arrays of similar structure as this method's return value.
  */
 protected function buildHierarchy(array $limit_plugin_ids = NULL)
 {
     static $hierarchy = NULL;
     if (is_null($hierarchy)) {
         $parents = [];
         $children = [];
         $definitions = $this->paymentStatusManager->getDefinitions();
         if (is_array($limit_plugin_ids)) {
             $definitions = array_intersect_key($definitions, array_flip($limit_plugin_ids));
         }
         uasort($definitions, array($this, 'sort'));
         foreach ($definitions as $plugin_id => $definition) {
             if (!empty($definition['parent_id'])) {
                 $children[$definition['parent_id']][] = $plugin_id;
             } else {
                 $parents[] = $plugin_id;
             }
         }
         $hierarchy = $this->buildHierarchyLevel($parents, $children);
     }
     return $hierarchy;
 }
Пример #13
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());
 }
 /**
  * @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));
 }
 /**
  * {@inheritdoc}
  */
 public function render(ResultRow $values)
 {
     $plugin_id = $this->getValue($values);
     $plugin_definition = $this->paymentStatusManager->getDefinition($plugin_id);
     return $plugin_definition['label'];
 }
 /**
  * {@inheritdoc}
  */
 function isOrHasAncestor($plugin_id)
 {
     return $this->paymentStatusManager->isOrHasAncestor($this->getPluginId(), $plugin_id);
 }
Пример #17
0
 /**
  * {@inheritdoc}
  */
 public function doRefundPayment()
 {
     $this->getPayment()->setPaymentStatus($this->paymentStatusManager->createInstance($this->getRefundStatusId()));
     $this->getPayment()->save();
 }