public function testAfterGetProductAttributes() { $subject = $this->getMock('Magento\\Quote\\Model\\Quote\\Config', [], [], '', false); $attributeCode = 'code of the attribute'; $expected = [0 => $attributeCode]; $this->ruleResource->expects($this->once())->method('getActiveAttributes')->will($this->returnValue([['attribute_code' => $attributeCode, 'enabled' => true]])); $this->assertEquals($expected, $this->plugin->afterGetProductAttributes($subject, [])); }
/** * Append sales rule product attribute keys to select by quote item collection * * @param \Magento\Quote\Model\Quote\Config $subject * @param array $attributeKeys * * @return array * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function afterGetProductAttributes(\Magento\Quote\Model\Quote\Config $subject, array $attributeKeys) { $attributes = $this->_ruleResource->getActiveAttributes(); foreach ($attributes as $attribute) { $attributeKeys[] = $attribute['attribute_code']; } return $attributeKeys; }
/** * @param string $entityType * @param array $entityData * @param array $arguments * @return array * @throws \Exception */ public function execute($entityType, $entityData, $arguments = []) { $linkField = $this->metadataPool->getMetadata($entityType)->getLinkField(); $entityId = $entityData[$linkField]; $entityData['customer_group_ids'] = $this->ruleResource->getCustomerGroupIds($entityId); $entityData['website_ids'] = $this->ruleResource->getWebsiteIds($entityId); return $entityData; }
public function testLoadWebsiteIds() { $websiteIds = [1]; $object = $this->getMockBuilder('Magento\\Framework\\Model\\AbstractModel')->disableOriginalConstructor()->getMock(); $object->expects($this->once())->method('getId')->willReturn(1); $this->adapter->expects($this->once())->method('select')->willReturn($this->select); $this->select->expects($this->once())->method('from')->with('salesrule_website', ['website_id'])->willReturnSelf(); $this->select->expects($this->once())->method('where')->with('rule_id = ?', 1)->willReturnSelf(); $this->adapter->expects($this->once())->method('fetchCol')->with($this->select)->willReturn($websiteIds); $object->expects($this->once())->method('setData')->with('website_ids', $websiteIds); $this->model->loadWebsiteIds($object); }
public function testExecuteWithString() { $customers = '1,2'; $websites = '3,4,5'; $entityData = ['row_id' => 1, 'rule_id' => 1, 'website_ids' => $websites, 'customer_group_ids' => $customers]; $className = '\\Magento\\Framework\\EntityManager\\EntityMetadata'; $metadata = $this->getMock($className, [], [], '', false); $metadata->expects($this->once())->method('getLinkField')->willReturn('rule_id'); $this->metadataPool->expects($this->once())->method('getMetadata')->willReturn($metadata); $this->ruleResource->expects($this->any())->method('bindRuleToEntity')->withConsecutive([1, [3, 4, 5]], [1, [1, 2]]); $result = $this->model->execute(RuleInterface::class, $entityData); $this->assertEquals($entityData, $result); }
/** * test Execute */ public function testExecute() { $entityData = ['row_id' => 2, 'rule_id' => 1]; $customers = [1, 2]; $websites = [3, 4, 5]; $className = '\\Magento\\Framework\\Model\\Entity\\EntityMetadata'; $metadata = $this->getMock($className, [], [], '', false); $metadata->expects($this->once())->method('getLinkField')->willReturn('rule_id'); $this->metadataPool->expects($this->once())->method('getMetadata')->willReturn($metadata); $this->ruleResource->expects($this->once())->method('getCustomerGroupIds')->willReturn($customers); $this->ruleResource->expects($this->once())->method('getWebsiteIds')->willReturn($websites); $result = $this->model->execute(RuleInterface::class, $entityData); $expected = ['row_id' => 2, 'rule_id' => 1, 'customer_group_ids' => [1, 2], 'website_ids' => [3, 4, 5]]; $this->assertEquals($expected, $result); }
/** * @expectedException \Exception * @expectedExceptionMessage To test exception */ public function testDeletionRollbackOnFailure() { $expectedException = new \Exception(__('To test exception')); $this->transactionManagerMock->expects($this->once())->method('start'); $abstractModelMock = $this->getMockBuilder('Magento\\Rule\\Model\\AbstractModel')->disableOriginalConstructor()->setMethods([])->getMock(); $abstractModelMock->expects($this->once())->method('beforeDelete')->willThrowException($expectedException); $this->transactionManagerMock->expects($this->once())->method('rollBack'); $this->model->delete($abstractModelMock); }
/** * {@inheritdoc} */ public function loadWebsiteIds(\Magento\Framework\Model\AbstractModel $object) { $pluginInfo = $this->pluginList->getNext($this->subjectType, 'loadWebsiteIds'); if (!$pluginInfo) { return parent::loadWebsiteIds($object); } else { return $this->___callPlugins('loadWebsiteIds', func_get_args(), $pluginInfo); } }
/** * @param string $entityType * @param array $entityData * @return array * @throws \Exception */ public function execute($entityType, $entityData) { $linkField = $this->metadataPool->getMetadata($entityType)->getLinkField(); if (isset($entityData['website_ids'])) { $websiteIds = $entityData['website_ids']; if (!is_array($websiteIds)) { $websiteIds = explode(',', (string) $websiteIds); } $this->ruleResource->bindRuleToEntity($entityData[$linkField], $websiteIds, 'website'); } if (isset($entityData['customer_group_ids'])) { $customerGroupIds = $entityData['customer_group_ids']; if (!is_array($customerGroupIds)) { $customerGroupIds = explode(',', (string) $customerGroupIds); } $this->ruleResource->bindRuleToEntity($entityData[$linkField], $customerGroupIds, 'customer_group'); } return $entityData; }
/** * {@inheritdoc} */ public function getValidationRulesBeforeSave() { $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getValidationRulesBeforeSave'); if (!$pluginInfo) { return parent::getValidationRulesBeforeSave(); } else { return $this->___callPlugins('getValidationRulesBeforeSave', func_get_args(), $pluginInfo); } }
public function testDelete() { $this->entityManager->expects($this->once())->method('delete')->with($this->rule); $this->assertEquals($this->model->delete($this->rule), $this->model); }