/**
  * Delete Catalog Rule on backend.
  *
  * @return array
  */
 public function run()
 {
     $this->catalogRuleIndex->open();
     $this->catalogRuleIndex->getCatalogRuleGrid()->resetFilter();
     while ($this->catalogRuleIndex->getCatalogRuleGrid()->isFirstRowVisible()) {
         $this->catalogRuleIndex->getCatalogRuleGrid()->openFirstRow();
         $this->catalogRuleEdit->getFormPageActions()->delete();
     }
 }
 /**
  * Assert that displayed Catalog Price Rule data on edit page equals passed from fixture.
  *
  * @param CatalogRule $catalogPriceRule
  * @param CatalogRuleIndex $pageCatalogRuleIndex
  * @param CatalogRuleEdit $catalogRuleEdit
  * @return void
  */
 public function processAssert(CatalogRule $catalogPriceRule, CatalogRuleIndex $pageCatalogRuleIndex, CatalogRuleEdit $catalogRuleEdit)
 {
     $filter['name'] = $catalogPriceRule->getName();
     $pageCatalogRuleIndex->open();
     $pageCatalogRuleIndex->getCatalogRuleGrid()->searchAndOpen($filter);
     $formData = $this->prepareFormData($catalogRuleEdit->getEditForm()->getData($catalogPriceRule));
     $fixtureData = $this->prepareFixtureData($catalogPriceRule->getData());
     $diff = $this->verifyData($formData, $fixtureData);
     \PHPUnit_Framework_Assert::assertEmpty($diff, $diff);
 }
 /**
  * Delete Catalog Price Rule test.
  *
  * @param CatalogRule $catalogPriceRule
  * @return void
  */
 public function test(CatalogRule $catalogPriceRule)
 {
     // Precondition
     $catalogPriceRule->persist();
     $filter = ['name' => $catalogPriceRule->getName(), 'rule_id' => $catalogPriceRule->getId()];
     // Steps
     $this->catalogRuleIndex->open();
     $this->catalogRuleIndex->getCatalogRuleGrid()->searchAndOpen($filter);
     $this->catalogRuleEdit->getFormPageActions()->delete();
 }
 /**
  * Assert that data in grid on Catalog Price Rules page according to fixture.
  *
  * @param CatalogRule $catalogPriceRule
  * @param CatalogRuleIndex $pageCatalogRuleIndex
  * @return void
  */
 public function processAssert(CatalogRule $catalogPriceRule, CatalogRuleIndex $pageCatalogRuleIndex)
 {
     $data = $catalogPriceRule->getData();
     $filter = ['name' => $data['name'], 'is_active' => $data['is_active']];
     //add ruleWebsite to filter if there is one
     if ($catalogPriceRule->hasData('website_ids')) {
         $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.');
 }
 /**
  * Assert that Catalog Price Rule is not presented in grid and cannot be found using ID, Rule name.
  *
  * @param CatalogRule $catalogPriceRule
  * @param CatalogRuleIndex $catalogRuleIndex
  * @return void
  */
 public function processAssert(CatalogRule $catalogPriceRule, CatalogRuleIndex $catalogRuleIndex)
 {
     $filter = ['rule_id' => $catalogPriceRule->getId(), 'name' => $catalogPriceRule->getName()];
     $catalogRuleIndex->open();
     \PHPUnit_Framework_Assert::assertFalse($catalogRuleIndex->getCatalogRuleGrid()->isRowVisible($filter), "Catalog Price Rule {$filter['rule_id']} with name {$filter['name']} is present in Catalog Price Rule grid.");
 }
 /**
  * Assert that success message is displayed after Catalog Price Rule saved.
  *
  * @param CatalogRuleIndex $pageCatalogRuleIndex
  * @return void
  */
 public function processAssert(CatalogRuleIndex $pageCatalogRuleIndex)
 {
     $actualMessages = $pageCatalogRuleIndex->getMessagesBlock()->getSuccessMessages();
     $actualMessages = is_array($actualMessages) ? $actualMessages : [$actualMessages];
     \PHPUnit_Framework_Assert::assertContains(self::SUCCESS_MESSAGE, $actualMessages);
 }
 /**
  * Delete sales rule, catalog rule, all tax rules and setup default tax configuration.
  *
  * @return void
  */
 public function tearDown()
 {
     if (isset($this->salesRule)) {
         $this->promoQuoteIndex->open();
         $this->promoQuoteIndex->getPromoQuoteGrid()->searchAndOpen(['name' => $this->salesRule->getName()]);
         $this->promoQuoteEdit->getFormPageActions()->delete();
         $this->salesRule = null;
     }
     if (isset($this->catalogRule)) {
         $this->catalogRuleIndex->open();
         $this->catalogRuleIndex->getCatalogRuleGrid()->searchAndOpen(['name' => $this->catalogRule->getName()]);
         $this->catalogRuleEdit->getFormPageActions()->delete();
         $this->catalogRule = null;
     }
     $this->objectManager->create('Mage\\Tax\\Test\\TestStep\\DeleteAllTaxRulesStep')->run();
     // TODO: Move set default configuration and create default tax rule to "tearDownAfterClass" method after fix bug MAGETWO-29331
     $this->objectManager->create('Mage\\Core\\Test\\TestStep\\SetupConfigurationStep', ['configData' => 'default_tax_configuration'])->run();
     $this->objectManager->create('\\Mage\\Tax\\Test\\TestStep\\CreateTaxRuleStep', ['taxRule' => 'default'])->run();
 }
 /**
  * Delete sales rule, catalog rule, all tax rules and setup default tax configuration.
  *
  * @return void
  */
 public function tearDown()
 {
     if (isset($this->salesRule)) {
         $this->promoQuoteIndex->open();
         $this->promoQuoteIndex->getPromoQuoteGrid()->searchAndOpen(['name' => $this->salesRule->getName()]);
         $this->promoQuoteEdit->getFormPageActions()->delete();
         $this->salesRule = null;
     }
     if (isset($this->catalogRule)) {
         $this->catalogRuleIndex->open();
         $this->catalogRuleIndex->getCatalogRuleGrid()->searchAndOpen(['name' => $this->catalogRule->getName()]);
         $this->catalogRuleEdit->getFormPageActions()->delete();
         $this->catalogRule = null;
     }
     $this->objectManager->create('Mage\\Tax\\Test\\TestStep\\DeleteAllTaxRulesStep')->run();
 }
 /**
  * Assert that message "There are rules that have been changed but were not applied..."
  * is present on page after Save (without applying Rule)
  * or after Edit (without applying Rule) action on the Catalog Price Rules page.
  *
  * @param CatalogRuleIndex $pageCatalogRuleIndex
  * @return void
  */
 public function processAssert(CatalogRuleIndex $pageCatalogRuleIndex)
 {
     \PHPUnit_Framework_Assert::assertEquals(self::NOTICE_MESSAGE_RULES . self::NOTICE_MESSAGE_APPLY, $pageCatalogRuleIndex->getMessagesBlock()->getNoticeMessages());
 }
 /**
  * Save and apply catalog rule on backend.
  *
  * @return void
  */
 public function run()
 {
     $this->catalogRuleIndex->open();
     $this->catalogRuleIndex->getCatalogRuleGrid()->searchAndOpen(['rule_id' => $this->catalogRuleId]);
     $this->catalogRuleEdit->getFormPageActions()->saveAndApply();
 }
 /**
  * Assert that success delete message is appeared on Catalog Price Rules page.
  *
  * @param CatalogRuleIndex $pageCatalogRuleIndex
  * @return void
  */
 public function processAssert(CatalogRuleIndex $pageCatalogRuleIndex)
 {
     \PHPUnit_Framework_Assert::assertEquals(self::SUCCESS_DELETE_MESSAGE, $pageCatalogRuleIndex->getMessagesBlock()->getSuccessMessages());
 }