/**
  * Update catalog price rule
  *
  * @param CatalogRule $catalogPriceRule
  * @param CatalogRule $catalogPriceRuleOriginal
  * @param string $saveAction
  * @return array
  */
 public function testUpdateCatalogPriceRule(CatalogRule $catalogPriceRule, CatalogRule $catalogPriceRuleOriginal, $saveAction)
 {
     // Preconditions
     $catalogPriceRuleOriginal->persist();
     //Prepare data
     $productSimple = $this->fixtureFactory->createByCode('catalogProductSimple', ['dataSet' => 'product_with_category']);
     if ($saveAction == 'saveAndApply') {
         /** @var CategoryIds $sourceCategories */
         $sourceCategories = $productSimple->getDataFieldConfig('category_ids')['source'];
         $replace = ['conditions' => ['conditions' => ['%category_1%' => $sourceCategories->getIds()[0]]]];
     } else {
         $replace = [];
     }
     $filter = ['name' => $catalogPriceRuleOriginal->getName(), 'rule_id' => $catalogPriceRuleOriginal->getId()];
     // Steps
     $this->catalogRuleIndex->open();
     $this->catalogRuleIndex->getCatalogRuleGrid()->searchAndOpen($filter);
     $this->catalogRuleNew->getEditForm()->fill($catalogPriceRule, null, $replace);
     $this->catalogRuleNew->getFormPageActions()->{$saveAction}();
     // Prepare data for tear down
     $this->catalogRules[] = $catalogPriceRule;
     // Create simple product with category
     $productSimple->persist();
     return ['products' => [$productSimple]];
 }
 /**
  * Delete Catalog Price Rule test
  *
  * @param CatalogRule $catalogPriceRule
  * @return void
  */
 public function testDeleteCatalogPriceRule(CatalogRule $catalogPriceRule)
 {
     // Precondition
     $catalogPriceRule->persist();
     $filter = ['name' => $catalogPriceRule->getName(), 'rule_id' => $catalogPriceRule->getId()];
     // Steps
     $this->catalogRuleIndex->open();
     $this->catalogRuleIndex->getCatalogRuleGrid()->searchAndOpen($filter);
     $this->catalogRuleNew->getFormPageActions()->delete();
 }
 /**
  * Assert that displayed Catalog Price Rule data on edit page equals passed from fixture.
  *
  * @param CatalogRule $catalogPriceRule
  * @param CatalogRuleIndex $pageCatalogRuleIndex
  * @param CatalogRuleNew $pageCatalogRuleNew
  * @param CatalogRule $catalogPriceRuleOriginal
  * @return void
  */
 public function processAssert(CatalogRule $catalogPriceRule, CatalogRuleIndex $pageCatalogRuleIndex, CatalogRuleNew $pageCatalogRuleNew, CatalogRule $catalogPriceRuleOriginal = null)
 {
     $data = $catalogPriceRuleOriginal === null ? $catalogPriceRule->getData() : array_merge($catalogPriceRuleOriginal->getData(), $catalogPriceRule->getData());
     $filter['name'] = $data['name'];
     $pageCatalogRuleIndex->open();
     $pageCatalogRuleIndex->getCatalogRuleGrid()->searchAndOpen($filter);
     $formData = $pageCatalogRuleNew->getEditForm()->getData($catalogPriceRule);
     $fixtureData = $catalogPriceRule->getData();
     //convert discount_amount to float to compare
     if (isset($formData['discount_amount'])) {
         $formData['discount_amount'] = floatval($formData['discount_amount']);
     }
     if (isset($fixtureData['discount_amount'])) {
         $fixtureData['discount_amount'] = floatval($fixtureData['discount_amount']);
     }
     $diff = $this->verifyData($formData, $fixtureData);
     \PHPUnit_Framework_Assert::assertTrue(empty($diff), implode(' ', $diff));
 }
 /**
  * Assert that data in grid on Catalog Price Rules page according to fixture
  *
  * @param CatalogRule $catalogPriceRule
  * @param CatalogRuleIndex $pageCatalogRuleIndex
  * @param CatalogRule $catalogPriceRuleOriginal
  * @return void
  */
 public function processAssert(CatalogRule $catalogPriceRule, CatalogRuleIndex $pageCatalogRuleIndex, CatalogRule $catalogPriceRuleOriginal = null)
 {
     $data = $catalogPriceRuleOriginal === null ? $catalogPriceRule->getData() : array_merge($catalogPriceRuleOriginal->getData(), $catalogPriceRule->getData());
     $filter = ['name' => $data['name'], 'is_active' => $data['is_active']];
     //add ruleWebsite to filter if there is one
     if ($catalogPriceRule->getWebsiteIds() != null) {
         $ruleWebsite = $catalogPriceRule->getWebsiteIds();
         $ruleWebsite = is_array($ruleWebsite) ? reset($ruleWebsite) : $ruleWebsite;
         $filter['rule_website'] = $ruleWebsite;
     }
     //add from_date & to_date to filter if there are ones
     if (isset($data['from_date']) && isset($data['to_date'])) {
         $dateArray['from_date'] = date("M j, Y", strtotime($catalogPriceRule->getFromDate()));
         $dateArray['to_date'] = date("M j, Y", strtotime($catalogPriceRule->getToDate()));
         $filter = array_merge($filter, $dateArray);
     }
     $pageCatalogRuleIndex->open();
     $errorMessage = implode(', ', $filter);
     \PHPUnit_Framework_Assert::assertTrue($pageCatalogRuleIndex->getCatalogRuleGrid()->isRowVisible($filter), 'Catalog Price Rule with following data: \'' . $errorMessage . '\' ' . 'is absent in Catalog Price Rule grid.');
 }
 /**
  * Test product prices with tax.
  *
  * @param CatalogProductSimple $product
  * @param string $configData
  * @param SalesRule $salesRule [optional]
  * @param CatalogRule $catalogRule [optional]
  * @return void
  */
 public function test(CatalogProductSimple $product, $configData, SalesRule $salesRule = null, CatalogRule $catalogRule = null)
 {
     //Preconditions
     if ($salesRule !== null) {
         $salesRule->persist();
         $this->salesRule = $salesRule;
     }
     if ($catalogRule !== null) {
         $catalogRule->persist();
         $this->catalogRule = $catalogRule;
     }
     $this->objectManager->create('Magento\\Config\\Test\\TestStep\\SetupConfigurationStep', ['configData' => $configData])->run();
     $product->persist();
 }
 /**
  * Assert that Catalog Price Rule is not presented in grid and cannot be found using ID, Rule name
  *
  * @param CatalogRule $catalogPriceRule
  * @param CatalogRuleIndex $pageCatalogRuleIndex
  * @return void
  */
 public function processAssert(CatalogRule $catalogPriceRule, CatalogRuleIndex $pageCatalogRuleIndex)
 {
     $filter = ['rule_id' => $catalogPriceRule->getId(), 'name' => $catalogPriceRule->getName()];
     $pageCatalogRuleIndex->open();
     \PHPUnit_Framework_Assert::assertFalse($pageCatalogRuleIndex->getCatalogRuleGrid()->isRowVisible($filter), 'Catalog Price Rule \'' . $filter['rule_id'] . '\', ' . 'with name \'' . $filter['name'] . '\', ' . 'is present in Catalog Price Rule grid.');
 }