Exemplo n.º 1
0
 /**
  * Assert that product is displayed in up-sell section
  *
  * @param BrowserInterface $browser
  * @param FixtureInterface $product
  * @param InjectableFixture[] $relatedProducts,
  * @param CatalogProductView $catalogProductView
  * @return void
  */
 public function processAssert(BrowserInterface $browser, FixtureInterface $product, array $relatedProducts, CatalogProductView $catalogProductView)
 {
     $browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html');
     foreach ($relatedProducts as $relatedProduct) {
         \PHPUnit_Framework_Assert::assertTrue($catalogProductView->getUpsellBlock()->isUpsellProductVisible($relatedProduct->getName()), 'Product \'' . $relatedProduct->getName() . '\' is absent in up-sells products.');
     }
 }
Exemplo n.º 2
0
 /**
  * Post request for creating simple product
  *
  * @param FixtureInterface $fixture [optional]
  * @return mixed|string
  * @throws \Exception
  *
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function persist(FixtureInterface $fixture = null)
 {
     $config = $fixture->getDataConfig();
     $prefix = isset($config['input_prefix']) ? $config['input_prefix'] : null;
     // @todo remove "if" when fixtures refactored
     if ($fixture instanceof InjectableFixture) {
         $fields = $fixture->getData();
         if ($prefix) {
             $data[$prefix] = $fields;
         } else {
             $data = $fields;
         }
     } else {
         $data = $this->_prepareData($fixture->getData('fields'), $prefix);
     }
     if ($fixture->getData('category_id')) {
         $data['product']['category_ids'] = $fixture->getCategoryIds();
     }
     $url = $this->_getUrl($config);
     $curl = new BackendDecorator(new CurlTransport(), new Config());
     $curl->addOption(CURLOPT_HEADER, 1);
     $curl->write(CurlInterface::POST, $url, '1.0', [], $data);
     $response = $curl->read();
     $curl->close();
     if (!strpos($response, 'data-ui-id="messages-message-success"')) {
         throw new \Exception("Product creation by curl handler was not successful! Response: {$response}");
     }
     preg_match("~Location: [^\\s]*\\/id\\/(\\d+)~", $response, $matches);
     return isset($matches[1]) ? $matches[1] : null;
 }
Exemplo n.º 3
0
 /**
  * Curl creation of Admin User Role
  *
  * @param FixtureInterface $fixture
  * @return array|mixed
  * @throws \Exception
  *
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function persist(FixtureInterface $fixture = null)
 {
     $data = $fixture->getData();
     $data['all'] = $data['resource_access'] == 'All' ? 1 : 0;
     if (isset($data['roles_resources'])) {
         foreach ((array) $data['roles_resources'] as $resource) {
             $data['resource'][] = $resource;
         }
     }
     unset($data['roles_resources']);
     $data['gws_is_all'] = isset($data['gws_is_all']) ? $data['gws_is_all'] : '1';
     if ($fixture->hasData('in_role_user')) {
         $adminUsers = $fixture->getDataFieldConfig('in_role_user')['source']->getAdminUsers();
         $userIds = [];
         foreach ($adminUsers as $adminUser) {
             $userIds[] = $adminUser->getUserId() . "=true";
         }
         $data['in_role_user'] = implode('&', $userIds);
     }
     $url = $_ENV['app_backend_url'] . 'admin/user_role/saverole/active_tab/info/';
     $curl = new BackendDecorator(new CurlTransport(), new Config());
     $curl->addOption(CURLOPT_HEADER, 1);
     $curl->write(CurlInterface::POST, $url, '1.0', [], $data);
     $response = $curl->read();
     $curl->close();
     if (!strpos($response, 'data-ui-id="messages-message-success"')) {
         throw new \Exception("Role creating by curl handler was not successful! Response: {$response}");
     }
     $url = 'admin/user_role/roleGrid/sort/role_id/dir/desc/';
     $regExpPattern = '/class=\\"\\scol\\-id col\\-role_id\\W*>\\W+(\\d+)\\W+<\\/td>\\W+<td[\\w\\s\\"=\\-]*?>\\W+?' . $data['rolename'] . '/siu';
     $extractor = new Extractor($url, $regExpPattern);
     return ['role_id' => $extractor->getData()[1]];
 }
 /**
  * Get grouped price with fixture product and product page
  *
  * @param View $view
  * @param FixtureInterface $product
  * @return array
  */
 protected function getGroupedPrice(View $view, FixtureInterface $product)
 {
     $fields = $product->getData();
     $groupPrice['onPage'] = $view->getPriceBlock()->getSpecialPrice();
     $groupPrice['fixture'] = number_format($fields['group_price'][array_search($this->customerGroup, $fields['group_price'])]['price'], 2);
     return $groupPrice;
 }
Exemplo n.º 5
0
 /**
  * Prepare data from text to values
  *
  * @param FixtureInterface $fixture
  * @return array
  */
 protected function prepareData(FixtureInterface $fixture)
 {
     $data = ['store' => $this->replaceMappingData($fixture->getData()), 'store_action' => 'add', 'store_type' => 'store'];
     $data['store']['group_id'] = $fixture->getDataFieldConfig('group_id')['source']->getStoreGroup()->getGroupId();
     $data['store']['store_id'] = isset($data['store']['store_id']) ? $data['store']['store_id'] : '';
     return $data;
 }
Exemplo n.º 6
0
 /**
  * Fill the customer data
  *
  * @param FixtureInterface $customer
  * @param SimpleElement|null $element
  * @return $this
  */
 public function fill(FixtureInterface $customer, SimpleElement $element = null)
 {
     /** @var Customer $customer */
     if ($customer->hasData()) {
         return parent::fill($customer, $element);
     }
 }
 /**
  * Prepare filter for assert.
  *
  * @param FixtureInterface $product
  * @param array $review
  * @param string $gridStatus [optional]
  * @return array
  *
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function prepareFilter(FixtureInterface $product, array $review, $gridStatus = '')
 {
     $filter = [];
     foreach ($this->filter as $key => $item) {
         list($type, $param) = [$key, $item];
         if (is_numeric($key)) {
             $type = $param = $item;
         }
         switch ($param) {
             case 'name':
             case 'sku':
                 $value = $product->getData($param);
                 break;
             case 'select_stores':
                 $value = isset($review[$param]) ? $review[$param][0] : null;
                 break;
             case 'status_id':
                 $value = $gridStatus != '' ? $gridStatus : (isset($review[$param]) ? $review[$param] : null);
                 break;
             case 'type':
                 $value = isset($review[$param]) ? $review[$param] : 'Administrator';
                 break;
             default:
                 $value = isset($review[$param]) ? $review[$param] : null;
                 break;
         }
         if ($value !== null) {
             $filter += [$type => $value];
         }
     }
     return $filter;
 }
Exemplo n.º 8
0
 /**
  * Prepare data for POST request.
  *
  * @param FixtureInterface $fixture
  * @return array
  */
 protected function prepareData(FixtureInterface $fixture)
 {
     $result = [];
     $data = $fixture->getData();
     $result['rate'][$data['currency_from']][$data['currency_to']] = $data['rate'];
     return $result;
 }
Exemplo n.º 9
0
 /**
  * Fill the root form.
  *
  * @param FixtureInterface $fixture
  * @param SimpleElement|null $element
  * @param array|null $mapping
  * @return $this
  */
 public function fill(FixtureInterface $fixture, SimpleElement $element = null, array $mapping = null)
 {
     $attribute = $fixture->getDataFieldConfig('custom_attribute')['source']->getAttribute();
     $mapping['custom_attribute']['selector'] = sprintf($this->inputSelector, $attribute->getAttributeCode());
     $this->_fill($mapping, $element);
     return $this;
 }
Exemplo n.º 10
0
 /**
  * Preparing matrix data
  *
  * @param FixtureInterface $product
  * @return array
  */
 protected function prepareVariationsMatrix(FixtureInterface $product)
 {
     /** @var ConfigurableAttributesData $configurableAttributesData */
     $configurableAttributesData = $product->getDataFieldConfig('configurable_attributes_data')['source'];
     $attributesData = $configurableAttributesData->getAttributesData();
     $assignedProducts = $configurableAttributesData->getProducts();
     $matrixData = $product->getConfigurableAttributesData()['matrix'];
     $result = [];
     foreach ($matrixData as $variationKey => $variation) {
         // For assigned products doesn't send data about them
         if (isset($assignedProducts[$variationKey])) {
             continue;
         }
         $compositeKeys = explode(' ', $variationKey);
         $keyIds = [];
         $configurableAttribute = [];
         foreach ($compositeKeys as $compositeKey) {
             list($attributeKey, $optionKey) = explode(':', $compositeKey);
             $attribute = $attributesData[$attributeKey];
             $keyIds[] = $attribute['options'][$optionKey]['id'];
             $configurableAttribute[] = sprintf('"%s":"%s"', $attribute['attribute_code'], $attribute['options'][$optionKey]['id']);
         }
         $keyIds = implode('-', $keyIds);
         $variation['configurable_attribute'] = '{' . implode(',', $configurableAttribute) . '}';
         $result[$keyIds] = $variation;
     }
     return $result;
 }
Exemplo n.º 11
0
 /**
  * Get data of the tabs.
  *
  * @param FixtureInterface|null $fixture
  * @param Element|null $element
  * @return array
  *
  * @SuppressWarnings(PHPMD.UnusedLocalVariable)
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function getData(FixtureInterface $fixture = null, Element $element = null)
 {
     $data = [];
     if (null === $fixture) {
         foreach ($this->tabs as $tabName => $tab) {
             $this->openTab($tabName);
             $tabData = $this->getTabElement($tabName)->getDataFormTab();
             $data = array_merge($data, $tabData);
         }
     } else {
         $tabsFields = $fixture->hasData() ? $this->getFieldsByTabs($fixture) : [];
         $tabsFields['frontend_properties'] = array_merge_recursive($tabsFields['frontend_properties'], $tabsFields['settings']);
         unset($tabsFields['settings']);
         foreach ($tabsFields as $tabName => $fields) {
             $this->openTab($tabName);
             if (isset($fields['widgetOptions'])) {
                 unset($fields['widgetOptions']['value']['type_id']);
                 $fields['widgetOptions'] = $fields['widgetOptions']['value'];
             } elseif (isset($fields['layout'])) {
                 $fields['layout'] = $fields['layout']['value'];
             }
             $tabData = $this->getTabElement($tabName)->getDataFormTab($fields, $this->_rootElement);
             $data = array_merge($data, $tabData);
         }
     }
     $data['type'] = $this->type[$data['type']];
     return $data;
 }
Exemplo n.º 12
0
 /**
  * Prepare and return data of review
  *
  * @param FixtureInterface $review
  * @return array
  */
 protected function getPreparedData(FixtureInterface $review)
 {
     $data = $review->getData();
     /* Prepare ratings */
     if ($review->hasData('ratings')) {
         $sourceRatings = $review->getDataFieldConfig('ratings')['source'];
         $ratings = [];
         foreach ($data['ratings'] as $rating) {
             $ratings[$rating['title']] = $rating['rating'];
         }
         $data['ratings'] = [];
         foreach ($sourceRatings->getRatings() as $ratingFixture) {
             /** @var Rating $ratingFixture */
             $ratingCode = $ratingFixture->getRatingCode();
             if (isset($ratings[$ratingCode])) {
                 $ratingOptions = $ratingFixture->getOptions();
                 $vote = $ratings[$ratingCode];
                 $data['ratings'][$ratingFixture->getRatingId()] = $ratingOptions[$vote];
             }
         }
     }
     if ($review->hasData('select_stores')) {
         foreach (array_keys($data['select_stores']) as $key) {
             if (isset($this->mappingData['select_stores'][$data['select_stores'][$key]])) {
                 $data['select_stores'][$key] = $this->mappingData['select_stores'][$data['select_stores'][$key]];
             }
         }
     }
     /* Prepare product id */
     $data['product_id'] = $data['entity_id'];
     unset($data['entity_id']);
     return $data;
 }
 /**
  * Prepare filter for assert
  *
  * @param FixtureInterface $product
  * @param Review $review
  * @param string $gridStatus
  * @return array
  */
 public function prepareFilter(FixtureInterface $product, Review $review, $gridStatus)
 {
     $filter = [];
     foreach ($this->filter as $key => $item) {
         list($type, $param) = [$key, $item];
         if (is_numeric($key)) {
             $type = $param = $item;
         }
         switch ($param) {
             case 'name':
             case 'sku':
                 $value = $product->getData($param);
                 break;
             case 'select_stores':
                 $value = $review->getData($param)[0];
                 break;
             case 'status_id':
                 $value = $gridStatus != '' ? $gridStatus : $review->getData($param);
                 break;
             default:
                 $value = $review->getData($param);
                 break;
         }
         if ($value !== null) {
             $filter += [$type => $value];
         }
     }
     return $filter;
 }
Exemplo n.º 14
0
 /**
  * Prepare data for curl.
  *
  * @param FixtureInterface $fixture
  * @return array
  */
 protected function prepareData(FixtureInterface $fixture)
 {
     $data = ['catalogevent' => $this->replaceMappingData($fixture->getData())];
     $data['catalogevent']['display_state'] = array_values($data['catalogevent']['display_state']);
     $categoryId = isset($data['catalogevent']['category_id']['id']) ? $data['catalogevent']['category_id']['id'] : $fixture->getDataFieldConfig('category_id')['source']->getCategory()->getId();
     return ['data' => $data, 'categoryId' => $categoryId];
 }
Exemplo n.º 15
0
 /**
  * Fill form with custom fields.
  * (for End To End Tests)
  *
  * @param FixtureInterface $fixture
  * @param array $fields
  * @param SimpleElement $element
  */
 public function fillCustom(FixtureInterface $fixture, array $fields, SimpleElement $element = null)
 {
     $data = $fixture->getData('fields');
     $dataForMapping = array_intersect_key($data, array_flip($fields));
     $mapping = $this->dataMapping($dataForMapping);
     $this->_fill($mapping, $element);
 }
Exemplo n.º 16
0
 /**
  * Fill the root form.
  *
  * @param FixtureInterface $fixture
  * @param SimpleElement|null $element
  * @return $this
  */
 public function fill(FixtureInterface $fixture, SimpleElement $element = null)
 {
     // Prepare price data
     $data = $fixture->getData();
     if (isset($data['price'])) {
         $data = array_merge($data, $data['price']);
         unset($data['price']);
     }
     // Mapping
     $mapping = $this->dataMapping($data);
     $attributeType = $attributeCode = '';
     if ($fixture->hasData('custom_attribute')) {
         /** @var CatalogProductAttribute $attribute */
         $attribute = $fixture->getDataFieldConfig('custom_attribute')['source']->getAttribute();
         $attributeType = $attribute->getFrontendInput();
         $attributeCode = $attribute->getAttributeCode();
     }
     if ($this->hasRender($attributeType)) {
         $element = $this->_rootElement->find(sprintf($this->customAttributeSelector, $attributeCode));
         $arguments = ['fixture' => $fixture, 'element' => $element, 'mapping' => $mapping];
         $this->callRender($attributeType, 'fill', $arguments);
     } else {
         $this->_fill($mapping, $element);
     }
     return $this;
 }
Exemplo n.º 17
0
 /**
  * Fill the root form.
  *
  * @param FixtureInterface $review
  * @param SimpleElement|null $element
  * @return $this
  */
 public function fill(FixtureInterface $review, SimpleElement $element = null)
 {
     if ($review->hasData('ratings')) {
         $this->fillRatings($review);
     }
     return parent::fill($review, $element);
 }
Exemplo n.º 18
0
 /**
  * Prepare data from text to values
  *
  * @param FixtureInterface $fixture
  * @return array
  */
 protected function prepareData($fixture)
 {
     $data = $this->replaceMappingData($fixture->getData());
     if (isset($data['website_ids'])) {
         $websiteIds = [];
         foreach ($data['website_ids'] as $websiteId) {
             $websiteIds[] = isset($this->websiteIds[$websiteId]) ? $this->websiteIds[$websiteId] : $websiteId;
         }
         $data['website_ids'] = $websiteIds;
     }
     if (isset($data['customer_group_ids'])) {
         $customerGroupIds = [];
         foreach ($data['customer_group_ids'] as $customerGroupId) {
             $customerGroupIds[] = isset($this->customerGroupIds[$customerGroupId]) ? $this->customerGroupIds[$customerGroupId] : $customerGroupId;
         }
         $data['customer_group_ids'] = $customerGroupIds;
     }
     if (!isset($data['stop_rules_processing'])) {
         $data['stop_rules_processing'] = 0;
     }
     if (!isset($data['rule'])) {
         $data['rule'] = null;
     }
     $data['rule'] = ['conditions' => $this->prepareCondition($data['rule'])];
     return $data;
 }
Exemplo n.º 19
0
 /**
  * Post request for creating sales rule.
  *
  * @param FixtureInterface $fixture
  * @return array
  * @throws \Exception
  */
 public function persist(FixtureInterface $fixture = null)
 {
     $this->mapTypeParams = array_merge($this->mapTypeParams, $this->additionalMapTypeParams);
     $url = $_ENV['app_backend_url'] . 'sales_rule/promo_quote/save/';
     $data = $this->replaceMappingData($fixture->getData());
     $data['rule'] = [];
     if (isset($data['conditions_serialized'])) {
         $data['rule']['conditions'] = $this->prepareCondition($data['conditions_serialized']);
         unset($data['conditions_serialized']);
     }
     $data['website_ids'] = $this->prepareWebsites($data);
     $data['customer_group_ids'] = $this->prepareCustomerGroup($data);
     if (isset($data['actions_serialized'])) {
         $this->mapTypeParams['Conditions combination']['type'] = 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product\\Combine';
         $data['rule']['actions'] = $this->prepareCondition($data['actions_serialized']);
         unset($data['actions_serialized']);
     }
     $curl = new BackendDecorator(new CurlTransport(), $this->_configuration);
     $curl->write(CurlInterface::POST, $url, '1.0', [], $data);
     $response = $curl->read();
     $curl->close();
     if (!strpos($response, 'data-ui-id="messages-message-success"')) {
         throw new \Exception("Sales rule entity creating by curl handler was not successful! Response: {$response}");
     }
     preg_match('`<tr.*title=".*sales_rule\\/promo_quote\\/edit\\/id\\/([\\d]+)`ims', $response, $matches);
     if (empty($matches)) {
         throw new \Exception('Cannot find Sales Rule id');
     }
     return ['id' => $matches[1]];
 }
 /**
  * Assert that products are displayed in up-sell section.
  *
  * @param Browser $browser
  * @param FixtureInterface $product
  * @param array $upSellProducts
  * @param CatalogProductView $catalogProductView
  * @return void
  */
 public function processAssert(Browser $browser, FixtureInterface $product, array $upSellProducts, CatalogProductView $catalogProductView)
 {
     $browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html');
     foreach ($upSellProducts as $upSellProduct) {
         \PHPUnit_Framework_Assert::assertTrue($catalogProductView->getUpsellBlock()->getItemBlock($upSellProduct)->isVisible(), "Product {$upSellProduct->getName()} is absent in up-sells products.");
     }
 }
Exemplo n.º 21
0
 /**
  * Get configurable product options
  *
  * @param FixtureInterface|null $product [optional]
  * @return array
  * @throws \Exception
  */
 public function getOptions(FixtureInterface $product)
 {
     /** @var ConfigurableProduct $product */
     $attributesData = $product->hasData('configurable_attributes_data') ? $product->getConfigurableAttributesData()['attributes_data'] : [];
     $listOptions = $this->getListOptions();
     $result = [];
     foreach ($attributesData as $option) {
         $title = $option['label'];
         if (!isset($listOptions[$title])) {
             throw new \Exception("Can't find option: \"{$title}\"");
         }
         /** @var SimpleElement $optionElement */
         $optionElement = $listOptions[$title];
         $typeMethod = preg_replace('/[^a-zA-Z]/', '', $option['frontend_input']);
         $getTypeData = 'get' . ucfirst(strtolower($typeMethod)) . 'Data';
         $optionData = $this->{$getTypeData}($optionElement);
         $optionData['title'] = $title;
         $optionData['type'] = $option['frontend_input'];
         $optionData['is_require'] = $optionElement->find($this->required, Locator::SELECTOR_XPATH)->isVisible() ? 'Yes' : 'No';
         foreach ($optionData['options'] as $key => $value) {
             $optionData['options'][$key]['price'] = $this->getOptionPrice($title, $value['title']);
         }
         $result[$title] = $optionData;
     }
     return $result;
 }
Exemplo n.º 22
0
 /**
  * Get data of the tabs.
  *
  * @param FixtureInterface $fixture
  * @param SimpleElement $element
  * @return array
  * @throws \Exception
  *
  * @SuppressWarnings(PHPMD.UnusedLocalVariable)
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function getData(FixtureInterface $fixture = null, SimpleElement $element = null)
 {
     $this->waitForElementVisible($this->propertiesTab);
     $data = [];
     if (null === $fixture) {
         foreach ($this->tabs as $tabName => $tab) {
             if ($this->isTabVisible($tabName)) {
                 $this->openTab($tabName);
                 $this->expandAllToggles();
                 $tabData = $this->getTabElement($tabName)->getDataFormTab();
                 $data = array_merge($data, $tabData);
             }
         }
     } else {
         $isHasData = $fixture instanceof InjectableFixture ? $fixture->hasData() : true;
         $tabsFields = $isHasData ? $this->getFieldsByTabs($fixture) : [];
         foreach ($tabsFields as $tabName => $fields) {
             if ($this->isTabVisible($tabName)) {
                 $this->openTab($tabName);
                 $this->expandAllToggles();
                 $tabData = $this->getTabElement($tabName)->getDataFormTab($fields, $this->_rootElement);
                 $data = array_merge($data, $tabData);
             }
         }
     }
     return $data;
 }
Exemplo n.º 23
0
 /**
  * Assert that displayed product data on product page(front-end) equals passed from fixture:
  * 1. Product Name
  * 2. Price
  * 3. Special price
  * 4. SKU
  * 5. Description
  * 6. Short Description
  *
  * @param BrowserInterface $browser
  * @param CatalogProductView $catalogProductView
  * @param FixtureInterface $product
  * @return void
  */
 public function processAssert(BrowserInterface $browser, CatalogProductView $catalogProductView, FixtureInterface $product)
 {
     $browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html');
     $this->product = $product;
     $this->productView = $catalogProductView->getViewBlock();
     $errors = $this->verify();
     \PHPUnit_Framework_Assert::assertEmpty($errors, "\nFound the following errors:\n" . implode(" \n", $errors));
 }
Exemplo n.º 24
0
 /**
  * Fill currency rate form.
  *
  * @param FixtureInterface $fixture
  * @param SimpleElement|null $element
  * @return $this
  */
 public function fill(FixtureInterface $fixture, SimpleElement $element = null)
 {
     /** @var \Magento\Directory\Test\Fixture\CurrencyRate $fixture */
     $this->placeholders['currency_from'] = $fixture->getCurrencyFrom();
     $this->placeholders['currency_to'] = $fixture->getCurrencyTo();
     $this->applyPlaceholders();
     return parent::fill($fixture, $element);
 }
 /**
  * Verify product special price on product view page
  *
  * @param FixtureInterface $product
  * @param View $productViewBlock
  * @return void
  */
 public function assertPrice(FixtureInterface $product, View $productViewBlock)
 {
     $fields = $product->getData();
     $specialPrice = $productViewBlock->getPriceBlock()->getSpecialPrice();
     if (isset($fields['special_price'])) {
         \PHPUnit_Framework_Assert::assertEquals(number_format($fields['special_price'], 2), $specialPrice, $this->errorMessage);
     }
 }
 /**
  * Assertion that tier prices are displayed correctly
  *
  * @param BrowserInterface $browser
  * @param CatalogProductView $catalogProductView
  * @param FixtureInterface $product
  * @return void
  */
 public function processAssert(BrowserInterface $browser, CatalogProductView $catalogProductView, FixtureInterface $product)
 {
     //Open product view page
     $browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html');
     $viewBlock = $catalogProductView->getBundleViewBlock();
     $viewBlock->clickCustomize();
     //Process assertions
     $this->assertPrice($product, $viewBlock);
 }
Exemplo n.º 27
0
 /**
  * Prepare data for url rewrite fixture.
  *
  * @param FixtureInterface $fixture
  * @return array
  */
 protected function prepareData(FixtureInterface $fixture)
 {
     $data = $fixture->getData();
     if (empty($data['entity_type']) && empty($this->getData()['target_path']) && !isset($data['target_path'])) {
         $entity = $fixture->getDataFieldConfig('target_path')['source']->getEntity();
         $data['target_path'] = $entity->hasData('identifier') ? $entity->getIdentifier() : $entity->getUrlKey() . '.html';
     }
     return $data;
 }
Exemplo n.º 28
0
 /**
  * Prepare POST data for creating product request.
  *
  * @param FixtureInterface $fixture
  * @param string|null $prefix [optional]
  * @return array
  *
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 protected function prepareData(FixtureInterface $fixture, $prefix = null)
 {
     $fields = $this->replaceMappingData($fixture->getData());
     if (!isset($fields['status'])) {
         // Default product is enabled
         $fields['status'] = 1;
     }
     if (!isset($fields['visibility'])) {
         // Default product is visible on Catalog, Search
         $fields['visibility'] = 4;
     }
     // Getting Tax class id
     if ($fixture->hasData('tax_class_id')) {
         $fields['tax_class_id'] = $fixture->getDataFieldConfig('tax_class_id')['source']->getTaxClassId();
     }
     if (!empty($fields['category_ids'])) {
         $categoryIds = [];
         foreach ($fixture->getDataFieldConfig('category_ids')['source']->getCategories() as $category) {
             $categoryIds[] = $category->getId();
         }
         $fields['category_ids'] = $categoryIds;
     }
     if (isset($fields['tier_price'])) {
         $fields['tier_price'] = $this->preparePriceData($fields['tier_price']);
     }
     if (isset($fields['fpt'])) {
         $attributeLabel = $fixture->getDataFieldConfig('attribute_set_id')['source']->getAttributeSet()->getDataFieldConfig('assigned_attributes')['source']->getAttributes()[0]->getFrontendLabel();
         $fields[$attributeLabel] = $this->prepareFptData($fields['fpt']);
     }
     if ($isCustomOptions = isset($fields['custom_options'])) {
         $fields = $this->prepareCustomOptionsData($fields);
     }
     if (!empty($fields['website_ids'])) {
         foreach ($fields['website_ids'] as &$value) {
             $value = isset($this->mappingData['website_ids'][$value]) ? $this->mappingData['website_ids'][$value] : $value;
         }
     }
     // Getting Attribute Set id
     if ($fixture->hasData('attribute_set_id')) {
         $attributeSetId = $fixture->getDataFieldConfig('attribute_set_id')['source']->getAttributeSet()->getAttributeSetId();
         $fields['attribute_set_id'] = $attributeSetId;
     }
     // Prepare assigned attribute
     if (isset($fields['attributes'])) {
         $fields += $fields['attributes'];
         unset($fields['attributes']);
     }
     if (isset($fields['custom_attribute'])) {
         $fields[$fields['custom_attribute']['code']] = $fields['custom_attribute']['value'];
     }
     $fields = $this->prepareStockData($fields);
     $fields = $prefix ? [$prefix => $fields] : $fields;
     if ($isCustomOptions) {
         $fields['affect_product_custom_options'] = 1;
     }
     return $fields;
 }
 /**
  * Assert form data equals fixture data.
  *
  * @param FixtureInterface $product
  * @param CatalogProductIndex $productGrid
  * @param CatalogProductEdit $productPage
  * @return void
  */
 public function processAssert(FixtureInterface $product, CatalogProductIndex $productGrid, CatalogProductEdit $productPage)
 {
     $filter = ['sku' => $product->getSku() . '-1'];
     $productGrid->open()->getProductGrid()->searchAndOpen($filter);
     $formData = $productPage->getProductForm()->getData($product);
     $fixtureData = $this->prepareFixtureData($product->getData());
     $errors = $this->verifyData($fixtureData, $formData);
     \PHPUnit_Framework_Assert::assertEmpty($errors, $errors);
 }
Exemplo n.º 30
0
 /**
  * Get data of the tabs.
  *
  * @param FixtureInterface|null $fixture
  * @param Element|null $element
  * @return array
  */
 public function getData(FixtureInterface $fixture = null, Element $element = null)
 {
     $widgetType = $fixture->getWidgetOptions()['type_id'];
     if ($this->hasRender($widgetType)) {
         return $this->callRender($widgetType, 'getData', ['InjectableFixture' => $fixture, 'Element' => $element]);
     } else {
         return parent::getData($fixture, $element);
     }
 }