From 000252d5ea271125c94c59cc65e5e723ef446407 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Soko=C5=82owski?= Date: Fri, 16 Aug 2024 07:48:49 +0200 Subject: [PATCH 01/16] Create commerce context --- src/CommerceContext.php | 152 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 src/CommerceContext.php diff --git a/src/CommerceContext.php b/src/CommerceContext.php new file mode 100644 index 0000000..b60afeb --- /dev/null +++ b/src/CommerceContext.php @@ -0,0 +1,152 @@ +getHash() as $nodeHash) { + $coupon = (object) $nodeHash; + /** @var \Drupal\commerce_promotion\Entity\PromotionInterface $promotion */ + $promotion = $this->getPromotionByName($coupon->promotion); + if ($promotion) { + $coupon_saved = $this->couponCreate($coupon); + $coupon_loaded = Coupon::load($coupon_saved->id); + $promotion->get('coupons')->appendItem($coupon_loaded); + $promotion->save(); + } + else { + throw new \Exception("No parent promotion found."); + } + } + } + + /** + * Load promotion by name. + */ + public function getPromotionByName($promotion_name) { + foreach ($this->promotions as $promotion) { + $loaded_promotion = Promotion::load($promotion->id); + if ($loaded_promotion->label() === $promotion_name) { + return $loaded_promotion; + } + } + + return NULL; + } + + /** + * Create coupon. + */ + public function couponCreate($coupon) { + $saved = $this->getDriver()->createEntity('commerce_promotion_coupon', $coupon); + return $saved; + } + + /** + * Visit promotion edit page. + * + * @Then I visit promotion :title edit page + */ + public function iVisitPromotionEditPage($title) { + $promotions = \Drupal::entityTypeManager()->getStorage('commerce_promotion') + ->loadByProperties([ + 'name' => $title, + ]); + if (count($promotions) !== 1) { + throw new \Exception('Expected 1 promotion with title ' . $title . ' but found ' . count($promotions)); + } + + $id = reset($promotions)->id(); + $this->getSession()->visit($this->locatePath("promotion/$id/edit")); + } + + /** + * Remove promotions by titles. + * + * @Then I remove promotions :titles + */ + public function iRemovePromotions($titles) { + $promotions = \Drupal::entityTypeManager()->getStorage('commerce_promotion') + ->loadByProperties([ + 'name' => explode(', ', $titles), + ]); + foreach ($promotions as $promotion) { + $promotion->delete(); + } + } + + /** + * @Then /^a product with SKU "([^"]*)" should exist$/ + */ + public function aProductWithSKUShouldExist($sku) { + /** @var \Drupal\commerce_product\ProductVariationStorage $variation_storage */ + $variation_storage = \Drupal::entityTypeManager()->getStorage('commerce_product_variation'); + $product_variations = $variation_storage->loadBySku($sku); + if (empty($product_variations)) { + throw new \Exception('No variation found with SKU ' . $sku); + } + } + + /** + * @Given I set :value exchange rates + */ + public function setManualExchangeRates($value) { + $currency_storage = \Drupal::service('entity_type.manager')->getStorage('commerce_currency'); + $currencies = $currency_storage->loadMultiple(); + $currencies = array_keys($currencies); + $database = \Drupal::database(); + $time = time(); + + foreach ($currencies as $currency) { + $query = $database->insert('commerce_exchanger_latest_rates') + ->fields([ + 'exchanger', + 'source', + 'target', + 'value', + 'timestamp', + 'manual', + ]); + + $query->values([ + 'exchanger' => 'manual', + 'source' => $currency, + 'target' => 'NOK', + 'value' => $value, + 'timestamp' => $time, + // A weird value just to identify records to remove in AfterScenario. + 'manual' => '666666', + ]); + $query->execute(); + } + } + + /** + * Remove exchange rates. + * + * @AfterScenario + */ + public function cleanExchangeRates() { + $database = \Drupal::database(); + $database->delete('commerce_exchanger_latest_rates') + ->condition('manual', '666666', '=') + ->execute(); + } + +} From ba7729b9579e46001d2119057f9532e9d6a31eb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Soko=C5=82owski?= Date: Fri, 16 Aug 2024 07:54:37 +0200 Subject: [PATCH 02/16] Codestyle fix --- src/CommerceContext.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/CommerceContext.php b/src/CommerceContext.php index b60afeb..ff93b6e 100644 --- a/src/CommerceContext.php +++ b/src/CommerceContext.php @@ -92,9 +92,11 @@ public function iRemovePromotions($titles) { } /** + * Check if product variation exist. + * * @Then /^a product with SKU "([^"]*)" should exist$/ */ - public function aProductWithSKUShouldExist($sku) { + public function aProductWithSkuShouldExist($sku) { /** @var \Drupal\commerce_product\ProductVariationStorage $variation_storage */ $variation_storage = \Drupal::entityTypeManager()->getStorage('commerce_product_variation'); $product_variations = $variation_storage->loadBySku($sku); @@ -104,6 +106,10 @@ public function aProductWithSKUShouldExist($sku) { } /** + * Set records DB for exchange rates. + * + * Valid for commerce_exchanger^2, because in version 1 the exchange rates are in config. + * * @Given I set :value exchange rates */ public function setManualExchangeRates($value) { From cd8dd6ae701fddef93375c69c60f452f248942a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Soko=C5=82owski?= Date: Fri, 16 Aug 2024 08:52:59 +0200 Subject: [PATCH 03/16] Codestyle fix --- src/CommerceContext.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/CommerceContext.php b/src/CommerceContext.php index ff93b6e..cc1d62e 100644 --- a/src/CommerceContext.php +++ b/src/CommerceContext.php @@ -20,13 +20,13 @@ class CommerceContext extends RawDrupalContext { * @Given coupons: */ public function createCoupons(TableNode $nodesTable) { + $storage = \Drupal::entityTypeManager()->getStorage('commerce_promotion_coupon'); foreach ($nodesTable->getHash() as $nodeHash) { $coupon = (object) $nodeHash; - /** @var \Drupal\commerce_promotion\Entity\PromotionInterface $promotion */ $promotion = $this->getPromotionByName($coupon->promotion); if ($promotion) { $coupon_saved = $this->couponCreate($coupon); - $coupon_loaded = Coupon::load($coupon_saved->id); + $coupon_loaded = $storage->load($coupon_saved->id); $promotion->get('coupons')->appendItem($coupon_loaded); $promotion->save(); } @@ -39,9 +39,10 @@ public function createCoupons(TableNode $nodesTable) { /** * Load promotion by name. */ - public function getPromotionByName($promotion_name) { + public function getPromotionByName($promotion_name): ?PromotionInterface { + $storage = \Drupal::entityTypeManager()->getStorage('commerce_promotion'); foreach ($this->promotions as $promotion) { - $loaded_promotion = Promotion::load($promotion->id); + $loaded_promotion = $storage->load($promotion->id); if ($loaded_promotion->label() === $promotion_name) { return $loaded_promotion; } From 23bb00d32484bdafe70be4cd57ac0fc6cb54a7c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Soko=C5=82owski?= Date: Fri, 16 Aug 2024 09:12:07 +0200 Subject: [PATCH 04/16] Codestyle fix --- src/CommerceContext.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/CommerceContext.php b/src/CommerceContext.php index cc1d62e..6d0c24e 100644 --- a/src/CommerceContext.php +++ b/src/CommerceContext.php @@ -3,8 +3,6 @@ namespace Frontkom\DrupalBehatDefinitions; use Behat\Gherkin\Node\TableNode; -use Drupal\commerce_promotion\Entity\Coupon; -use Drupal\commerce_promotion\Entity\Promotion; use Drupal\DrupalExtension\Context\RawDrupalContext; /** @@ -39,7 +37,7 @@ public function createCoupons(TableNode $nodesTable) { /** * Load promotion by name. */ - public function getPromotionByName($promotion_name): ?PromotionInterface { + public function getPromotionByName($promotion_name): { $storage = \Drupal::entityTypeManager()->getStorage('commerce_promotion'); foreach ($this->promotions as $promotion) { $loaded_promotion = $storage->load($promotion->id); From 9e668855b26a5321ab6e8a8ad219589c2de48da8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Soko=C5=82owski?= Date: Fri, 16 Aug 2024 09:15:00 +0200 Subject: [PATCH 05/16] Codestyle fix --- src/CommerceContext.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CommerceContext.php b/src/CommerceContext.php index 6d0c24e..1fa663f 100644 --- a/src/CommerceContext.php +++ b/src/CommerceContext.php @@ -37,7 +37,7 @@ public function createCoupons(TableNode $nodesTable) { /** * Load promotion by name. */ - public function getPromotionByName($promotion_name): { + public function getPromotionByName($promotion_name) { $storage = \Drupal::entityTypeManager()->getStorage('commerce_promotion'); foreach ($this->promotions as $promotion) { $loaded_promotion = $storage->load($promotion->id); From 39a4754f7d395e6185470a63add2a59bc58051f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Soko=C5=82owski?= Date: Fri, 16 Aug 2024 09:19:45 +0200 Subject: [PATCH 06/16] Codestyle fix --- src/CommerceContext.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/CommerceContext.php b/src/CommerceContext.php index 1fa663f..abb9aa0 100644 --- a/src/CommerceContext.php +++ b/src/CommerceContext.php @@ -12,6 +12,13 @@ */ class CommerceContext extends RawDrupalContext { + /** + * An array of promotions created during this context. + * + * @var array + */ + protected $promotions = []; + /** * Generate coupons. * @@ -96,7 +103,6 @@ public function iRemovePromotions($titles) { * @Then /^a product with SKU "([^"]*)" should exist$/ */ public function aProductWithSkuShouldExist($sku) { - /** @var \Drupal\commerce_product\ProductVariationStorage $variation_storage */ $variation_storage = \Drupal::entityTypeManager()->getStorage('commerce_product_variation'); $product_variations = $variation_storage->loadBySku($sku); if (empty($product_variations)) { From 1690b9dacc81001734f6c81ec2764bb315b8bb79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Soko=C5=82owski?= Date: Fri, 16 Aug 2024 09:29:01 +0200 Subject: [PATCH 07/16] Codestyle fix --- .github/assets/phpstan.neon | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/assets/phpstan.neon b/.github/assets/phpstan.neon index 2c0b4ce..05a53db 100644 --- a/.github/assets/phpstan.neon +++ b/.github/assets/phpstan.neon @@ -6,3 +6,8 @@ parameters: # We use this all over the place. Not that straightforward to use the Drupal container inside behat. # todo(eirik): Probably a way, investigate at some point. - "#Drupal calls should be avoided in classes, use dependency injection instead#" + + - + message: "#^Call to an undefined method Drupal\\\\Core\\\\Entity\\\\EntityStorageInterface\\:\\:loadBySku\\(\\)\\.$#" + count: 1 + path: web/modules/custom/this_module/src/CommerceContext.php From 6dfb6695e840837bee7791c6c14c752e08f23311 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Soko=C5=82owski?= Date: Fri, 16 Aug 2024 09:31:21 +0200 Subject: [PATCH 08/16] Codestyle fix --- .github/assets/phpstan.neon | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/assets/phpstan.neon b/.github/assets/phpstan.neon index 05a53db..4e6c2ee 100644 --- a/.github/assets/phpstan.neon +++ b/.github/assets/phpstan.neon @@ -6,8 +6,7 @@ parameters: # We use this all over the place. Not that straightforward to use the Drupal container inside behat. # todo(eirik): Probably a way, investigate at some point. - "#Drupal calls should be avoided in classes, use dependency injection instead#" - - - message: "#^Call to an undefined method Drupal\\\\Core\\\\Entity\\\\EntityStorageInterface\\:\\:loadBySku\\(\\)\\.$#" - count: 1 - path: web/modules/custom/this_module/src/CommerceContext.php + message: "#^Call to an undefined method Drupal\\\\Core\\\\Entity\\\\EntityStorageInterface\\:\\:loadBySku\\(\\)\\.$#" + count: 1 + path: web/modules/custom/this_module/src/CommerceContext.php From 293c1adde76043e97453f176762394ac7b2dbd84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Soko=C5=82owski?= Date: Fri, 16 Aug 2024 09:33:23 +0200 Subject: [PATCH 09/16] Codestyle fix --- .github/assets/phpstan.neon | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/assets/phpstan.neon b/.github/assets/phpstan.neon index 4e6c2ee..79689e9 100644 --- a/.github/assets/phpstan.neon +++ b/.github/assets/phpstan.neon @@ -6,7 +6,7 @@ parameters: # We use this all over the place. Not that straightforward to use the Drupal container inside behat. # todo(eirik): Probably a way, investigate at some point. - "#Drupal calls should be avoided in classes, use dependency injection instead#" - - - message: "#^Call to an undefined method Drupal\\\\Core\\\\Entity\\\\EntityStorageInterface\\:\\:loadBySku\\(\\)\\.$#" - count: 1 - path: web/modules/custom/this_module/src/CommerceContext.php + - + message: "#^Call to an undefined method Drupal\\\\Core\\\\Entity\\\\EntityStorageInterface\\:\\:loadBySku\\(\\)\\.$#" + count: 1 + path: web/modules/custom/this_module/src/CommerceContext.php From 3edede94f5ec6af7296bb8a08ecd8d610076e2d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Soko=C5=82owski?= Date: Tue, 8 Oct 2024 13:01:00 +0200 Subject: [PATCH 10/16] Add commerce as dev dependency --- .github/assets/phpstan.neon | 4 ---- composer.json | 3 +++ 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/assets/phpstan.neon b/.github/assets/phpstan.neon index 79689e9..2c0b4ce 100644 --- a/.github/assets/phpstan.neon +++ b/.github/assets/phpstan.neon @@ -6,7 +6,3 @@ parameters: # We use this all over the place. Not that straightforward to use the Drupal container inside behat. # todo(eirik): Probably a way, investigate at some point. - "#Drupal calls should be avoided in classes, use dependency injection instead#" - - - message: "#^Call to an undefined method Drupal\\\\Core\\\\Entity\\\\EntityStorageInterface\\:\\:loadBySku\\(\\)\\.$#" - count: 1 - path: web/modules/custom/this_module/src/CommerceContext.php diff --git a/composer.json b/composer.json index 67df96b..6e46a74 100644 --- a/composer.json +++ b/composer.json @@ -9,5 +9,8 @@ }, "require": { "drupal/drupal-extension": "^4.0 || ^5.0" + }, + "require-dev": { + "drupal/commerce": "*", } } From 1961d90ca98f4643a2e6642522fcd6de84ce117f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Soko=C5=82owski?= Date: Tue, 8 Oct 2024 13:04:01 +0200 Subject: [PATCH 11/16] Remove trailing comma --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 6e46a74..43c1301 100644 --- a/composer.json +++ b/composer.json @@ -11,6 +11,6 @@ "drupal/drupal-extension": "^4.0 || ^5.0" }, "require-dev": { - "drupal/commerce": "*", + "drupal/commerce": "*" } } From 38a1e64b8172d3996b63736010497c0482f2bdec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Soko=C5=82owski?= Date: Tue, 8 Oct 2024 13:14:35 +0200 Subject: [PATCH 12/16] Typehint variation storage --- src/CommerceContext.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/CommerceContext.php b/src/CommerceContext.php index abb9aa0..4d53f36 100644 --- a/src/CommerceContext.php +++ b/src/CommerceContext.php @@ -3,6 +3,7 @@ namespace Frontkom\DrupalBehatDefinitions; use Behat\Gherkin\Node\TableNode; +use Drupal\commerce_product\ProductVariationStorageInterface; use Drupal\DrupalExtension\Context\RawDrupalContext; /** @@ -103,6 +104,7 @@ public function iRemovePromotions($titles) { * @Then /^a product with SKU "([^"]*)" should exist$/ */ public function aProductWithSkuShouldExist($sku) { + /** @var \Drupal\commerce_product\ProductVariationStorageInterface $variation_storage */ $variation_storage = \Drupal::entityTypeManager()->getStorage('commerce_product_variation'); $product_variations = $variation_storage->loadBySku($sku); if (empty($product_variations)) { From 17a66e07e3713b4907906c477c63e78b2dd75fb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Soko=C5=82owski?= Date: Tue, 8 Oct 2024 14:02:30 +0200 Subject: [PATCH 13/16] Use entity to generate form edit URL --- src/CommerceContext.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/CommerceContext.php b/src/CommerceContext.php index 4d53f36..b244666 100644 --- a/src/CommerceContext.php +++ b/src/CommerceContext.php @@ -4,6 +4,7 @@ use Behat\Gherkin\Node\TableNode; use Drupal\commerce_product\ProductVariationStorageInterface; +use Drupal\commerce_promotion\Entity\PromotionInterface; use Drupal\DrupalExtension\Context\RawDrupalContext; /** @@ -71,6 +72,7 @@ public function couponCreate($coupon) { * @Then I visit promotion :title edit page */ public function iVisitPromotionEditPage($title) { + /** @var \Drupal\commerce_promotion\Entity\PromotionInterface[] $promotions */ $promotions = \Drupal::entityTypeManager()->getStorage('commerce_promotion') ->loadByProperties([ 'name' => $title, @@ -79,8 +81,8 @@ public function iVisitPromotionEditPage($title) { throw new \Exception('Expected 1 promotion with title ' . $title . ' but found ' . count($promotions)); } - $id = reset($promotions)->id(); - $this->getSession()->visit($this->locatePath("promotion/$id/edit")); + $promotion = reset($promotions); + $this->getSession()->visit($this->locatePath($promotion->toUrl('edit-form')->toString())); } /** From 0788f4158a9afc69c86e9e0873029cedfab9f49b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Soko=C5=82owski?= Date: Tue, 8 Oct 2024 14:47:41 +0200 Subject: [PATCH 14/16] Create abstract class for deleting entities --- src/CommerceContext.php | 49 +++++++++++---------------------------- src/EntityContextBase.php | 48 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 35 deletions(-) create mode 100644 src/EntityContextBase.php diff --git a/src/CommerceContext.php b/src/CommerceContext.php index b244666..25ecd92 100644 --- a/src/CommerceContext.php +++ b/src/CommerceContext.php @@ -12,14 +12,7 @@ * * Provide Behat step-definitions for common Commerce functionalities. */ -class CommerceContext extends RawDrupalContext { - - /** - * An array of promotions created during this context. - * - * @var array - */ - protected $promotions = []; +class CommerceContext extends EntityContextBase { /** * Generate coupons. @@ -31,15 +24,11 @@ public function createCoupons(TableNode $nodesTable) { foreach ($nodesTable->getHash() as $nodeHash) { $coupon = (object) $nodeHash; $promotion = $this->getPromotionByName($coupon->promotion); - if ($promotion) { - $coupon_saved = $this->couponCreate($coupon); - $coupon_loaded = $storage->load($coupon_saved->id); - $promotion->get('coupons')->appendItem($coupon_loaded); - $promotion->save(); - } - else { - throw new \Exception("No parent promotion found."); - } + + $coupon_saved = $this->couponCreate($coupon); + $coupon_loaded = $storage->load($coupon_saved->id); + $promotion->get('coupons')->appendItem($coupon_loaded); + $promotion->save(); } } @@ -48,14 +37,13 @@ public function createCoupons(TableNode $nodesTable) { */ public function getPromotionByName($promotion_name) { $storage = \Drupal::entityTypeManager()->getStorage('commerce_promotion'); - foreach ($this->promotions as $promotion) { - $loaded_promotion = $storage->load($promotion->id); - if ($loaded_promotion->label() === $promotion_name) { - return $loaded_promotion; - } + $promotions = $storage->loadByProperties(['name' => $promotion_name]); + + if (count($promotions) !== 1) { + throw new \Exception('Expected 1 promotion with title ' . $title . ' but found ' . count($promotions)); } - return NULL; + return reset($promotions); } /** @@ -69,19 +57,10 @@ public function couponCreate($coupon) { /** * Visit promotion edit page. * - * @Then I visit promotion :title edit page + * @Then I visit promotion :name edit page */ - public function iVisitPromotionEditPage($title) { - /** @var \Drupal\commerce_promotion\Entity\PromotionInterface[] $promotions */ - $promotions = \Drupal::entityTypeManager()->getStorage('commerce_promotion') - ->loadByProperties([ - 'name' => $title, - ]); - if (count($promotions) !== 1) { - throw new \Exception('Expected 1 promotion with title ' . $title . ' but found ' . count($promotions)); - } - - $promotion = reset($promotions); + public function iVisitPromotionEditPage($name) { + $promotion = $this->getPromotionByName($name); $this->getSession()->visit($this->locatePath($promotion->toUrl('edit-form')->toString())); } diff --git a/src/EntityContextBase.php b/src/EntityContextBase.php new file mode 100644 index 0000000..fb2a132 --- /dev/null +++ b/src/EntityContextBase.php @@ -0,0 +1,48 @@ +getStorage($entity_type_id) + ->loadByProperties([ + 'name' => explode(', ', $names), + ]); + foreach ($entities as $entity) { + $entity->delete(); + } + } + + /** + * Clean up created entities. + * + * @AfterScenario + */ + public function cleanUpEntities() { + foreach ($this->entites as $entity) { + $entity->delete(); + } + } + +} From 42ae5670a90565240a77f19936cea050311ab542 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Soko=C5=82owski?= Date: Wed, 9 Oct 2024 09:31:21 +0200 Subject: [PATCH 15/16] Codestyle fix --- src/CommerceContext.php | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/src/CommerceContext.php b/src/CommerceContext.php index 25ecd92..f3ae480 100644 --- a/src/CommerceContext.php +++ b/src/CommerceContext.php @@ -35,12 +35,12 @@ public function createCoupons(TableNode $nodesTable) { /** * Load promotion by name. */ - public function getPromotionByName($promotion_name) { + public function getPromotionByName($name) { $storage = \Drupal::entityTypeManager()->getStorage('commerce_promotion'); - $promotions = $storage->loadByProperties(['name' => $promotion_name]); + $promotions = $storage->loadByProperties(['name' => $name]); if (count($promotions) !== 1) { - throw new \Exception('Expected 1 promotion with title ' . $title . ' but found ' . count($promotions)); + throw new \Exception('Expected 1 promotion with title ' . $name . ' but found ' . count($promotions)); } return reset($promotions); @@ -64,21 +64,6 @@ public function iVisitPromotionEditPage($name) { $this->getSession()->visit($this->locatePath($promotion->toUrl('edit-form')->toString())); } - /** - * Remove promotions by titles. - * - * @Then I remove promotions :titles - */ - public function iRemovePromotions($titles) { - $promotions = \Drupal::entityTypeManager()->getStorage('commerce_promotion') - ->loadByProperties([ - 'name' => explode(', ', $titles), - ]); - foreach ($promotions as $promotion) { - $promotion->delete(); - } - } - /** * Check if product variation exist. * From f09d9dbe5df214ccc69ebbf83da1f73da6438bd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Soko=C5=82owski?= Date: Wed, 30 Oct 2024 10:38:10 +0100 Subject: [PATCH 16/16] Fix use statements sorting --- src/CommerceContext.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CommerceContext.php b/src/CommerceContext.php index f3ae480..55c5c17 100644 --- a/src/CommerceContext.php +++ b/src/CommerceContext.php @@ -3,9 +3,9 @@ namespace Frontkom\DrupalBehatDefinitions; use Behat\Gherkin\Node\TableNode; +use Drupal\DrupalExtension\Context\RawDrupalContext; use Drupal\commerce_product\ProductVariationStorageInterface; use Drupal\commerce_promotion\Entity\PromotionInterface; -use Drupal\DrupalExtension\Context\RawDrupalContext; /** * Class CommerceContext.