-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1014 from magento-epam/PR-7
[Epam] Extend functional test sprint 7 - MTO-147: [Variation] Display images for a configurable product on store front - MTO-139: [Test] Price for configurable product
- Loading branch information
Showing
19 changed files
with
897 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
...tests/app/Magento/ConfigurableProduct/Test/Constraint/AssertConfigurableProductImages.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\ConfigurableProduct\Test\Constraint; | ||
|
||
use Magento\Catalog\Test\Constraint\AssertProductPage; | ||
|
||
/** | ||
* Verify displayed images on product page are correct. | ||
*/ | ||
class AssertConfigurableProductImages extends AssertProductPage | ||
{ | ||
/** | ||
* Displayed images. | ||
* | ||
* @var array | ||
*/ | ||
private $displayedImages = []; | ||
|
||
/** | ||
* Verify displayed images on product page are correct. | ||
* | ||
* @return array | ||
*/ | ||
protected function verify() | ||
{ | ||
$errors = []; | ||
$errors[] = $this->verifyBaseImage(); | ||
$errors[] = $this->verifyOptionsImages(); | ||
|
||
return array_filter($errors); | ||
} | ||
|
||
/** | ||
* Verify correct base image is shown. | ||
* | ||
* @return null|string | ||
*/ | ||
private function verifyBaseImage() | ||
{ | ||
$message = null; | ||
$data = $this->product->getData(); | ||
|
||
$displayedImage = $this->productView->getBaseImageSource(); | ||
$this->displayedImages[] = $displayedImage; | ||
|
||
if ($this->areImagesDifferent($displayedImage, $data['image'][0]['file'])) { | ||
$message = 'Product image is not correct.'; | ||
} | ||
|
||
return $message; | ||
} | ||
|
||
/** | ||
* Verify displayed options images on product page are different. | ||
* | ||
* @return string|null | ||
*/ | ||
protected function verifyOptionsImages() | ||
{ | ||
$message = null; | ||
$configurableAttributes = $this->product->getData('configurable_attributes_data')['attributes_data']; | ||
$attribute = array_shift($configurableAttributes); | ||
$customOptions = []; | ||
|
||
foreach ($attribute['options'] as $option) { | ||
$customOptions[] = [ | ||
'type' => $attribute['frontend_input'], | ||
'title' => $attribute['frontend_label'], | ||
'value' => $option['label'] | ||
]; | ||
} | ||
|
||
foreach ($customOptions as $customOption) { | ||
$this->productView->getCustomOptionsBlock()->fillCustomOptions([$customOption]); | ||
$displayedImage = $this->productView->getBaseImageSource(); | ||
if (in_array($displayedImage, $this->displayedImages)) { | ||
$message = 'Option image is not correct.'; | ||
break; | ||
} | ||
|
||
$this->displayedImages[] = $displayedImage; | ||
} | ||
|
||
return $message; | ||
} | ||
|
||
/** | ||
* Compare images and return true if they are different. | ||
* | ||
* @param string $compared | ||
* @param string $toCompare | ||
* @return bool | ||
*/ | ||
private function areImagesDifferent($compared, $toCompare) | ||
{ | ||
preg_match('`/(\w*?)\.(\w*?)$`', $compared, $shownImage); | ||
preg_match('`/(\w*?)\.(\w*?)$`', $toCompare, $expectedImage); | ||
|
||
return strpos($shownImage[1], $expectedImage[1]) === false || $expectedImage[2] !== $shownImage[2]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.