/** * Tests listing. */ protected function testList() { $payment_status_id = strtolower($this->randomMachineName()); /** @var \Drupal\payment\Entity\PaymentStatusInterface $status */ $status = $this->paymentStatusStorage->create([]); $status->setId($payment_status_id)->setLabel($this->randomMachineName())->save(); $path = 'admin/config/services/payment/status'; $this->drupalGet($path); $this->assertResponse(403); $this->drupalLogin($this->drupalCreateUser(array('payment.payment_status.administer'))); $this->drupalGet($path); $this->assertResponse(200); // Assert that the "Add payment status" link is visible. $this->assertLinkByHref('admin/config/services/payment/status/add'); // Assert that all plugins are visible. $manager = Payment::statusManager(); foreach ($manager->getDefinitions() as $definition) { $this->assertText($definition['label']); if ($definition['description']) { $this->assertText($definition['description']); } } // Assert that all config entity operations are visible. $this->assertLinkByHref('admin/config/services/payment/status/edit/' . $payment_status_id); $this->assertLinkByHref('admin/config/services/payment/status/delete/' . $payment_status_id); }
/** * @covers ::statusManager */ public function testStatusManager() { $container = new Container(); $status_manager = $this->getMock(PaymentStatusManagerInterface::class); $container->set('plugin.manager.payment.status', $status_manager); \Drupal::setContainer($container); $this->assertSame($status_manager, Payment::statusManager()); }
/** * {@inheritdoc */ protected function setUp() { parent::setUp(); $this->bundle = 'payment_unavailable'; $this->lineItemManager = Payment::lineItemManager(); $this->statusManager = Payment::statusManager(); $this->payment = entity_create('payment', array('bundle' => $this->bundle)); }
/** * Tests CRUD(); */ protected function testCRUD() { $database = \Drupal::database(); $user = $this->drupalCreateUser(); $payment_type_configuration = array($this->randomMachineName() => $this->randomMachineName()); $payment_method = Payment::methodManager()->createInstance('payment_basic:no_payment_required'); // Test creating a payment. $payment = Generate::createPayment($user->id(), $payment_method); $payment->getPaymentType()->setConfiguration($payment_type_configuration); $this->assertTrue($payment instanceof PaymentInterface); // @todo The ID should be an integer, but for some reason the entity field // API returns a string. $this->assertTrue(is_numeric($payment->getOwnerId())); $this->assertEqual(count($payment->validate()), 0); $this->assertTrue($payment->getPaymentType() instanceof PaymentTypeInterface); // Test saving a payment. $this->assertFalse($payment->id()); // Set an extra status, so we can test for status IDs later. $payment->setPaymentStatus(Payment::statusManager()->createInstance('payment_success')); $payment->save(); // @todo The ID should be an integer, but for some reason the entity field // API returns a string. $this->assertTrue(is_numeric($payment->id())); $this->assertTrue(strlen($payment->uuid())); // @todo The ID should be an integer, but for some reason the entity field // API returns a string. $this->assertTrue(is_numeric($payment->getOwnerId())); // Check references to other tables. $payment_data = $database->select('payment', 'p')->fields('p', array('current_payment_status_delta'))->condition('id', $payment->id())->execute()->fetchAssoc(); $this->assertEqual($payment_data['current_payment_status_delta'], 1); /** @var \Drupal\payment\Entity\PaymentInterface $payment_loaded */ $payment_loaded = entity_load_unchanged('payment', $payment->id()); $this->assertEqual(count($payment_loaded->getLineItems()), count($payment->getLineItems())); foreach ($payment_loaded->getLineItems() as $line_item) { $this->assertTrue($line_item instanceof PaymentLineItemInterface); } $this->assertEqual(count($payment_loaded->getPaymentStatuses()), count($payment->getPaymentStatuses())); foreach ($payment_loaded->getPaymentStatuses() as $status) { $this->assertTrue($status instanceof PaymentStatusInterface); } $this->assertEqual($payment_loaded->getPaymentMethod()->getConfiguration(), $payment->getPaymentMethod()->getConfiguration()); $this->assertEqual($payment_loaded->getPaymentType()->getConfiguration(), $payment->getPaymentType()->getConfiguration()); }
/** * Tests the field. */ protected function testField() { // Create the field and field instance. $field_name = strtolower($this->randomMachineName()); entity_create('field_storage_config', array('cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, 'entity_type' => 'user', 'field_name' => $field_name, 'type' => 'payment_reference'))->save(); entity_create('field_config', array('bundle' => 'user', 'entity_type' => 'user', 'field_name' => $field_name, 'settings' => array('currency_code' => 'EUR', 'line_items_data' => [])))->save(); $payment = Generate::createPayment(mt_rand()); $payment->setPaymentStatus(Payment::statusManager()->createInstance('payment_success')); $payment->save(); PaymentReference::queue()->save('user.' . $field_name, $payment->id()); $this->assertEqual(PaymentReference::queue()->loadPaymentIds('user.' . $field_name, $payment->getOwnerId()), array($payment->id())); // Set a field value on an entity and test getting it. /** @var \Drupal\user\UserInterface $user */ $user = entity_create('user', array('name' => $this->randomString())); $user->get($field_name)->appendItem($payment->id()); $this->assertEqual($user->get($field_name)->first()->entity->id(), $payment->id()); // Save the entity, load it from storage and test getting the field value. $user->save(); $user = entity_load_unchanged('user', $user->id()); $this->assertEqual($user->{$field_name}[0]->target_id, $payment->id()); $this->assertEqual(PaymentReference::queue()->loadPaymentIds('user.' . $field_name, $payment->getOwnerId()), []); }