示例#1
0
文件: Curl.php 项目: aiesh/magento2
 /**
  * Post request for creating customer in frontend
  *
  * @param FixtureInterface|null $customer
  * @return array
  * @throws \Exception
  */
 public function persist(FixtureInterface $customer = null)
 {
     $address = [];
     $result = [];
     /** @var CustomerInjectable $customer */
     $url = $_ENV['app_frontend_url'] . 'customer/account/createpost/?nocookie=true';
     $data = $customer->getData();
     if ($customer->hasData('address')) {
         $address = $customer->getAddress();
         unset($data['address']);
     }
     $curl = new CurlTransport();
     $curl->write(CurlInterface::POST, $url, '1.0', [], $data);
     $response = $curl->read();
     $curl->close();
     if (!strpos($response, 'data-ui-id="global-messages-message-success"')) {
         throw new \Exception("Customer entity creating  by curl handler was not successful! Response: {$response}");
     }
     $result['id'] = $this->getCustomerId($customer->getEmail());
     $data['customer_id'] = $result['id'];
     if (!empty($address)) {
         $data['address'] = $address;
         $this->addAddress($data);
     }
     return $result;
 }
 /**
  * Prepare filter for assert
  *
  * @param FixtureInterface $product
  * @param ReviewInjectable $review
  * @param string $gridStatus
  * @return array
  */
 public function prepareFilter(FixtureInterface $product, ReviewInjectable $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;
 }
示例#3
0
文件: Curl.php 项目: aiesh/magento2
 /**
  * Prepare data from text to values
  *
  * @param FixtureInterface $fixture
  * @return array
  */
 protected function prepareData(FixtureInterface $fixture)
 {
     $data['store'] = $this->replaceMappingData($fixture->getData());
     $data['store_action'] = isset($data['store_action']) ? $data['store_action'] : 'add';
     $data['store_type'] = isset($data['store_type']) ? $data['store_type'] : 'store';
     return $data;
 }
 /**
  * Get configurable product options
  *
  * @param FixtureInterface|null $product [optional]
  * @return array
  * @throws \Exception
  */
 public function getOptions(FixtureInterface $product)
 {
     if ($product instanceof InjectableFixture) {
         /** @var ConfigurableProductInjectable $product */
         $attributesData = $product->hasData('configurable_attributes_data') ? $product->getConfigurableAttributesData()['attributes_data'] : [];
     } else {
         /** @var ConfigurableProduct $product */
         $attributesData = $product->getConfigurableAttributes();
         foreach ($attributesData as $key => $attributeData) {
             $attributeData['label'] = $attributeData['label']['value'];
             $attributeData['frontend_input'] = 'dropdown';
             $attributesData[$key] = $attributeData;
         }
     }
     $listOptions = $this->getListOptions();
     $result = [];
     foreach ($attributesData as $option) {
         $title = $option['label'];
         if (!isset($listOptions[$title])) {
             throw new \Exception("Can't find option: \"{$title}\"");
         }
         /** @var Element $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';
         $result[$title] = $optionData;
     }
     return $result;
 }
 /**
  * Get grouped price with fixture product and product page
  *
  * @param View $view
  * @param FixtureInterface $product
  * @return array
  */
 protected function getGroupedPrice(View $view, FixtureInterface $product)
 {
     $groupPrice['onPage'] = $view->getProductPrice();
     $groupPrice['onPage'] = isset($groupPrice['onPage']['price_regular_price']) ? str_replace('As low as $', '', $groupPrice['onPage']['price_regular_price']) : str_replace('$', '', $groupPrice['onPage']['price_from']);
     $groupPrice['fixture'] = $product->getDataFieldConfig('price')['source']->getPreset()['price_from'];
     return $groupPrice;
 }
示例#6
0
文件: Curl.php 项目: aiesh/magento2
 /**
  * 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;
 }
示例#7
0
 /**
  * Post request for creating Subcategory
  *
  * @param FixtureInterface $fixture [optional]
  * @return mixed|string
  */
 public function persist(FixtureInterface $fixture = null)
 {
     $data['general'] = $fixture->getData();
     foreach ($data['general'] as $key => $value) {
         if ($value == 'Yes') {
             $data['general'][$key] = 1;
         }
         if ($value == 'No') {
             $data['general'][$key] = 0;
         }
     }
     $diff = array_diff($this->dataUseConfig, array_keys($data['general']));
     if (!empty($diff)) {
         $data['use_config'] = $diff;
     }
     $parentCategoryId = $data['general']['parent_id'];
     $url = $_ENV['app_backend_url'] . 'catalog/category/save/store/0/parent/' . $parentCategoryId . '/';
     $curl = new BackendDecorator(new CurlTransport(), new Config());
     $curl->write(CurlInterface::POST, $url, '1.0', array(), $data);
     $response = $curl->read();
     $curl->close();
     preg_match('#http://.+/id/(\\d+).+store/#m', $response, $matches);
     $id = isset($matches[1]) ? $matches[1] : null;
     return ['id' => $id];
 }
示例#8
0
文件: Curl.php 项目: aiesh/magento2
 /**
  * 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 ($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]];
 }
 /**
  * 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 Browser $browser
  * @param CatalogProductView $catalogProductView
  * @param FixtureInterface $product
  * @return void
  */
 public function processAssert(Browser $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));
 }
 /**
  * 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->getData('sku')];
     $productGrid->open()->getProductGrid()->searchAndOpen($filter);
     $fields = $this->convertDownloadableArray($this->prepareFixtureData($product));
     $fieldsForm = $productPage->getForm()->getData($product);
     \PHPUnit_Framework_Assert::assertEquals($fields, $fieldsForm, 'Form data not equals fixture data.');
 }
示例#11
0
 /**
  * Page initialization
  *
  * @param FixtureInterface $fixture
  * @return void
  */
 public function init(FixtureInterface $fixture)
 {
     $dataConfig = $fixture->getDataConfig();
     $params = isset($dataConfig['create_url_params']) ? $dataConfig['create_url_params'] : array();
     foreach ($params as $paramName => $paramValue) {
         $this->_url .= '/' . $paramName . '/' . $paramValue;
     }
 }
示例#12
0
 /**
  * Prepare data from text to values
  *
  * @param FixtureInterface $fixture
  * @return array
  */
 protected function prepareData(FixtureInterface $fixture)
 {
     $data['store'] = $this->replaceMappingData($fixture->getData());
     $data['store_action'] = isset($data['store_action']) ? $data['store_action'] : 'add';
     $data['store_type'] = isset($data['store_type']) ? $data['store_type'] : 'store';
     $data['store']['group_id'] = $fixture->getDataFieldConfig('group_id')['source']->getStoreGroup()->getGroupId();
     return $data;
 }
 /**
  * Verify product special price on product view page
  *
  * @param CatalogProductView $catalogProductView
  * @param FixtureInterface $product
  * @param string $block [optional]
  * @return void
  */
 public function assertPrice(FixtureInterface $product, CatalogProductView $catalogProductView, $block = '')
 {
     $fields = $product->getData();
     $specialPrice = $catalogProductView->getViewBlock()->getPriceBlock()->getSpecialPrice();
     if (isset($fields['special_price'])) {
         \PHPUnit_Framework_Assert::assertEquals(number_format($fields['special_price'], 2), $specialPrice, $this->errorMessage);
     }
 }
 /**
  * Create product
  *
  * @param FixtureInterface $fixture [optional]
  * @return mixed|string
  */
 public function persist(FixtureInterface $fixture = null)
 {
     Factory::getApp()->magentoBackendLoginUser();
     $createProductPage = Factory::getPageFactory()->getCatalogProductNew();
     $createProductPage->open(['type' => $fixture->getDataConfig()['create_url_params']['type'], 'set' => $fixture->getDataConfig()['create_url_params']['set']]);
     $createProductPage->getProductForm()->fill($fixture);
     $createProductPage->getFormPageActions()->save();
     $createProductPage->getMessagesBlock()->assertSuccessMessage();
 }
 /**
  * Assertion that tier prices are displayed correctly
  *
  * @param CatalogProductView $catalogProductView
  * @param FixtureInterface $product
  * @param Browser $browser
  * @return void
  */
 public function processAssert(CatalogProductView $catalogProductView, FixtureInterface $product, Browser $browser)
 {
     //Open product view page
     $browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html');
     $viewBlock = $catalogProductView->getViewBlock();
     $viewBlock->clickCustomize();
     //Process assertions
     $this->assertPrice($product, $catalogProductView);
 }
示例#16
0
 /**
  * Get data of Customer information, addresses on tabs.
  *
  * @param FixtureInterface $customer
  * @param FixtureInterface|FixtureInterface[]|null $address
  * @return array
  */
 public function getDataCustomer(FixtureInterface $customer, $address = null)
 {
     $data = ['customer' => $customer->hasData() ? parent::getData($customer) : parent::getData()];
     if (null !== $address) {
         $this->openTab('addresses');
         $data['addresses'] = $this->getTabElement('addresses')->getDataAddresses($address);
     }
     return $data;
 }
 /**
  * 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);
 }
 /**
  * Assert the product is not displayed on Compare Products page
  *
  * @param CatalogProductCompare $comparePage
  * @param FixtureInterface $product
  * @param int $countProducts [optional]
  * @return void
  */
 public function processAssert(CatalogProductCompare $comparePage, FixtureInterface $product, $countProducts = 0)
 {
     $comparePage->open();
     $compareBlock = $comparePage->getCompareProductsBlock();
     if ($countProducts > 1) {
         \PHPUnit_Framework_Assert::assertFalse($compareBlock->isProductVisibleInCompareBlock($product->getName()), 'The product displays on Compare Products page.');
     } else {
         \PHPUnit_Framework_Assert::assertEquals(self::SUCCESS_MESSAGE, $compareBlock->getEmptyMessage(), 'The product displays on Compare Products page.');
     }
 }
示例#19
0
 /**
  * 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()];
     $productGrid->open()->getProductGrid()->searchAndOpen($filter);
     $fieldsForm = $productPage->getForm()->getData($product);
     $fieldsFixture = $this->prepareFixtureData($product->getData());
     $fieldsFixture['associated'] = $this->prepareGroupedOptions($fieldsFixture['associated']);
     $errors = $this->verifyData($fieldsFixture, $fieldsForm);
     \PHPUnit_Framework_Assert::assertEmpty($errors, $errors);
 }
示例#20
0
 /**
  * Find cart item blocks for associated products
  *
  * @param FixtureInterface $product
  * @return array
  */
 protected function findCartItems(FixtureInterface $product)
 {
     $cartItems = [];
     /** @var GroupedProductInjectable $product */
     $associatedProducts = $product->getAssociated()['products'];
     foreach ($associatedProducts as $product) {
         $cartItems[$product->getSku()] = parent::getCartItem($product);
     }
     return $cartItems;
 }
示例#21
0
文件: Curl.php 项目: aiesh/magento2
 /**
  * Post request for creating tax class
  *
  * @param FixtureInterface $fixture [optional]
  * @return mixed|string
  */
 public function persist(FixtureInterface $fixture = null)
 {
     $data = $fixture->getData();
     $url = $_ENV['app_backend_url'] . 'tax/tax/ajaxSAve/?isAjax=true';
     $curl = new BackendDecorator(new CurlTransport(), new Config());
     $curl->write(CurlInterface::POST, $url, '1.0', array(), $data);
     $response = $curl->read();
     $curl->close();
     $id = $this->getClassId($response);
     return ['id' => $id];
 }
 /**
  * Assert the product is not displayed on Compare Products block on my account page
  *
  * @param CmsIndex $cmsIndex
  * @param CustomerAccountIndex $customerAccountIndex
  * @param int $countProducts [optional]
  * @param FixtureInterface $product [optional]
  * @return void
  */
 public function processAssert(CmsIndex $cmsIndex, CustomerAccountIndex $customerAccountIndex, $countProducts = 0, FixtureInterface $product = null)
 {
     $cmsIndex->open();
     $cmsIndex->getLinksBlock()->openLink("My Account");
     $compareBlock = $customerAccountIndex->getCompareProductsBlock();
     if ($countProducts > 1 && $product !== null) {
         \PHPUnit_Framework_Assert::assertFalse($compareBlock->isProductVisibleInCompareBlock($product->getName()), 'The product displays on Compare Products block on my account page.');
     } else {
         \PHPUnit_Framework_Assert::assertEquals(self::SUCCESS_MESSAGE, $compareBlock->getEmptyMessage(), 'The product displays on Compare Products block on my account page.');
     }
 }
示例#23
0
 /**
  * Fill popup form
  *
  * @param FixtureInterface $product
  * @param Element|null $element
  * @return $this
  */
 public function fill(FixtureInterface $product, Element $element = null)
 {
     $data = $product->getData('affect_configurable_product_attributes');
     if (!empty($data)) {
         $this->_rootElement->find($this->affectedAttributeSetNew)->click();
         $fields = ['new_attribute_set_name' => strval($data)];
         $mapping = $this->dataMapping($fields);
         $this->_fill($mapping, $element);
     }
     return $this;
 }
 /**
  * Assert that product is not visible in the assigned category
  *
  * @param CatalogCategoryView $catalogCategoryView
  * @param CmsIndex $cmsIndex
  * @param FixtureInterface $product
  * @param CatalogCategory|null $category
  * @return void
  */
 public function processAssert(CatalogCategoryView $catalogCategoryView, CmsIndex $cmsIndex, FixtureInterface $product, CatalogCategory $category = null)
 {
     $categoryName = $category ? $category->getName() : $product->getCategoryIds()[0];
     $cmsIndex->open();
     $cmsIndex->getTopmenu()->selectCategoryByName($categoryName);
     $isProductVisible = $catalogCategoryView->getListProductBlock()->isProductVisible($product->getName());
     while (!$isProductVisible && $catalogCategoryView->getBottomToolbar()->nextPage()) {
         $isProductVisible = $catalogCategoryView->getListProductBlock()->isProductVisible($product->getName());
     }
     \PHPUnit_Framework_Assert::assertFalse($isProductVisible, 'Product is exist on category page.');
 }
 /**
  * Fill popup form
  *
  * @param FixtureInterface $product
  * @param Element|null $element [optional]
  * @return $this
  */
 public function fill(FixtureInterface $product, Element $element = null)
 {
     $affectedAttributeSet = $product->getData('affected_attribute_set');
     if ($affectedAttributeSet) {
         $fields = ['new_attribute_set_name' => $affectedAttributeSet];
         $mapping = $this->dataMapping($fields);
         $this->_rootElement->find($this->affectedAttributeSetNew)->click();
         $this->_fill($mapping, $element);
     }
     return $this;
 }
示例#26
0
 /**
  * Prepare POST data for creating customer request
  *
  * @param FixtureInterface $fixture
  * @return array
  */
 protected function prepareData(FixtureInterface $fixture)
 {
     $data = $fixture->getData('fields');
     foreach ($data as $key => $values) {
         $value = $this->getValue($values);
         if (null === $value) {
             continue;
         }
         $data[$key] = $value;
     }
     return $data;
 }
示例#27
0
 /**
  * Post request for creating url rewrite
  *
  * @param FixtureInterface $fixture
  * @throws \Exception
  * @return mixed|void
  */
 public function persist(FixtureInterface $fixture = null)
 {
     $url = $_ENV['app_backend_url'] . $this->url . $fixture->getIdPath();
     $data = $this->replaceMappingData($fixture->getData());
     $curl = new BackendDecorator(new CurlTransport(), new Config());
     $curl->write(CurlInterface::POST, $url, '1.0', array(), $data);
     $response = $curl->read();
     if (!strpos($response, 'data-ui-id="messages-message-success"')) {
         throw new \Exception("Product creation by curl handler was not successful! Response: {$response}");
     }
     $curl->close();
 }
示例#28
0
 /**
  * Get cart item block
  *
  * @param FixtureInterface $product
  * @return \Magento\Checkout\Test\Block\Cart\CartItem
  */
 public function getCartItem(FixtureInterface $product)
 {
     $dataConfig = $product->getDataConfig();
     $typeId = isset($dataConfig['type_id']) ? $dataConfig['type_id'] : null;
     $cartItem = null;
     if ($this->hasRender($typeId)) {
         $cartItem = $this->callRender($typeId, 'getCartItem', ['product' => $product]);
     } else {
         $cartItemBlock = $this->_rootElement->find(sprintf($this->cartItemByProductName, $product->getName()), Locator::SELECTOR_XPATH);
         $cartItem = $this->blockFactory->create('Magento\\Checkout\\Test\\Block\\Cart\\CartItem', ['element' => $cartItemBlock]);
     }
     return $cartItem;
 }
示例#29
0
 /**
  * Execute handler
  *
  * @param FixtureInterface $fixture [optional]
  * @return mixed
  */
 public function persist(FixtureInterface $fixture = null)
 {
     /** @var \Magento\Customer\Test\Fixture\Address $fixture */
     // Pages
     $loginPage = Factory::getPageFactory()->getCustomerAccountLogin();
     $addressPage = Factory::getPageFactory()->getCustomerAddressEdit();
     $loginPage->open();
     if ($loginPage->getLoginBlock()->isVisible()) {
         $loginPage->getLoginBlock()->login($fixture->getCustomer());
     }
     $addressPage->open();
     $addressPage->getEditForm()->editCustomerAddress($fixture);
 }
示例#30
0
 /**
  * Post request for creating customer
  *
  * @param FixtureInterface $fixture [optional]
  * @return mixed|string
  */
 public function persist(FixtureInterface $fixture = null)
 {
     $data = $fixture->getData('fields');
     $fields = array();
     foreach ($data as $key => $field) {
         $fields[$key] = $field['value'];
     }
     $url = $_ENV['app_frontend_url'] . 'customer/account/createpost/?nocookie=true';
     $curl = new CurlTransport();
     $curl->write(CurlInterface::POST, $url, '1.0', array(), $fields);
     $response = $curl->read();
     $curl->close();
     return $response;
 }