Skip to content

Commit 6f18f6e

Browse files
author
Vitaliy Boyko
committed
Fixed unit tests
1 parent f7e1bf1 commit 6f18f6e

File tree

2 files changed

+51
-32
lines changed

2 files changed

+51
-32
lines changed

app/code/Magento/CatalogRule/Model/Rule.php

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ protected function _getWebsitesMap()
433433
}
434434

435435
/**
436-
* {@inheritdoc}
436+
* @inheritdoc
437437
*/
438438
public function validateData(DataObject $dataObject)
439439
{
@@ -582,7 +582,7 @@ protected function _invalidateCache()
582582
}
583583

584584
/**
585-
* {@inheritdoc}
585+
* @inheritdoc
586586
*
587587
* @return $this
588588
*/
@@ -610,14 +610,19 @@ public function afterSave()
610610
*/
611611
public function reindex()
612612
{
613-
$productIds = $this->_productIds ? array_keys(array_filter($this->_productIds, function (array $data) {
614-
return array_filter($data);
615-
})) : [];
613+
$productIds = $this->_productIds ? array_keys(
614+
array_filter(
615+
$this->_productIds,
616+
function (array $data) {
617+
return array_filter($data);
618+
}
619+
)
620+
) : [];
616621
$this->_ruleProductProcessor->reindexList($productIds);
617622
}
618623

619624
/**
620-
* {@inheritdoc}
625+
* @inheritdoc
621626
*
622627
* @return $this
623628
*/
@@ -668,6 +673,8 @@ protected function dataDiff($array1, $array2)
668673
}
669674

670675
/**
676+
* Getter for conditions field set ID
677+
*
671678
* @param string $formName
672679
* @return string
673680
*/
@@ -676,82 +683,80 @@ public function getConditionsFieldSetId($formName = '')
676683
return $formName . 'rule_conditions_fieldset_' . $this->getId();
677684
}
678685

679-
//@codeCoverageIgnoreStart
680-
681686
/**
682-
* {@inheritdoc}
687+
* @inheritdoc
683688
*/
684689
public function getRuleId()
685690
{
686691
return $this->getData(self::RULE_ID);
687692
}
688693

689694
/**
690-
* {@inheritdoc}
695+
* @inheritdoc
691696
*/
692697
public function setRuleId($ruleId)
693698
{
694699
return $this->setData(self::RULE_ID, $ruleId);
695700
}
696701

697702
/**
698-
* {@inheritdoc}
703+
* @inheritdoc
699704
*/
700705
public function getName()
701706
{
702707
return $this->getData(self::NAME);
703708
}
704709

705710
/**
706-
* {@inheritdoc}
711+
* @inheritdoc
707712
*/
708713
public function setName($name)
709714
{
710715
return $this->setData(self::NAME, $name);
711716
}
712717

713718
/**
714-
* {@inheritdoc}
719+
* @inheritdoc
715720
*/
716721
public function getDescription()
717722
{
718723
return $this->getData(self::DESCRIPTION);
719724
}
720725

721726
/**
722-
* {@inheritdoc}
727+
* @inheritdoc
723728
*/
724729
public function setDescription($description)
725730
{
726731
return $this->setData(self::DESCRIPTION, $description);
727732
}
728733

729734
/**
730-
* {@inheritdoc}
735+
* @inheritdoc
731736
*/
732737
public function getIsActive()
733738
{
734739
return $this->getData(self::IS_ACTIVE);
735740
}
736741

737742
/**
738-
* {@inheritdoc}
743+
* @inheritdoc
739744
*/
740745
public function setIsActive($isActive)
741746
{
742747
return $this->setData(self::IS_ACTIVE, $isActive);
743748
}
744749

745750
/**
746-
* {@inheritdoc}
751+
* @inheritdoc
747752
*/
748753
public function getRuleCondition()
749754
{
750755
return $this->getRuleConditionConverter()->arrayToDataModel($this->getConditions()->asArray());
751756
}
752757

753758
/**
754-
* {@inheritdoc}
759+
* @inheritdoc
755760
*/
756761
public function setRuleCondition($condition)
757762
{
@@ -762,63 +767,63 @@ public function setRuleCondition($condition)
762767
}
763768

764769
/**
765-
* {@inheritdoc}
770+
* @inheritdoc
766771
*/
767772
public function getStopRulesProcessing()
768773
{
769774
return $this->getData(self::STOP_RULES_PROCESSING);
770775
}
771776

772777
/**
773-
* {@inheritdoc}
778+
* @inheritdoc
774779
*/
775780
public function setStopRulesProcessing($isStopProcessing)
776781
{
777782
return $this->setData(self::STOP_RULES_PROCESSING, $isStopProcessing);
778783
}
779784

780785
/**
781-
* {@inheritdoc}
786+
* @inheritdoc
782787
*/
783788
public function getSortOrder()
784789
{
785790
return $this->getData(self::SORT_ORDER);
786791
}
787792

788793
/**
789-
* {@inheritdoc}
794+
* @inheritdoc
790795
*/
791796
public function setSortOrder($sortOrder)
792797
{
793798
return $this->setData(self::SORT_ORDER, $sortOrder);
794799
}
795800

796801
/**
797-
* {@inheritdoc}
802+
* @inheritdoc
798803
*/
799804
public function getSimpleAction()
800805
{
801806
return $this->getData(self::SIMPLE_ACTION);
802807
}
803808

804809
/**
805-
* {@inheritdoc}
810+
* @inheritdoc
806811
*/
807812
public function setSimpleAction($action)
808813
{
809814
return $this->setData(self::SIMPLE_ACTION, $action);
810815
}
811816

812817
/**
813-
* {@inheritdoc}
818+
* @inheritdoc
814819
*/
815820
public function getDiscountAmount()
816821
{
817822
return $this->getData(self::DISCOUNT_AMOUNT);
818823
}
819824

820825
/**
821-
* {@inheritdoc}
826+
* @inheritdoc
822827
*/
823828
public function setDiscountAmount($amount)
824829
{
@@ -842,7 +847,7 @@ public function getToDate()
842847
}
843848

844849
/**
845-
* {@inheritdoc}
850+
* @inheritdoc
846851
*
847852
* @return \Magento\CatalogRule\Api\Data\RuleExtensionInterface|null
848853
*/
@@ -852,7 +857,7 @@ public function getExtensionAttributes()
852857
}
853858

854859
/**
855-
* {@inheritdoc}
860+
* @inheritdoc
856861
*
857862
* @param \Magento\CatalogRule\Api\Data\RuleExtensionInterface $extensionAttributes
858863
* @return $this
@@ -863,6 +868,8 @@ public function setExtensionAttributes(RuleExtensionInterface $extensionAttribut
863868
}
864869

865870
/**
871+
* Getter for the rule condition converter
872+
*
866873
* @return Data\Condition\Converter
867874
* @deprecated 100.1.0
868875
*/
@@ -875,8 +882,6 @@ private function getRuleConditionConverter()
875882
return $this->ruleConditionConverter;
876883
}
877884

878-
//@codeCoverageIgnoreEnd
879-
880885
/**
881886
* @inheritDoc
882887
*/

app/code/Magento/CatalogRule/Test/Unit/Model/RuleTest.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,13 +311,27 @@ public function testAfterDelete()
311311
}
312312

313313
/**
314-
* Test after update action
314+
* Test after update action for inactive rule
315315
*
316316
* @return void
317317
*/
318-
public function testAfterUpdate()
318+
public function testAfterUpdateInactive()
319319
{
320320
$this->rule->isObjectNew(false);
321+
$this->rule->setIsActive(0);
322+
$this->_ruleProductProcessor->expects($this->never())->method('getIndexer');
323+
$this->rule->afterSave();
324+
}
325+
326+
/**
327+
* Test after update action for active rule
328+
*
329+
* @return void
330+
*/
331+
public function testAfterUpdateActive()
332+
{
333+
$this->rule->isObjectNew(false);
334+
$this->rule->setIsActive(1);
321335
$indexer = $this->createMock(\Magento\Framework\Indexer\IndexerInterface::class);
322336
$indexer->expects($this->once())->method('invalidate');
323337
$this->_ruleProductProcessor->expects($this->once())->method('getIndexer')->will($this->returnValue($indexer));

0 commit comments

Comments
 (0)