9 use Magento\Catalog\Test\Page\Product\CatalogProductView;
10 use Magento\Mtf\Client\BrowserInterface;
12 use Magento\Mtf\Fixture\FixtureInterface;
33 'Select/Drop-down' => [
41 'Select/Radio Buttons' => [
45 'Select/Checkbox' => [
49 'Select/Multiple Select' => [
57 'Date/Date & Time' => [
83 CatalogProductView $catalogProductView,
85 BrowserInterface $browser
87 $browser->open($_ENV[
'app_frontend_url'] .
$product->getUrlKey() .
'.html');
90 $priceBlock = $catalogProductView->getViewBlock()->getPriceBlock();
91 $specialPrice = $priceBlock->getSpecialPrice();
92 $price = $priceBlock->getPrice();
93 $actualPrice = $specialPrice ? $specialPrice :
$price;
95 $fixtureCustomOptions = $this->
prepareOptions($product, $actualPrice);
96 $formCustomOptions = $catalogProductView->getViewBlock()->getOptions(
$product)[
'custom_options'];
97 $error = $this->
verifyData($fixtureCustomOptions, $formCustomOptions);
98 \PHPUnit\Framework\Assert::assertEmpty($error, $error);
112 ?
$product->getDataFieldConfig(
'custom_options')[
'source']->getCustomOptions()
114 $actualPrice = $actualPrice ?:
$product->getPrice();
130 protected function verifyData(array $fixtureData, array $formData, $isStrict =
false, $isPrepareError =
true)
133 foreach ($fixtureData as $key =>
$value) {
134 if (in_array($key, $this->skippedFields,
true)) {
137 $formValue = isset($formData[$key]) ? $formData[$key] :
null;
140 return $this->prepareErrorsForOutput($fixtureData, $formData, $isStrict, $isPrepareError,
$errors);
151 private function checkNotEqualValuesErrors(
$value, $formValue, $key)
157 if ((
int)
$value === (
int)$formValue + 1) {
163 if (is_array($formValue)) {
166 return sprintf(
'- %s: "%s" instead of "%s"', $key, $formValue,
$value);
179 private function prepareErrorsForOutput(array $fixtureData, array $formData, $isStrict, $isPrepareError,
$errors)
182 $diffData = array_diff(array_keys($formData), array_keys($fixtureData));
184 $errors[] =
'- fields ' . implode(
', ', $diffData) .
' is absent in fixture';
187 if ($isPrepareError) {
202 private function verifyDataForErrors($formValue, $key,
$errors,
$value)
204 if (is_numeric($formValue)) {
205 $formValue = (float)$formValue;
207 if (
null === $formValue) {
208 $errors[] =
'- field "' . $key .
'" is absent in form';
211 if (!empty($valueErrors)) {
215 $notEqualValuesErrors = $this->checkNotEqualValuesErrors(
$value, $formValue, $key);
216 if ($notEqualValuesErrors) {
217 $errors[] = $notEqualValuesErrors;
231 $skippedField = isset($this->skippedFieldOptions[
$customOption[
'type']])
236 if (
'Percent' ==
$option[
'price_type']) {
254 return 'Value of custom option on the page is correct.';
prepareOptions(FixtureInterface $product, $actualPrice=null)
elseif(isset( $params[ 'redirect_parent']))
verifyData(array $fixtureData, array $formData, $isStrict=false, $isPrepareError=true)
processAssert(CatalogProductView $catalogProductView, FixtureInterface $product, BrowserInterface $browser)