Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AssertDownloadableSamplesData.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 {
27  'title',
28  'downloadable',
29  ];
30 
36  protected $linkField = [
37  'title',
38  ];
39 
48  public function processAssert(
49  CatalogProductView $productView,
50  DownloadableProduct $product,
51  BrowserInterface $browser
52  ) {
53  $browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html');
54 
55  $fixtureSampleLinks = $this->prepareFixtureData($product);
56  $pageOptions = $productView->getViewBlock()->getOptions($product);
57  $pageSampleLinks = isset($pageOptions['downloadable_options']['downloadable_sample'])
58  ? $this->preparePageData($pageOptions['downloadable_options']['downloadable_sample'])
59  : [];
60  $error = $this->verifyData($fixtureSampleLinks, $pageSampleLinks);
61  \PHPUnit\Framework\Assert::assertEmpty($error, $error);
62  }
63 
70  protected function prepareFixtureData(DownloadableProduct $product)
71  {
72  $data = $this->sortDataByPath($product->getDownloadableSample(), 'downloadable/sample::sort_order');
73 
74  foreach ($data['downloadable']['sample'] as $key => $link) {
75  $link = array_intersect_key($link, array_flip($this->linkField));
76  $data['downloadable']['sample'][$key] = $link;
77  }
78  $data = array_intersect_key($data, array_flip($this->downloadableSampleField));
79 
80  return $data;
81  }
82 
89  protected function preparePageData(array $data)
90  {
91  foreach ($data['downloadable']['sample'] as $key => $link) {
92  $link = array_intersect_key($link, array_flip($this->linkField));
93  $data['downloadable']['sample'][$key] = $link;
94  }
95  $data = array_intersect_key($data, array_flip($this->downloadableSampleField));
96 
97  return $data;
98  }
99 
105  public function toString()
106  {
107  return 'Sample block for downloadable product on front-end is visible.';
108  }
109 }
verifyData(array $fixtureData, array $formData, $isStrict=false, $isPrepareError=true)
processAssert(CatalogProductView $productView, DownloadableProduct $product, BrowserInterface $browser)