Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CreateCaseBuilderTest.php
Go to the documentation of this file.
1 <?php
7 
17 
23 class CreateCaseBuilderTest extends \PHPUnit\Framework\TestCase
24 {
28  private $objectManager;
29 
33  private $caseBuilder;
34 
38  private $dateTimeFactory;
39 
43  protected function setUp()
44  {
47  $this->objectManager = Bootstrap::getObjectManager();
48  $this->dateTimeFactory = $this->objectManager->create(DateTimeFactory::class);
49  $this->caseBuilder = $this->objectManager->create(CreateCaseBuilder::class);
50  }
51 
60  public function testCreateCaseBuilderWithFullSetOfData()
61  {
63  $order = $this->objectManager->create(Order::class);
64  $order->loadByIncrementId('100000001');
65 
66  $orderItems = $order->getAllItems();
67  $payment = $order->getPayment();
68  $billingAddress = $order->getBillingAddress();
69  $shippingAddress = $order->getShippingAddress();
70 
72  $customerRepository = $this->objectManager->create(CustomerRepositoryInterface::class);
73  $customer = $customerRepository->getById($order->getCustomerId());
74 
75  $productMetadata = $this->objectManager->create(ProductMetadataInterface::class);
76 
78  $signifydOrderSessionId = $this->objectManager->create(SignifydOrderSessionId::class);
79 
80  $expected = [
81  'purchase' => [
82  'orderSessionId' => $signifydOrderSessionId->get($order->getQuoteId()),
83  'browserIpAddress' => $order->getRemoteIp(),
84  'orderId' => $order->getIncrementId(),
85  'createdAt' => date('c', strtotime(date('Y-m-d 00:00:55'))),
86  'paymentGateway' => 'paypal_account',
87  'transactionId' => $payment->getLastTransId(),
88  'currency' => $order->getOrderCurrencyCode(),
89  'avsResponseCode' => '',
90  'cvvResponseCode' => '',
91  'orderChannel' => 'WEB',
92  'totalPrice' => $order->getGrandTotal(),
93  'shipments' => [
94  0 => [
95  'shipper' => 'Flat Rate',
96  'shippingMethod' => 'Fixed',
97  'shippingPrice' => $order->getShippingAmount()
98  ]
99  ],
100  'products' => [
101  0 => [
102  'itemId' => $orderItems[0]->getSku(),
103  'itemName' => $orderItems[0]->getName(),
104  'itemPrice' => $orderItems[0]->getPrice(),
105  'itemQuantity' => $orderItems[0]->getQtyOrdered(),
106  'itemUrl' => $orderItems[0]->getProduct()->getProductUrl(),
107  'itemWeight' => $orderItems[0]->getProduct()->getWeight()
108  ],
109  1 => [
110  'itemId' => $orderItems[1]->getSku(),
111  'itemName' => $orderItems[1]->getName(),
112  'itemPrice' => $orderItems[1]->getPrice(),
113  'itemQuantity' => $orderItems[1]->getQtyOrdered(),
114  'itemUrl' => $orderItems[1]->getProduct()->getProductUrl(),
115  'itemWeight' => $orderItems[1]->getProduct()->getWeight()
116  ]
117  ],
118  'paymentMethod' => 'PAYPAL_ACCOUNT'
119  ],
120  'card' => [
121  'cardHolderName' => 'firstname lastname',
122  'last4' => $payment->getCcLast4(),
123  'expiryMonth' => $payment->getCcExpMonth(),
124  'expiryYear' => $payment->getCcExpYear(),
125  'billingAddress' => [
126  'streetAddress' => 'street',
127  'city' => $billingAddress->getCity(),
128  'provinceCode' => $billingAddress->getRegionCode(),
129  'postalCode' => $billingAddress->getPostcode(),
130  'countryCode' => $billingAddress->getCountryId(),
131  'unit' => ''
132  ]
133  ],
134  'recipient' => [
135  'fullName' => $shippingAddress->getName(),
136  'confirmationEmail' => $shippingAddress->getEmail(),
137  'confirmationPhone' => $shippingAddress->getTelephone(),
138  'deliveryAddress' => [
139  'streetAddress' => '6161 West Centinela Avenue',
140  'unit' => 'app. 33',
141  'city' => $shippingAddress->getCity(),
142  'provinceCode' => $shippingAddress->getRegionCode(),
143  'postalCode' => $shippingAddress->getPostcode(),
144  'countryCode' => $shippingAddress->getCountryId()
145  ]
146  ],
147  'userAccount' => [
148  'email' => $customer->getEmail(),
149  'username' => $customer->getEmail(),
150  'phone' => $order->getBillingAddress()->getTelephone(),
151  'accountNumber' => $customer->getId(),
152  'createdDate' => $this->formatDate($customer->getCreatedAt()),
153  'lastUpdateDate' => $this->formatDate($customer->getUpdatedAt()),
154  'aggregateOrderCount' => 2,
155  'aggregateOrderDollars' => 150.0
156  ],
157  'seller' => $this->getSellerData(),
158  'platformAndClient' => [
159  'storePlatform' => $productMetadata->getName() . ' ' . $productMetadata->getEdition(),
160  'storePlatformVersion' => $productMetadata->getVersion(),
161  'signifydClientApp' => $productMetadata->getName(),
162  'signifydClientAppVersion' => '1.0'
163  ]
164  ];
165 
166  self::assertEquals(
167  $expected,
168  $this->caseBuilder->build($order->getEntityId())
169  );
170  }
171 
179  public function testCreateCaseBuilderWithVirtualProductAndGuest()
180  {
182  $order = $this->objectManager->create(Order::class);
183  $order->loadByIncrementId('100000002');
184 
185  $scope = $this->objectManager->get(ScopeInterface::class);
186  $scope->setCurrentScope(Area::AREA_ADMINHTML);
187 
188  $orderItems = $order->getAllItems();
189  $product = $orderItems[0]->getProduct();
190  $payment = $order->getPayment();
191  $billingAddress = $order->getBillingAddress();
192  $productMetadata = $this->objectManager->create(ProductMetadataInterface::class);
193 
195  $quoteSessionId = $this->objectManager->create(SignifydOrderSessionId::class);
196 
197  $expected = [
198  'purchase' => [
199  'orderSessionId' => $quoteSessionId->get($order->getQuoteId()),
200  'browserIpAddress' => $order->getRemoteIp(),
201  'orderId' => $order->getIncrementId(),
202  'createdAt' => '2016-12-12T12:00:55+00:00',
203  'paymentGateway' => $payment->getMethod(),
204  'transactionId' => $payment->getLastTransId(),
205  'currency' => $order->getOrderCurrencyCode(),
206  'avsResponseCode' => 'Y',
207  'cvvResponseCode' => 'M',
208  'orderChannel' => 'PHONE',
209  'totalPrice' => $order->getGrandTotal(),
210  'products' => [
211  0 => [
212  'itemId' => $orderItems[0]->getSku(),
213  'itemName' => $orderItems[0]->getName(),
214  'itemPrice' => $orderItems[0]->getPrice(),
215  'itemQuantity' => $orderItems[0]->getQtyOrdered(),
216  'itemUrl' => $product->getProductUrl()
217  ],
218  ],
219  'paymentMethod' => 'PAYMENT_CARD'
220  ],
221  'card' => [
222  'cardHolderName' => 'firstname lastname',
223  'billingAddress' => [
224  'streetAddress' => 'street',
225  'city' => $billingAddress->getCity(),
226  'provinceCode' => $billingAddress->getRegionCode(),
227  'postalCode' => $billingAddress->getPostcode(),
228  'countryCode' => $billingAddress->getCountryId(),
229  'unit' => ''
230  ]
231  ],
232  'seller' => $this->getSellerData(),
233  'platformAndClient' => [
234  'storePlatform' => $productMetadata->getName() . ' ' . $productMetadata->getEdition(),
235  'storePlatformVersion' => $productMetadata->getVersion(),
236  'signifydClientApp' => $productMetadata->getName(),
237  'signifydClientAppVersion' => '1.0'
238  ]
239  ];
240 
241  self::assertEquals(
242  $expected,
243  $this->caseBuilder->build($order->getEntityId())
244  );
245  }
246 
252  private function getSellerData()
253  {
254  return [
255  'name' => 'Sample Store',
256  'domain' => 'm2.com',
257  'shipFromAddress' => [
258  'streetAddress' => '6161 West Centinela Avenue',
259  'unit' => 'app. 111',
260  'city' => 'Culver City',
261  'provinceCode' => 'AE',
262  'postalCode' => '90230',
263  'countryCode' => 'US',
264  ],
265  'corporateAddress' => [
266  'streetAddress' => '5th Avenue',
267  'unit' => '75',
268  'city' => 'New York',
269  'provinceCode' => 'MH',
270  'postalCode' => '19032',
271  'countryCode' => 'US',
272  ],
273  ];
274  }
275 
282  private function formatDate($date)
283  {
284  $result = $this->dateTimeFactory->create(
285  $date,
286  new \DateTimeZone('UTC')
287  );
288 
289  return $result->format(\DateTime::ATOM);
290  }
291 }
$billingAddress
Definition: order.php:25
$customer
Definition: customers.php:11
$shippingAddress
Definition: order.php:40
$order
Definition: order.php:55
$customerRepository
$payment
Definition: order.php:17
if(defined('TESTS_MAGENTO_INSTALLATION') &&TESTS_MAGENTO_INSTALLATION==='enabled') $bootstrap
Definition: bootstrap.php:73