Skip to content
Snippets Groups Projects
Commit bca421b6 authored by Jakub Piasecki's avatar Jakub Piasecki Committed by Jonathan Sacksick
Browse files

Issue #3466897 by zaporylie: Customer Subscription list view is broken in 10.3.

parent 67721719
No related branches found
No related tags found
1 merge request!36Issue #3466897 by zaporylie: Customer Subscription list view is broken in 10.3
Pipeline #248643 passed
......@@ -185,3 +185,22 @@ function commerce_recurring_update_8108(&$sandbox): void {
$field = FieldConfig::create($config);
$field->save();
}
/**
* Update customer subscription list view and change default url rewrite pattern.
*/
function commerce_recurring_update_8109() {
$config_factory = \Drupal::configFactory();
$view = $config_factory->getEditable('views.view.commerce_user_subscriptions');
if ($view->get('display.default.display_options.fields.title.alter.path') === 'user/{{ raw_arguments.uid }}/subscriptions/{{ subscription_id }}') {
return "The view is already up-to-date.";
}
if ($view->get('display.default.display_options.fields.title.alter.path') === 'user/{{ arguments.uid }}/subscriptions/{{ subscription_id }}') {
$view->set('display.default.display_options.fields.title.alter.path', 'user/{{ raw_arguments.uid }}/subscriptions/{{ subscription_id }}');
$view->save(TRUE);
return "The views.view.commerce_user_subscriptions view was updated";
}
return "The views.view.commerce_user_subscriptions couldn't be updated as the default path for the title field has been overridden with custom value. Test if rewrite pattern is correct.";
}
......@@ -216,7 +216,7 @@ display:
alter_text: false
text: ''
make_link: true
path: 'user/{{ arguments.uid }}/subscriptions/{{ subscription_id }}'
path: 'user/{{ raw_arguments.uid }}/subscriptions/{{ subscription_id }}'
absolute: false
external: false
replace_spaces: false
......
<?php
namespace Drupal\Tests\commerce_recurring\Functional;
use Drupal\commerce_payment\Entity\PaymentGateway;
use Drupal\commerce_payment\Entity\PaymentMethod;
use Drupal\commerce_recurring\Entity\BillingSchedule;
use Drupal\Core\Datetime\Entity\DateFormat;
use Drupal\profile\Entity\Profile;
use Drupal\Tests\commerce\Functional\CommerceBrowserTestBase;
/**
* Defines base class for commerce_recurring test cases.
*/
abstract class SubscriptionBrowserTestBase extends CommerceBrowserTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'commerce_payment_example',
'commerce_product',
'commerce_recurring',
];
/**
* The test billing schedule.
*
* @var \Drupal\commerce_recurring\Entity\BillingScheduleInterface
*/
protected $billingSchedule;
/**
* The test billing profile.
*
* @var \Drupal\profile\Entity\ProfileInterface
*/
protected $billingProfile;
/**
* The test payment gateway.
*
* @var \Drupal\commerce_payment\Entity\PaymentGatewayInterface
*/
protected $paymentGateway;
/**
* The test payment method.
*
* @var \Drupal\commerce_payment\Entity\PaymentMethodInterface
*/
protected $paymentMethod;
/**
* Holds the date pattern string for the "html_date" format.
*
* @var string
*/
protected $dateFormat;
/**
* Holds the date pattern string for the "html_time" format.
*
* @var string
*/
protected $timeFormat;
/**
* The test variation.
*
* @var \Drupal\commerce_product\Entity\ProductVariationInterface
*/
protected $variation;
/**
* The recurring order manager.
*
* @var \Drupal\commerce_recurring\RecurringOrderManagerInterface
*/
protected $recurringOrderManager;
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
$this->variation = $this->createEntity('commerce_product_variation', [
'type' => 'default',
'sku' => strtolower($this->randomMachineName()),
'price' => [
'number' => '39.99',
'currency_code' => 'USD',
],
]);
$this->createEntity('commerce_product', [
'type' => 'default',
'title' => 'My product',
'variations' => [$this->variation],
'stores' => [$this->store],
]);
/** @var \Drupal\commerce_recurring\Entity\BillingScheduleInterface $billing_schedule */
$this->billingSchedule = $this->createEntity('commerce_billing_schedule', [
'id' => 'test_id',
'label' => 'Hourly schedule',
'displayLabel' => 'Hourly schedule',
'billingType' => BillingSchedule::BILLING_TYPE_POSTPAID,
'plugin' => 'fixed',
'configuration' => [
'interval' => [
'number' => '1',
'unit' => 'hour',
],
],
]);
$profile = Profile::create([
'type' => 'customer',
'address' => [
'country_code' => 'US',
],
]);
$profile->save();
$this->billingProfile = $this->reloadEntity($profile);
/** @var \Drupal\commerce_payment\Entity\PaymentGatewayInterface $payment_gateway */
$payment_gateway = PaymentGateway::create([
'id' => 'example',
'label' => 'Example',
'plugin' => 'example_onsite',
]);
$payment_gateway->save();
$this->paymentGateway = $this->reloadEntity($payment_gateway);
/** @var \Drupal\commerce_payment\Entity\PaymentMethodInterface $payment_method */
$payment_method = PaymentMethod::create([
'type' => 'credit_card',
'payment_gateway' => $this->paymentGateway,
'card_type' => 'visa',
'card_number' => 1,
'uid' => $this->adminUser->id(),
'billing_profile' => $this->billingProfile,
]);
$payment_method->save();
$this->paymentMethod = $this->reloadEntity($payment_method);
$this->dateFormat = DateFormat::load('html_date')->getPattern();
$this->timeFormat = DateFormat::load('html_time')->getPattern();
$this->recurringOrderManager = $this->container->get('commerce_recurring.order_manager');
}
/**
* {@inheritdoc}
*/
protected function getAdministratorPermissions() {
return [
'administer commerce_subscription',
] + parent::getAdministratorPermissions();
}
}
......@@ -2,165 +2,16 @@
namespace Drupal\Tests\commerce_recurring\Functional;
use Drupal\commerce_payment\Entity\PaymentGateway;
use Drupal\commerce_payment\Entity\PaymentMethod;
use Drupal\commerce_recurring\Entity\BillingSchedule;
use Drupal\commerce_recurring\Entity\Subscription;
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\Core\Datetime\Entity\DateFormat;
use Drupal\profile\Entity\Profile;
use Drupal\Tests\commerce\Functional\CommerceBrowserTestBase;
/**
* Tests the subscription UI.
*
* @group commerce_recurring
*/
class SubscriptionTest extends CommerceBrowserTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'commerce_payment_example',
'commerce_product',
'commerce_recurring',
];
/**
* The test billing schedule.
*
* @var \Drupal\commerce_recurring\Entity\BillingScheduleInterface
*/
protected $billingSchedule;
/**
* The test billing profile.
*
* @var \Drupal\profile\Entity\ProfileInterface
*/
protected $billingProfile;
/**
* The test payment gateway.
*
* @var \Drupal\commerce_payment\Entity\PaymentGatewayInterface
*/
protected $paymentGateway;
/**
* The test payment method.
*
* @var \Drupal\commerce_payment\Entity\PaymentMethodInterface
*/
protected $paymentMethod;
/**
* Holds the date pattern string for the "html_date" format.
*
* @var string
*/
protected $dateFormat;
/**
* Holds the date pattern string for the "html_time" format.
*
* @var string
*/
protected $timeFormat;
/**
* The test variation.
*
* @var \Drupal\commerce_product\Entity\ProductVariationInterface
*/
protected $variation;
/**
* The recurring order manager.
*
* @var \Drupal\commerce_recurring\RecurringOrderManagerInterface
*/
protected $recurringOrderManager;
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
$this->variation = $this->createEntity('commerce_product_variation', [
'type' => 'default',
'sku' => strtolower($this->randomMachineName()),
'price' => [
'number' => '39.99',
'currency_code' => 'USD',
],
]);
$this->createEntity('commerce_product', [
'type' => 'default',
'title' => 'My product',
'variations' => [$this->variation],
'stores' => [$this->store],
]);
/** @var \Drupal\commerce_recurring\Entity\BillingScheduleInterface $billing_schedule */
$this->billingSchedule = $this->createEntity('commerce_billing_schedule', [
'id' => 'test_id',
'label' => 'Hourly schedule',
'displayLabel' => 'Hourly schedule',
'billingType' => BillingSchedule::BILLING_TYPE_POSTPAID,
'plugin' => 'fixed',
'configuration' => [
'interval' => [
'number' => '1',
'unit' => 'hour',
],
],
]);
$profile = Profile::create([
'type' => 'customer',
'address' => [
'country_code' => 'US',
],
]);
$profile->save();
$this->billingProfile = $this->reloadEntity($profile);
/** @var \Drupal\commerce_payment\Entity\PaymentGatewayInterface $payment_gateway */
$payment_gateway = PaymentGateway::create([
'id' => 'example',
'label' => 'Example',
'plugin' => 'example_onsite',
]);
$payment_gateway->save();
$this->paymentGateway = $this->reloadEntity($payment_gateway);
/** @var \Drupal\commerce_payment\Entity\PaymentMethodInterface $payment_method */
$payment_method = PaymentMethod::create([
'type' => 'credit_card',
'payment_gateway' => $this->paymentGateway,
'card_type' => 'visa',
'card_number' => 1,
'uid' => $this->adminUser->id(),
'billing_profile' => $this->billingProfile,
]);
$payment_method->save();
$this->paymentMethod = $this->reloadEntity($payment_method);
$this->dateFormat = DateFormat::load('html_date')->getPattern();
$this->timeFormat = DateFormat::load('html_time')->getPattern();
$this->recurringOrderManager = $this->container->get('commerce_recurring.order_manager');
}
/**
* {@inheritdoc}
*/
protected function getAdministratorPermissions() {
return [
'administer commerce_subscription',
] + parent::getAdministratorPermissions();
}
class SubscriptionTest extends SubscriptionBrowserTestBase {
/**
* Tests creating a subscription.
......
<?php
namespace Drupal\Tests\commerce_recurring\Functional;
/**
* Tests normal user operations with subscriptions.
*
* @group commerce_recurring
*/
class SubscriptionUserTest extends SubscriptionBrowserTestBase {
/**
* A test user with normal privileges.
*
* @var \Drupal\user\UserInterface
*/
protected $user;
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
$permissions = [
'view own commerce_subscription',
];
$this->user = $this->drupalCreateUser($permissions);
$this->drupalLogin($this->user);
}
/**
* Tests viewing a customer order page.
*/
public function testViewCustomerOrder() {
$uid = $this->loggedInUser->id();
/** @var \Drupal\commerce_recurring\Entity\SubscriptionInterface $subscription */
$subscription = $this->createEntity('commerce_subscription', [
'title' => $this->randomString(),
'uid' => $uid,
'billing_schedule' => $this->billingSchedule,
'type' => 'product_variation',
'purchased_entity' => $this->variation,
'store_id' => $this->store->id(),
'unit_price' => $this->variation->getPrice(),
'starts' => time() + 3600,
'trial_starts' => time(),
'state' => 'active',
]);
// Check that we can view the orders page.
$this->drupalGet('/user/' . $uid . '/subscriptions/');
$this->assertSession()->statusCodeEquals(200);
// Verify the subscription can be viewed.
$this->assertSession()->linkByHrefExists('/user/' . $uid . '/subscriptions/' . $subscription->id());
$this->drupalGet('/user/' . $uid . '/subscriptions/' . $subscription->id());
$this->assertSession()->statusCodeEquals(200);
// Click subscription and make sure it works.
$this->drupalGet('/user/' . $uid . '/subscriptions/');
$this->getSession()->getPage()->clickLink($subscription->getTitle());
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->pageTextContains($subscription->getTitle());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment