@@ -20,23 +20,55 @@ class GiftMessageTest extends GraphQlAbstract
20
20
*/
21
21
private $ getMaskedQuoteIdByReservedOrderId ;
22
22
23
- protected function setUp ()
23
+ protected function setUp (): void
24
24
{
25
25
$ objectManager = Bootstrap::getObjectManager ();
26
26
$ this ->getMaskedQuoteIdByReservedOrderId = $ objectManager ->get (GetMaskedQuoteIdByReservedOrderId::class);
27
27
}
28
28
29
29
/**
30
+ * @magentoConfigFixture default_store sales/gift_options/allow_items 1
30
31
* @magentoApiDataFixture Magento/GiftMessage/_files/guest/quote_with_item_message.php
31
32
* @throws NoSuchEntityException
32
33
* @throws Exception
33
34
*/
34
35
public function testGiftMessageCartForItem ()
35
36
{
36
37
$ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ->execute ('test_guest_order_with_gift_message ' );
38
+ foreach ($ this ->requestCartResult ($ maskedQuoteId )['cart ' ]['items ' ] as $ item ) {
39
+ self ::assertArrayHasKey ('gift_message ' , $ item );
40
+ self ::assertArrayHasKey ('to ' , $ item ['gift_message ' ]);
41
+ self ::assertArrayHasKey ('from ' , $ item ['gift_message ' ]);
42
+ self ::assertArrayHasKey ('message ' , $ item ['gift_message ' ]);
43
+ }
44
+ }
45
+
46
+ /**
47
+ * @magentoConfigFixture default_store sales/gift_options/allow_items 0
48
+ * @magentoApiDataFixture Magento/GiftMessage/_files/guest/quote_with_item_message.php
49
+ * @throws NoSuchEntityException
50
+ * @throws Exception
51
+ */
52
+ public function testGiftMessageCartForItemNotAllow ()
53
+ {
54
+ $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ->execute ('test_guest_order_with_gift_message ' );
55
+ foreach ($ this ->requestCartResult ($ maskedQuoteId )['cart ' ]['items ' ] as $ item ) {
56
+ self ::assertArrayHasKey ('gift_message ' , $ item );
57
+ self ::assertNull ($ item ['gift_message ' ]);
58
+ }
59
+ }
60
+
61
+ /**
62
+ * @param string $quoteId
63
+ *
64
+ * @return array|bool|float|int|string
65
+ * @throws Exception
66
+ */
67
+ private function requestCartResult (string $ quoteId )
68
+ {
37
69
$ query = <<<QUERY
38
70
{
39
- cart(cart_id: " $ maskedQuoteId ") {
71
+ cart(cart_id: " $ quoteId ") {
40
72
items {
41
73
product {
42
74
name
@@ -52,12 +84,6 @@ public function testGiftMessageCartForItem()
52
84
}
53
85
}
54
86
QUERY ;
55
- $ response = $ this ->graphQlQuery ($ query );
56
- foreach ($ response ['cart ' ]['items ' ] as $ item ) {
57
- self ::assertArrayHasKey ('gift_message ' , $ item );
58
- self ::assertArrayHasKey ('to ' , $ item ['gift_message ' ]);
59
- self ::assertArrayHasKey ('from ' , $ item ['gift_message ' ]);
60
- self ::assertArrayHasKey ('message ' , $ item ['gift_message ' ]);
61
- }
87
+ return $ this ->graphQlQuery ($ query );
62
88
}
63
89
}
0 commit comments