Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AssertImagesAreVisibleOnProductPage.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Catalog\Test\Page\Product\CatalogProductView;
10 use Magento\Mtf\Client\BrowserInterface;
12 use Magento\Mtf\Fixture\FixtureInterface;
13 
19 {
25  protected $productView;
26 
32  protected $product;
33 
46  public function processAssert(
47  BrowserInterface $browser,
48  CatalogProductView $catalogProductView,
49  FixtureInterface $product
50  ) {
51  $browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html');
52 
53  $this->product = $product;
54  $this->productView = $catalogProductView->getViewBlock();
55 
56  $errors = $this->verify();
57  \PHPUnit\Framework\Assert::assertEmpty(
58  $errors,
59  "\nFound the following errors:\n" . implode(" \n", $errors)
60  );
61  }
62 
68  protected function verify()
69  {
70  $errors = [];
71 
72  $errors[] = $this->verifyGallery();
73  $errors[] = $this->verifyBaseImage();
74  $errors[] = $this->verifyFullImage();
75 
76  return array_filter($errors);
77  }
78 
84  protected function verifyGallery()
85  {
86  if ($this->productView->isGalleryVisible()) {
87  return null;
88  }
89 
90  return 'Gallery for product ' . $this->product->getName() . ' is not visible.';
91  }
92 
98  protected function verifyBaseImage()
99  {
100  if (!$this->productView->isBaseImageVisible()) {
101  return 'Base image for product ' . $this->product->getName() . ' is not visible.';
102  }
103 
104  if (!$this->isImageLoaded($this->productView->getBaseImageSource())) {
105  return 'Base image file is corrupted or does not exist for product ' . $this->product->getName();
106  }
107 
108  return null;
109  }
110 
116  protected function verifyFullImage()
117  {
118  // click base image to see full image
119  $this->productView->clickBaseImage();
120  if (!$this->productView->isFullImageVisible()) {
121  return 'Full image for product ' . $this->product->getName() . ' should be visible after click on base one';
122  }
123 
124  if (!$this->isImageLoaded($this->productView->getFullImageSource())) {
125  return 'Full image file is corrupted or does not exist for product ' . $this->product->getName();
126  }
127 
128  $this->productView->closeFullImage();
129 
130  return null;
131  }
132 
139  protected function isImageLoaded($src)
140  {
141  return (bool) file_get_contents($src, 0, null, 0, 1);
142  }
143 
149  public function toString()
150  {
151  return 'Product images on product view page are correct.';
152  }
153 }
processAssert(BrowserInterface $browser, CatalogProductView $catalogProductView, FixtureInterface $product)
$errors
Definition: overview.phtml:9