Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
GroupedProductViewTest.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
13 
15 {
16 
20  public function testAllFieldsGroupedProduct()
21  {
22  $productSku = 'grouped-product';
23  $query
24  = <<<QUERY
25 {
26  products(filter: {sku: {eq: "{$productSku}"}}) {
27  items {
28  id
29  attribute_set_id
30  created_at
31  name
32  sku
33  type_id
34  ... on GroupedProduct {
35  items{
36  qty
37  position
38  product{
39  sku
40  name
41  type_id
42  url_key
43  }
44  }
45  }
46  }
47  }
48 }
49 QUERY;
50 
51  $response = $this->graphQlQuery($query);
53  $productRepository = ObjectManager::getInstance()->get(ProductRepositoryInterface::class);
54  $groupedProduct = $productRepository->get($productSku, false, null, true);
55 
56  $this->assertGroupedProductItems($groupedProduct, $response['products']['items'][0]);
57  }
58 
59  private function assertGroupedProductItems($product, $actualResponse)
60  {
61  $this->assertNotEmpty(
62  $actualResponse['items'],
63  "Precondition failed: 'grouped product items' must not be empty"
64  );
65  $this->assertEquals(2, count($actualResponse['items']));
66  $groupedProductLinks = $product->getProductLinks();
67  foreach ($actualResponse['items'] as $itemIndex => $bundleItems) {
68  $this->assertNotEmpty($bundleItems);
69  $associatedProductSku = $groupedProductLinks[$itemIndex]->getLinkedProductSku();
70 
71  $productsRepository = ObjectManager::getInstance()->get(ProductRepositoryInterface::class);
73  $associatedProduct = $productsRepository->get($associatedProductSku);
74 
75  $this->assertEquals(
76  $groupedProductLinks[$itemIndex]->getExtensionAttributes()->getQty(),
77  $actualResponse['items'][$itemIndex]['qty']
78  );
79  $this->assertEquals(
80  $groupedProductLinks[$itemIndex]->getPosition(),
81  $actualResponse['items'][$itemIndex]['position']
82  );
83  $this->assertResponseFields(
84  $actualResponse['items'][$itemIndex]['product'],
85  [
86  'sku' => $associatedProductSku,
87  'type_id' => $groupedProductLinks[$itemIndex]->getLinkedProductType(),
88  'url_key'=> $associatedProduct->getUrlKey(),
89  'name' => $associatedProduct->getName()
90 
91  ]
92  );
93  }
94  }
95 }
$response
Definition: 404.php:11
assertResponseFields($actualResponse, $assertionMap)
taxRateField this edit on("click.mselect-delete", ".mselect-delete", function() { if(!confirm('<?=/*@escapeNotVerified */__( 'Do you really want to delete this tax rate?') ?>')) { return;} var that=$(this), select=that.closest('.mselect-list').prev(), rateValue=that.parent().find( 'input[type="checkbox"]').val();$( 'body').trigger( 'processStart');var ajaxOptions={ type:'POST', data:{ tax_calculation_rate_id:rateValue, form_key:$( 'input[name="form_key"]').val() }, dataType:'json', url:'<?=/*@escapeNotVerified */$block->getTaxRateDeleteUrl() ?>', success:function(result, status) { $( 'body').trigger( 'processStop');if(result.success) { that.parent().remove();select.find( 'option').each(function() { if(this.value===rateValue) { $(this).remove();} });select.trigger( 'change.hiddenSelect');} else { if(result.error_message) alert({ content:result.error_message });else alert({ content:'<?=/*@escapeNotVerified */__( 'An error occurred') ?>' });} }, error:function() { $( 'body').trigger( 'processStop');alert({ content:'<?=/*@escapeNotVerified */__( 'An error occurred') ?>' });} };$.ajax(ajaxOptions);}) .on( 'click.mselectAdd'
Definition: edit.phtml:164
graphQlQuery(string $query, array $variables=[], string $operationName='', array $headers=[])