CoreAssertions.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  1. <?php
  2. namespace Webkul\Core\Tests\Concerns;
  3. use Webkul\CartRule\Contracts\CartRule;
  4. use Webkul\CartRule\Contracts\CartRuleCoupon;
  5. use Webkul\CatalogRule\Contracts\CatalogRule;
  6. use Webkul\Checkout\Contracts\Cart;
  7. use Webkul\Checkout\Contracts\CartItem;
  8. use Webkul\Checkout\Contracts\CartPayment;
  9. use Webkul\Checkout\Contracts\CartShippingRate;
  10. use Webkul\Sales\Contracts\Invoice;
  11. use Webkul\Sales\Contracts\InvoiceItem;
  12. use Webkul\Sales\Contracts\OrderItem;
  13. use Webkul\Sales\Contracts\OrderPayment;
  14. use Webkul\Sales\Contracts\OrderTransaction;
  15. use Webkul\Sales\Models\Order;
  16. trait CoreAssertions
  17. {
  18. /**
  19. * Assert model wise.
  20. */
  21. public function assertModelWise(array $modelWiseAssertions): void
  22. {
  23. foreach ($modelWiseAssertions as $modelClassName => $modelAssertions) {
  24. foreach ($modelAssertions as $assertion) {
  25. $this->assertDatabaseHas(app($modelClassName)->getTable(), $assertion);
  26. }
  27. }
  28. }
  29. /**
  30. * Assert that two numbers are equal with optional decimal precision.
  31. */
  32. public function assertPrice(float $expected, float $actual, ?int $decimal = null): void
  33. {
  34. $decimal = $decimal ?? core()->getCurrentChannel()->decimal;
  35. $expectedFormatted = number_format($expected, $decimal);
  36. $actualFormatted = number_format($actual, $decimal);
  37. $this->assertEquals($expectedFormatted, $actualFormatted);
  38. }
  39. /**
  40. * Prepare order for assertion.
  41. */
  42. public function prepareOrder(Order $order): array
  43. {
  44. return [
  45. 'status' => $order->status,
  46. 'channel_name' => $order->channel_name,
  47. 'is_guest' => $order->is_guest,
  48. 'customer_email' => $order->customer_email,
  49. 'customer_first_name' => $order->customer_first_name,
  50. 'customer_last_name' => $order->customer_last_name,
  51. 'shipping_method' => $order->shipping_method,
  52. 'shipping_title' => $order->shipping_title,
  53. 'shipping_description' => $order->shipping_description,
  54. 'coupon_code' => $order->coupon_code,
  55. 'is_gift' => $order->is_gift,
  56. 'total_item_count' => $order->total_item_count,
  57. 'total_qty_ordered' => $order->total_qty_ordered,
  58. 'base_currency_code' => $order->base_currency_code,
  59. 'channel_currency_code' => $order->channel_currency_code,
  60. 'order_currency_code' => $order->order_currency_code,
  61. 'grand_total' => $order->grand_total,
  62. 'base_grand_total' => $order->base_grand_total,
  63. 'grand_total_invoiced' => $order->grand_total_invoiced,
  64. 'base_grand_total_invoiced' => $order->base_grand_total_invoiced,
  65. 'grand_total_refunded' => $order->grand_total_refunded,
  66. 'base_grand_total_refunded' => $order->base_grand_total_refunded,
  67. 'sub_total' => $order->sub_total,
  68. 'base_sub_total' => $order->base_sub_total,
  69. 'sub_total_invoiced' => $order->sub_total_invoiced,
  70. 'grand_total_refunded' => $order->grand_total_refunded,
  71. 'base_grand_total_refunded' => $order->base_grand_total_refunded,
  72. 'sub_total' => $order->sub_total,
  73. 'base_sub_total' => $order->base_sub_total,
  74. 'sub_total_invoiced' => $order->sub_total_invoiced,
  75. 'base_sub_total_invoiced' => $order->base_sub_total_invoiced,
  76. 'sub_total_refunded' => $order->sub_total_refunded,
  77. 'discount_percent' => $order->discount_percent,
  78. 'discount_amount' => $order->discount_amount,
  79. 'base_discount_amount' => $order->base_discount_amount,
  80. 'discount_invoiced' => $order->discount_invoiced,
  81. 'base_discount_invoiced' => $order->base_discount_invoiced,
  82. 'discount_refunded' => $order->discount_refunded,
  83. 'base_discount_refunded' => $order->base_discount_refunded,
  84. 'tax_amount' => $order->tax_amount,
  85. 'base_tax_amount' => $order->base_tax_amount,
  86. 'tax_amount_invoiced' => $order->tax_amount_invoiced,
  87. 'base_tax_amount_invoiced' => $order->base_tax_amount_invoiced,
  88. 'tax_amount_refunded' => $order->tax_amount_refunded,
  89. 'base_tax_amount_refunded' => $order->base_tax_amount_refunded,
  90. 'shipping_amount' => $order->shipping_amount,
  91. 'base_shipping_amount' => $order->base_shipping_amount,
  92. 'shipping_invoiced' => $order->shipping_invoiced,
  93. 'base_shipping_invoiced' => $order->base_shipping_invoiced,
  94. 'shipping_refunded' => $order->shipping_refunded,
  95. 'base_shipping_refunded' => $order->base_shipping_refunded,
  96. 'shipping_discount_amount' => $order->shipping_discount_amount,
  97. 'base_shipping_discount_amount' => $order->base_shipping_discount_amount,
  98. 'customer_id' => $order->customer_id,
  99. 'customer_type' => $order->customer_type,
  100. 'channel_id' => $order->channel_id,
  101. 'channel_type' => $order->channel_type,
  102. 'cart_id' => $order->cart_id,
  103. 'applied_cart_rule_ids' => $order->applied_cart_rule_ids,
  104. ];
  105. }
  106. /**
  107. * Prepare order using cart for assertion.
  108. */
  109. public function prepareOrderUsingCart(Cart $cart): array
  110. {
  111. return [
  112. 'cart_id' => $cart->id,
  113. 'customer_id' => $cart->customer_id,
  114. 'is_guest' => $cart->is_guest,
  115. 'customer_email' => $cart->customer_email,
  116. 'customer_first_name' => $cart->customer_first_name,
  117. 'customer_last_name' => $cart->customer_last_name,
  118. 'total_item_count' => $cart->items_count,
  119. 'total_qty_ordered' => $cart->items_qty,
  120. 'base_currency_code' => $cart->base_currency_code,
  121. 'channel_currency_code' => $cart->channel_currency_code,
  122. 'order_currency_code' => $cart->cart_currency_code,
  123. 'grand_total' => $cart->grand_total,
  124. 'base_grand_total' => $cart->base_grand_total,
  125. 'sub_total' => $cart->sub_total,
  126. 'base_sub_total' => $cart->base_sub_total,
  127. 'tax_amount' => $cart->tax_total,
  128. 'base_tax_amount' => $cart->base_tax_total,
  129. 'coupon_code' => $cart->coupon_code,
  130. 'applied_cart_rule_ids' => $cart->applied_cart_rule_ids,
  131. 'discount_amount' => $cart->discount_amount,
  132. 'base_discount_amount' => $cart->base_discount_amount,
  133. ];
  134. }
  135. /**
  136. * Prepare Order Item for assertion.
  137. */
  138. public function prepareOrderItem(OrderItem $orderItem): array
  139. {
  140. return [
  141. 'id' => $orderItem->id,
  142. 'sku' => $orderItem->sku,
  143. 'type' => $orderItem->type,
  144. 'name' => $orderItem->name,
  145. 'coupon_code' => $orderItem->coupon_code,
  146. 'weight' => $orderItem->weight,
  147. 'total_weight' => $orderItem->total_weight,
  148. 'qty_ordered' => $orderItem->qty_ordered,
  149. 'qty_shipped' => $orderItem->qty_shipped,
  150. 'qty_invoiced' => $orderItem->qty_invoiced,
  151. 'qty_canceled' => $orderItem->qty_canceled,
  152. 'qty_refunded' => $orderItem->qty_refunded,
  153. 'price' => $orderItem->price,
  154. 'base_price' => $orderItem->base_price,
  155. 'total' => $orderItem->total,
  156. 'base_total' => $orderItem->base_total,
  157. 'total_invoiced' => $orderItem->total_invoiced,
  158. 'base_total_invoiced' => $orderItem->base_total_invoiced,
  159. 'amount_refunded' => $orderItem->amount_refunded,
  160. 'base_amount_refunded' => $orderItem->base_amount_refunded,
  161. 'discount_percent' => $orderItem->discount_percent,
  162. 'discount_amount' => $orderItem->discount_amount,
  163. 'base_discount_amount' => $orderItem->base_discount_amount,
  164. 'discount_invoiced' => $orderItem->discount_invoiced,
  165. 'base_discount_invoiced' => $orderItem->base_discount_invoiced,
  166. ];
  167. }
  168. /**
  169. * Prepare order items for assertion.
  170. */
  171. public function prepareOrderItemUsingCartItem(CartItem $cartItem)
  172. {
  173. return [
  174. 'product_id' => $cartItem->product_id,
  175. 'sku' => $cartItem->sku,
  176. 'type' => $cartItem->type,
  177. 'name' => $cartItem->name,
  178. 'weight' => $cartItem->weight,
  179. 'total_weight' => $cartItem->total_weight,
  180. 'qty_ordered' => $cartItem->quantity,
  181. 'price' => $cartItem->price,
  182. 'base_price' => $cartItem->base_price,
  183. 'total' => $cartItem->total,
  184. 'base_total' => $cartItem->base_total,
  185. 'tax_percent' => $cartItem->tax_percent,
  186. 'tax_amount' => $cartItem->tax_amount,
  187. 'base_tax_amount' => $cartItem->base_tax_amount,
  188. 'tax_category_id' => $cartItem->tax_category_id,
  189. 'discount_percent' => $cartItem->discount_percent,
  190. 'discount_amount' => $cartItem->discount_amount,
  191. 'base_discount_amount' => $cartItem->base_discount_amount,
  192. ];
  193. }
  194. /**
  195. * Prepare Order Payment for Assertion.
  196. */
  197. public function prepareOrderPaymentUsingCartPayment(CartPayment $cartPayment): array
  198. {
  199. return [
  200. 'method' => $cartPayment->method,
  201. 'method_title' => $cartPayment->method_title,
  202. ];
  203. }
  204. public function prepareOrderTransaction(OrderTransaction $orderTransaction): array
  205. {
  206. return [
  207. 'order_id' => $orderTransaction->order_id,
  208. 'invoice_id' => $orderTransaction->invoice_id,
  209. 'transaction_id' => $orderTransaction->transaction_id,
  210. 'type' => $orderTransaction->type,
  211. 'payment_method' => $orderTransaction->payment_method,
  212. 'status' => $orderTransaction->status,
  213. 'amount' => $orderTransaction->amount,
  214. ];
  215. }
  216. /**
  217. * Prepare the cart for assertion.
  218. */
  219. public function prepareCart(Cart $cart): array
  220. {
  221. return [
  222. 'id' => $cart->id,
  223. 'customer_email' => $cart->customer_email,
  224. 'customer_first_name' => $cart->customer_first_name,
  225. 'customer_last_name' => $cart->customer_last_name,
  226. 'shipping_method' => $cart->shipping_method,
  227. 'coupon_code' => $cart->coupon_code,
  228. 'is_gift' => $cart->is_gift,
  229. 'items_count' => $cart->items_count,
  230. 'items_qty' => $cart->items_qty,
  231. 'exchange_rate' => $cart->exchange_rate,
  232. 'global_currency_code' => $cart->global_currency_code,
  233. 'base_currency_code' => $cart->base_currency_code,
  234. 'channel_currency_code' => $cart->channel_currency_code,
  235. 'cart_currency_code' => $cart->cart_currency_code,
  236. 'grand_total' => $cart->grand_total,
  237. 'base_grand_total' => $cart->base_grand_total,
  238. 'sub_total' => $cart->sub_total,
  239. 'base_sub_total' => $cart->base_sub_total,
  240. 'tax_total' => $cart->tax_total,
  241. 'base_tax_total' => $cart->base_tax_total,
  242. 'discount_amount' => $cart->discount_amount,
  243. 'base_discount_amount' => $cart->base_discount_amount,
  244. 'checkout_method' => $cart->checkout_method,
  245. 'is_guest' => $cart->is_guest,
  246. 'is_active' => $cart->is_active,
  247. 'applied_cart_rule_ids' => $cart->applied_cart_rule_ids,
  248. 'customer_id' => $cart->customer_id,
  249. 'channel_id' => $cart->channel_id,
  250. ];
  251. }
  252. /**
  253. * Prepare cart item for assertion.
  254. */
  255. public function prepareCartItem(CartItem $cartItem): array
  256. {
  257. return [
  258. 'quantity' => $cartItem->quantity,
  259. 'sku' => $cartItem->sku,
  260. 'type' => $cartItem->type,
  261. 'name' => $cartItem->name,
  262. 'coupon_code' => $cartItem->coupon_code,
  263. 'weight' => $cartItem->weight,
  264. 'total_weight' => $cartItem->total_weight,
  265. 'base_total_weight' => $cartItem->base_total_weight,
  266. 'price' => core()->convertPrice($cartItem->price),
  267. 'base_price' => $cartItem->base_price,
  268. 'custom_price' => $cartItem->custom_price,
  269. 'total' => $cartItem->total,
  270. 'base_total' => $cartItem->base_total,
  271. 'tax_percent' => $cartItem->tax_percent,
  272. 'tax_amount' => $cartItem->tax_amount,
  273. 'base_tax_amount' => $cartItem->base_tax_amount,
  274. 'discount_percent' => $cartItem->discount_percent,
  275. 'base_discount_amount' => $cartItem->base_discount_amount,
  276. 'tax_percent' => number_format($cartItem->tax_percent, 4),
  277. 'tax_amount' => number_format($cartItem->tax_amount, 4),
  278. 'base_tax_amount' => number_format($cartItem->base_tax_amount, 4),
  279. 'discount_amount' => number_format($cartItem->discount_amount, 4),
  280. 'base_discount_amount' => number_format($cartItem->base_discount_amount, 4),
  281. 'parent_id' => $cartItem->parent_id,
  282. 'product_id' => $cartItem->product_id,
  283. 'cart_id' => $cartItem->cart_id,
  284. 'tax_category_id' => $cartItem->tax_category_id,
  285. 'applied_cart_rule_ids' => $cartItem->applied_cart_rule_ids,
  286. ];
  287. }
  288. /**
  289. * Prepare cart payment for assertion.
  290. */
  291. public function prepareCartPayment(CartPayment $cartPayment): array
  292. {
  293. return [
  294. 'cart_id' => $cartPayment->cart_id,
  295. 'method' => $cartPayment->method,
  296. 'method_title' => $cartPayment->method_title,
  297. ];
  298. }
  299. /**
  300. * Prepare cart shipping rate for assertion.
  301. */
  302. public function prepareCartShippingRate(CartShippingRate $cartShippingRate): array
  303. {
  304. return [
  305. 'carrier' => $cartShippingRate->carrier,
  306. 'carrier_title' => $cartShippingRate->carrier_title,
  307. 'method' => $cartShippingRate->method,
  308. 'method_title' => $cartShippingRate->method_title,
  309. 'method_description' => $cartShippingRate->method_description,
  310. 'cart_address_id' => $cartShippingRate->cart_address_id,
  311. ];
  312. }
  313. /**
  314. * Prepare address for assertion.
  315. */
  316. public function prepareAddress(mixed $address, ?string $type = null): array
  317. {
  318. return [
  319. 'additional' => $address->additional,
  320. 'address' => $address->address,
  321. 'address_type' => $type ?? $address->address_type,
  322. 'city' => $address->city,
  323. 'company_name' => $address->company_name,
  324. 'country' => $address->country,
  325. 'default_address' => $address->default_address,
  326. 'email' => $address->email,
  327. 'first_name' => $address->first_name,
  328. 'gender' => $address->gender,
  329. 'last_name' => $address->last_name,
  330. 'phone' => $address->phone,
  331. 'postcode' => $address->postcode,
  332. 'state' => $address->state,
  333. 'vat_id' => $address->vat_id,
  334. 'customer_id' => ! $type ? $address->customer_id : null,
  335. ];
  336. }
  337. /**
  338. * Assert order payment for assertion.
  339. */
  340. public function prepareOrderPayment(OrderPayment $orderPayment): array
  341. {
  342. return [
  343. 'order_id' => $orderPayment->order_id,
  344. 'method' => $orderPayment->method,
  345. 'method_title' => $orderPayment->method_title,
  346. ];
  347. }
  348. /**
  349. * Prepare invoice for assertion.
  350. */
  351. public function prepareInvoice(Order $order, OrderItem $orderItem): array
  352. {
  353. return [
  354. 'order_id' => $order->id,
  355. 'state' => 'paid',
  356. 'total_qty' => 1,
  357. 'base_currency_code' => $order->base_currency_code,
  358. 'channel_currency_code' => $order->channel_currency_code,
  359. 'order_currency_code' => $order->order_currency_code,
  360. 'email_sent' => 1,
  361. 'discount_amount' => 0,
  362. 'base_discount_amount' => 0,
  363. 'sub_total' => $orderItem->base_price,
  364. 'base_sub_total' => $orderItem->base_price,
  365. 'grand_total' => $orderItem->price,
  366. 'base_grand_total' => $orderItem->price,
  367. ];
  368. }
  369. /**
  370. * Assert invoice item for assertion.
  371. */
  372. public function prepareInvoiceItem(InvoiceItem $invoiceItem): array
  373. {
  374. return [
  375. 'id' => $invoiceItem->id,
  376. 'parent_id' => $invoiceItem->parent_id,
  377. 'name' => $invoiceItem->name,
  378. 'description' => $invoiceItem->description,
  379. 'sku' => $invoiceItem->sku,
  380. 'qty' => $invoiceItem->qty,
  381. 'price' => $invoiceItem->price,
  382. 'base_price' => $invoiceItem->base_price,
  383. 'total' => $invoiceItem->total,
  384. 'base_total' => $invoiceItem->base_total,
  385. 'tax_amount' => $invoiceItem->tax_amount,
  386. 'base_tax_amount' => $invoiceItem->base_tax_amount,
  387. 'discount_percent' => $invoiceItem->discount_percent,
  388. 'discount_amount' => $invoiceItem->discount_amount,
  389. 'base_discount_amount' => $invoiceItem->base_discount_amount,
  390. 'product_id' => $invoiceItem->product_id,
  391. 'product_type' => $invoiceItem->product_type,
  392. 'order_item_id' => $invoiceItem->order_item_id,
  393. 'invoice_id' => $invoiceItem->invoice_id,
  394. ];
  395. }
  396. /**
  397. * Assert Cart Rule for assertion.
  398. */
  399. public function prepareCartRule(CartRule $cartRule): array
  400. {
  401. return [
  402. 'id' => $cartRule->id,
  403. 'name' => $cartRule->name,
  404. 'description' => $cartRule->description,
  405. 'starts_from' => $cartRule->starts_from,
  406. 'ends_till' => $cartRule->ends_till,
  407. 'status' => $cartRule->status,
  408. 'coupon_type' => $cartRule->coupon_type,
  409. 'use_auto_generation' => $cartRule->use_auto_generation,
  410. 'usage_per_customer' => $cartRule->usage_per_customer,
  411. 'uses_per_coupon' => $cartRule->uses_per_coupon,
  412. 'times_used' => $cartRule->times_used,
  413. 'condition_type' => $cartRule->condition_type,
  414. 'end_other_rules' => $cartRule->end_other_rules,
  415. 'uses_attribute_conditions' => $cartRule->uses_attribute_conditions,
  416. 'action_type' => $cartRule->action_type,
  417. 'discount_amount' => $cartRule->discount_amount,
  418. 'discount_quantity' => $cartRule->discount_quantity,
  419. 'discount_step' => $cartRule->discount_step,
  420. 'apply_to_shipping' => $cartRule->apply_to_shipping,
  421. 'free_shipping' => $cartRule->free_shipping,
  422. 'sort_order' => $cartRule->sort_order,
  423. ];
  424. }
  425. /**
  426. * Assert cart rule customer group for assertion.
  427. */
  428. public function prepareCartRuleCustomerGroup(CartRule $cartRule): void
  429. {
  430. foreach ($cartRule->cart_rule_customer_groups as $cartRuleCustomerGroup) {
  431. $this->assertDatabaseHas('cart_rule_customer_groups', [
  432. 'cart_rule_id' => $cartRule->id,
  433. 'customer_group_id' => $cartRuleCustomerGroup->id,
  434. ]);
  435. }
  436. }
  437. /**
  438. * Assert cart rule for assertion.
  439. */
  440. public function prepareCartRuleChannel(CartRule $cartRule): void
  441. {
  442. foreach ($cartRule->cart_rule_channels as $cartRuleChannel) {
  443. $this->assertDatabaseHas('cart_rule_channels', [
  444. 'cart_rule_id' => $cartRule->id,
  445. 'channel_id' => $cartRuleChannel->id,
  446. ]);
  447. }
  448. }
  449. /**
  450. * Assert Cart Rule Coupon for assertion.
  451. */
  452. public function prepareCartRuleCoupon(CartRuleCoupon $cartRuleCoupon): array
  453. {
  454. return [
  455. 'code' => $cartRuleCoupon->code,
  456. 'usage_limit' => $cartRuleCoupon->usage_limit,
  457. 'usage_per_customer' => $cartRuleCoupon->usage_per_customer,
  458. 'times_used' => $cartRuleCoupon->times_used,
  459. 'type' => $cartRuleCoupon->type,
  460. 'is_primary' => $cartRuleCoupon->is_primary,
  461. 'expired_at' => $cartRuleCoupon->expired_at,
  462. ];
  463. }
  464. /**
  465. * Assert cart rule coupon for assertion.
  466. */
  467. public function prepareCatalogRule(CatalogRule $catalogRule): array
  468. {
  469. return [
  470. 'name' => $catalogRule->name,
  471. 'description' => $catalogRule->description,
  472. 'starts_from' => $catalogRule->starts_from,
  473. 'ends_till' => $catalogRule->ends_till,
  474. 'status' => $catalogRule->status,
  475. 'condition_type' => $catalogRule->condition_type,
  476. 'conditions' => $catalogRule->conditions,
  477. 'end_other_rules' => $catalogRule->end_other_rules,
  478. 'action_type' => $catalogRule->action_type,
  479. 'discount_amount' => $catalogRule->discount_amount,
  480. 'sort_order' => $catalogRule->sort_order,
  481. ];
  482. }
  483. /**
  484. * Assert Catalog Rule Coupon for assertion.
  485. */
  486. public function prepareCatalogRuleCoupon(CatalogRule $catalogRule): array
  487. {
  488. return [
  489. 'name' => $catalogRule->name,
  490. 'description' => $catalogRule->description,
  491. 'starts_from' => $catalogRule->starts_from,
  492. 'ends_till' => $catalogRule->ends_till,
  493. 'status' => $catalogRule->status,
  494. 'condition_type' => $catalogRule->condition_type,
  495. 'conditions' => $catalogRule->conditions,
  496. 'end_other_rules' => $catalogRule->end_other_rules,
  497. 'action_type' => $catalogRule->action_type,
  498. 'discount_amount' => $catalogRule->discount_amount,
  499. 'sort_order' => $catalogRule->sort_order,
  500. ];
  501. }
  502. /**
  503. * Assert Catalog Rule Channel for assertion.
  504. */
  505. public function prepareCatalogRuleChannel(CatalogRule $catalogRule): void
  506. {
  507. foreach ($catalogRule->channels as $catalogRuleChannel) {
  508. $this->assertDatabaseHas('catalog_rule_channels', [
  509. 'catalog_rule_id' => $catalogRule->id,
  510. 'channel_id' => $catalogRuleChannel->id,
  511. ]);
  512. }
  513. }
  514. /**
  515. * Assert Catalog Rule Customer Group for assertion.
  516. */
  517. public function prepareCatalogRuleCustomerGroup(CatalogRule $catalogRule): void
  518. {
  519. foreach ($catalogRule->customer_groups as $customerGroup) {
  520. $this->assertDatabaseHas('catalog_rule_customer_groups', [
  521. 'catalog_rule_id' => $catalogRule->id,
  522. 'customer_group_id' => $customerGroup->id,
  523. ]);
  524. }
  525. }
  526. }