Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AssertDownloadableLinksData.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Catalog\Test\Page\Product\CatalogProductView;
10 use Magento\Downloadable\Test\Fixture\DownloadableProduct;
11 use Magento\Mtf\Client\BrowserInterface;
13 
20 {
21  /* tags */
22  const SEVERITY = 'low';
23  /* end tags */
24 
31  'title',
32  'downloadable',
33  ];
34 
40  protected $linkField = [
41  'title',
42  'links_purchased_separately',
43  'price',
44  ];
45 
54  public function processAssert(
55  CatalogProductView $catalogProductView,
56  DownloadableProduct $product,
57  BrowserInterface $browser
58  ) {
59  $browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html');
60 
61  $fixtureDownloadableLinks = $this->prepareFixtureData($product);
62  $pageOptions = $catalogProductView->getViewBlock()->getOptions($product);
63  $pageDownloadableLinks = $this->preparePageData($pageOptions['downloadable_options']['downloadable_links']);
64  $error = $this->verifyData($fixtureDownloadableLinks, $pageDownloadableLinks);
65  \PHPUnit\Framework\Assert::assertEmpty($error, $error);
66  }
67 
74  protected function prepareFixtureData(DownloadableProduct $product)
75  {
76  $data = $this->sortDataByPath($product->getDownloadableLinks(), 'downloadable/link::sort_order');
77 
78  foreach ($data['downloadable']['link'] as $key => $link) {
79  $link['links_purchased_separately'] = $data['links_purchased_separately'];
80  $link = array_intersect_key($link, array_flip($this->linkField));
81 
82  $data['downloadable']['link'][$key] = $link;
83  }
84  $data = array_intersect_key($data, array_flip($this->downloadableLinksField));
85 
86  return $data;
87  }
88 
95  protected function preparePageData(array $data)
96  {
97  foreach ($data['downloadable']['link'] as $key => $link) {
98  $link = array_intersect_key($link, array_flip($this->linkField));
99  $data['downloadable']['link'][$key] = $link;
100  }
101  $data = array_intersect_key($data, array_flip($this->downloadableLinksField));
102 
103  return $data;
104  }
105 
111  public function toString()
112  {
113  return 'Link block for downloadable product on front-end is visible.';
114  }
115 }
verifyData(array $fixtureData, array $formData, $isStrict=false, $isPrepareError=true)