From ebc27ff8d2e2487b5d0aaf8b53a33c246f4e4494 Mon Sep 17 00:00:00 2001
From: Andrew Boudnikov <andrei_boudnikov@epam.com>
Date: Tue, 10 Jan 2017 13:24:27 +0300
Subject: [PATCH] MTA-3987: Added use_default_price field to
 CatalogProductSimple fixture

- Added use_default_price field to CatalogProductSimple fixture
- Added use_default_price field to product form
- Modified LiselectstoreElement to work with context
- Modified date data source to work with magento timezone
- Added magento_timezone environment variable to phpunit.xml.dist
- Added price scope setting to the config data repository
---
 .../Client/Element/LiselectstoreElement.php   |  2 +-
 dev/tests/functional/phpunit.xml.dist         |  1 +
 .../Backend/Test/Fixture/Source/Date.php      | 29 +++++++++++++++++-
 .../Block/Adminhtml/Product/ProductForm.xml   |  4 +++
 .../Test/Fixture/CatalogProductSimple.xml     |  1 +
 .../Test/Repository/CatalogProductSimple.xml  | 30 +++++++++++++++++++
 .../Catalog/Test/Repository/ConfigData.xml    | 16 ++++++++++
 7 files changed, 81 insertions(+), 2 deletions(-)

diff --git a/dev/tests/functional/lib/Magento/Mtf/Client/Element/LiselectstoreElement.php b/dev/tests/functional/lib/Magento/Mtf/Client/Element/LiselectstoreElement.php
index 65985c017d0..1ef99365d95 100644
--- a/dev/tests/functional/lib/Magento/Mtf/Client/Element/LiselectstoreElement.php
+++ b/dev/tests/functional/lib/Magento/Mtf/Client/Element/LiselectstoreElement.php
@@ -74,7 +74,7 @@ class LiselectstoreElement extends SimpleElement
         }
         $optionSelector = './/' . implode($this->optionMaskFollowing, $optionSelector) . '/a';
 
-        $option = $this->driver->find($optionSelector, Locator::SELECTOR_XPATH);
+        $option = $this->context->find($optionSelector, Locator::SELECTOR_XPATH);
         if (!$option->isVisible()) {
             throw new \Exception('[' . implode('/', $value) . '] option is not visible in store switcher.');
         }
diff --git a/dev/tests/functional/phpunit.xml.dist b/dev/tests/functional/phpunit.xml.dist
index bcd8adec52e..afc68476ee4 100644
--- a/dev/tests/functional/phpunit.xml.dist
+++ b/dev/tests/functional/phpunit.xml.dist
@@ -39,6 +39,7 @@
         <env name="basedir" value="var/log" />
         <env name="credentials_file_path" value="./credentials.xml.dist" />
         <env name="mage_mode" value="developer" />
+        <env name="magento_timezone" value="America/Los_Angeles" />
     </php>
 
 </phpunit>
diff --git a/dev/tests/functional/tests/app/Magento/Backend/Test/Fixture/Source/Date.php b/dev/tests/functional/tests/app/Magento/Backend/Test/Fixture/Source/Date.php
index 9bc78a1416e..2d625e2a721 100644
--- a/dev/tests/functional/tests/app/Magento/Backend/Test/Fixture/Source/Date.php
+++ b/dev/tests/functional/tests/app/Magento/Backend/Test/Fixture/Source/Date.php
@@ -13,9 +13,17 @@ use Magento\Mtf\Fixture\DataSource;
  *
  * Data keys:
  *  - pattern (Format a local time/date with delta, e.g. 'm/d/Y -3 days' = current day - 3 days)
+ *  - apply_timezone (true if it is needed to apply timezone)
  */
 class Date extends DataSource
 {
+    /**
+     * Indicates whether timezone setting is applied or not.
+     *
+     * @var bool
+     */
+    private $isTimezoneApplied;
+
     /**
      * @constructor
      * @param array $params
@@ -35,7 +43,16 @@ class Date extends DataSource
             if (!$timestamp) {
                 throw new \Exception('Invalid date format for "' . $this->params['attribute_code'] . '" field');
             }
-            $date = date(str_replace($delta, '', $data['pattern']), $timestamp);
+            if (isset($data['apply_timezone']) && $data['apply_timezone'] === true) {
+                $date = new \DateTime();
+                $date->setTimestamp($timestamp);
+                $date->setTimezone(new \DateTimeZone($_ENV['magento_timezone']));
+                $date = $date->format(str_replace($delta, '', $data['pattern']));
+                $this->isTimezoneApplied = true;
+            } else {
+                $date = date(str_replace($delta, '', $data['pattern']), $timestamp);
+                $this->isTimezoneApplied = false;
+            }
             if (!$date) {
                 $date = date('m/d/Y');
             }
@@ -44,4 +61,14 @@ class Date extends DataSource
             $this->data = $data;
         }
     }
+
+    /**
+     * Verifies if timezone setting has been already applied.
+     *
+     * @return bool
+     */
+    public function isTimezoneApplied()
+    {
+        return $this->isTimezoneApplied;
+    }
 }
diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/ProductForm.xml b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/ProductForm.xml
index 2f0b248b800..ebab7cc83b2 100644
--- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/ProductForm.xml
+++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/ProductForm.xml
@@ -57,6 +57,10 @@
                 <selector>[name="use_default[name]"]</selector>
                 <input>checkbox</input>
             </use_default_name>
+            <use_default_price>
+                <selector>[name="use_default[price]"]</selector>
+                <input>checkbox</input>
+            </use_default_price>
         </fields>
     </product-details>
     <advanced-pricing>
diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/CatalogProductSimple.xml b/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/CatalogProductSimple.xml
index bb2c8bc6ead..8f73299d5f6 100644
--- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/CatalogProductSimple.xml
+++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/CatalogProductSimple.xml
@@ -48,6 +48,7 @@
         <field name="msrp_display_actual_price_type" is_required="0" />
         <field name="name" is_required="1" group="product-details" />
         <field name="use_default_name" group="product-details" />
+        <field name="use_default_price" group="product-details" />
         <field name="old_id" is_required="0" />
         <field name="options_container" is_required="0" />
         <field name="page_layout" is_required="0" />
diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/CatalogProductSimple.xml b/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/CatalogProductSimple.xml
index 79b00f58cd7..e9791de338b 100644
--- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/CatalogProductSimple.xml
+++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/CatalogProductSimple.xml
@@ -1799,5 +1799,35 @@
                 <item name="dataset" xsi:type="string">simple_order_default</item>
             </field>
         </dataset>
+
+        <dataset name="product_with_additional_website">
+            <field name="sku" xsi:type="string">simple_product_with_category_%isolation%</field>
+            <field name="name" xsi:type="string">Simple product with category %isolation%</field>
+            <field name="quantity_and_stock_status" xsi:type="array">
+                <item name="qty" xsi:type="string">777</item>
+                <item name="is_in_stock" xsi:type="string">In Stock</item>
+            </field>
+            <field name="product_has_weight" xsi:type="string">This item has weight</field>
+            <field name="weight" xsi:type="string">1</field>
+            <field name="attribute_set_id" xsi:type="array">
+                <item name="dataset" xsi:type="string">default</item>
+            </field>
+            <field name="price" xsi:type="array">
+                <item name="value" xsi:type="string">10</item>
+                <item name="dataset" xsi:type="string" />
+            </field>
+            <field name="category_ids" xsi:type="array">
+                <item name="dataset" xsi:type="string">default_subcategory</item>
+            </field>
+            <field name="website_ids" xsi:type="array">
+                <item name="0" xsi:type="array">
+                    <item name="dataset" xsi:type="string">default</item>
+                </item>
+                <item name="1" xsi:type="array">
+                    <item name="dataset" xsi:type="string">custom_store</item>
+                </item>
+            </field>
+            <field name="url_key" xsi:type="string">simple-product-%isolation%</field>
+        </dataset>
     </repository>
 </config>
diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/ConfigData.xml b/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/ConfigData.xml
index 308bff86926..28ea191568c 100644
--- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/ConfigData.xml
+++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/ConfigData.xml
@@ -45,5 +45,21 @@
                 <item name="inherit" xsi:type="number">1</item>
             </field>
         </dataset>
+        <dataset name="price_scope_website">
+            <field name="catalog/price/scope" xsi:type="array">
+                <item name="scope" xsi:type="string">default</item>
+                <item name="scope_id" xsi:type="number">0</item>
+                <item name="label" xsi:type="string">Website</item>
+                <item name="value" xsi:type="number">1</item>
+            </field>
+        </dataset>
+        <dataset name="price_scope_website_rollback">
+            <field name="catalog/price/scope" xsi:type="array">
+                <item name="scope" xsi:type="string">default</item>
+                <item name="scope_id" xsi:type="number">0</item>
+                <item name="label" xsi:type="string">Global</item>
+                <item name="value" xsi:type="number">0</item>
+            </field>
+        </dataset>
     </repository>
 </config>
-- 
GitLab